#include "content/browser/attribution_reporting/attribution_data_host_manager_impl.h"
#include <stddef.h>
#include <stdint.h>
#include <memory>
#include <optional>
#include <string>
#include <string_view>
#include <utility>
#include <vector>
#include "base/atomic_sequence_num.h"
#include "base/barrier_closure.h"
#include "base/check_op.h"
#include "base/containers/flat_map.h"
#include "base/memory/raw_ref.h"
#include "base/memory/scoped_refptr.h"
#include "base/metrics/histogram_base.h"
#include "base/run_loop.h"
#include "base/strings/strcat.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "base/time/time.h"
#include "components/attribution_reporting/aggregatable_dedup_key.h"
#include "components/attribution_reporting/aggregatable_trigger_data.h"
#include "components/attribution_reporting/aggregatable_values.h"
#include "components/attribution_reporting/aggregation_keys.h"
#include "components/attribution_reporting/attribution_scopes_data.h"
#include "components/attribution_reporting/attribution_scopes_set.h"
#include "components/attribution_reporting/constants.h"
#include "components/attribution_reporting/data_host.mojom.h"
#include "components/attribution_reporting/destination_set.h"
#include "components/attribution_reporting/event_report_windows.h"
#include "components/attribution_reporting/event_trigger_data.h"
#include "components/attribution_reporting/features.h"
#include "components/attribution_reporting/filters.h"
#include "components/attribution_reporting/max_event_level_reports.h"
#include "components/attribution_reporting/os_registration.h"
#include "components/attribution_reporting/os_registration_error.mojom-shared.h"
#include "components/attribution_reporting/registrar.h"
#include "components/attribution_reporting/registration_eligibility.mojom.h"
#include "components/attribution_reporting/registration_header_error.h"
#include "components/attribution_reporting/registration_info.h"
#include "components/attribution_reporting/source_registration.h"
#include "components/attribution_reporting/source_registration_error.mojom.h"
#include "components/attribution_reporting/source_registration_time_config.mojom.h"
#include "components/attribution_reporting/source_type.mojom.h"
#include "components/attribution_reporting/suitable_origin.h"
#include "components/attribution_reporting/trigger_config.h"
#include "components/attribution_reporting/trigger_registration_error.mojom-shared.h"
#include "content/browser/attribution_reporting/attribution_background_registrations_id.h"
#include "content/browser/attribution_reporting/attribution_beacon_id.h"
#include "content/browser/attribution_reporting/attribution_constants.h"
#include "content/browser/attribution_reporting/attribution_data_host_manager.h"
#include "content/browser/attribution_reporting/attribution_input_event.h"
#include "content/browser/attribution_reporting/attribution_os_level_manager.h"
#include "content/browser/attribution_reporting/attribution_suitable_context.h"
#include "content/browser/attribution_reporting/attribution_test_utils.h"
#include "content/browser/attribution_reporting/attribution_trigger.h"
#include "content/browser/attribution_reporting/os_registration.h"
#include "content/browser/attribution_reporting/test/mock_attribution_manager.h"
#include "content/browser/attribution_reporting/test/mock_content_browser_client.h"
#include "content/public/browser/content_browser_client.h"
#include "content/public/browser/global_routing_id.h"
#include "content/public/test/browser_task_environment.h"
#include "content/public/test/test_utils.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "mojo/public/cpp/test_support/test_utils.h"
#include "net/base/schemeful_site.h"
#include "net/http/http_response_headers.h"
#include "services/data_decoder/public/cpp/test_support/in_process_data_decoder.h"
#include "services/network/public/cpp/features.h"
#include "services/network/public/mojom/attribution.mojom-shared.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/abseil-cpp/absl/numeric/int128.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/common/tokens/tokens.h"
#include "url/gurl.h"
#include "url/origin.h"
namespace content {
namespace {
DestinationSet;
FilterPair;
OsRegistrationItem;
OsSourceRegistrationError;
OsTriggerRegistrationError;
RegistrationInfoError;
SourceRegistration;
SuitableOrigin;
TriggerRegistration;
OsRegistrationError;
RegistrationEligibility;
SourceRegistrationError;
SourceType;
TriggerRegistrationError;
AttributionSupport;
AttributionFilters;
FilterConfig;
_;
AllOf;
Field;
InSequence;
Mock;
Property;
Return;
SizeIs;
Checkpoint;
constexpr char kRegisterSourceJson[] = …;
constexpr char kRegisterTriggerJson[] = …;
constexpr char kNavigationDataHostStatusHistogram[] = …;
constexpr char kRegisterDataHostOutcomeHistogram[] = …;
constexpr char kProcessRegisterDataHostDelayHistogram[] = …;
constexpr char kNavigationUnexpectedRegistrationHistogram[] = …;
constexpr char kBackgroundNavigationOutcome[] = …;
constexpr char kRegistrationMethod[] = …;
kAttributionReportingRegisterOsSourceHeader;
kAttributionReportingRegisterOsTriggerHeader;
kAttributionReportingRegisterSourceHeader;
kAttributionReportingRegisterTriggerHeader;
const GlobalRenderFrameHostId kFrameId = …;
constexpr attribution_reporting::Registrar kRegistrar = …;
constexpr BeaconId kBeaconId(123);
constexpr int64_t kNavigationId(456);
constexpr int64_t kLastNavigationId(1234);
constexpr char kDevtoolsRequestId[] = …;
constexpr BackgroundRegistrationsId kBackgroundId(789);
constexpr bool kViaServiceWorker = …;
constexpr bool kIsForBackgroundRequests = …;
constexpr size_t kExpectedRegistrations = …;
class AttributionDataHostManagerImplTest : public testing::Test { … };
MATCHER_P(SourceIsWithinFencedFrameIs, matcher, "") { … }
TEST_F(AttributionDataHostManagerImplTest, SourceDataHost_SourceRegistered) { … }
TEST_F(AttributionDataHostManagerImplTest,
SourceDataHost_ReceiverDestinationsMayDiffer) { … }
TEST_F(AttributionDataHostManagerImplTest, TriggerDataHost_TriggerRegistered) { … }
TEST_F(AttributionDataHostManagerImplTest,
TriggerDataHost_ReceiverModeCheckPerformed) { … }
TEST_F(AttributionDataHostManagerImplTest,
MixedDataHost_AllowsSourcesAndTriggers) { … }
TEST_F(AttributionDataHostManagerImplTest,
SourceDataHost_ReceiverModeCheckPerformed) { … }
TEST_F(AttributionDataHostManagerImplTest,
SourceDataHost_InvalidForSourceType) { … }
TEST_F(AttributionDataHostManagerImplTest,
SourceDataHost_NavigationSourceRegistered) { … }
TEST_F(AttributionDataHostManagerImplTest,
UnexpectedNavigationRegistrationsPatterns) { … }
TEST_F(AttributionDataHostManagerImplTest,
SourceDataHostDisconnectedBeforeBinding_NavigationSourceRegistered) { … }
TEST_F(AttributionDataHostManagerImplTest,
SourceDataHostRegistration_RegistrationsPerNavigationRecorded) { … }
TEST_F(AttributionDataHostManagerImplTest,
SourceDataHostRegistration_LimitNavigationOnUniqueAttributionScopeSet) { … }
TEST_F(AttributionDataHostManagerImplTest, NoSourceOrTrigger) { … }
TEST_F(AttributionDataHostManagerImplTest,
SourceModeReceiverConnected_TriggerNotDelayed) { … }
TEST_F(AttributionDataHostManagerImplTest,
TriggerModeReceiverConnected_TriggerNotDelayed) { … }
TEST_F(AttributionDataHostManagerImplTest,
NavigationSourceReceiverConnected_TriggerDelayed) { … }
TEST_F(AttributionDataHostManagerImplTest,
NavigationSourceReceiverConnected_TriggerDroppedDueToLimitReached) { … }
TEST_F(AttributionDataHostManagerImplTest,
NavigationSourceReceiverConnectedAndRedirect_TriggerDelayed) { … }
TEST_F(AttributionDataHostManagerImplTest,
NavigationSourceReceiverConnected_TriggerDelayedUntilTimeout) { … }
TEST_F(AttributionDataHostManagerImplTest,
NavigationSourceReceiverConnected_MultipleTriggersDelayedUntilTimeout) { … }
TEST_F(AttributionDataHostManagerImplTest,
NavigationSourceReceiverConnected_TriggerNotDelayed) { … }
TEST_F(AttributionDataHostManagerImplTest,
NavigationRedirectSource_SourceRegisteredBeforeNav) { … }
TEST_F(AttributionDataHostManagerImplTest,
ClientOsAttributionDisabled_OsSourceNotRegistered) { … }
TEST_F(AttributionDataHostManagerImplTest, NavigationRedirectOsSource) { … }
TEST_F(AttributionDataHostManagerImplTest,
NavigationRedirectOsSource_InvalidOsHeader) { … }
TEST_F(AttributionDataHostManagerImplTest,
NavigationRedirectOsSource_WebAndOsHeaders) { … }
TEST_F(AttributionDataHostManagerImplTest,
DataHost_NavigationTiedOsRegistrationsAreBuffered) { … }
TEST_F(AttributionDataHostManagerImplTest,
FencedFrame_NavigationTiedOsRegistrationsAreBuffered) { … }
TEST_F(
AttributionDataHostManagerImplTest,
NavigationTiedOsRegistrationsAreBuffered_AfterTimeoutRegistrationsAreSentDirectlyToTheOS) { … }
TEST_F(AttributionDataHostManagerImplTest,
NavigationRedirectSource_NavigationFinishesBeforeParsing) { … }
TEST_F(AttributionDataHostManagerImplTest, NavigationRedirectSource_InOrder) { … }
TEST_F(AttributionDataHostManagerImplTest,
NavigationRedirectSource_ParsingFinishesBeforeAndAfterNav) { … }
TEST_F(AttributionDataHostManagerImplTest,
NavigationRedirectSource_ParsingFailsBeforeAndSucceedsAfterNav) { … }
TEST_F(AttributionDataHostManagerImplTest,
NavigationRedirectSource_TriggerDelayed) { … }
TEST_F(AttributionDataHostManagerImplTest,
NavigationRedirectSource_NavigationFinishedQueueSkipped) { … }
TEST_F(AttributionDataHostManagerImplTest, TwoTriggerReceivers) { … }
TEST_F(AttributionDataHostManagerImplTest,
NavigationSourceReceiverConnectsFails_TriggerNotDelayed) { … }
TEST_F(AttributionDataHostManagerImplTest,
SourceModeReceiverConnected_DelayedTriggersHandledInOrder) { … }
TEST_F(AttributionDataHostManagerImplTest,
SourceModeReceiverConnectsDisconnects_DelayedTriggersFlushed) { … }
TEST_F(AttributionDataHostManagerImplTest, NavigationDataHostNotRegistered) { … }
TEST_F(AttributionDataHostManagerImplTest,
NavigationDataHost_CannotRegisterTrigger) { … }
TEST_F(AttributionDataHostManagerImplTest,
DuplicateAttributionSrcToken_NotRegistered) { … }
TEST_F(AttributionDataHostManagerImplTest,
SourceDataHostWithinFencedFrame_SourceRegistered) { … }
TEST_F(AttributionDataHostManagerImplTest,
TriggerDataHostWithinFencedFrame_TriggerRegistered) { … }
TEST_F(AttributionDataHostManagerImplTest,
NavigationSourceWithinFencedFrame_SourceRegistered) { … }
TEST_F(AttributionDataHostManagerImplTest,
NavigationRedirectSourceWithinFencedFrame_SourceRegistered) { … }
TEST_F(AttributionDataHostManagerImplTest, NavigationBeaconSource_Registered) { … }
TEST_F(AttributionDataHostManagerImplTest,
NavigationBeaconOsSource_Registered) { … }
TEST_F(AttributionDataHostManagerImplTest,
NavigationBeaconSource_ParsingFailed) { … }
TEST_F(AttributionDataHostManagerImplTest,
NavigationBeaconSource_UntrustworthyReportingOrigin) { … }
TEST_F(AttributionDataHostManagerImplTest,
NavigationBeaconSource_TriggerDelayed) { … }
TEST_F(AttributionDataHostManagerImplTest,
MultipleNavigationBeaconSource_TriggerDelayed) { … }
TEST_F(AttributionDataHostManagerImplTest,
AllChannelsRegistrattions_TriggerDelayed) { … }
TEST_F(AttributionDataHostManagerImplTest,
MultipleNavigationBeaconSource_TriggerDelayedUntilTimeout) { … }
TEST_F(AttributionDataHostManagerImplTest,
NavigationBeaconSource_NavigationBeaconFinishedQueueSkipped) { … }
TEST_F(AttributionDataHostManagerImplTest,
NavigationBeaconSource_NavigationBeaconFailedQueueSkipped) { … }
TEST_F(AttributionDataHostManagerImplTest, EventBeaconSource_DataReceived) { … }
TEST_F(AttributionDataHostManagerImplTest, OsSourceAvailable) { … }
TEST_F(AttributionDataHostManagerImplTest, OsTriggerAvailable) { … }
TEST_F(AttributionDataHostManagerImplTest, WebDisabled_SourceNotRegistered) { … }
TEST_F(AttributionDataHostManagerImplTest, HeadersSize_SourceMetricsRecorded) { … }
class AttributionDataHostManagerImplWithInBrowserMigrationTest
: public AttributionDataHostManagerImplTest { … };
class AttributionDataHostManagerImplWithInBrowserMigrationAndAppToWebTest
: public AttributionDataHostManagerImplWithInBrowserMigrationTest { … };
TEST_F(AttributionDataHostManagerImplWithInBrowserMigrationAndAppToWebTest,
Background_NavigationTiedOsRegistrationsAreBuffered) { … }
TEST_F(AttributionDataHostManagerImplWithInBrowserMigrationAndAppToWebTest,
BufferedNavigationTiedOsRegistrations_FlushedUponReachingLimit) { … }
TEST_F(AttributionDataHostManagerImplWithInBrowserMigrationAndAppToWebTest,
HeadersSize_TriggerMetricsRecorded) { … }
TEST_F(
AttributionDataHostManagerImplWithInBrowserMigrationTest,
Background_NavigationTiedOnOngoingNavigation_TriggerDeferredUntilBackgroundSourceRegistrationCompletes) { … }
TEST_F(
AttributionDataHostManagerImplWithInBrowserMigrationAndAppToWebTest,
Background_NavigationTiedOnCompletedNavigation_TriggerDeferredUntilBackgroundSourceRegistrationCompletes) { … }
TEST_F(AttributionDataHostManagerImplWithInBrowserMigrationTest,
Background_NavigationTiedToCompletedNavigation) { … }
TEST_F(AttributionDataHostManagerImplWithInBrowserMigrationTest,
Background_NavigationTiedToCompletedIneligibleNavigation) { … }
TEST_F(
AttributionDataHostManagerImplWithInBrowserMigrationTest,
BackgroundNavigationTied_FewerThanExpectedBackgroundRegistrationsReceivedInTime) { … }
TEST_F(AttributionDataHostManagerImplWithInBrowserMigrationTest,
Background_MultipleRegistrationTiedToCompletedNavigation) { … }
TEST_F(AttributionDataHostManagerImplWithInBrowserMigrationTest,
Background_NavigationTiedWithDelay) { … }
TEST_F(AttributionDataHostManagerImplWithInBrowserMigrationAndAppToWebTest,
Background_NavigationTiedWithDelay_OsAndWebHeaders) { … }
TEST_F(AttributionDataHostManagerImplWithInBrowserMigrationAndAppToWebTest,
BackgroundOsSource) { … }
TEST_F(AttributionDataHostManagerImplWithInBrowserMigrationAndAppToWebTest,
BackgroundOsSource_OsAttributionClientDisabled) { … }
TEST_F(AttributionDataHostManagerImplWithInBrowserMigrationTest,
Background_NonNavigationTied) { … }
TEST_F(AttributionDataHostManagerImplWithInBrowserMigrationTest,
BackgroundTrigger) { … }
TEST_F(AttributionDataHostManagerImplWithInBrowserMigrationTest,
Background_NonSuitableReportingUrl) { … }
TEST_F(AttributionDataHostManagerImplWithInBrowserMigrationAndAppToWebTest,
BackgroundOsTrigger) { … }
TEST_F(AttributionDataHostManagerImplWithInBrowserMigrationAndAppToWebTest,
BackgroundOsTrigger_OsAttributionClientDisabled) { … }
TEST_F(AttributionDataHostManagerImplWithInBrowserMigrationTest,
BackgroundTrigger_ParsingFails) { … }
TEST_F(AttributionDataHostManagerImplWithInBrowserMigrationAndAppToWebTest,
Background_InvalidHeaders) { … }
struct PreferredPlatformTestCase { … };
const PreferredPlatformTestCase kPreferredPlatformTestCases[] = …;
class AttributionDataHostManagerImplPreferredPlatformEnabledTest
: public AttributionDataHostManagerImplTest,
public ::testing::WithParamInterface<PreferredPlatformTestCase> { … };
INSTANTIATE_TEST_SUITE_P(…);
TEST_P(AttributionDataHostManagerImplPreferredPlatformEnabledTest,
NavigationRegistration) { … }
TEST_P(AttributionDataHostManagerImplPreferredPlatformEnabledTest,
BeaconRegistration) { … }
class
AttributionDataHostManagerImplWithInBrowserMigrationAndPreferredPlatformTest
: public AttributionDataHostManagerImplWithInBrowserMigrationAndAppToWebTest,
public ::testing::WithParamInterface<PreferredPlatformTestCase> { … };
INSTANTIATE_TEST_SUITE_P(…);
TEST_P(
AttributionDataHostManagerImplWithInBrowserMigrationAndPreferredPlatformTest,
BackgroundSource) { … }
TEST_P(
AttributionDataHostManagerImplWithInBrowserMigrationAndPreferredPlatformTest,
BackgroundTrigger) { … }
TEST_F(AttributionDataHostManagerImplTest,
DataHost_ReportRegistrationHeaderError) { … }
TEST_F(AttributionDataHostManagerImplTest,
NavigationRegistration_ReportRegistrationHeaderError) { … }
TEST_F(AttributionDataHostManagerImplTest,
NavigationRegistrationOsSource_ReportRegistrationHeaderError) { … }
TEST_F(AttributionDataHostManagerImplTest,
DataHostRegistration_RegistrarSupportChecked) { … }
TEST_F(AttributionDataHostManagerImplWithInBrowserMigrationTest,
BackgroundTrigger_ReportRegistrationHeaderError) { … }
TEST_F(AttributionDataHostManagerImplWithInBrowserMigrationAndAppToWebTest,
BackgroundOsTrigger_ReportRegistrationHeaderError) { … }
TEST_F(AttributionDataHostManagerImplTest, RegistrationInfoErrorMetric) { … }
}
}