diff options
Diffstat (limited to 'chrome/common/json_pref_store_unittest.cc')
-rw-r--r-- | chrome/common/json_pref_store_unittest.cc | 56 |
1 files changed, 36 insertions, 20 deletions
diff --git a/chrome/common/json_pref_store_unittest.cc b/chrome/common/json_pref_store_unittest.cc index e38aba2..326e32d 100644 --- a/chrome/common/json_pref_store_unittest.cc +++ b/chrome/common/json_pref_store_unittest.cc @@ -54,9 +54,9 @@ TEST_F(JsonPrefStoreTest, NonExistentFile) { FilePath bogus_input_file = data_dir_.AppendASCII("read.txt"); ASSERT_FALSE(file_util::PathExists(bogus_input_file)); JsonPrefStore pref_store(bogus_input_file, message_loop_proxy_.get()); - EXPECT_EQ(PrefStore::PREF_READ_ERROR_NO_FILE, pref_store.ReadPrefs()); + EXPECT_EQ(PersistentPrefStore::PREF_READ_ERROR_NO_FILE, + pref_store.ReadPrefs()); EXPECT_FALSE(pref_store.ReadOnly()); - EXPECT_TRUE(pref_store.prefs()->empty()); } // Test fallback behavior for an invalid file. @@ -65,9 +65,9 @@ TEST_F(JsonPrefStoreTest, InvalidFile) { FilePath invalid_file = test_dir_.AppendASCII("invalid.json"); ASSERT_TRUE(file_util::CopyFile(invalid_file_original, invalid_file)); JsonPrefStore pref_store(invalid_file, message_loop_proxy_.get()); - EXPECT_EQ(PrefStore::PREF_READ_ERROR_JSON_PARSE, pref_store.ReadPrefs()); + EXPECT_EQ(PersistentPrefStore::PREF_READ_ERROR_JSON_PARSE, + pref_store.ReadPrefs()); EXPECT_FALSE(pref_store.ReadOnly()); - EXPECT_TRUE(pref_store.prefs()->empty()); // The file should have been moved aside. EXPECT_FALSE(file_util::PathExists(invalid_file)); @@ -85,9 +85,8 @@ TEST_F(JsonPrefStoreTest, Basic) { FilePath input_file = test_dir_.AppendASCII("write.json"); ASSERT_TRUE(file_util::PathExists(input_file)); JsonPrefStore pref_store(input_file, message_loop_proxy_.get()); - ASSERT_EQ(PrefStore::PREF_READ_ERROR_NONE, pref_store.ReadPrefs()); + ASSERT_EQ(PersistentPrefStore::PREF_READ_ERROR_NONE, pref_store.ReadPrefs()); ASSERT_FALSE(pref_store.ReadOnly()); - DictionaryValue* prefs = pref_store.prefs(); // The JSON file looks like this: // { @@ -105,38 +104,55 @@ TEST_F(JsonPrefStoreTest, Basic) { std::string cnn("http://www.cnn.com"); + Value* actual; + EXPECT_EQ(PrefStore::READ_OK, + pref_store.GetValue(prefs::kHomePage, &actual)); std::string string_value; - EXPECT_TRUE(prefs->GetString(prefs::kHomePage, &string_value)); + EXPECT_TRUE(actual->GetAsString(&string_value)); EXPECT_EQ(cnn, string_value); const char kSomeDirectory[] = "some_directory"; + EXPECT_EQ(PrefStore::READ_OK, pref_store.GetValue(kSomeDirectory, &actual)); FilePath::StringType path; - EXPECT_TRUE(prefs->GetString(kSomeDirectory, &path)); + EXPECT_TRUE(actual->GetAsString(&path)); EXPECT_EQ(FilePath::StringType(FILE_PATH_LITERAL("/usr/local/")), path); FilePath some_path(FILE_PATH_LITERAL("/usr/sbin/")); - prefs->SetString(kSomeDirectory, some_path.value()); - EXPECT_TRUE(prefs->GetString(kSomeDirectory, &path)); + + pref_store.SetValue(kSomeDirectory, + Value::CreateStringValue(some_path.value())); + EXPECT_EQ(PrefStore::READ_OK, pref_store.GetValue(kSomeDirectory, &actual)); + EXPECT_TRUE(actual->GetAsString(&path)); EXPECT_EQ(some_path.value(), path); // Test reading some other data types from sub-dictionaries. - bool boolean; - EXPECT_TRUE(prefs->GetBoolean(kNewWindowsInTabs, &boolean)); + EXPECT_EQ(PrefStore::READ_OK, + pref_store.GetValue(kNewWindowsInTabs, &actual)); + bool boolean = false; + EXPECT_TRUE(actual->GetAsBoolean(&boolean)); EXPECT_TRUE(boolean); - prefs->SetBoolean(kNewWindowsInTabs, false); - EXPECT_TRUE(prefs->GetBoolean(kNewWindowsInTabs, &boolean)); + pref_store.SetValue(kNewWindowsInTabs, + Value::CreateBooleanValue(false)); + EXPECT_EQ(PrefStore::READ_OK, + pref_store.GetValue(kNewWindowsInTabs, &actual)); + EXPECT_TRUE(actual->GetAsBoolean(&boolean)); EXPECT_FALSE(boolean); - int integer; - EXPECT_TRUE(prefs->GetInteger(kMaxTabs, &integer)); + EXPECT_EQ(PrefStore::READ_OK, pref_store.GetValue(kMaxTabs, &actual)); + int integer = 0; + EXPECT_TRUE(actual->GetAsInteger(&integer)); EXPECT_EQ(20, integer); - prefs->SetInteger(kMaxTabs, 10); - EXPECT_TRUE(prefs->GetInteger(kMaxTabs, &integer)); + pref_store.SetValue(kMaxTabs, Value::CreateIntegerValue(10)); + EXPECT_EQ(PrefStore::READ_OK, pref_store.GetValue(kMaxTabs, &actual)); + EXPECT_TRUE(actual->GetAsInteger(&integer)); EXPECT_EQ(10, integer); - prefs->SetString(kLongIntPref, base::Int64ToString(214748364842LL)); - EXPECT_TRUE(prefs->GetString(kLongIntPref, &string_value)); + pref_store.SetValue(kLongIntPref, + Value::CreateStringValue( + base::Int64ToString(214748364842LL))); + EXPECT_EQ(PrefStore::READ_OK, pref_store.GetValue(kLongIntPref, &actual)); + EXPECT_TRUE(actual->GetAsString(&string_value)); int64 value; base::StringToInt64(string_value, &value); EXPECT_EQ(214748364842LL, value); |