Home | History | Annotate | Download | only in prefs
      1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #include <set>
      6 #include <string>
      7 
      8 #include "base/memory/scoped_ptr.h"
      9 #include "base/values.h"
     10 #include "chrome/browser/policy/configuration_policy_pref_store.h"
     11 #include "chrome/browser/policy/dummy_configuration_policy_provider.h"
     12 #include "chrome/browser/prefs/pref_notifier.h"
     13 #include "chrome/browser/prefs/pref_value_store.h"
     14 #include "chrome/browser/prefs/testing_pref_store.h"
     15 #include "chrome/common/pref_names.h"
     16 #include "content/browser/browser_thread.h"
     17 #include "testing/gmock/include/gmock/gmock.h"
     18 #include "testing/gtest/include/gtest/gtest.h"
     19 
     20 using testing::_;
     21 using testing::AnyNumber;
     22 using testing::Mock;
     23 using testing::Invoke;
     24 
     25 namespace {
     26 
     27 // Allows to capture pref notifications through gmock.
     28 class MockPrefNotifier : public PrefNotifier {
     29  public:
     30   MOCK_METHOD1(OnPreferenceChanged, void(const std::string&));
     31   MOCK_METHOD0(OnInitializationCompleted, void());
     32 };
     33 
     34 }  // namespace
     35 
     36 // Names of the preferences used in this test.
     37 namespace prefs {
     38 const char kManagedPlatformPref[] = "this.pref.managed_platform";
     39 const char kManagedCloudPref[] = "this.pref.managed_cloud";
     40 const char kCommandLinePref[] = "this.pref.command_line";
     41 const char kExtensionPref[] = "this.pref.extension";
     42 const char kUserPref[] = "this.pref.user";
     43 const char kRecommendedPlatformPref[] = "this.pref.recommended_platform";
     44 const char kRecommendedCloudPref[] = "this.pref.recommended_cloud";
     45 const char kDefaultPref[] = "this.pref.default";
     46 const char kMissingPref[] = "this.pref.does_not_exist";
     47 }
     48 
     49 // Potentially expected values of all preferences used in this test program.
     50 namespace managed_platform_pref {
     51 const char kManagedPlatformValue[] = "managed_platform:managed_platform";
     52 }
     53 
     54 namespace managed_cloud_pref {
     55 const char kManagedPlatformValue[] = "managed_cloud:managed_platform";
     56 const char kManagedCloudValue[] = "managed_cloud:managed_cloud";
     57 }
     58 
     59 namespace extension_pref {
     60 const char kManagedPlatformValue[] = "extension:managed_platform";
     61 const char kManagedCloudValue[] = "extension:managed_cloud";
     62 const char kExtensionValue[] = "extension:extension";
     63 }
     64 
     65 namespace command_line_pref {
     66 const char kManagedPlatformValue[] = "command_line:managed_platform";
     67 const char kManagedCloudValue[] = "command_line:managed_cloud";
     68 const char kExtensionValue[] = "command_line:extension";
     69 const char kCommandLineValue[] = "command_line:command_line";
     70 }
     71 
     72 namespace user_pref {
     73 const char kManagedPlatformValue[] = "user:managed_platform";
     74 const char kManagedCloudValue[] = "user:managed_cloud";
     75 const char kExtensionValue[] = "user:extension";
     76 const char kCommandLineValue[] = "user:command_line";
     77 const char kUserValue[] = "user:user";
     78 }
     79 
     80 namespace recommended_platform_pref {
     81 const char kManagedPlatformValue[] = "recommended_platform:managed_platform";
     82 const char kManagedCloudValue[] = "recommended_platform:managed_cloud";
     83 const char kExtensionValue[] = "recommended_platform:extension";
     84 const char kCommandLineValue[] = "recommended_platform:command_line";
     85 const char kUserValue[] = "recommended_platform:user";
     86 const char kRecommendedPlatformValue[] =
     87     "recommended_platform:recommended_platform";
     88 }
     89 
     90 namespace recommended_cloud_pref {
     91 const char kManagedPlatformValue[] = "recommended_cloud:managed_platform";
     92 const char kManagedCloudValue[] = "recommended_cloud:managed_cloud";
     93 const char kExtensionValue[] = "recommended_cloud:extension";
     94 const char kCommandLineValue[] = "recommended_cloud:command_line";
     95 const char kUserValue[] = "recommended_cloud:user";
     96 const char kRecommendedPlatformValue[] =
     97     "recommended_cloud:recommended_platform";
     98 const char kRecommendedCloudValue[] = "recommended_cloud:recommended_cloud";
     99 }
    100 
    101 namespace default_pref {
    102 const char kManagedPlatformValue[] = "default:managed_platform";
    103 const char kManagedCloudValue[] = "default:managed_cloud";
    104 const char kExtensionValue[] = "default:extension";
    105 const char kCommandLineValue[] = "default:command_line";
    106 const char kUserValue[] = "default:user";
    107 const char kRecommendedPlatformValue[] = "default:recommended_platform";
    108 const char kRecommendedCloudValue[] = "default:recommended_cloud";
    109 const char kDefaultValue[] = "default:default";
    110 }
    111 
    112 class PrefValueStoreTest : public testing::Test {
    113  protected:
    114   virtual void SetUp() {
    115     // Create TestingPrefStores.
    116     CreateManagedPlatformPrefs();
    117     CreateManagedCloudPrefs();
    118     CreateExtensionPrefs();
    119     CreateCommandLinePrefs();
    120     CreateUserPrefs();
    121     CreateRecommendedPlatformPrefs();
    122     CreateRecommendedCloudPrefs();
    123     CreateDefaultPrefs();
    124 
    125     // Create a fresh PrefValueStore.
    126     pref_value_store_.reset(new PrefValueStore(
    127         managed_platform_pref_store_,
    128         managed_cloud_pref_store_,
    129         extension_pref_store_,
    130         command_line_pref_store_,
    131         user_pref_store_,
    132         recommended_platform_pref_store_,
    133         recommended_cloud_pref_store_,
    134         default_pref_store_,
    135         &pref_notifier_));
    136   }
    137 
    138   void CreateManagedPlatformPrefs() {
    139     managed_platform_pref_store_ = new TestingPrefStore;
    140     managed_platform_pref_store_->SetString(
    141         prefs::kManagedPlatformPref,
    142         managed_platform_pref::kManagedPlatformValue);
    143   }
    144 
    145   void CreateManagedCloudPrefs() {
    146     managed_cloud_pref_store_ = new TestingPrefStore;
    147     managed_cloud_pref_store_->SetString(
    148         prefs::kManagedPlatformPref,
    149         managed_cloud_pref::kManagedPlatformValue);
    150     managed_cloud_pref_store_->SetString(
    151         prefs::kManagedCloudPref,
    152         managed_cloud_pref::kManagedCloudValue);
    153   }
    154 
    155   void CreateExtensionPrefs() {
    156     extension_pref_store_ = new TestingPrefStore;
    157     extension_pref_store_->SetString(
    158         prefs::kManagedPlatformPref,
    159         extension_pref::kManagedPlatformValue);
    160     extension_pref_store_->SetString(
    161         prefs::kManagedCloudPref,
    162         extension_pref::kManagedCloudValue);
    163     extension_pref_store_->SetString(
    164         prefs::kExtensionPref,
    165         extension_pref::kExtensionValue);
    166   }
    167 
    168   void CreateCommandLinePrefs() {
    169     command_line_pref_store_ = new TestingPrefStore;
    170     command_line_pref_store_->SetString(
    171         prefs::kManagedPlatformPref,
    172         command_line_pref::kManagedPlatformValue);
    173     command_line_pref_store_->SetString(
    174         prefs::kManagedCloudPref,
    175         command_line_pref::kManagedCloudValue);
    176     command_line_pref_store_->SetString(
    177         prefs::kExtensionPref,
    178         command_line_pref::kExtensionValue);
    179     command_line_pref_store_->SetString(
    180         prefs::kCommandLinePref,
    181         command_line_pref::kCommandLineValue);
    182   }
    183 
    184   void CreateUserPrefs() {
    185     user_pref_store_ = new TestingPrefStore;
    186     user_pref_store_->SetString(
    187         prefs::kManagedPlatformPref,
    188         user_pref::kManagedPlatformValue);
    189     user_pref_store_->SetString(
    190         prefs::kManagedCloudPref,
    191         user_pref::kManagedCloudValue);
    192     user_pref_store_->SetString(
    193         prefs::kCommandLinePref,
    194         user_pref::kCommandLineValue);
    195     user_pref_store_->SetString(
    196         prefs::kExtensionPref,
    197         user_pref::kExtensionValue);
    198     user_pref_store_->SetString(
    199         prefs::kUserPref,
    200         user_pref::kUserValue);
    201   }
    202 
    203   void CreateRecommendedPlatformPrefs() {
    204     recommended_platform_pref_store_ = new TestingPrefStore;
    205     recommended_platform_pref_store_->SetString(
    206         prefs::kManagedPlatformPref,
    207         recommended_platform_pref::kManagedPlatformValue);
    208     recommended_platform_pref_store_->SetString(
    209         prefs::kManagedCloudPref,
    210         recommended_platform_pref::kManagedCloudValue);
    211     recommended_platform_pref_store_->SetString(
    212         prefs::kCommandLinePref,
    213         recommended_platform_pref::kCommandLineValue);
    214     recommended_platform_pref_store_->SetString(
    215         prefs::kExtensionPref,
    216         recommended_platform_pref::kExtensionValue);
    217     recommended_platform_pref_store_->SetString(
    218         prefs::kUserPref,
    219         recommended_platform_pref::kUserValue);
    220     recommended_platform_pref_store_->SetString(
    221         prefs::kRecommendedPlatformPref,
    222         recommended_platform_pref::kRecommendedPlatformValue);
    223   }
    224 
    225   void CreateRecommendedCloudPrefs() {
    226     recommended_cloud_pref_store_ = new TestingPrefStore;
    227     recommended_cloud_pref_store_->SetString(
    228         prefs::kManagedPlatformPref,
    229         recommended_cloud_pref::kManagedPlatformValue);
    230     recommended_cloud_pref_store_->SetString(
    231         prefs::kManagedCloudPref,
    232         recommended_cloud_pref::kManagedCloudValue);
    233     recommended_cloud_pref_store_->SetString(
    234         prefs::kCommandLinePref,
    235         recommended_cloud_pref::kCommandLineValue);
    236     recommended_cloud_pref_store_->SetString(
    237         prefs::kExtensionPref,
    238         recommended_cloud_pref::kExtensionValue);
    239     recommended_cloud_pref_store_->SetString(
    240         prefs::kUserPref,
    241         recommended_cloud_pref::kUserValue);
    242     recommended_cloud_pref_store_->SetString(
    243         prefs::kRecommendedPlatformPref,
    244         recommended_cloud_pref::kRecommendedPlatformValue);
    245     recommended_cloud_pref_store_->SetString(
    246         prefs::kRecommendedCloudPref,
    247         recommended_cloud_pref::kRecommendedCloudValue);
    248   }
    249 
    250   void CreateDefaultPrefs() {
    251     default_pref_store_ = new TestingPrefStore;
    252     default_pref_store_->SetString(
    253         prefs::kManagedPlatformPref,
    254         default_pref::kManagedPlatformValue);
    255     default_pref_store_->SetString(
    256         prefs::kManagedCloudPref,
    257         default_pref::kManagedCloudValue);
    258     default_pref_store_->SetString(
    259         prefs::kCommandLinePref,
    260         default_pref::kCommandLineValue);
    261     default_pref_store_->SetString(
    262         prefs::kExtensionPref,
    263         default_pref::kExtensionValue);
    264     default_pref_store_->SetString(
    265         prefs::kUserPref,
    266         default_pref::kUserValue);
    267     default_pref_store_->SetString(
    268         prefs::kRecommendedPlatformPref,
    269         default_pref::kRecommendedPlatformValue);
    270     default_pref_store_->SetString(
    271         prefs::kRecommendedCloudPref,
    272         default_pref::kRecommendedCloudValue);
    273     default_pref_store_->SetString(
    274         prefs::kDefaultPref,
    275         default_pref::kDefaultValue);
    276   }
    277 
    278   MockPrefNotifier pref_notifier_;
    279   scoped_ptr<PrefValueStore> pref_value_store_;
    280 
    281   scoped_refptr<TestingPrefStore> managed_platform_pref_store_;
    282   scoped_refptr<TestingPrefStore> managed_cloud_pref_store_;
    283   scoped_refptr<TestingPrefStore> extension_pref_store_;
    284   scoped_refptr<TestingPrefStore> command_line_pref_store_;
    285   scoped_refptr<TestingPrefStore> user_pref_store_;
    286   scoped_refptr<TestingPrefStore> recommended_platform_pref_store_;
    287   scoped_refptr<TestingPrefStore> recommended_cloud_pref_store_;
    288   scoped_refptr<TestingPrefStore> default_pref_store_;
    289 };
    290 
    291 TEST_F(PrefValueStoreTest, GetValue) {
    292   const Value* value;
    293 
    294   // The following tests read a value from the PrefService. The preferences are
    295   // set in a way such that all lower-priority stores have a value and we can
    296   // test whether overrides work correctly.
    297 
    298   // Test getting a managed platform value.
    299   value = NULL;
    300   ASSERT_TRUE(pref_value_store_->GetValue(prefs::kManagedPlatformPref,
    301                                           Value::TYPE_STRING, &value));
    302   std::string actual_str_value;
    303   EXPECT_TRUE(value->GetAsString(&actual_str_value));
    304   EXPECT_EQ(managed_platform_pref::kManagedPlatformValue, actual_str_value);
    305 
    306   // Test getting a managed cloud value.
    307   value = NULL;
    308   ASSERT_TRUE(pref_value_store_->GetValue(prefs::kManagedCloudPref,
    309                                           Value::TYPE_STRING, &value));
    310   EXPECT_TRUE(value->GetAsString(&actual_str_value));
    311   EXPECT_EQ(managed_cloud_pref::kManagedCloudValue, actual_str_value);
    312 
    313   // Test getting an extension value.
    314   value = NULL;
    315   ASSERT_TRUE(pref_value_store_->GetValue(prefs::kExtensionPref,
    316                                           Value::TYPE_STRING, &value));
    317   EXPECT_TRUE(value->GetAsString(&actual_str_value));
    318   EXPECT_EQ(extension_pref::kExtensionValue, actual_str_value);
    319 
    320   // Test getting a command-line value.
    321   value = NULL;
    322   ASSERT_TRUE(pref_value_store_->GetValue(prefs::kCommandLinePref,
    323                                           Value::TYPE_STRING, &value));
    324   EXPECT_TRUE(value->GetAsString(&actual_str_value));
    325   EXPECT_EQ(command_line_pref::kCommandLineValue, actual_str_value);
    326 
    327   // Test getting a user-set value.
    328   value = NULL;
    329   ASSERT_TRUE(pref_value_store_->GetValue(prefs::kUserPref,
    330                                           Value::TYPE_STRING, &value));
    331   EXPECT_TRUE(value->GetAsString(&actual_str_value));
    332   EXPECT_EQ(user_pref::kUserValue, actual_str_value);
    333 
    334   // Test getting a user set value overwriting a recommended value.
    335   value = NULL;
    336   ASSERT_TRUE(pref_value_store_->GetValue(prefs::kRecommendedPlatformPref,
    337                                           Value::TYPE_STRING, &value));
    338   EXPECT_TRUE(value->GetAsString(&actual_str_value));
    339   EXPECT_EQ(recommended_platform_pref::kRecommendedPlatformValue,
    340             actual_str_value);
    341 
    342   // Test getting a recommended value.
    343   value = NULL;
    344   ASSERT_TRUE(pref_value_store_->GetValue(prefs::kRecommendedCloudPref,
    345                                           Value::TYPE_STRING, &value));
    346   EXPECT_TRUE(value->GetAsString(&actual_str_value));
    347   EXPECT_EQ(recommended_cloud_pref::kRecommendedCloudValue, actual_str_value);
    348 
    349   // Test getting a default value.
    350   value = NULL;
    351   ASSERT_TRUE(pref_value_store_->GetValue(prefs::kDefaultPref,
    352                                           Value::TYPE_STRING, &value));
    353   EXPECT_TRUE(value->GetAsString(&actual_str_value));
    354   EXPECT_EQ(default_pref::kDefaultValue, actual_str_value);
    355 
    356   // Test getting a preference value that the |PrefValueStore|
    357   // does not contain.
    358   FundamentalValue tmp_dummy_value(true);
    359   value = &tmp_dummy_value;
    360   ASSERT_FALSE(pref_value_store_->GetValue(prefs::kMissingPref,
    361                                            Value::TYPE_STRING, &value));
    362   ASSERT_TRUE(value == NULL);
    363 }
    364 
    365 TEST_F(PrefValueStoreTest, PrefChanges) {
    366   // Check pref controlled by highest-priority store.
    367   EXPECT_CALL(pref_notifier_, OnPreferenceChanged(prefs::kManagedPlatformPref));
    368   managed_platform_pref_store_->NotifyPrefValueChanged(
    369       prefs::kManagedPlatformPref);
    370   Mock::VerifyAndClearExpectations(&pref_notifier_);
    371 
    372   EXPECT_CALL(pref_notifier_, OnPreferenceChanged(_)).Times(0);
    373   managed_cloud_pref_store_->NotifyPrefValueChanged(
    374       prefs::kManagedPlatformPref);
    375   extension_pref_store_->NotifyPrefValueChanged(
    376       prefs::kManagedPlatformPref);
    377   command_line_pref_store_->NotifyPrefValueChanged(
    378       prefs::kManagedPlatformPref);
    379   user_pref_store_->NotifyPrefValueChanged(
    380       prefs::kManagedPlatformPref);
    381   recommended_platform_pref_store_->NotifyPrefValueChanged(
    382       prefs::kManagedPlatformPref);
    383   recommended_cloud_pref_store_->NotifyPrefValueChanged(
    384       prefs::kManagedPlatformPref);
    385   default_pref_store_->NotifyPrefValueChanged(
    386       prefs::kManagedPlatformPref);
    387   Mock::VerifyAndClearExpectations(&pref_notifier_);
    388 
    389   // Check pref controlled by user store.
    390   EXPECT_CALL(pref_notifier_, OnPreferenceChanged(prefs::kUserPref));
    391   managed_platform_pref_store_->NotifyPrefValueChanged(prefs::kUserPref);
    392   Mock::VerifyAndClearExpectations(&pref_notifier_);
    393 
    394   EXPECT_CALL(pref_notifier_, OnPreferenceChanged(prefs::kUserPref));
    395   managed_cloud_pref_store_->NotifyPrefValueChanged(prefs::kUserPref);
    396   Mock::VerifyAndClearExpectations(&pref_notifier_);
    397 
    398   EXPECT_CALL(pref_notifier_, OnPreferenceChanged(prefs::kUserPref));
    399   extension_pref_store_->NotifyPrefValueChanged(prefs::kUserPref);
    400   Mock::VerifyAndClearExpectations(&pref_notifier_);
    401 
    402   EXPECT_CALL(pref_notifier_, OnPreferenceChanged(prefs::kUserPref));
    403   command_line_pref_store_->NotifyPrefValueChanged(prefs::kUserPref);
    404   Mock::VerifyAndClearExpectations(&pref_notifier_);
    405 
    406   EXPECT_CALL(pref_notifier_, OnPreferenceChanged(prefs::kUserPref));
    407   user_pref_store_->NotifyPrefValueChanged(prefs::kUserPref);
    408   Mock::VerifyAndClearExpectations(&pref_notifier_);
    409 
    410   EXPECT_CALL(pref_notifier_, OnPreferenceChanged(_)).Times(0);
    411   recommended_platform_pref_store_->NotifyPrefValueChanged(
    412       prefs::kUserPref);
    413   recommended_cloud_pref_store_->NotifyPrefValueChanged(
    414       prefs::kUserPref);
    415   default_pref_store_->NotifyPrefValueChanged(
    416       prefs::kUserPref);
    417   Mock::VerifyAndClearExpectations(&pref_notifier_);
    418 
    419   // Check pref controlled by default-pref store.
    420   EXPECT_CALL(pref_notifier_, OnPreferenceChanged(prefs::kDefaultPref));
    421   managed_platform_pref_store_->NotifyPrefValueChanged(prefs::kDefaultPref);
    422   Mock::VerifyAndClearExpectations(&pref_notifier_);
    423 
    424   EXPECT_CALL(pref_notifier_, OnPreferenceChanged(prefs::kDefaultPref));
    425   managed_cloud_pref_store_->NotifyPrefValueChanged(prefs::kDefaultPref);
    426   Mock::VerifyAndClearExpectations(&pref_notifier_);
    427 
    428   EXPECT_CALL(pref_notifier_, OnPreferenceChanged(prefs::kDefaultPref));
    429   extension_pref_store_->NotifyPrefValueChanged(prefs::kDefaultPref);
    430   Mock::VerifyAndClearExpectations(&pref_notifier_);
    431 
    432   EXPECT_CALL(pref_notifier_, OnPreferenceChanged(prefs::kDefaultPref));
    433   command_line_pref_store_->NotifyPrefValueChanged(prefs::kDefaultPref);
    434   Mock::VerifyAndClearExpectations(&pref_notifier_);
    435 
    436   EXPECT_CALL(pref_notifier_, OnPreferenceChanged(prefs::kDefaultPref));
    437   user_pref_store_->NotifyPrefValueChanged(prefs::kDefaultPref);
    438   Mock::VerifyAndClearExpectations(&pref_notifier_);
    439 
    440   EXPECT_CALL(pref_notifier_, OnPreferenceChanged(prefs::kDefaultPref));
    441   recommended_platform_pref_store_->NotifyPrefValueChanged(prefs::kDefaultPref);
    442   Mock::VerifyAndClearExpectations(&pref_notifier_);
    443 
    444   EXPECT_CALL(pref_notifier_, OnPreferenceChanged(prefs::kDefaultPref));
    445   recommended_cloud_pref_store_->NotifyPrefValueChanged(prefs::kDefaultPref);
    446   Mock::VerifyAndClearExpectations(&pref_notifier_);
    447 
    448   EXPECT_CALL(pref_notifier_, OnPreferenceChanged(prefs::kDefaultPref));
    449   default_pref_store_->NotifyPrefValueChanged(prefs::kDefaultPref);
    450   Mock::VerifyAndClearExpectations(&pref_notifier_);
    451 }
    452 
    453 TEST_F(PrefValueStoreTest, OnInitializationCompleted) {
    454   EXPECT_CALL(pref_notifier_, OnInitializationCompleted()).Times(0);
    455   managed_platform_pref_store_->SetInitializationCompleted();
    456   managed_cloud_pref_store_->SetInitializationCompleted();
    457   extension_pref_store_->SetInitializationCompleted();
    458   command_line_pref_store_->SetInitializationCompleted();
    459   recommended_platform_pref_store_->SetInitializationCompleted();
    460   recommended_cloud_pref_store_->SetInitializationCompleted();
    461   default_pref_store_->SetInitializationCompleted();
    462   Mock::VerifyAndClearExpectations(&pref_notifier_);
    463 
    464   // The notification should only be triggered after the last store is done.
    465   EXPECT_CALL(pref_notifier_, OnInitializationCompleted()).Times(1);
    466   user_pref_store_->SetInitializationCompleted();
    467   Mock::VerifyAndClearExpectations(&pref_notifier_);
    468 }
    469 
    470 TEST_F(PrefValueStoreTest, PrefValueInManagedStore) {
    471   EXPECT_TRUE(pref_value_store_->PrefValueInManagedStore(
    472       prefs::kManagedPlatformPref));
    473   EXPECT_TRUE(pref_value_store_->PrefValueInManagedStore(
    474       prefs::kManagedCloudPref));
    475   EXPECT_FALSE(pref_value_store_->PrefValueInManagedStore(
    476       prefs::kExtensionPref));
    477   EXPECT_FALSE(pref_value_store_->PrefValueInManagedStore(
    478       prefs::kCommandLinePref));
    479   EXPECT_FALSE(pref_value_store_->PrefValueInManagedStore(
    480       prefs::kUserPref));
    481   EXPECT_FALSE(pref_value_store_->PrefValueInManagedStore(
    482       prefs::kRecommendedPlatformPref));
    483   EXPECT_FALSE(pref_value_store_->PrefValueInManagedStore(
    484       prefs::kRecommendedCloudPref));
    485   EXPECT_FALSE(pref_value_store_->PrefValueInManagedStore(
    486       prefs::kDefaultPref));
    487   EXPECT_FALSE(pref_value_store_->PrefValueInManagedStore(
    488       prefs::kMissingPref));
    489 }
    490 
    491 TEST_F(PrefValueStoreTest, PrefValueInExtensionStore) {
    492   EXPECT_TRUE(pref_value_store_->PrefValueInExtensionStore(
    493       prefs::kManagedPlatformPref));
    494   EXPECT_TRUE(pref_value_store_->PrefValueInExtensionStore(
    495       prefs::kManagedCloudPref));
    496   EXPECT_TRUE(pref_value_store_->PrefValueInExtensionStore(
    497       prefs::kExtensionPref));
    498   EXPECT_FALSE(pref_value_store_->PrefValueInExtensionStore(
    499       prefs::kCommandLinePref));
    500   EXPECT_FALSE(pref_value_store_->PrefValueInExtensionStore(
    501       prefs::kUserPref));
    502   EXPECT_FALSE(pref_value_store_->PrefValueInExtensionStore(
    503       prefs::kRecommendedPlatformPref));
    504   EXPECT_FALSE(pref_value_store_->PrefValueInExtensionStore(
    505       prefs::kRecommendedCloudPref));
    506   EXPECT_FALSE(pref_value_store_->PrefValueInExtensionStore(
    507       prefs::kDefaultPref));
    508   EXPECT_FALSE(pref_value_store_->PrefValueInExtensionStore(
    509       prefs::kMissingPref));
    510 }
    511 
    512 TEST_F(PrefValueStoreTest, PrefValueInUserStore) {
    513   EXPECT_TRUE(pref_value_store_->PrefValueInUserStore(
    514       prefs::kManagedPlatformPref));
    515   EXPECT_TRUE(pref_value_store_->PrefValueInUserStore(
    516       prefs::kManagedCloudPref));
    517   EXPECT_TRUE(pref_value_store_->PrefValueInUserStore(
    518       prefs::kExtensionPref));
    519   EXPECT_TRUE(pref_value_store_->PrefValueInUserStore(
    520       prefs::kCommandLinePref));
    521   EXPECT_TRUE(pref_value_store_->PrefValueInUserStore(
    522       prefs::kUserPref));
    523   EXPECT_FALSE(pref_value_store_->PrefValueInUserStore(
    524       prefs::kRecommendedPlatformPref));
    525   EXPECT_FALSE(pref_value_store_->PrefValueInUserStore(
    526       prefs::kRecommendedCloudPref));
    527   EXPECT_FALSE(pref_value_store_->PrefValueInUserStore(
    528       prefs::kDefaultPref));
    529   EXPECT_FALSE(pref_value_store_->PrefValueInUserStore(
    530       prefs::kMissingPref));
    531 }
    532 
    533 TEST_F(PrefValueStoreTest, PrefValueFromExtensionStore) {
    534   EXPECT_FALSE(pref_value_store_->PrefValueFromExtensionStore(
    535       prefs::kManagedPlatformPref));
    536   EXPECT_FALSE(pref_value_store_->PrefValueFromExtensionStore(
    537       prefs::kManagedCloudPref));
    538   EXPECT_TRUE(pref_value_store_->PrefValueFromExtensionStore(
    539       prefs::kExtensionPref));
    540   EXPECT_FALSE(pref_value_store_->PrefValueFromExtensionStore(
    541       prefs::kCommandLinePref));
    542   EXPECT_FALSE(pref_value_store_->PrefValueFromExtensionStore(
    543       prefs::kUserPref));
    544   EXPECT_FALSE(pref_value_store_->PrefValueFromExtensionStore(
    545       prefs::kRecommendedPlatformPref));
    546   EXPECT_FALSE(pref_value_store_->PrefValueFromExtensionStore(
    547       prefs::kRecommendedCloudPref));
    548   EXPECT_FALSE(pref_value_store_->PrefValueFromExtensionStore(
    549       prefs::kDefaultPref));
    550   EXPECT_FALSE(pref_value_store_->PrefValueFromExtensionStore(
    551       prefs::kMissingPref));
    552 }
    553 
    554 TEST_F(PrefValueStoreTest, PrefValueFromUserStore) {
    555   EXPECT_FALSE(pref_value_store_->PrefValueFromUserStore(
    556       prefs::kManagedPlatformPref));
    557   EXPECT_FALSE(pref_value_store_->PrefValueFromUserStore(
    558       prefs::kManagedCloudPref));
    559   EXPECT_FALSE(pref_value_store_->PrefValueFromUserStore(
    560       prefs::kExtensionPref));
    561   EXPECT_FALSE(pref_value_store_->PrefValueFromUserStore(
    562       prefs::kCommandLinePref));
    563   EXPECT_TRUE(pref_value_store_->PrefValueFromUserStore(
    564       prefs::kUserPref));
    565   EXPECT_FALSE(pref_value_store_->PrefValueFromUserStore(
    566       prefs::kRecommendedPlatformPref));
    567   EXPECT_FALSE(pref_value_store_->PrefValueFromUserStore(
    568       prefs::kRecommendedCloudPref));
    569   EXPECT_FALSE(pref_value_store_->PrefValueFromUserStore(
    570       prefs::kDefaultPref));
    571   EXPECT_FALSE(pref_value_store_->PrefValueFromUserStore(
    572       prefs::kMissingPref));
    573 }
    574 
    575 TEST_F(PrefValueStoreTest, PrefValueFromDefaultStore) {
    576   EXPECT_FALSE(pref_value_store_->PrefValueFromDefaultStore(
    577       prefs::kManagedPlatformPref));
    578   EXPECT_FALSE(pref_value_store_->PrefValueFromDefaultStore(
    579       prefs::kManagedCloudPref));
    580   EXPECT_FALSE(pref_value_store_->PrefValueFromDefaultStore(
    581       prefs::kExtensionPref));
    582   EXPECT_FALSE(pref_value_store_->PrefValueFromDefaultStore(
    583       prefs::kCommandLinePref));
    584   EXPECT_FALSE(pref_value_store_->PrefValueFromDefaultStore(
    585       prefs::kUserPref));
    586   EXPECT_FALSE(pref_value_store_->PrefValueFromDefaultStore(
    587       prefs::kRecommendedPlatformPref));
    588   EXPECT_FALSE(pref_value_store_->PrefValueFromDefaultStore(
    589       prefs::kRecommendedCloudPref));
    590   EXPECT_TRUE(pref_value_store_->PrefValueFromDefaultStore(
    591       prefs::kDefaultPref));
    592   EXPECT_FALSE(pref_value_store_->PrefValueFromDefaultStore(
    593       prefs::kMissingPref));
    594 }
    595 
    596 TEST_F(PrefValueStoreTest, PrefValueUserModifiable) {
    597   EXPECT_FALSE(pref_value_store_->PrefValueUserModifiable(
    598       prefs::kManagedPlatformPref));
    599   EXPECT_FALSE(pref_value_store_->PrefValueUserModifiable(
    600       prefs::kManagedCloudPref));
    601   EXPECT_FALSE(pref_value_store_->PrefValueUserModifiable(
    602       prefs::kExtensionPref));
    603   EXPECT_FALSE(pref_value_store_->PrefValueUserModifiable(
    604       prefs::kCommandLinePref));
    605   EXPECT_TRUE(pref_value_store_->PrefValueUserModifiable(
    606       prefs::kUserPref));
    607   EXPECT_TRUE(pref_value_store_->PrefValueUserModifiable(
    608       prefs::kRecommendedPlatformPref));
    609   EXPECT_TRUE(pref_value_store_->PrefValueUserModifiable(
    610       prefs::kRecommendedCloudPref));
    611   EXPECT_TRUE(pref_value_store_->PrefValueUserModifiable(
    612       prefs::kDefaultPref));
    613   EXPECT_TRUE(pref_value_store_->PrefValueUserModifiable(
    614       prefs::kMissingPref));
    615 }
    616 
    617 TEST_F(PrefValueStoreTest, PrefValueExtensionModifiable) {
    618   EXPECT_FALSE(pref_value_store_->PrefValueExtensionModifiable(
    619       prefs::kManagedPlatformPref));
    620   EXPECT_FALSE(pref_value_store_->PrefValueExtensionModifiable(
    621       prefs::kManagedCloudPref));
    622   EXPECT_TRUE(pref_value_store_->PrefValueExtensionModifiable(
    623       prefs::kExtensionPref));
    624   EXPECT_TRUE(pref_value_store_->PrefValueExtensionModifiable(
    625       prefs::kCommandLinePref));
    626   EXPECT_TRUE(pref_value_store_->PrefValueExtensionModifiable(
    627       prefs::kUserPref));
    628   EXPECT_TRUE(pref_value_store_->PrefValueExtensionModifiable(
    629       prefs::kRecommendedPlatformPref));
    630   EXPECT_TRUE(pref_value_store_->PrefValueExtensionModifiable(
    631       prefs::kRecommendedCloudPref));
    632   EXPECT_TRUE(pref_value_store_->PrefValueExtensionModifiable(
    633       prefs::kDefaultPref));
    634   EXPECT_TRUE(pref_value_store_->PrefValueExtensionModifiable(
    635       prefs::kMissingPref));
    636 }
    637