#include "base/test/bind.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.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/e2e_tests/account_capabilities_observer.h"
#include "chrome/browser/signin/e2e_tests/live_test.h"
#include "chrome/browser/signin/e2e_tests/signin_util.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "components/optimization_guide/core/model_execution/model_execution_features.h"
#include "components/optimization_guide/core/optimization_guide_features.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "ui/compositor/scoped_animation_duration_scale_mode.h"
namespace optimization_guide {
#if 0
class ModelExecutionLiveTest : public signin::test::LiveTest {
public:
ModelExecutionLiveTest() = default;
~ModelExecutionLiveTest() override = default;
void SetUp() override {
scoped_feature_list_.InitWithFeatures(
{features::kOptimizationGuideModelExecution,
features::internal::kTabOrganizationSettingsVisibility},
{});
LiveTest::SetUp();
ui::ScopedAnimationDurationScaleMode disable_animation(
ui::ScopedAnimationDurationScaleMode::ZERO_DURATION);
}
OptimizationGuideKeyedService* GetOptGuideKeyedService() {
return OptimizationGuideKeyedServiceFactory::GetForProfile(
browser()->profile());
}
bool IsSettingVisible(optimization_guide::UserVisibleFeatureKey feature) {
return GetOptGuideKeyedService()->IsSettingVisible(feature);
}
syncer::SyncService* sync_service() {
return signin::test::sync_service(browser());
}
protected:
base::test::ScopedFeatureList scoped_feature_list_;
base::HistogramTester histogram_tester_;
signin::test::SignInFunctions sign_in_functions =
signin::test::SignInFunctions(
base::BindLambdaForTesting(
[this]() -> Browser* { return this->browser(); }),
base::BindLambdaForTesting(
[this](int index,
const GURL& url,
ui::PageTransition transition) -> bool {
return this->AddTabAtIndex(index, url, transition);
}));
};
IN_PROC_BROWSER_TEST_F(ModelExecutionLiveTest, PRE_SimpleSyncFlow) {
signin::test::TestAccount ta;
CHECK(GetTestAccountsUtil()->GetAccount("TEST_ACCOUNT_1", ta));
sign_in_functions.TurnOnSync(ta, 0);
EXPECT_TRUE(sync_service()->IsSyncFeatureEnabled());
EXPECT_TRUE(IsSettingVisible(
UserVisibleFeatureKey::kTabOrganization));
histogram_tester_.ExpectBucketCount(
"OptimizationGuide.ModelExecution.SettingsVisibilityResult."
"TabOrganization",
ModelExecutionFeaturesController::SettingsVisibilityResult::
kVisibleFieldTrialEnabled,
1);
}
IN_PROC_BROWSER_TEST_F(ModelExecutionLiveTest, SimpleSyncFlow) {
signin::test::TestAccount ta;
CHECK(GetTestAccountsUtil()->GetAccount("TEST_ACCOUNT_1", ta));
EXPECT_TRUE(sync_service()->IsSyncFeatureEnabled());
EXPECT_TRUE(IsSettingVisible(
UserVisibleFeatureKey::kTabOrganization));
histogram_tester_.ExpectBucketCount(
"OptimizationGuide.ModelExecution.SettingsVisibilityResult."
"TabOrganization",
ModelExecutionFeaturesController::SettingsVisibilityResult::
kVisibleFieldTrialEnabled,
1);
}
IN_PROC_BROWSER_TEST_F(ModelExecutionLiveTest,
PRE_SimpleSyncFlowForMinorAccount) {
signin::test::TestAccount ta;
CHECK(GetTestAccountsUtil()->GetAccount("TEST_ACCOUNT_MINOR", ta));
sign_in_functions.TurnOnSync(ta, 0);
EXPECT_TRUE(sync_service()->IsSyncFeatureEnabled());
EXPECT_FALSE(IsSettingVisible(
UserVisibleFeatureKey::kTabOrganization));
histogram_tester_.ExpectBucketCount(
"OptimizationGuide.ModelExecution.SettingsVisibilityResult."
"TabOrganization",
ModelExecutionFeaturesController::SettingsVisibilityResult::
kNotVisibleModelExecutionCapability,
1);
}
IN_PROC_BROWSER_TEST_F(ModelExecutionLiveTest,
SimpleSyncFlowForMinorAccount) {
signin::test::TestAccount ta;
CHECK(GetTestAccountsUtil()->GetAccount("TEST_ACCOUNT_MINOR", ta));
EXPECT_TRUE(sync_service()->IsSyncFeatureEnabled());
EXPECT_FALSE(IsSettingVisible(
UserVisibleFeatureKey::kTabOrganization));
histogram_tester_.ExpectBucketCount(
"OptimizationGuide.ModelExecution.SettingsVisibilityResult."
"TabOrganization",
ModelExecutionFeaturesController::SettingsVisibilityResult::
kNotVisibleModelExecutionCapability,
1);
}
#endif
}