#include <string>
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/metrics/histogram_tester.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/subresource_filter/subresource_filter_browser_test_harness.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/content_settings/core/common/content_settings.h"
#include "components/content_settings/core/common/content_settings_types.h"
#include "components/embedder_support/switches.h"
#include "components/metrics/content/subprocess_metrics_provider.h"
#include "components/page_load_metrics/browser/observers/ad_metrics/ads_page_load_metrics_observer.h"
#include "components/page_load_metrics/browser/observers/ad_metrics/frame_tree_data.h"
#include "components/page_load_metrics/browser/page_load_metrics_test_waiter.h"
#include "components/subresource_filter/content/browser/ad_tagging_browser_test_utils.h"
#include "components/subresource_filter/content/browser/subresource_filter_observer_test_utils.h"
#include "components/subresource_filter/core/common/test_ruleset_utils.h"
#include "components/ukm/test_ukm_recorder.h"
#include "content/public/browser/render_widget_host_view.h"
#include "content/public/test/back_forward_cache_util.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/hit_test_region_observer.h"
#include "content/public/test/test_frame_navigation_observer.h"
#include "content/public/test/test_navigation_observer.h"
#include "services/metrics/public/cpp/ukm_builders.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/frame/from_ad_state.h"
#include "url/gurl.h"
namespace subresource_filter {
namespace {
RenderFrameHost;
CreateAllowlistSuffixRule;
CreateSuffixRule;
void AddExternalStylesheet(const content::ToRenderFrameHost& adapter,
const GURL& url) { … }
class AdTaggingPageLoadMetricsTestWaiter
: public page_load_metrics::PageLoadMetricsTestWaiter { … };
class AdTaggingBrowserTest : public SubresourceFilterBrowserTest { … };
content::RenderFrameHost* AdTaggingBrowserTest::CreateDocWrittenFrameImpl(
const content::ToRenderFrameHost& adapter,
bool ad_script) { … }
content::RenderFrameHost*
AdTaggingBrowserTest::CreateFrameWithDocWriteAbortedLoadImpl(
const content::ToRenderFrameHost& adapter,
bool ad_script) { … }
content::RenderFrameHost*
AdTaggingBrowserTest::CreateFrameWithWindowStopAbortedLoadImpl(
const content::ToRenderFrameHost& adapter,
bool ad_script) { … }
void AdTaggingBrowserTest::NavigateFrame(
content::RenderFrameHost* render_frame_host,
const GURL& url) { … }
IN_PROC_BROWSER_TEST_F(AdTaggingBrowserTest,
AdContentSettingAllowed_AdTaggingDisabled) { … }
IN_PROC_BROWSER_TEST_F(AdTaggingBrowserTest,
AdContentSettingBlocked_AdTaggingEnabled) { … }
IN_PROC_BROWSER_TEST_F(AdTaggingBrowserTest, FramesByURL) { … }
const char kSubresourceFilterOriginStatusHistogram[] = …;
IN_PROC_BROWSER_TEST_F(AdTaggingBrowserTest, VerifySameOriginWithoutNavigate) { … }
IN_PROC_BROWSER_TEST_F(AdTaggingBrowserTest, VerifyCrossOriginWithoutNavigate) { … }
IN_PROC_BROWSER_TEST_F(AdTaggingBrowserTest,
VerifyCrossOriginWithImmediateNavigate) { … }
IN_PROC_BROWSER_TEST_F(AdTaggingBrowserTest,
VerifySameOriginWithCrossOriginRenavigate) { … }
IN_PROC_BROWSER_TEST_F(AdTaggingBrowserTest, FrameLoadedByAdScript) { … }
IN_PROC_BROWSER_TEST_F(AdTaggingBrowserTest, SameOriginFrameTagging) { … }
IN_PROC_BROWSER_TEST_F(AdTaggingBrowserTest,
ChildrenOfSameOriginFrames_CorrectlyTagged) { … }
IN_PROC_BROWSER_TEST_F(AdTaggingBrowserTest,
FramesWithDocWriteAbortedLoad_StillCorrectlyTagged) { … }
IN_PROC_BROWSER_TEST_F(AdTaggingBrowserTest,
FramesWithWindowStopAbortedLoad_StillCorrectlyTagged) { … }
IN_PROC_BROWSER_TEST_F(
AdTaggingBrowserTest,
ChildrenOfFrameWithDocWriteAbortedLoad_StillCorrectlyTagged) { … }
IN_PROC_BROWSER_TEST_F(
AdTaggingBrowserTest,
ChildrenOfFrameWithWindowStopAbortedLoad_StillCorrectlyTagged) { … }
IN_PROC_BROWSER_TEST_F(
AdTaggingBrowserTest,
NavigationToLessRestrictiveUrl_MostRestrictiveLoadPolicyUnchanged) { … }
IN_PROC_BROWSER_TEST_F(AdTaggingBrowserTest,
VanillaExternalStylesheet_ResourcesNotTagged) { … }
IN_PROC_BROWSER_TEST_F(AdTaggingBrowserTest,
AdExternalStylesheet_ResourcesTagged) { … }
IN_PROC_BROWSER_TEST_F(
AdTaggingBrowserTest,
SameDocumentHistoryNavigationAbortedByParentHistoryNavigation) { … }
class AdClickMetricsBrowserTest : public AdTaggingBrowserTest { … };
IN_PROC_BROWSER_TEST_F(AdClickMetricsBrowserTest, BrowserInitiated) { … }
IN_PROC_BROWSER_TEST_F(AdClickMetricsBrowserTest,
WindowOpen_FromAdScriptWithoutGesture) { … }
IN_PROC_BROWSER_TEST_F(AdClickMetricsBrowserTest,
WindowOpen_FromNonAdScriptWithGesture) { … }
IN_PROC_BROWSER_TEST_F(AdClickMetricsBrowserTest,
WindowOpen_FromAdScriptWithGesture) { … }
IN_PROC_BROWSER_TEST_F(AdClickMetricsBrowserTest,
WindowOpen_FromAdIframeWithoutGesture) { … }
IN_PROC_BROWSER_TEST_F(AdClickMetricsBrowserTest,
WindowOpen_FromAdIframeWithGesture) { … }
IN_PROC_BROWSER_TEST_F(
AdClickMetricsBrowserTest,
AdClickMetrics_AnchorClickTopNavigationFromCrossOriginAdIframe) { … }
IN_PROC_BROWSER_TEST_F(AdClickMetricsBrowserTest,
AdClickMetrics_AnchorClickPopupFromCrossOriginAdIframe) { … }
IN_PROC_BROWSER_TEST_F(AdClickMetricsBrowserTest,
SetTopLocationFromCrossOriginAdIframe) { … }
IN_PROC_BROWSER_TEST_F(AdClickMetricsBrowserTest,
SetTopLocationFromCrossOriginNonAdIframe) { … }
IN_PROC_BROWSER_TEST_F(AdClickMetricsBrowserTest,
NavigateCrossOriginIframeFromNonAdScript) { … }
IN_PROC_BROWSER_TEST_F(AdClickMetricsBrowserTest,
NavigateCrossOriginIframeFromAdScript) { … }
class AdTaggingEventFromSubframeBrowserTest
: public AdTaggingBrowserTest,
public ::testing::WithParamInterface<
std::tuple<bool , bool >> { … };
IN_PROC_BROWSER_TEST_P(AdTaggingEventFromSubframeBrowserTest,
DISABLED_WindowOpenFromSubframe) { … }
INSTANTIATE_TEST_SUITE_P(…);
class AdTaggingEventWithScriptInStackBrowserTest
: public AdTaggingBrowserTest,
public ::testing::WithParamInterface<bool > { … };
IN_PROC_BROWSER_TEST_P(AdTaggingEventWithScriptInStackBrowserTest,
DISABLED_WindowOpenWithScriptInStack) { … }
INSTANTIATE_TEST_SUITE_P(…);
class AdTaggingFencedFrameBrowserTest : public AdTaggingBrowserTest { … };
IN_PROC_BROWSER_TEST_F(AdTaggingFencedFrameBrowserTest,
FencedFrameMatchingSuffixRuleIsTagged) { … }
IN_PROC_BROWSER_TEST_F(AdTaggingFencedFrameBrowserTest,
FencedFrameCreatedByAdScriptIsTagged) { … }
IN_PROC_BROWSER_TEST_F(AdTaggingFencedFrameBrowserTest,
FencedFrameWithAdParentIsTagged) { … }
IN_PROC_BROWSER_TEST_F(AdTaggingFencedFrameBrowserTest,
IFrameNestedInFencedFrameIsTagged) { … }
IN_PROC_BROWSER_TEST_F(AdTaggingFencedFrameBrowserTest,
FencedFrameNestedInFencedFrameIsTagged) { … }
IN_PROC_BROWSER_TEST_F(AdTaggingFencedFrameBrowserTest,
AdClickMetrics_PopupFromAdFencedFrame) { … }
IN_PROC_BROWSER_TEST_F(AdTaggingFencedFrameBrowserTest,
AdClickMetrics_PopupFromNonAdFencedFrame) { … }
IN_PROC_BROWSER_TEST_F(
AdTaggingFencedFrameBrowserTest,
AdClickMetrics_TopNavigationFromOpaqueModeAdFencedFrame) { … }
IN_PROC_BROWSER_TEST_F(AdTaggingFencedFrameBrowserTest,
AdClickMetrics_ReloadFromOpaqueModeAdFencedFrame) { … }
IN_PROC_BROWSER_TEST_F(
AdTaggingFencedFrameBrowserTest,
AdClickMetrics_AnchorClickTopNavigationFromOpaqueModeAdFencedFrame) { … }
IN_PROC_BROWSER_TEST_F(
AdTaggingFencedFrameBrowserTest,
AdClickMetrics_TopNavigationFromOpaqueModeNonAdFencedFrame) { … }
}
}