#include <string>
#include "base/containers/contains.h"
#include "base/files/file_path.h"
#include "base/functional/bind.h"
#include "base/path_service.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/timer/elapsed_timer.h"
#include "build/build_config.h"
#include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h"
#include "chrome/browser/browser_features.h"
#include "chrome/browser/preloading/chrome_preloading.h"
#include "chrome/browser/preloading/prefetch/search_prefetch/cache_alias_search_prefetch_url_loader.h"
#include "chrome/browser/preloading/prefetch/search_prefetch/field_trial_settings.h"
#include "chrome/browser/preloading/prefetch/search_prefetch/search_prefetch_request.h"
#include "chrome/browser/preloading/prefetch/search_prefetch/search_prefetch_service.h"
#include "chrome/browser/preloading/prefetch/search_prefetch/search_prefetch_service_factory.h"
#include "chrome/browser/preloading/prefetch/search_prefetch/search_preload_test_response_utils.h"
#include "chrome/browser/preloading/prefetch/search_prefetch/streaming_search_prefetch_url_loader.h"
#include "chrome/browser/preloading/prerender/prerender_manager.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/test/base/chrome_test_utils.h"
#include "chrome/test/base/platform_browser_test.h"
#include "chrome/test/base/search_test_utils.h"
#include "components/omnibox/browser/autocomplete_input.h"
#include "components/omnibox/browser/autocomplete_result.h"
#include "components/search_engines/template_url_data.h"
#include "components/search_engines/template_url_service.h"
#include "content/public/browser/preloading.h"
#include "content/public/browser/web_contents.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/navigation_handle_observer.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/base/net_errors.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 "services/network/public/mojom/early_hints.mojom.h"
#include "services/network/public/mojom/url_loader.mojom.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/features.h"
#if !BUILDFLAG(IS_ANDROID)
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/location_bar/location_bar.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/omnibox/browser/autocomplete_controller.h"
#include "components/omnibox/browser/omnibox_controller.h"
#include "components/omnibox/browser/omnibox_edit_model.h"
#include "components/omnibox/browser/omnibox_view.h"
#endif
namespace {
UkmEntry;
Preloading_Attempt;
Preloading_Prediction;
PrerenderPageLoad;
static const auto kMockElapsedTime = …;
class SearchPreloadUnifiedBrowserTest : public PlatformBrowserTest,
public SearchPreloadResponseController { … };
#if BUILDFLAG(IS_LINUX)
#define MAYBE_PrerenderHintReceivedBeforeSucceed …
#else
#define MAYBE_PrerenderHintReceivedBeforeSucceed …
#endif
IN_PROC_BROWSER_TEST_F(SearchPreloadUnifiedBrowserTest,
MAYBE_PrerenderHintReceivedBeforeSucceed) { … }
IN_PROC_BROWSER_TEST_F(SearchPreloadUnifiedBrowserTest,
PrerenderHintReceivedAfterSucceed) { … }
IN_PROC_BROWSER_TEST_F(SearchPreloadUnifiedBrowserTest,
FailedPrefetchCannotBeUpgraded) { … }
IN_PROC_BROWSER_TEST_F(SearchPreloadUnifiedBrowserTest,
SuggestionChangeBeforeStartPrerender) { … }
IN_PROC_BROWSER_TEST_F(SearchPreloadUnifiedBrowserTest,
SetLoaderTimeCorrectly) { … }
#if BUILDFLAG(IS_ANDROID)
#define MAYBE_NavigationFailsAfterPrefetchServedTheResponse …
#else
#define MAYBE_NavigationFailsAfterPrefetchServedTheResponse …
#endif
IN_PROC_BROWSER_TEST_F(SearchPreloadUnifiedBrowserTest,
MAYBE_NavigationFailsAfterPrefetchServedTheResponse) { … }
IN_PROC_BROWSER_TEST_F(SearchPreloadUnifiedBrowserTest, ChunkedResponseBody) { … }
IN_PROC_BROWSER_TEST_F(SearchPreloadUnifiedBrowserTest, DoNotRefetchSameTerms) { … }
class HoldbackSearchPreloadUnifiedBrowserTest
: public SearchPreloadUnifiedBrowserTest { … };
class DSEPrerenderHoldbackSearchPreloadUnifiedBrowserTest
: public HoldbackSearchPreloadUnifiedBrowserTest { … };
IN_PROC_BROWSER_TEST_F(DSEPrerenderHoldbackSearchPreloadUnifiedBrowserTest,
PrerenderDSEHoldbackTest) { … }
class PreloadingConfigHoldbackSearchPreloadUnifiedBrowserTest
: public HoldbackSearchPreloadUnifiedBrowserTest { … };
IN_PROC_BROWSER_TEST_F(PreloadingConfigHoldbackSearchPreloadUnifiedBrowserTest,
PrerenderDSEHoldbackTest) { … }
class HTTPCacheSearchPreloadUnifiedBrowserTest
: public SearchPreloadUnifiedBrowserTest { … };
IN_PROC_BROWSER_TEST_F(HTTPCacheSearchPreloadUnifiedBrowserTest,
BackwardHitHttpCache) { … }
IN_PROC_BROWSER_TEST_F(SearchPreloadUnifiedBrowserTest,
PrerenderGetDestroyedAfterPrefetchExpired) { … }
#if !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_CHROMEOS_LACROS)
IN_PROC_BROWSER_TEST_F(SearchPreloadUnifiedBrowserTest, TriggerAndActivate) { … }
IN_PROC_BROWSER_TEST_F(SearchPreloadUnifiedBrowserTest,
PrerenderFailAfterResponseServed) { … }
#endif
IN_PROC_BROWSER_TEST_F(SearchPreloadUnifiedBrowserTest,
SuggestionChangeAfterStartPrerender) { … }
void CheckCorrectForwardingResultMetric(
base::HistogramTester& histogram_tester,
StreamingSearchPrefetchURLLoader::ForwardingResult result,
int count) { … }
IN_PROC_BROWSER_TEST_F(SearchPreloadUnifiedBrowserTest,
PrefetchSucceedAfterPrerenderFailed) { … }
IN_PROC_BROWSER_TEST_F(SearchPreloadUnifiedBrowserTest,
FetchPrerenderActivated) { … }
IN_PROC_BROWSER_TEST_F(SearchPreloadUnifiedBrowserTest,
PrerenderHintReceivedAfterCompletion) { … }
IN_PROC_BROWSER_TEST_F(SearchPreloadUnifiedBrowserTest,
PrefetchErrorCancelsPrerender) { … }
IN_PROC_BROWSER_TEST_F(SearchPreloadUnifiedBrowserTest,
PrerenderDiscardedBeforeServingData) { … }
IN_PROC_BROWSER_TEST_F(SearchPreloadUnifiedBrowserTest,
ServingToPrerenderingUntilCompletion) { … }
IN_PROC_BROWSER_TEST_F(SearchPreloadUnifiedBrowserTest,
ServingToPrerenderNavigationTwice) { … }
class SearchPreloadServingTestURLLoader
: public network::mojom::URLLoaderClient,
public mojo::DataPipeDrainer::Client { … };
IN_PROC_BROWSER_TEST_F(SearchPreloadUnifiedBrowserTest,
PrerenderHandlerExecutedAfterPrefetchHandler) { … }
#if !BUILDFLAG(IS_ANDROID)
#if (BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_LINUX)) && \
defined(ADDRESS_SANITIZER)
#define MAYBE_OpenPrefetchedResponseInBackgroundedTab …
#else
#define MAYBE_OpenPrefetchedResponseInBackgroundedTab …
#endif
IN_PROC_BROWSER_TEST_F(SearchPreloadUnifiedBrowserTest,
MAYBE_OpenPrefetchedResponseInBackgroundedTab) { … }
#endif
}