#include <string>
#include "base/files/file_path.h"
#include "base/functional/bind.h"
#include "base/path_service.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "base/timer/elapsed_timer.h"
#include "build/build_config.h"
#include "chrome/browser/preloading/chrome_preloading.h"
#include "chrome/browser/preloading/preloading_prefs.h"
#include "chrome/browser/preloading/prerender/prerender_manager.h"
#include "chrome/browser/preloading/prerender/prerender_utils.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/chrome_features.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/webui_url_constants.h"
#include "chrome/test/base/chrome_test_utils.h"
#include "chrome/test/base/platform_browser_test.h"
#include "components/page_load_metrics/browser/navigation_handle_user_data.h"
#include "components/prefs/pref_service.h"
#include "content/public/browser/devtools_agent_host.h"
#include "content/public/common/content_features.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/preloading_test_util.h"
#include "content/public/test/prerender_test_util.h"
#include "content/public/test/test_navigation_observer.h"
#include "net/dns/mock_host_resolver.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "services/metrics/public/cpp/ukm_builders.h"
#include "services/metrics/public/cpp/ukm_recorder.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/mojom/use_counter/metrics/web_feature.mojom.h"
namespace {
namespace {
constexpr int kFinalStatusActivated = …;
constexpr int kFinalStatusInvalidSchemeNavigation = …;
constexpr int kFinalStatusTriggerDestroyed = …;
constexpr int kFinalStatusTabClosedWithoutUserGesture = …;
constexpr int kFinalStatusCrossSiteNavigationInMainFrameNavigation = …;
}
UkmEntry;
Preloading_Attempt;
static const auto kMockElapsedTime = …;
class PrerenderBrowserTest : public PlatformBrowserTest { … };
IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderAndActivate) { … }
void PrerenderBrowserTest::TestPrerenderAndActivateInNewTab(
const std::string& link_click_script,
bool should_be_activated) { … }
#if BUILDFLAG(IS_ANDROID)
#define MAYBE_PrerenderAndActivate_InNewTab …
#else
#define MAYBE_PrerenderAndActivate_InNewTab …
#endif
IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest,
MAYBE_PrerenderAndActivate_InNewTab) { … }
#if BUILDFLAG(IS_ANDROID)
#define MAYBE_PrerenderAndActivate_InNewTab_Noopener …
#else
#define MAYBE_PrerenderAndActivate_InNewTab_Noopener …
#endif
IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest,
MAYBE_PrerenderAndActivate_InNewTab_Noopener) { … }
#if BUILDFLAG(IS_ANDROID)
#define MAYBE_PrerenderAndActivate_InNewTab_Opener …
#else
#define MAYBE_PrerenderAndActivate_InNewTab_Opener …
#endif
IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest,
MAYBE_PrerenderAndActivate_InNewTab_Opener) { … }
IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest,
PrerenderAndActivate_InNewTab_CurrentTab) { … }
#if BUILDFLAG(IS_ANDROID)
#define MAYBE_MainFrameNavigation_InNewTab …
#else
#define MAYBE_MainFrameNavigation_InNewTab …
#endif
IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest,
MAYBE_MainFrameNavigation_InNewTab) { … }
IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest,
PrerenderTriggeredByEmbedderAndActivate) { … }
IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, EmbedderTrigger_ChromeUrl) { … }
IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, UseCounter) { … }
IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, DisableNetworkPrediction) { … }
IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PreloadingHoldbackOverridden) { … }
IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PreloadingHoldbackNotOverridden) { … }
IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, SameOriginMainFrameNavigation) { … }
IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest,
SameSiteCrossOriginMainFrameNavigation) { … }
IN_PROC_BROWSER_TEST_F(
PrerenderBrowserTest,
CrossSiteMainFrameNavigationCancelsEmbedderTriggeredPrerendering) { … }
IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest,
PrerenderWebContentsDelegate_CloseContents) { … }
class PrerenderNewTabPageBrowserTest
: public PrerenderBrowserTest,
public testing::WithParamInterface<content::PreloadingPredictor> { … };
INSTANTIATE_TEST_SUITE_P(…);
IN_PROC_BROWSER_TEST_P(PrerenderNewTabPageBrowserTest,
PrerenderTriggeredByNewTabPageAndActivate) { … }
IN_PROC_BROWSER_TEST_P(
PrerenderNewTabPageBrowserTest,
PrerenderTriggeredByNewTabPageMouseDownAfterHoverAndActivate) { … }
IN_PROC_BROWSER_TEST_P(PrerenderNewTabPageBrowserTest,
NewTabPagePrerenderNonHttps) { … }
IN_PROC_BROWSER_TEST_P(PrerenderNewTabPageBrowserTest,
PrerenderTriggeredCancelAndRetrigger) { … }
IN_PROC_BROWSER_TEST_P(PrerenderNewTabPageBrowserTest,
DestroyedOnNavigatedAway) { … }
}