chromium/chrome/browser/safe_browsing/safe_browsing_navigation_observer_interactive_test.cc

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

#include "base/functional/callback.h"
#include "build/build_config.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/safe_browsing/test_safe_browsing_navigation_observer_manager.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/prefs/pref_service.h"
#include "components/safe_browsing/core/common/safe_browsing_prefs.h"
#include "components/sessions/content/session_tab_helper.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/content_browser_test.h"
#include "content/public/test/prerender_test_util.h"
#include "content/public/test/test_navigation_observer.h"
#include "net/dns/mock_host_resolver.h"

namespace safe_browsing {

// Infrastructure copied from these
// src\chrome\browser\safe_browsing\safe_browsing_navigation_observer_browsertest.cc
// The tests in this file are for files that needs to be interactive tests.
// Each test should have a comment why it needs to be interactive.

// Copied as an example page from:
// chrome/browser/safe_browsing/safe_browsing_navigation_observer_browsertest.cc
const char kLandingURL[] =;
const char kCopyReferrerUrl[] =;
const char kCopyReferrerInnerUrl[] =;

class SBNavigationObserverBrowserTest : public InProcessBrowserTest {};

// This test needs to be interactive as JS copy to clipboard only works for the
// focused window and frame. With regular tests they run in parallel so they
// will fail if the window loose focus before it finished.
// The test use kLandingURL as the target, not using any functionality from
// this page.
// TODO(crbug.com/41487061): Test is flaky on Mac ARM64 builders.
#if BUILDFLAG(IS_MAC) && defined(ARCH_CPU_ARM64)
#define MAYBE_VerifyCopiedUrlReferrerChain
#else
#define MAYBE_VerifyCopiedUrlReferrerChain
#endif
IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest,
                       MAYBE_VerifyCopiedUrlReferrerChain) {}

// This test needs to be interactive as JS copy to clipboard only works for the
// focused window and frame. With regular tests they run in parallel so they
// will fail if the window loose focus before it finished.
// The test use kLandingURL as the target, not using any functionality from
// this page.
IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest,
                       VerifyIdentifyReferrerChainByEventURL) {}

// This test needs to be interactive as JS copy to clipboard only works for the
// focused window and frame. With regular tests they run in parallel so they
// will fail if the window loose focus before it finished.
// The test use kLandingURL as the target, not using any functionality from
// this page.
// TODO(crbug.com/41487061): Test is flaky on Mac Arm64 builders.
#if BUILDFLAG(IS_MAC) && defined(ARCH_CPU_ARM64)
#define MAYBE_VerifyCopiedInnerUrlReferrerChain
#else
#define MAYBE_VerifyCopiedInnerUrlReferrerChain
#endif
IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest,
                       MAYBE_VerifyCopiedInnerUrlReferrerChain) {}

}  // namespace safe_browsing