#include <memory>
#include "base/base64.h"
#include "base/files/file_util.h"
#include "base/functional/callback_helpers.h"
#include "base/path_service.h"
#include "base/run_loop.h"
#include "base/strings/strcat.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/scoped_run_loop_timeout.h"
#include "base/threading/thread_restrictions.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/browser_process.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/profiles/profile.h"
#include "chrome/browser/profiles/profile_key.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/profiles/profile_test_util.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/component_updater/pref_names.h"
#include "components/metrics/content/subprocess_metrics_provider.h"
#include "components/optimization_guide/core/model_util.h"
#include "components/optimization_guide/core/optimization_guide_constants.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/prediction_manager.h"
#include "components/optimization_guide/core/prediction_model_download_manager.h"
#include "components/optimization_guide/core/store_update_data.h"
#include "components/optimization_guide/proto/models.pb.h"
#include "components/prefs/pref_service.h"
#include "components/variations/hashing.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/network_connection_change_simulator.h"
#include "net/base/ip_address.h"
#include "net/dns/mock_host_resolver.h"
#include "net/test/embedded_test_server/http_request.h"
#include "net/test/embedded_test_server/http_response.h"
#include "testing/gmock/include/gmock/gmock.h"
#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "ash/constants/ash_switches.h"
#endif
namespace {
constexpr int kSuccessfulModelVersion = …;
constexpr base::TimeDelta kModelFileDownloadTimeout = …;
enum class PredictionModelsFetcherRemoteResponseType { … };
}
namespace optimization_guide {
namespace {
void SetUpValidModelInfoReceival(ModelFileObserver* model_file_observer,
base::RunLoop* run_loop,
const std::set<base::FilePath::StringType>&
expected_additional_files = { … }
void SetUpNoModelInfoReceival(ModelFileObserver* model_file_observer) { … }
}
class PredictionManagerBrowserTestBase : public InProcessBrowserTest { … };
class PredictionManagerBrowserTest : public PredictionManagerBrowserTestBase { … };
IN_PROC_BROWSER_TEST_F(PredictionManagerBrowserTest,
ComponentUpdatesPrefDisabled) { … }
IN_PROC_BROWSER_TEST_F(PredictionManagerBrowserTest,
ModelsAndFeaturesStoreInitialized) { … }
IN_PROC_BROWSER_TEST_F(PredictionManagerBrowserTest,
PredictionModelFetchFailed) { … }
class PredictionManagerModelDownloadingBrowserTest
: public PredictionManagerBrowserTest { … };
IN_PROC_BROWSER_TEST_F(PredictionManagerModelDownloadingBrowserTest,
DISABLED_TestIncognitoUsesModelFromRegularProfile) { … }
#if BUILDFLAG(IS_CHROMEOS_ASH) && defined(ADDRESS_SANITIZER)
#define MAYBE_TestIncognitoDoesntFetchModels …
#else
#define MAYBE_TestIncognitoDoesntFetchModels …
#endif
IN_PROC_BROWSER_TEST_F(PredictionManagerModelDownloadingBrowserTest,
MAYBE_TestIncognitoDoesntFetchModels) { … }
IN_PROC_BROWSER_TEST_F(PredictionManagerModelDownloadingBrowserTest,
TestDownloadUrlAcceptedByDownloadServiceButInvalid) { … }
IN_PROC_BROWSER_TEST_F(PredictionManagerModelDownloadingBrowserTest,
TestSuccessfulModelFileFlow) { … }
IN_PROC_BROWSER_TEST_F(PredictionManagerModelDownloadingBrowserTest,
TestSuccessfulModelFileFlowWithAdditionalFile) { … }
IN_PROC_BROWSER_TEST_F(PredictionManagerModelDownloadingBrowserTest,
TestSuccessfulModelFileFlowWithInvalidAdditionalFile) { … }
IN_PROC_BROWSER_TEST_F(PredictionManagerModelDownloadingBrowserTest,
TestModelHasNoUpdateFlow) { … }
IN_PROC_BROWSER_TEST_F(PredictionManagerModelDownloadingBrowserTest,
TestEmptyModelRemovedFlow) { … }
IN_PROC_BROWSER_TEST_F(PredictionManagerModelDownloadingBrowserTest,
TestSwitchProfileDoesntCrash) { … }
#if !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_CHROMEOS_ASH)
IN_PROC_BROWSER_TEST_F(PredictionManagerModelDownloadingBrowserTest,
GuestProfileReceivesModel) { … }
#endif
class PredictionManagerModelPackageOverrideTest : public InProcessBrowserTest { … };
IN_PROC_BROWSER_TEST_F(PredictionManagerModelPackageOverrideTest, TestE2E) { … }
}