#include "base/strings/string_util.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/test.pb.h"
#include "base/test/with_feature_override.h"
#include "build/build_config.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/metrics/chrome_metrics_service_accessor.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/signin/identity_test_environment_profile_adaptor.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/metrics_services_manager/metrics_services_manager.h"
#include "components/optimization_guide/core/feature_registry/feature_registration.h"
#include "components/optimization_guide/core/feature_registry/mqls_feature_registry.h"
#include "components/optimization_guide/core/model_execution/feature_keys.h"
#include "components/optimization_guide/core/model_execution/model_execution_features.h"
#include "components/optimization_guide/core/model_execution/model_execution_manager.h"
#include "components/optimization_guide/core/model_execution/model_execution_prefs.h"
#include "components/optimization_guide/core/model_execution/optimization_guide_model_execution_error.h"
#include "components/optimization_guide/core/model_quality/model_quality_log_entry.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_logger.h"
#include "components/optimization_guide/core/optimization_guide_switches.h"
#include "components/optimization_guide/core/optimization_guide_util.h"
#include "components/optimization_guide/proto/model_quality_service.pb.h"
#include "components/policy/core/browser/browser_policy_connector.h"
#include "components/policy/core/common/mock_configuration_policy_provider.h"
#include "components/policy/core/common/policy_map.h"
#include "components/policy/policy_constants.h"
#include "components/signin/public/base/signin_switches.h"
#include "components/signin/public/identity_manager/account_capabilities_test_mutator.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "net/dns/mock_host_resolver.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "third_party/tflite/buildflags.h"
namespace optimization_guide {
namespace {
enum class ModelExecutionRemoteResponseType { … };
proto::ExecuteResponse BuildComposeResponse(const std::string& output) { … }
proto::ExecuteResponse BuildTestErrorExecuteResponse(
const proto::ErrorState& state) { … }
class ScopedSetMetricsConsent { … };
}
class ModelExecutionBrowserTestBase : public InProcessBrowserTest { … };
class ModelExecutionDisabledBrowserTest : public ModelExecutionBrowserTestBase { … };
IN_PROC_BROWSER_TEST_F(ModelExecutionDisabledBrowserTest,
ModelExecutionDisabled) { … }
IN_PROC_BROWSER_TEST_F(ModelExecutionDisabledBrowserTest,
CanCreateOnDeviceSessionExecutionDisabled) { … }
IN_PROC_BROWSER_TEST_F(
ModelExecutionDisabledBrowserTest,
CanCreateOnDeviceSessionExecutionDisabledNullDebugReason) { … }
class ModelExecutionEnabledOnDeviceDisabledBrowserTest
: public ModelExecutionBrowserTestBase { … };
IN_PROC_BROWSER_TEST_F(ModelExecutionEnabledOnDeviceDisabledBrowserTest,
CanCreateOnDeviceSessionOnDeviceDisabled) { … }
IN_PROC_BROWSER_TEST_F(
ModelExecutionEnabledOnDeviceDisabledBrowserTest,
CanCreateOnDeviceSessionExecutionDisabledNullDebugReason) { … }
class ModelExecutionEnabledBrowserTest : public ModelExecutionBrowserTestBase { … };
IN_PROC_BROWSER_TEST_F(ModelExecutionEnabledBrowserTest,
ModelExecutionDisabledInIncognito) { … }
IN_PROC_BROWSER_TEST_F(ModelExecutionEnabledBrowserTest,
ModelExecutionFailsNoUserSignIn) { … }
IN_PROC_BROWSER_TEST_F(ModelExecutionEnabledBrowserTest,
ModelExecutionSuccess) { … }
IN_PROC_BROWSER_TEST_F(ModelExecutionEnabledBrowserTest,
ModelExecutionFailsForUnsuccessfulResponse) { … }
IN_PROC_BROWSER_TEST_F(ModelExecutionEnabledBrowserTest,
ModelExecutionFailsForMalformedResponse) { … }
IN_PROC_BROWSER_TEST_F(ModelExecutionEnabledBrowserTest,
ModelExecutionFailsForErrorFilteredResponse) { … }
IN_PROC_BROWSER_TEST_F(ModelExecutionEnabledBrowserTest,
ModelExecutionFailsForUnsupportedLanguageResponse) { … }
IN_PROC_BROWSER_TEST_F(ModelExecutionEnabledBrowserTest,
CanCreateOnDeviceSessionNoModelAvailable) { … }
IN_PROC_BROWSER_TEST_F(
ModelExecutionEnabledBrowserTest,
CanCreateOnDeviceSessionExecutionDisabledNullDebugReason) { … }
class ModelExecutionInternalsPageBrowserTest
: public ModelExecutionEnabledBrowserTest { … };
IN_PROC_BROWSER_TEST_F(ModelExecutionInternalsPageBrowserTest,
LoggedInInternalsPage) { … }
class ModelExecutionEnabledBrowserTestWithExplicitBrowserSignin
: public ModelExecutionEnabledBrowserTest { … };
IN_PROC_BROWSER_TEST_F(
ModelExecutionEnabledBrowserTestWithExplicitBrowserSignin,
PRE_EnableFeatureViaPref) { … }
IN_PROC_BROWSER_TEST_F(
ModelExecutionEnabledBrowserTestWithExplicitBrowserSignin,
EnableFeatureViaPref) { … }
IN_PROC_BROWSER_TEST_F(
ModelExecutionEnabledBrowserTestWithExplicitBrowserSignin,
PRE_HistorySearchRecordsSyntheticFieldTrial) { … }
IN_PROC_BROWSER_TEST_F(
ModelExecutionEnabledBrowserTestWithExplicitBrowserSignin,
HistorySearchRecordsSyntheticFieldTrial) { … }
class ModelExecutionComposeLoggingDisabledTest
: public ModelExecutionEnabledBrowserTest { … };
IN_PROC_BROWSER_TEST_F(ModelExecutionComposeLoggingDisabledTest,
LoggingForFeatureNotEnabled) { … }
class ModelExecutionNewFeaturesEnabledAutomaticallyTest
: public ModelExecutionEnabledBrowserTest { … };
IN_PROC_BROWSER_TEST_F(ModelExecutionNewFeaturesEnabledAutomaticallyTest,
PRE_NewFeaturesEnabledWhenMainToggleEnabled) { … }
IN_PROC_BROWSER_TEST_F(ModelExecutionNewFeaturesEnabledAutomaticallyTest,
NewFeaturesEnabledWhenMainToggleEnabled) { … }
#if !BUILDFLAG(IS_ANDROID)
class ModelExecutionEnterprisePolicyBrowserTest
: public ModelExecutionEnabledBrowserTest { … };
IN_PROC_BROWSER_TEST_F(ModelExecutionEnterprisePolicyBrowserTest,
DisableThenEnable) { … }
IN_PROC_BROWSER_TEST_F(ModelExecutionEnterprisePolicyBrowserTest,
DisableThenEnableCompose) { … }
IN_PROC_BROWSER_TEST_F(ModelExecutionEnterprisePolicyBrowserTest,
EnableComposeWithoutLogging) { … }
IN_PROC_BROWSER_TEST_F(ModelExecutionEnterprisePolicyBrowserTest,
DisableThenEnableWallpaperSearch) { … }
IN_PROC_BROWSER_TEST_F(ModelExecutionEnterprisePolicyBrowserTest,
EnableTabOrganizationWithoutLogging) { … }
#endif
}