#include <map>
#include <memory>
#include <string>
#include <vector>
#include "base/command_line.h"
#include "base/containers/flat_set.h"
#include "base/files/file_util.h"
#include "base/functional/bind.h"
#include "base/path_service.h"
#include "base/run_loop.h"
#include "base/strings/strcat.h"
#include "base/task/thread_pool/thread_pool_instance.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/optimization_guide/browser_test_util.h"
#include "chrome/browser/optimization_guide/optimization_guide_keyed_service.h"
#include "chrome/browser/optimization_guide/optimization_guide_keyed_service_factory.h"
#include "chrome/browser/preloading/prefetch/no_state_prefetch/no_state_prefetch_manager_factory.h"
#include "chrome/browser/preloading/prefetch/no_state_prefetch/no_state_prefetch_test_utils.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/identity_test_environment_profile_adaptor.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/content_settings/core/common/features.h"
#include "components/google/core/common/google_switches.h"
#include "components/google/core/common/google_util.h"
#include "components/metrics/content/subprocess_metrics_provider.h"
#include "components/no_state_prefetch/browser/no_state_prefetch_handle.h"
#include "components/no_state_prefetch/browser/no_state_prefetch_manager.h"
#include "components/optimization_guide/core/hints_component_info.h"
#include "components/optimization_guide/core/hints_component_util.h"
#include "components/optimization_guide/core/hints_fetcher.h"
#include "components/optimization_guide/core/optimization_guide_constants.h"
#include "components/optimization_guide/core/optimization_guide_enums.h"
#include "components/optimization_guide/core/optimization_guide_features.h"
#include "components/optimization_guide/core/optimization_guide_prefs.h"
#include "components/optimization_guide/core/optimization_guide_store.h"
#include "components/optimization_guide/core/optimization_guide_switches.h"
#include "components/optimization_guide/core/optimization_guide_test_util.h"
#include "components/optimization_guide/core/optimization_hints_component_update_listener.h"
#include "components/optimization_guide/core/test_hints_component_creator.h"
#include "components/optimization_guide/core/top_host_provider.h"
#include "components/optimization_guide/proto/hints.pb.h"
#include "components/prefs/pref_service.h"
#include "components/site_engagement/content/site_engagement_service.h"
#include "components/ukm/test_ukm_recorder.h"
#include "components/variations/hashing.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_base.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/network_connection_change_simulator.h"
#include "content/public/test/prerender_test_util.h"
#include "net/dns/mock_host_resolver.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "net/test/embedded_test_server/http_request.h"
#include "net/test/embedded_test_server/http_response.h"
#include "services/metrics/public/cpp/ukm_builders.h"
#include "services/network/public/cpp/network_connection_tracker.h"
#include "services/network/test/test_network_connection_tracker.h"
#include "third_party/blink/public/common/features.h"
namespace {
constexpr char kGoogleHost[] = …;
constexpr char kGoogleSearchUrlPath[] = …;
GURL GetURLWithGoogleHost(net::EmbeddedTestServer* server,
const std::string& relative_url) { … }
std::unique_ptr<net::test_server::HttpResponse> HandleGoogleSearchUrlRequest(
const net::test_server::HttpRequest& request) { … }
}
class HintsFetcherDisabledBrowserTest : public InProcessBrowserTest { … };
IN_PROC_BROWSER_TEST_F(HintsFetcherDisabledBrowserTest, HintsFetcherDisabled) { … }
class HintsFetcherBrowserTest : public HintsFetcherDisabledBrowserTest { … };
IN_PROC_BROWSER_TEST_F(HintsFetcherBrowserTest, HintsFetcherEnabled) { … }
IN_PROC_BROWSER_TEST_F(HintsFetcherBrowserTest,
HintsFetcherFetchedHintsLoaded) { … }
IN_PROC_BROWSER_TEST_F(HintsFetcherBrowserTest,
HintsFetcherWithResponsesSuccessful) { … }
IN_PROC_BROWSER_TEST_F(HintsFetcherBrowserTest,
HintsFetcherWithResponsesUnsuccessful) { … }
IN_PROC_BROWSER_TEST_F(HintsFetcherBrowserTest,
HintsFetcherWithResponsesMalformed) { … }
IN_PROC_BROWSER_TEST_F(HintsFetcherBrowserTest,
HintsFetcherWithResponsesUnsuccessfulAtNavigationTime) { … }
IN_PROC_BROWSER_TEST_F(
HintsFetcherBrowserTest,
HintsFetcherWithResponsesHungShouldRecordWhenActiveRequestCanceled) { … }
IN_PROC_BROWSER_TEST_F(HintsFetcherBrowserTest,
DISABLED_HintsFetcherClearFetchedHints) { … }
IN_PROC_BROWSER_TEST_F(HintsFetcherBrowserTest, HintsFetcherOverrideTimer) { … }
IN_PROC_BROWSER_TEST_F(HintsFetcherBrowserTest, HintsFetcherFetches) { … }
IN_PROC_BROWSER_TEST_F(HintsFetcherBrowserTest,
OnDemandFetchRepeatedlyNoCache) { … }
IN_PROC_BROWSER_TEST_F(HintsFetcherBrowserTest,
HintsFetcher_NavigationFetch_URLKeyedNotRefetched) { … }
IN_PROC_BROWSER_TEST_F(
HintsFetcherBrowserTest,
HintsFetcher_NavigationFetch_FetchWithNewlyRegisteredOptType) { … }
IN_PROC_BROWSER_TEST_F(
HintsFetcherBrowserTest,
HintsFetcher_NavigationFetch_CacheNotClearedOnLaunchedOptTypes) { … }
class HintsFetcherPre3pcdBrowserTest : public HintsFetcherBrowserTest { … };
IN_PROC_BROWSER_TEST_F(HintsFetcherPre3pcdBrowserTest,
HintsFetcherDoesntFetchOnNSP) { … }
class HintsFetcherSearchPageBrowserTest : public HintsFetcherBrowserTest { … };
#if BUILDFLAG(IS_LINUX) && defined(LEAK_SANITIZER)
#define MAYBE_HintsFetcher_SRP_Slow_Connection …
#else
#define MAYBE_HintsFetcher_SRP_Slow_Connection …
#endif
IN_PROC_BROWSER_TEST_F(HintsFetcherSearchPageBrowserTest,
MAYBE_HintsFetcher_SRP_Slow_Connection) { … }
class HintsFetcherSearchPagePrerenderingBrowserTest
: public HintsFetcherSearchPageBrowserTest { … };
IN_PROC_BROWSER_TEST_F(HintsFetcherSearchPagePrerenderingBrowserTest,
HintsFetcherFetchedHintsLoadedAfterActivate) { … }
class HintsFetcherSearchPageDisabledBrowserTest
: public HintsFetcherDisabledBrowserTest { … };
IN_PROC_BROWSER_TEST_F(HintsFetcherSearchPageDisabledBrowserTest,
HintsFetcherStillFetchesNavigations) { … }
class HintsFetcherSearchPageLimitedURLsBrowserTest
: public HintsFetcherDisabledBrowserTest { … };
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_CHROMEOS)
#define MAYBE_HintsFetcherLimitedResults …
#else
#define MAYBE_HintsFetcherLimitedResults …
#endif
IN_PROC_BROWSER_TEST_F(HintsFetcherSearchPageLimitedURLsBrowserTest,
MAYBE_HintsFetcherLimitedResults) { … }
class PersonalizedHintsFetcherBrowserTest : public HintsFetcherBrowserTest { … };
IN_PROC_BROWSER_TEST_F(PersonalizedHintsFetcherBrowserTest, NoUserSignIn) { … }
IN_PROC_BROWSER_TEST_F(PersonalizedHintsFetcherBrowserTest, UserSignedIn) { … }