diff options
author | dbeam <dbeam@chromium.org> | 2015-04-29 12:30:57 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-04-29 19:31:25 +0000 |
commit | f377cefbea76754a5a0eb43049640bb28bcff8dd (patch) | |
tree | 0cb63a4d601d906fc854a46abb4dbf8f3a165855 /components/content_settings | |
parent | fc58da521f25f9aeeeb9a59e89a9ce87dc78143f (diff) | |
download | chromium_src-f377cefbea76754a5a0eb43049640bb28bcff8dd.zip chromium_src-f377cefbea76754a5a0eb43049640bb28bcff8dd.tar.gz chromium_src-f377cefbea76754a5a0eb43049640bb28bcff8dd.tar.bz2 |
Add a field trial to enable plugin power saver for all users.
R=tommycli@chromium.org,bauerb@chromium.org
BUG=478918
Review URL: https://codereview.chromium.org/1112723002
Cr-Commit-Position: refs/heads/master@{#327546}
Diffstat (limited to 'components/content_settings')
3 files changed, 35 insertions, 24 deletions
diff --git a/components/content_settings/core/browser/plugins_field_trial.cc b/components/content_settings/core/browser/plugins_field_trial.cc index 98cd97a..6452eee 100644 --- a/components/content_settings/core/browser/plugins_field_trial.cc +++ b/components/content_settings/core/browser/plugins_field_trial.cc @@ -8,10 +8,15 @@ #include "base/metrics/field_trial.h" #include "components/plugins/common/plugins_switches.h" +using base::FieldTrialList; + namespace content_settings { // static -const char PluginsFieldTrial::kFieldTrialName[] = "ForcePluginPowerSaver"; +const char PluginsFieldTrial::kForceFieldTrial[] = "ForcePluginPowerSaver"; + +// static +const char PluginsFieldTrial::kEnableFieldTrial[] = "PluginPowerSaver"; // static ContentSetting PluginsFieldTrial::EffectiveContentSetting( @@ -29,14 +34,21 @@ ContentSetting PluginsFieldTrial::EffectiveContentSetting( // static bool PluginsFieldTrial::IsPluginPowerSaverEnabled() { + std::string enable_group = FieldTrialList::FindFullName(kEnableFieldTrial); + std::string force_group = FieldTrialList::FindFullName(kForceFieldTrial); + const base::CommandLine* cl = base::CommandLine::ForCurrentProcess(); if (cl->HasSwitch(plugins::switches::kDisablePluginPowerSaver)) return false; if (cl->HasSwitch(plugins::switches::kEnablePluginPowerSaver)) return true; - std::string group_name = base::FieldTrialList::FindFullName(kFieldTrialName); - return !group_name.empty() && group_name != "Disabled"; + if (!enable_group.empty() && enable_group != "Disabled") + return true; + if (!force_group.empty() && force_group != "Disabled") + return true; + + return false; } // static diff --git a/components/content_settings/core/browser/plugins_field_trial.h b/components/content_settings/core/browser/plugins_field_trial.h index ccc39df..eb7269c 100644 --- a/components/content_settings/core/browser/plugins_field_trial.h +++ b/components/content_settings/core/browser/plugins_field_trial.h @@ -14,7 +14,11 @@ namespace content_settings { // This class manages the Plugins field trials. class PluginsFieldTrial { public: - static const char kFieldTrialName[]; + // A legacy field trial used to dogfood Plugin Power Saver. Remove soon. + static const char kForceFieldTrial[]; + + // The field trial responsible for rolling out Plugin Power Saver to users. + static const char kEnableFieldTrial[]; // Returns the effective content setting for plugins. Passes non-plugin // content settings through without modification. diff --git a/components/content_settings/core/browser/plugins_field_trial_unittest.cc b/components/content_settings/core/browser/plugins_field_trial_unittest.cc index 052f8a5..b052d99 100644 --- a/components/content_settings/core/browser/plugins_field_trial_unittest.cc +++ b/components/content_settings/core/browser/plugins_field_trial_unittest.cc @@ -15,18 +15,12 @@ #include "components/pref_registry/testing_pref_service_syncable.h" #include "testing/gtest/include/gtest/gtest.h" -namespace content_settings { - -namespace { - -const auto& kFieldTrialName = PluginsFieldTrial::kFieldTrialName; +using base::FieldTrialList; -void ForceFieldTrialGroup(const std::string& group_name) { - using base::FieldTrialList; - ASSERT_TRUE(FieldTrialList::CreateFieldTrial(kFieldTrialName, group_name)); -} +namespace content_settings { -} // namespace +const char* kEnableFieldTrial = PluginsFieldTrial::kEnableFieldTrial; +const char* kForceFieldTrial = PluginsFieldTrial::kForceFieldTrial; class PluginsFieldTrialTest : public testing::Test { public: @@ -42,48 +36,49 @@ TEST_F(PluginsFieldTrialTest, DisabledByDefault) { base::CommandLine* cl = base::CommandLine::ForCurrentProcess(); ASSERT_FALSE(cl->HasSwitch(plugins::switches::kDisablePluginPowerSaver)); ASSERT_FALSE(cl->HasSwitch(plugins::switches::kEnablePluginPowerSaver)); - ASSERT_FALSE(base::FieldTrialList::TrialExists(kFieldTrialName)); + ASSERT_FALSE(base::FieldTrialList::TrialExists(kEnableFieldTrial)); + ASSERT_FALSE(base::FieldTrialList::TrialExists(kForceFieldTrial)); EXPECT_FALSE(PluginsFieldTrial::IsPluginPowerSaverEnabled()); } -TEST_F(PluginsFieldTrialTest, FieldTrialEnabled) { - ForceFieldTrialGroup("Enabled"); +TEST_F(PluginsFieldTrialTest, EnabledByFieldTrial) { + ASSERT_TRUE(FieldTrialList::CreateFieldTrial(kForceFieldTrial, "Dogfood")); EXPECT_TRUE(PluginsFieldTrial::IsPluginPowerSaverEnabled()); } -TEST_F(PluginsFieldTrialTest, FieldTrialDisabled) { - ForceFieldTrialGroup("Disabled"); +TEST_F(PluginsFieldTrialTest, DisabledByFieldTrial) { + ASSERT_TRUE(FieldTrialList::CreateFieldTrial(kEnableFieldTrial, "Disabled")); EXPECT_FALSE(PluginsFieldTrial::IsPluginPowerSaverEnabled()); } -TEST_F(PluginsFieldTrialTest, SwitchEnabled) { +TEST_F(PluginsFieldTrialTest, EnabledBySwitch) { base::CommandLine* cl = base::CommandLine::ForCurrentProcess(); cl->AppendSwitch(plugins::switches::kEnablePluginPowerSaver); EXPECT_TRUE(PluginsFieldTrial::IsPluginPowerSaverEnabled()); } -TEST_F(PluginsFieldTrialTest, SwitchDisabled) { +TEST_F(PluginsFieldTrialTest, DisabledBySwitch) { base::CommandLine* cl = base::CommandLine::ForCurrentProcess(); cl->AppendSwitch(plugins::switches::kDisablePluginPowerSaver); EXPECT_FALSE(PluginsFieldTrial::IsPluginPowerSaverEnabled()); } TEST_F(PluginsFieldTrialTest, SwitchOverridesFieldTrial1) { - ForceFieldTrialGroup("Disabled"); + ASSERT_TRUE(FieldTrialList::CreateFieldTrial(kForceFieldTrial, "Disabled")); base::CommandLine* cl = base::CommandLine::ForCurrentProcess(); cl->AppendSwitch(plugins::switches::kEnablePluginPowerSaver); EXPECT_TRUE(PluginsFieldTrial::IsPluginPowerSaverEnabled()); } TEST_F(PluginsFieldTrialTest, SwitchOverridesFieldTrial2) { - ForceFieldTrialGroup("Enabled"); + ASSERT_TRUE(FieldTrialList::CreateFieldTrial(kEnableFieldTrial, "Enabled")); base::CommandLine* cl = base::CommandLine::ForCurrentProcess(); cl->AppendSwitch(plugins::switches::kDisablePluginPowerSaver); EXPECT_FALSE(PluginsFieldTrial::IsPluginPowerSaverEnabled()); } TEST_F(PluginsFieldTrialTest, NoPrefLeftBehind) { - ForceFieldTrialGroup("Enabled"); + ASSERT_TRUE(FieldTrialList::CreateFieldTrial(kEnableFieldTrial, "Enabled")); user_prefs::TestingPrefServiceSyncable prefs; { DefaultProvider::RegisterProfilePrefs(prefs.registry()); |