chromium/chrome/browser/page_load_metrics/observers/ad_metrics/overlay_popup_ad_intervention_browsertest.cc

// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <memory>

#include "base/test/scoped_feature_list.h"
#include "build/build_config.h"
#include "chrome/browser/subresource_filter/subresource_filter_browser_test_harness.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/test/base/chrome_test_utils.h"
#include "components/infobars/content/content_infobar_manager.h"
#include "components/infobars/core/infobar.h"
#include "components/infobars/core/infobar_delegate.h"
#include "components/infobars/core/infobar_manager.h"
#include "components/page_load_metrics/browser/observers/ad_metrics/ad_intervention_browser_test_utils.h"
#include "components/page_load_metrics/browser/page_load_metrics_test_waiter.h"
#include "components/subresource_filter/content/browser/content_subresource_filter_throttle_manager.h"
#include "components/subresource_filter/core/common/common_features.h"
#include "components/subresource_filter/core/common/test_ruleset_utils.h"
#include "components/subresource_filter/core/mojom/subresource_filter.mojom.h"
#include "components/ukm/test_ukm_recorder.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/test_navigation_observer.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/features.h"
#include "url/gurl.h"

namespace {

const char kAdsInterventionRecordedHistogram[] =;

}  // namespace

class OverlayPopupAdViolationBrowserTest
    : public subresource_filter::SubresourceFilterBrowserTest {};

// TODO(crbug.com/40761472): Fails on Linux MSan and ChromeOS.
#if BUILDFLAG(IS_CHROMEOS) || (BUILDFLAG(IS_LINUX) && defined(MEMORY_SANITIZER))
#define MAYBE_NoOverlayPopupAd_AdInterventionNotTriggered
#else
#define MAYBE_NoOverlayPopupAd_AdInterventionNotTriggered
#endif
IN_PROC_BROWSER_TEST_F(OverlayPopupAdViolationBrowserTest,
                       MAYBE_NoOverlayPopupAd_AdInterventionNotTriggered) {}

// TODO(crbug.com/40856777): Fix flakiness and re-enable test.
#if (BUILDFLAG(IS_LINUX) &&                                     \
     (defined(MEMORY_SANITIZER) || defined(LEAK_SANITIZER))) || \
    (BUILDFLAG(IS_CHROMEOS) && !defined(NDEBUG)) ||             \
    (defined(LEAK_SANITIZER) && BUILDFLAG(IS_CHROMEOS) &&       \
     defined(ADDRESS_SANITIZER))
#define MAYBE_OverlayPopupAd_AdInterventionTriggered
#else
#define MAYBE_OverlayPopupAd_AdInterventionTriggered
#endif
IN_PROC_BROWSER_TEST_F(OverlayPopupAdViolationBrowserTest,
                       MAYBE_OverlayPopupAd_AdInterventionTriggered) {}

class OverlayPopupAdViolationBrowserTestWithoutEnforcement
    : public OverlayPopupAdViolationBrowserTest {};

// TODO(crbug.com/40248595): Fails on Linux MSan, and ChromeOS Debug as
// well as Asan LSsan.
#if (BUILDFLAG(IS_LINUX) && defined(MEMORY_SANITIZER)) || \
    (BUILDFLAG(IS_CHROMEOS) &&                            \
     (!defined(NDEBUG) || defined(ADDRESS_SANITIZER) ||   \
      defined(LEAK_SANITIZER)))
#define MAYBE_OverlayPopupAd_NoAdInterventionTriggered
#else
#define MAYBE_OverlayPopupAd_NoAdInterventionTriggered
#endif
IN_PROC_BROWSER_TEST_F(OverlayPopupAdViolationBrowserTestWithoutEnforcement,
                       MAYBE_OverlayPopupAd_NoAdInterventionTriggered) {}