}
TEST_F(ScopedUserPrefUpdateTest, ScopedDictPrefUpdateWithDefaults) {
- base::Value::Dict defaults;
- defaults.Set("firstkey", "value");
- defaults.Set("secondkey", "value");
+ auto defaults =
+ base::Value::Dict().Set("firstkey", "value").Set("secondkey", "value");
std::string pref_name = "mypref";
prefs_.registry()->RegisterDictionaryPref(pref_name, std::move(defaults));
update->Append("thirdvalue");
EXPECT_EQ(3u, prefs_.GetList(pref_name).size());
}
-
-// Tests for deprecated APIs.
-
-TEST_F(ScopedUserPrefUpdateTest, RegularUse) {
- // Dictionary that will be expected to be set at the end.
- base::Value expected_dictionary(base::Value::Type::DICTIONARY);
- expected_dictionary.SetStringKey(kKey, kValue);
-
- {
- EXPECT_CALL(dict_observer_, OnPreferenceChanged(_)).Times(0);
- DictionaryPrefUpdate update(&prefs_, kDictPref);
- base::Value* value = update.Get();
- ASSERT_TRUE(value);
- value->SetStringKey(kKey, kValue);
-
- // The dictionary was created for us but the creation should have happened
- // silently without notifications.
- Mock::VerifyAndClearExpectations(&dict_observer_);
-
- // Modifications happen online and are instantly visible, though.
- EXPECT_EQ(expected_dictionary, prefs_.GetDict(kDictPref));
-
- // Now we are leaving the scope of the update so we should be notified.
- dict_observer_.Expect(kDictPref, &expected_dictionary);
- }
- Mock::VerifyAndClearExpectations(&dict_observer_);
-
- EXPECT_EQ(expected_dictionary, prefs_.GetDict(kDictPref));
-}
-
-TEST_F(ScopedUserPrefUpdateTest, NeverTouchAnything) {
- const base::Value::Dict& old_value = prefs_.GetDict(kDictPref);
- EXPECT_CALL(dict_observer_, OnPreferenceChanged(_)).Times(0);
- { DictionaryPrefUpdate update(&prefs_, kDictPref); }
- const base::Value::Dict& new_value = prefs_.GetDict(kDictPref);
- EXPECT_EQ(old_value, new_value);
- Mock::VerifyAndClearExpectations(&dict_observer_);
-}
-
-TEST_F(ScopedUserPrefUpdateTest, UpdatingDictionaryPrefWithDefaults) {
- base::Value::Dict defaults;
- defaults.Set("firstkey", "value");
- defaults.Set("secondkey", "value");
-
- std::string pref_name = "mypref";
- prefs_.registry()->RegisterDictionaryPref(pref_name, std::move(defaults));
- EXPECT_EQ(2u, prefs_.GetDict(pref_name).size());
-
- DictionaryPrefUpdate update(&prefs_, pref_name);
- update->SetStringKey("thirdkey", "value");
- EXPECT_EQ(3u, prefs_.GetDict(pref_name).size());
-}