#include "base/functional/callback_forward.h"
#include "base/memory/raw_ptr.h"
#include "base/metrics/field_trial_params.h"
#include "base/test/bind.h"
#include "base/test/gmock_expected_support.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/simple_test_clock.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "chrome/browser/content_settings/cookie_settings_factory.h"
#include "chrome/browser/dips/dips_service.h"
#include "chrome/browser/dips/dips_storage.h"
#include "chrome/browser/dips/dips_test_utils.h"
#include "chrome/browser/dips/dips_utils.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/subresource_filter/subresource_filter_browser_test_harness.h"
#include "chrome/browser/tpcd/experiment/tpcd_experiment_features.h"
#include "chrome/browser/tpcd/heuristics/opener_heuristic_metrics.h"
#include "chrome/browser/tpcd/heuristics/opener_heuristic_tab_helper.h"
#include "chrome/browser/tpcd/heuristics/opener_heuristic_utils.h"
#include "chrome/test/base/chrome_test_utils.h"
#include "components/content_settings/core/browser/cookie_settings.h"
#include "components/content_settings/core/common/content_settings.h"
#include "components/content_settings/core/common/features.h"
#include "components/content_settings/core/common/pref_names.h"
#include "components/prefs/pref_service.h"
#include "components/subresource_filter/content/browser/ad_tagging_browser_test_utils.h"
#include "components/subresource_filter/core/common/test_ruleset_utils.h"
#include "components/ukm/test_ukm_recorder.h"
#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/web_contents_observer.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_navigation_observer.h"
#include "net/cookies/site_for_cookies.h"
#include "net/dns/mock_host_resolver.h"
#include "services/metrics/public/cpp/ukm_source.h"
#include "services/metrics/public/cpp/ukm_source_id.h"
#include "services/network/public/cpp/features.h"
#include "third_party/blink/public/common/switches.h"
#include "ui/base/window_open_disposition.h"
#if !BUILDFLAG(IS_ANDROID)
#include "chrome/browser/ui/browser.h"
#endif
HasValue;
ValueIs;
NavigationHandle;
RenderFrameHost;
WebContents;
WebContentsObserver;
ElementsAre;
Field;
Optional;
Pair;
EnableForIframeTypes;
namespace {
struct AccessGrantTestCase { … };
const AccessGrantTestCase kAccessGrantTestCases[] = …;
class PopupObserver : public WebContentsObserver { … };
class NavigationFinishObserver : public WebContentsObserver { … };
}
class OpenerHeuristicBrowserTest
: public subresource_filter::SubresourceFilterBrowserTest { … };
IN_PROC_BROWSER_TEST_F(OpenerHeuristicBrowserTest,
RootWindowDoesntHavePopupState) { … }
#if BUILDFLAG(IS_ANDROID)
#define MAYBE_PopupsWithOpenerHavePopupState …
#else
#define MAYBE_PopupsWithOpenerHavePopupState …
#endif
IN_PROC_BROWSER_TEST_F(OpenerHeuristicBrowserTest,
MAYBE_PopupsWithOpenerHavePopupState) { … }
#if BUILDFLAG(IS_ANDROID)
#define MAYBE_PopupsWithoutOpenerDoNotHavePopupState …
#else
#define MAYBE_PopupsWithoutOpenerDoNotHavePopupState …
#endif
IN_PROC_BROWSER_TEST_F(OpenerHeuristicBrowserTest,
MAYBE_PopupsWithoutOpenerDoNotHavePopupState) { … }
#if BUILDFLAG(IS_ANDROID)
#define MAYBE_NewTabURLsHavePopupState …
#else
#define MAYBE_NewTabURLsHavePopupState …
#endif
IN_PROC_BROWSER_TEST_F(OpenerHeuristicBrowserTest,
MAYBE_NewTabURLsHavePopupState) { … }
class OpenerHeuristicIframeInitiatorBrowserTest
: public OpenerHeuristicBrowserTest,
public testing::WithParamInterface<
::testing::tuple<EnableForIframeTypes, bool>> { … };
IN_PROC_BROWSER_TEST_P(
OpenerHeuristicIframeInitiatorBrowserTest,
URLsInitiatedByFirstPartyIframes_HavePopupStateWithFlag) { … }
IN_PROC_BROWSER_TEST_P(
OpenerHeuristicIframeInitiatorBrowserTest,
URLsInitiatedByThirdPartyIframes_HavePopupStateWithFlag) { … }
INSTANTIATE_TEST_SUITE_P(…);
IN_PROC_BROWSER_TEST_F(OpenerHeuristicBrowserTest,
PopupPastInteractionIsReported_WithoutInteraction) { … }
IN_PROC_BROWSER_TEST_F(OpenerHeuristicBrowserTest,
PopupPastInteractionIsReported_WithoutRedirect) { … }
#if !BUILDFLAG(IS_ANDROID)
class OpenerHeuristicPastInteractionGrantBrowserTest
: public OpenerHeuristicBrowserTest,
public testing::WithParamInterface<AccessGrantTestCase> { … };
IN_PROC_BROWSER_TEST_P(OpenerHeuristicPastInteractionGrantBrowserTest,
PopupPastInteractionIsReported_WithStorageAccessGrant) { … }
#if BUILDFLAG(IS_MAC)
#define MAYBE_AdTaggedPopupPastInteractionIsReported_WithStorageAccessGrant …
#else
#define MAYBE_AdTaggedPopupPastInteractionIsReported_WithStorageAccessGrant …
#endif
IN_PROC_BROWSER_TEST_P(
OpenerHeuristicPastInteractionGrantBrowserTest,
MAYBE_AdTaggedPopupPastInteractionIsReported_WithStorageAccessGrant) { … }
INSTANTIATE_TEST_SUITE_P(…);
#endif
#if BUILDFLAG(IS_ANDROID)
#define MAYBE_PopupPastInteractionIsReported_ServerRedirect …
#else
#define MAYBE_PopupPastInteractionIsReported_ServerRedirect …
#endif
IN_PROC_BROWSER_TEST_F(OpenerHeuristicBrowserTest,
MAYBE_PopupPastInteractionIsReported_ServerRedirect) { … }
#if BUILDFLAG(IS_ANDROID)
#define MAYBE_PopupPastInteractionIsReported_ClientRedirect …
#else
#define MAYBE_PopupPastInteractionIsReported_ClientRedirect …
#endif
IN_PROC_BROWSER_TEST_F(OpenerHeuristicBrowserTest,
MAYBE_PopupPastInteractionIsReported_ClientRedirect) { … }
IN_PROC_BROWSER_TEST_F(OpenerHeuristicBrowserTest,
PopupPastInteractionIsReportedOnlyOnce) { … }
IN_PROC_BROWSER_TEST_F(OpenerHeuristicBrowserTest,
PopupPastInteractionIsFollowedByPostPopupCookieAccess) { … }
IN_PROC_BROWSER_TEST_F(OpenerHeuristicBrowserTest, PopupInteraction) { … }
#if !BUILDFLAG(IS_ANDROID)
class OpenerHeuristicCurrentInteractionGrantBrowserTest
: public OpenerHeuristicBrowserTest,
public testing::WithParamInterface<AccessGrantTestCase> { … };
IN_PROC_BROWSER_TEST_P(OpenerHeuristicCurrentInteractionGrantBrowserTest,
PopupInteractionWithStorageAccessGrant) { … }
IN_PROC_BROWSER_TEST_P(OpenerHeuristicCurrentInteractionGrantBrowserTest,
AdTaggedPopupInteractionWithStorageAccessGrant) { … }
INSTANTIATE_TEST_SUITE_P(…);
#endif
IN_PROC_BROWSER_TEST_F(OpenerHeuristicBrowserTest,
PopupInteractionIsOnlyReportedOnce) { … }
IN_PROC_BROWSER_TEST_F(OpenerHeuristicBrowserTest,
PopupInteraction_IgnoreUncommitted) { … }
#if BUILDFLAG(IS_MAC)
#define MAYBE_PopupInteraction_IsFollowedByPostPopupCookieAccess …
#else
#define MAYBE_PopupInteraction_IsFollowedByPostPopupCookieAccess …
#endif
IN_PROC_BROWSER_TEST_F(
OpenerHeuristicBrowserTest,
MAYBE_PopupInteraction_IsFollowedByPostPopupCookieAccess) { … }
IN_PROC_BROWSER_TEST_F(OpenerHeuristicBrowserTest,
TopLevelIsReported_PastInteraction_NoSameSiteIframe) { … }
IN_PROC_BROWSER_TEST_F(OpenerHeuristicBrowserTest,
TopLevelIsReported_HasSameSiteIframe) { … }
IN_PROC_BROWSER_TEST_F(OpenerHeuristicBrowserTest, TopLevel_PopupProvider) { … }
IN_PROC_BROWSER_TEST_F(OpenerHeuristicBrowserTest, TopLevel_PopupId) { … }
#if BUILDFLAG(IS_MAC)
#define MAYBE_TopLevel_PastInteraction_AdTagged …
#else
#define MAYBE_TopLevel_PastInteraction_AdTagged …
#endif
IN_PROC_BROWSER_TEST_F(OpenerHeuristicBrowserTest,
MAYBE_TopLevel_PastInteraction_AdTagged) { … }
IN_PROC_BROWSER_TEST_F(OpenerHeuristicBrowserTest,
TopLevel_CurrentInteraction_AdTagged) { … }
IN_PROC_BROWSER_TEST_F(OpenerHeuristicBrowserTest,
PastAndCurrentInteractionAreBothReportedToDipsDb) { … }
#if !BUILDFLAG(IS_ANDROID)
class OpenerHeuristicBackfillGrantBrowserTest
: public OpenerHeuristicBrowserTest,
public testing::WithParamInterface<bool> { … };
IN_PROC_BROWSER_TEST_P(OpenerHeuristicBackfillGrantBrowserTest,
TrackingProtectionOnboardingCreatesBackfillGrants) { … }
INSTANTIATE_TEST_SUITE_P(…);
#endif