Refactor the storage layer out of about_flags.

This step is a preparation for moving owner flags storage from local state to
signed settings.

BUG=221353
TEST=existing about_flags tests still pass.

Review URL: https://chromiumcodereview.appspot.com/16542004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@205854 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/browser/about_flags_unittest.cc b/chrome/browser/about_flags_unittest.cc
index 4251cff..0c94f450 100644
--- a/chrome/browser/about_flags_unittest.cc
+++ b/chrome/browser/about_flags_unittest.cc
@@ -8,6 +8,7 @@
 #include "base/strings/utf_string_conversions.h"
 #include "base/values.h"
 #include "chrome/browser/about_flags.h"
+#include "chrome/browser/pref_service_flags_storage.h"
 #include "chrome/common/chrome_switches.h"
 #include "chrome/common/pref_names.h"
 #include "grit/chromium_strings.h"
@@ -111,7 +112,7 @@
 
 class AboutFlagsTest : public ::testing::Test {
  protected:
-  AboutFlagsTest() {
+  AboutFlagsTest() : flags_storage_(&prefs_) {
     prefs_.registry()->RegisterListPref(prefs::kEnabledLabsExperiments);
     testing::ClearState();
   }
@@ -133,18 +134,19 @@
   }
 
   TestingPrefServiceSimple prefs_;
+  PrefServiceFlagsStorage flags_storage_;
 };
 
 
 TEST_F(AboutFlagsTest, NoChangeNoRestart) {
   EXPECT_FALSE(IsRestartNeededToCommitChanges());
-  SetExperimentEnabled(&prefs_, kFlags1, false);
+  SetExperimentEnabled(&flags_storage_, kFlags1, false);
   EXPECT_FALSE(IsRestartNeededToCommitChanges());
 }
 
 TEST_F(AboutFlagsTest, ChangeNeedsRestart) {
   EXPECT_FALSE(IsRestartNeededToCommitChanges());
-  SetExperimentEnabled(&prefs_, kFlags1, true);
+  SetExperimentEnabled(&flags_storage_, kFlags1, true);
   EXPECT_TRUE(IsRestartNeededToCommitChanges());
 }
 
@@ -153,19 +155,19 @@
   ASSERT_EQ(kFlags4, experiment.internal_name);
   EXPECT_FALSE(IsRestartNeededToCommitChanges());
   // Enable the 2nd choice of the multi-value.
-  SetExperimentEnabled(&prefs_, experiment.NameForChoice(2), true);
+  SetExperimentEnabled(&flags_storage_, experiment.NameForChoice(2), true);
   EXPECT_TRUE(IsRestartNeededToCommitChanges());
   testing::ClearState();
   EXPECT_FALSE(IsRestartNeededToCommitChanges());
   // Enable the default choice now.
-  SetExperimentEnabled(&prefs_, experiment.NameForChoice(0), true);
+  SetExperimentEnabled(&flags_storage_, experiment.NameForChoice(0), true);
   EXPECT_TRUE(IsRestartNeededToCommitChanges());
 }
 
 TEST_F(AboutFlagsTest, AddTwoFlagsRemoveOne) {
   // Add two experiments, check they're there.
-  SetExperimentEnabled(&prefs_, kFlags1, true);
-  SetExperimentEnabled(&prefs_, kFlags2, true);
+  SetExperimentEnabled(&flags_storage_, kFlags1, true);
+  SetExperimentEnabled(&flags_storage_, kFlags2, true);
 
   const ListValue* experiments_list = prefs_.GetList(
       prefs::kEnabledLabsExperiments);
@@ -182,7 +184,7 @@
   EXPECT_TRUE(s0 == kFlags2 || s1 == kFlags2);
 
   // Remove one experiment, check the other's still around.
-  SetExperimentEnabled(&prefs_, kFlags2, false);
+  SetExperimentEnabled(&flags_storage_, kFlags2, false);
 
   experiments_list = prefs_.GetList(prefs::kEnabledLabsExperiments);
   ASSERT_TRUE(experiments_list != NULL);
@@ -193,21 +195,21 @@
 
 TEST_F(AboutFlagsTest, AddTwoFlagsRemoveBoth) {
   // Add two experiments, check the pref exists.
-  SetExperimentEnabled(&prefs_, kFlags1, true);
-  SetExperimentEnabled(&prefs_, kFlags2, true);
+  SetExperimentEnabled(&flags_storage_, kFlags1, true);
+  SetExperimentEnabled(&flags_storage_, kFlags2, true);
   const ListValue* experiments_list = prefs_.GetList(
       prefs::kEnabledLabsExperiments);
   ASSERT_TRUE(experiments_list != NULL);
 
   // Remove both, the pref should have been removed completely.
-  SetExperimentEnabled(&prefs_, kFlags1, false);
-  SetExperimentEnabled(&prefs_, kFlags2, false);
+  SetExperimentEnabled(&flags_storage_, kFlags1, false);
+  SetExperimentEnabled(&flags_storage_, kFlags2, false);
   experiments_list = prefs_.GetList(prefs::kEnabledLabsExperiments);
   EXPECT_TRUE(experiments_list == NULL || experiments_list->GetSize() == 0);
 }
 
 TEST_F(AboutFlagsTest, ConvertFlagsToSwitches) {
-  SetExperimentEnabled(&prefs_, kFlags1, true);
+  SetExperimentEnabled(&flags_storage_, kFlags1, true);
 
   CommandLine command_line(CommandLine::NO_PROGRAM);
   command_line.AppendSwitch("foo");
@@ -215,7 +217,7 @@
   EXPECT_TRUE(command_line.HasSwitch("foo"));
   EXPECT_FALSE(command_line.HasSwitch(kSwitch1));
 
-  ConvertFlagsToSwitches(&prefs_, &command_line);
+  ConvertFlagsToSwitches(&flags_storage_, &command_line);
 
   EXPECT_TRUE(command_line.HasSwitch("foo"));
   EXPECT_TRUE(command_line.HasSwitch(kSwitch1));
@@ -228,7 +230,7 @@
   switch_list[switches::kFlagSwitchesEnd] = CommandLine::StringType();
   switch_list["foo"] = CommandLine::StringType();
 
-  SetExperimentEnabled(&prefs_, kFlags1, true);
+  SetExperimentEnabled(&flags_storage_, kFlags1, true);
 
   // This shouldn't do anything before ConvertFlagsToSwitches() wasn't called.
   RemoveFlagsSwitches(&switch_list);
@@ -243,7 +245,7 @@
   // Call ConvertFlagsToSwitches(), then RemoveFlagsSwitches() again.
   CommandLine command_line(CommandLine::NO_PROGRAM);
   command_line.AppendSwitch("foo");
-  ConvertFlagsToSwitches(&prefs_, &command_line);
+  ConvertFlagsToSwitches(&flags_storage_, &command_line);
   RemoveFlagsSwitches(&switch_list);
 
   // Now the about:flags-related switch should have been removed.
@@ -254,15 +256,15 @@
 // Tests enabling experiments that aren't supported on the current platform.
 TEST_F(AboutFlagsTest, PersistAndPrune) {
   // Enable experiments 1 and 3.
-  SetExperimentEnabled(&prefs_, kFlags1, true);
-  SetExperimentEnabled(&prefs_, kFlags3, true);
+  SetExperimentEnabled(&flags_storage_, kFlags1, true);
+  SetExperimentEnabled(&flags_storage_, kFlags3, true);
   CommandLine command_line(CommandLine::NO_PROGRAM);
   EXPECT_FALSE(command_line.HasSwitch(kSwitch1));
   EXPECT_FALSE(command_line.HasSwitch(kSwitch3));
 
   // Convert the flags to switches. Experiment 3 shouldn't be among the switches
   // as it is not applicable to the current platform.
-  ConvertFlagsToSwitches(&prefs_, &command_line);
+  ConvertFlagsToSwitches(&flags_storage_, &command_line);
   EXPECT_TRUE(command_line.HasSwitch(kSwitch1));
   EXPECT_FALSE(command_line.HasSwitch(kSwitch3));
 
@@ -283,14 +285,14 @@
 // line.
 TEST_F(AboutFlagsTest, CheckValues) {
   // Enable experiments 1 and 2.
-  SetExperimentEnabled(&prefs_, kFlags1, true);
-  SetExperimentEnabled(&prefs_, kFlags2, true);
+  SetExperimentEnabled(&flags_storage_, kFlags1, true);
+  SetExperimentEnabled(&flags_storage_, kFlags2, true);
   CommandLine command_line(CommandLine::NO_PROGRAM);
   EXPECT_FALSE(command_line.HasSwitch(kSwitch1));
   EXPECT_FALSE(command_line.HasSwitch(kSwitch2));
 
   // Convert the flags to switches.
-  ConvertFlagsToSwitches(&prefs_, &command_line);
+  ConvertFlagsToSwitches(&flags_storage_, &command_line);
   EXPECT_TRUE(command_line.HasSwitch(kSwitch1));
   EXPECT_EQ(std::string(), command_line.GetSwitchValueASCII(kSwitch1));
   EXPECT_TRUE(command_line.HasSwitch(kSwitch2));
@@ -345,16 +347,16 @@
   // be set.
   {
     CommandLine command_line(CommandLine::NO_PROGRAM);
-    ConvertFlagsToSwitches(&prefs_, &command_line);
+    ConvertFlagsToSwitches(&flags_storage_, &command_line);
     EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch1));
     EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch2));
   }
 
   // Enable the 2nd choice of the multi-value.
-  SetExperimentEnabled(&prefs_, experiment.NameForChoice(2), true);
+  SetExperimentEnabled(&flags_storage_, experiment.NameForChoice(2), true);
   {
     CommandLine command_line(CommandLine::NO_PROGRAM);
-    ConvertFlagsToSwitches(&prefs_, &command_line);
+    ConvertFlagsToSwitches(&flags_storage_, &command_line);
     EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch1));
     EXPECT_TRUE(command_line.HasSwitch(kMultiSwitch2));
     EXPECT_EQ(std::string(kValueForMultiSwitch2),
@@ -362,10 +364,10 @@
   }
 
   // Disable the multi-value experiment.
-  SetExperimentEnabled(&prefs_, experiment.NameForChoice(0), true);
+  SetExperimentEnabled(&flags_storage_, experiment.NameForChoice(0), true);
   {
     CommandLine command_line(CommandLine::NO_PROGRAM);
-    ConvertFlagsToSwitches(&prefs_, &command_line);
+    ConvertFlagsToSwitches(&flags_storage_, &command_line);
     EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch1));
     EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch2));
   }
@@ -378,36 +380,36 @@
   // Nothing selected.
   {
     CommandLine command_line(CommandLine::NO_PROGRAM);
-    ConvertFlagsToSwitches(&prefs_, &command_line);
+    ConvertFlagsToSwitches(&flags_storage_, &command_line);
     EXPECT_FALSE(command_line.HasSwitch(kSwitch1));
     EXPECT_FALSE(command_line.HasSwitch(kSwitch2));
   }
 
   // "Enable" option selected.
-  SetExperimentEnabled(&prefs_, experiment.NameForChoice(1), true);
+  SetExperimentEnabled(&flags_storage_, experiment.NameForChoice(1), true);
   {
     CommandLine command_line(CommandLine::NO_PROGRAM);
-    ConvertFlagsToSwitches(&prefs_, &command_line);
+    ConvertFlagsToSwitches(&flags_storage_, &command_line);
     EXPECT_TRUE(command_line.HasSwitch(kSwitch1));
     EXPECT_FALSE(command_line.HasSwitch(kSwitch2));
     EXPECT_EQ(kEnableDisableValue1, command_line.GetSwitchValueASCII(kSwitch1));
   }
 
   // "Disable" option selected.
-  SetExperimentEnabled(&prefs_, experiment.NameForChoice(2), true);
+  SetExperimentEnabled(&flags_storage_, experiment.NameForChoice(2), true);
   {
     CommandLine command_line(CommandLine::NO_PROGRAM);
-    ConvertFlagsToSwitches(&prefs_, &command_line);
+    ConvertFlagsToSwitches(&flags_storage_, &command_line);
     EXPECT_FALSE(command_line.HasSwitch(kSwitch1));
     EXPECT_TRUE(command_line.HasSwitch(kSwitch2));
     EXPECT_EQ(kEnableDisableValue2, command_line.GetSwitchValueASCII(kSwitch2));
   }
 
   // "Default" option selected, same as nothing selected.
-  SetExperimentEnabled(&prefs_, experiment.NameForChoice(0), true);
+  SetExperimentEnabled(&flags_storage_, experiment.NameForChoice(0), true);
   {
     CommandLine command_line(CommandLine::NO_PROGRAM);
-    ConvertFlagsToSwitches(&prefs_, &command_line);
+    ConvertFlagsToSwitches(&flags_storage_, &command_line);
     EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch1));
     EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch2));
   }