#include "base/files/file_enumerator.h"
#include "base/files/file_util.h"
#include "base/ranges/algorithm.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_run_loop_timeout.h"
#include "base/test/task_environment.h"
#include "base/threading/thread_restrictions.h"
#include "build/build_config.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/optimization_guide/browser_test_util.h"
#include "chrome/browser/optimization_guide/chrome_prediction_model_store.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/test/base/in_process_browser_test.h"
#include "components/optimization_guide/core/model_store_metadata_entry.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_switches.h"
#include "components/optimization_guide/core/prediction_manager.h"
#include "components/optimization_guide/core/prediction_model_fetch_timer.h"
#include "components/optimization_guide/proto/models.pb.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.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"
#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "ash/constants/ash_switches.h"
#include "chrome/browser/ash/profiles/profile_helper.h"
#endif
namespace optimization_guide {
namespace {
constexpr int kSuccessfulModelVersion = …;
constexpr char kTestLocaleFoo[] = …;
constexpr char kTestLocaleBar[] = …;
constexpr base::TimeDelta kModelFileDownloadTimeout = …;
Profile* CreateProfile() { … }
proto::ModelCacheKey CreateModelCacheKey(const std::string& locale) { … }
}
class PredictionModelStoreBrowserTestBase : public InProcessBrowserTest { … };
class PredictionModelStoreBrowserTest
: public PredictionModelStoreBrowserTestBase { … };
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_LINUX) || \
(BUILDFLAG(IS_MAC) && defined(ADDRESS_SANITIZER))
#define MAYBE_TestRegularProfile …
#else
#define MAYBE_TestRegularProfile …
#endif
IN_PROC_BROWSER_TEST_F(PredictionModelStoreBrowserTest,
MAYBE_TestRegularProfile) { … }
#if BUILDFLAG(IS_CHROMEOS) && defined(ADDRESS_SANITIZER)
#define MAYBE_TestIncognitoProfile …
#else
#define MAYBE_TestIncognitoProfile …
#endif
IN_PROC_BROWSER_TEST_F(PredictionModelStoreBrowserTest,
MAYBE_TestIncognitoProfile) { … }
IN_PROC_BROWSER_TEST_F(PredictionModelStoreBrowserTest,
TestSimilarProfilesShareModel) { … }
IN_PROC_BROWSER_TEST_F(PredictionModelStoreBrowserTest,
TestDissimilarProfilesNotShareModel) { … }
IN_PROC_BROWSER_TEST_F(PredictionModelStoreBrowserTest,
TestSimilarProfilesShareModelWithServerModelCacheKey) { … }
IN_PROC_BROWSER_TEST_F(
PredictionModelStoreBrowserTest,
TestDissimilarProfilesNotShareModelWithServerModelCacheKey) { … }
IN_PROC_BROWSER_TEST_F(PredictionModelStoreBrowserTest,
TestSimilarProfilesOnModelVersionUpdate) { … }
IN_PROC_BROWSER_TEST_F(PredictionModelStoreBrowserTest,
PRE_TestOldModelRemovedOnModelUpdate) { … }
IN_PROC_BROWSER_TEST_F(PredictionModelStoreBrowserTest,
TestOldModelRemovedOnModelUpdate) { … }
IN_PROC_BROWSER_TEST_F(PredictionModelStoreBrowserTest,
TestInconsistentLocalState) { … }
}