-
- // Test setting a managed pref after overriding the managed PrefStore.
- managed_pref_store->SetInteger(kManagedPref, 20);
- EXPECT_TRUE(preference->IsManaged());
- ASSERT_EQ(base::Value(20), *(preference->GetValue()));
-
- // Test overriding the supervised and recommended PrefStore with already set
- // prefs.
- scoped_refptr<TestingPrefStore> supervised_pref_store =
- base::MakeRefCounted<TestingPrefStore>();
- scoped_refptr<TestingPrefStore> recommened_pref_store =
- base::MakeRefCounted<TestingPrefStore>();
- supervised_pref_store->SetInteger(kManagedPref, 30);
- supervised_pref_store->SetInteger(kSupervisedPref, 31);
- recommened_pref_store->SetInteger(kManagedPref, 40);
- recommened_pref_store->SetInteger(kRecommendedPref, 41);
- pref_service_->ChangePrefValueStore(
- nullptr /* managed_prefs */, supervised_pref_store.get(),
- nullptr /* extension_prefs */, recommened_pref_store.get());
- EXPECT_TRUE(preference->IsManaged());
- ASSERT_EQ(base::Value(20), *(preference->GetValue()));
- EXPECT_TRUE(supervised->IsManagedByCustodian());
- EXPECT_EQ(base::Value(31), *(supervised->GetValue()));
- EXPECT_TRUE(recommended->IsRecommended());
- EXPECT_EQ(base::Value(41), *(recommended->GetValue()));
-}
-
-// Tests that PrefChangeRegistrar works after PrefValueStore is changed.
-TEST_F(PrefValueStoreChangeTest, PrefChangeRegistrar) {
- MockPrefChangeCallback obs(pref_service_.get());
- PrefChangeRegistrar registrar;
- registrar.Init(pref_service_.get());
- registrar.Add(kManagedPref, obs.GetCallback());
- registrar.Add(kSupervisedPref, obs.GetCallback());
- registrar.Add(kRecommendedPref, obs.GetCallback());
-
- base::Value expected_value(10);
- obs.Expect(kManagedPref, &expected_value);
- user_pref_store_->SetInteger(kManagedPref, 10);
- Mock::VerifyAndClearExpectations(&obs);
- expected_value = base::Value(11);
- obs.Expect(kRecommendedPref, &expected_value);
- user_pref_store_->SetInteger(kRecommendedPref, 11);
- Mock::VerifyAndClearExpectations(&obs);
-
- // Test overriding the managed and supervised PrefStore with already set
- // prefs.
- scoped_refptr<TestingPrefStore> managed_pref_store =
- base::MakeRefCounted<TestingPrefStore>();
- scoped_refptr<TestingPrefStore> supervised_pref_store =
- base::MakeRefCounted<TestingPrefStore>();
- // Update |kManagedPref| before changing the PrefValueStore, the
- // PrefChangeRegistrar should get notified on |kManagedPref| as its value
- // changes.
- managed_pref_store->SetInteger(kManagedPref, 20);
- // Due to store precedence, the value of |kRecommendedPref| will not be
- // changed so PrefChangeRegistrar will not be notified.
- managed_pref_store->SetInteger(kRecommendedPref, 11);
- supervised_pref_store->SetInteger(kManagedPref, 30);
- supervised_pref_store->SetInteger(kRecommendedPref, 21);
- expected_value = base::Value(20);
- obs.Expect(kManagedPref, &expected_value);
- pref_service_->ChangePrefValueStore(
- managed_pref_store.get(), supervised_pref_store.get(),
- nullptr /* extension_prefs */, nullptr /* recommended_prefs */);
- Mock::VerifyAndClearExpectations(&obs);
-
- // Update a pref value after PrefValueStore change, it should also work.
- expected_value = base::Value(31);
- obs.Expect(kSupervisedPref, &expected_value);
- supervised_pref_store->SetInteger(kSupervisedPref, 31);
- Mock::VerifyAndClearExpectations(&obs);