#include "components/safe_browsing/content/browser/safe_browsing_navigation_observer.h"
#include <memory>
#include "base/functional/callback.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/scoped_refptr.h"
#include "base/run_loop.h"
#include "base/strings/stringprintf.h"
#include "base/test/scoped_feature_list.h"
#include "build/build_config.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/download/download_core_service.h"
#include "chrome/browser/download/download_prefs.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/safe_browsing/download_protection/download_protection_service.h"
#include "chrome/browser/safe_browsing/safe_browsing_navigation_observer_manager_factory.h"
#include "chrome/browser/safe_browsing/test_safe_browsing_navigation_observer_manager.h"
#include "chrome/browser/safe_browsing/test_safe_browsing_service.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/tabs/tab_strip_model.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/download/public/common/download_item.h"
#include "components/prefs/pref_service.h"
#include "components/safe_browsing/content/browser/safe_browsing_navigation_observer_manager.h"
#include "components/sessions/content/session_tab_helper.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/download_item_utils.h"
#include "content/public/browser/download_manager.h"
#include "content/public/browser/global_routing_id.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/fenced_frame_test_util.h"
#include "content/public/test/prerender_test_util.h"
#include "content/public/test/test_navigation_observer.h"
#include "content/public/test/test_utils.h"
#include "net/dns/mock_host_resolver.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "third_party/blink/public/common/features.h"
#include "url/gurl.h"
#include "url/url_canon.h"
DownloadManager;
DownloadItem;
namespace safe_browsing {
const char kSingleFrameTestURL[] = …;
const char kMultiFrameTestURL[] = …;
const char kSubFrameTestURL[] = …;
const char kRedirectURL[] = …;
const char kEmptyURL[] = …;
const char kBasicIframeURL[] = …;
const char kInitialSubframeUrl[] = …;
const char kDownloadDataURL[] = …;
const char kShortDataURL[] = …;
const char kIframeDirectDownloadURL[] = …;
const char kIframeRetargetingURL[] = …;
const char kDownloadItemURL[] = …;
const char kRedirectToLandingURL[] = …;
const char kLandingURL[] = …;
const char kLandingReferrerURL[] = …;
const char kLandingReferrerURLWithQuery[] = …;
const char kPageBeforeLandingReferrerURL[] = …;
const char kCreateIframeElementURL[] = …;
class DownloadItemCreatedObserver : public DownloadManager::Observer { … };
class SBNavigationObserverBrowserTest : public InProcessBrowserTest { … };
IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest, TypeInURLDownload) { … }
IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest, DirectDownload) { … }
IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest,
DirectDownloadNoReferrer) { … }
IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest,
DirectDownloadNoReferrerTargetBlank) { … }
IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest,
SingleMetaRefreshRedirect) { … }
IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest,
SingleMetaRefreshRedirectTargetBlank) { … }
IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest,
MultiMetaRefreshRedirects) { … }
IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest,
WindowLocationRedirect) { … }
IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest, MixRedirects) { … }
IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest, NewTabDownload) { … }
IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest,
NewTabDownloadWithDataURL) { … }
IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest,
SubFrameDirectDownload) { … }
IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest,
SubFrameNewTabDownload) { … }
IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest, CompleteReferrerChain) { … }
IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest,
ReferrerAttributionWithinTwoUserGestures) { … }
IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest,
PPAPIDownloadWithUserGestureOnHostingFrame) { … }
IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest,
PPAPIDownloadWithoutUserGestureOnHostingFrame) { … }
IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest, ServerRedirect) { … }
IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest, TwoServerRedirects) { … }
IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest,
RetargetingAndServerRedirect) { … }
IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest, AddIPMapping) { … }
IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest, IPListDedup) { … }
IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest,
DownloadViaHTML5FileApi) { … }
IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest,
DownloadAttributionWithURLFragment) { … }
IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest,
VerifySanitizeReferrerChain) { … }
IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest,
VerifyNumberOfRecentNavigationsToCollect) { … }
IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest,
AppendRecentNavigationsToIncompleteReferrerChain) { … }
IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest,
NewWindowAndNavigateSubframe) { … }
IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest,
ReferrerChainsMatchPrerender) { … }
IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest,
PrerenderReferrerChains) { … }
IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest,
FencedFrameNavigationEventsAndReferrerChain) { … }
IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest,
NavigateBackwardForward) { … }
IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest, ReloadNotRecorded) { … }
IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest,
CreateIframeElementGetsReferrerChain) { … }
IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest,
SetWindowLocationGetsReferrerChain) { … }
IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest,
NewTabClientRedirectByOpener) { … }
IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest,
IdentifyReferrerChainByPendingEventURL_TwoUserGestures) { … }
IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest,
IdentifyReferrerChainByPendingEventURL_ServerRedirect) { … }
IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest,
AllowlistDomainsRemoved_ReferrerChain) { … }
IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest,
AllowlistDomainsRemoved_ServerRedirect) { … }
IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest,
AllowlistDomainsRemoved_RecentNavigation) { … }
#if BUILDFLAG(IS_MAC)
#define MAYBE_AppendRecentNavigationsToEmptyReferrerChain …
#else
#define MAYBE_AppendRecentNavigationsToEmptyReferrerChain …
#endif
IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest,
MAYBE_AppendRecentNavigationsToEmptyReferrerChain) { … }
}