#include "third_party/blink/renderer/core/frame/attribution_src_loader.h"
#include <stddef.h>
#include <stdint.h>
#include <memory>
#include <optional>
#include <string>
#include <utility>
#include "base/functional/callback_helpers.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "base/uuid.h"
#include "build/build_config.h"
#include "build/buildflag.h"
#include "components/attribution_reporting/data_host.mojom-blink.h"
#include "components/attribution_reporting/os_registration.h"
#include "components/attribution_reporting/os_registration_error.mojom-shared.h"
#include "components/attribution_reporting/registration_eligibility.mojom-shared.h"
#include "components/attribution_reporting/registration_header_error.h"
#include "components/attribution_reporting/source_registration.h"
#include "components/attribution_reporting/source_registration_error.mojom-shared.h"
#include "components/attribution_reporting/suitable_origin.h"
#include "components/attribution_reporting/test_utils.h"
#include "components/attribution_reporting/trigger_registration.h"
#include "components/attribution_reporting/trigger_registration_error.mojom-shared.h"
#include "mojo/public/cpp/bindings/associated_receiver.h"
#include "services/network/public/cpp/features.h"
#include "services/network/public/mojom/attribution.mojom-blink.h"
#include "services/network/public/mojom/referrer_policy.mojom-blink.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/mojom/conversions/conversions.mojom-blink.h"
#include "third_party/blink/public/mojom/fetch/fetch_api_request.mojom-blink.h"
#include "third_party/blink/public/platform/web_runtime_features.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/execution_context/security_context.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/html/html_anchor_element.h"
#include "third_party/blink/renderer/core/loader/empty_clients.h"
#include "third_party/blink/renderer/core/page/page.h"
#include "third_party/blink/renderer/core/testing/fake_local_frame_host.h"
#include "third_party/blink/renderer/core/testing/page_test_base.h"
#include "third_party/blink/renderer/platform/exported/wrapped_resource_response.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"
#include "third_party/blink/renderer/platform/heap/persistent.h"
#include "third_party/blink/renderer/platform/loader/fetch/resource_request.h"
#include "third_party/blink/renderer/platform/loader/fetch/url_loader/url_loader_factory.h"
#include "third_party/blink/renderer/platform/testing/unit_test_helpers.h"
#include "third_party/blink/renderer/platform/testing/url_loader_mock_factory.h"
#include "third_party/blink/renderer/platform/testing/url_test_helpers.h"
#include "third_party/blink/renderer/platform/weborigin/kurl.h"
#include "third_party/blink/renderer/platform/weborigin/referrer.h"
#include "third_party/blink/renderer/platform/weborigin/security_origin.h"
#include "third_party/blink/renderer/platform/wtf/text/atomic_string.h"
#include "third_party/blink/renderer/platform/wtf/vector.h"
namespace blink {
namespace {
AttributionReportingEligibility;
AttributionSupport;
RegisterMockedErrorURLLoad;
RegisterMockedURLLoad;
ToKURL;
const char kAttributionReportingSupport[] = …;
const char kAttributionSrcRequestStatusMetric[] = …;
const char kUrl[] = …;
ResourceRequest GetAttributionRequest(
const KURL& url,
AttributionSupport support = AttributionSupport::kWeb) { … }
class AttributionSrcLocalFrameClient : public EmptyLocalFrameClient { … };
class MockDataHost : public attribution_reporting::mojom::blink::DataHost { … };
class MockAttributionHost : public mojom::blink::AttributionHost { … };
class AttributionSrcLoaderTest : public PageTestBase { … };
TEST_F(AttributionSrcLoaderTest, RegisterTrigger) { … }
TEST_F(AttributionSrcLoaderTest, AttributionSrcRequestsIgnored) { … }
TEST_F(AttributionSrcLoaderTest, AttributionSrcRequestsInvalidEligibleHeaders) { … }
TEST_F(AttributionSrcLoaderTest, AttributionSrcRequest_HistogramsRecorded) { … }
TEST_F(AttributionSrcLoaderTest, Referrer) { … }
TEST_F(AttributionSrcLoaderTest, NoReferrer) { … }
TEST_F(AttributionSrcLoaderTest, EligibleHeader_Register) { … }
TEST_F(AttributionSrcLoaderTest, EligibleHeader_RegisterNavigation) { … }
TEST_F(AttributionSrcLoaderTest, EagerlyClosesRemote) { … }
TEST_F(AttributionSrcLoaderTest, NoneSupport_NoAttributionSrcRequest) { … }
TEST_F(AttributionSrcLoaderTest, WebDisabled_TriggerNotRegistered) { … }
TEST_F(AttributionSrcLoaderTest, HeadersSize_RecordsMetrics) { … }
class AttributionSrcLoaderCrossAppWebRuntimeDisabledTest
: public AttributionSrcLoaderTest { … };
TEST_F(AttributionSrcLoaderCrossAppWebRuntimeDisabledTest,
OsTriggerNotRegistered) { … }
class AttributionSrcLoaderCrossAppWebEnabledTest
: public AttributionSrcLoaderTest { … };
TEST_F(AttributionSrcLoaderCrossAppWebEnabledTest, SupportHeader_Register) { … }
TEST_F(AttributionSrcLoaderCrossAppWebEnabledTest,
SupportHeader_RegisterNavigation) { … }
TEST_F(AttributionSrcLoaderCrossAppWebEnabledTest, RegisterOsTrigger) { … }
TEST_F(AttributionSrcLoaderCrossAppWebEnabledTest,
HeadersSize_OsMetricsRecorded) { … }
class AttributionSrcLoaderInBrowserMigrationEnabledTest
: public AttributionSrcLoaderTest { … };
TEST_F(AttributionSrcLoaderInBrowserMigrationEnabledTest,
MaybeRegisterAttributionHeaders_KeepAliveRequestsResponseIgnored) { … }
TEST_F(
AttributionSrcLoaderInBrowserMigrationEnabledTest,
MaybeRegisterAttributionHeadersNonKeepAlive_ResponseViaServiceWorkerProcessed) { … }
struct PreferredPlatformTestCase { … };
const PreferredPlatformTestCase kPreferredPlatformTestCases[] = …;
class AttributionSrcLoaderPreferredPlatformEnabledTest
: public AttributionSrcLoaderCrossAppWebEnabledTest,
public ::testing::WithParamInterface<PreferredPlatformTestCase> { … };
class AttributionSrcLoaderPreferredPlatformSourceTest
: public AttributionSrcLoaderPreferredPlatformEnabledTest { … };
INSTANTIATE_TEST_SUITE_P(…);
TEST_P(AttributionSrcLoaderPreferredPlatformSourceTest, PreferredPlatform) { … }
class AttributionSrcLoaderPreferredPlatformTriggerTest
: public AttributionSrcLoaderPreferredPlatformEnabledTest { … };
INSTANTIATE_TEST_SUITE_P(…);
TEST_P(AttributionSrcLoaderPreferredPlatformTriggerTest, PreferredPlatform) { … }
TEST_F(AttributionSrcLoaderTest, InvalidWebHeader_ErrorReported) { … }
TEST_F(AttributionSrcLoaderTest,
HasAttributionHeaderInAttributionSrcResponseMetric) { … }
TEST_F(AttributionSrcLoaderCrossAppWebEnabledTest,
InvalidOsHeader_ErrorReported) { … }
}
}