| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/values.h" | 5 #include "base/values.h" |
| 6 #include "chrome/browser/prefs/pref_value_map.h" | 6 #include "chrome/browser/prefs/pref_value_map.h" |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 | 8 |
| 9 class PrefValueMapTest : public testing::Test { | 9 class PrefValueMapTest : public testing::Test { |
| 10 }; | 10 }; |
| 11 | 11 |
| 12 TEST_F(PrefValueMapTest, SetValue) { | 12 TEST_F(PrefValueMapTest, SetValue) { |
| 13 PrefValueMap map; | 13 PrefValueMap map; |
| 14 const Value* result = NULL; | 14 const Value* result = NULL; |
| 15 EXPECT_FALSE(map.GetValue("key", &result)); | 15 EXPECT_FALSE(map.GetValue("key", &result)); |
| 16 EXPECT_FALSE(result); | 16 EXPECT_FALSE(result); |
| 17 | 17 |
| 18 EXPECT_TRUE(map.SetValue("key", Value::CreateStringValue("test"))); | 18 EXPECT_TRUE(map.SetValue("key", base::StringValue::New("test"))); |
| 19 EXPECT_FALSE(map.SetValue("key", Value::CreateStringValue("test"))); | 19 EXPECT_FALSE(map.SetValue("key", base::StringValue::New("test"))); |
| 20 EXPECT_TRUE(map.SetValue("key", Value::CreateStringValue("hi mom!"))); | 20 EXPECT_TRUE(map.SetValue("key", base::StringValue::New("hi mom!"))); |
| 21 | 21 |
| 22 EXPECT_TRUE(map.GetValue("key", &result)); | 22 EXPECT_TRUE(map.GetValue("key", &result)); |
| 23 EXPECT_TRUE(StringValue("hi mom!").Equals(result)); | 23 EXPECT_TRUE(StringValue("hi mom!").Equals(result)); |
| 24 } | 24 } |
| 25 | 25 |
| 26 TEST_F(PrefValueMapTest, GetAndSetIntegerValue) { | 26 TEST_F(PrefValueMapTest, GetAndSetIntegerValue) { |
| 27 PrefValueMap map; | 27 PrefValueMap map; |
| 28 ASSERT_TRUE(map.SetValue("key", Value::CreateIntegerValue(5))); | 28 ASSERT_TRUE(map.SetValue("key", base::NumberValue::New(5))); |
| 29 | 29 |
| 30 int int_value = 0; | 30 int int_value = 0; |
| 31 EXPECT_TRUE(map.GetInteger("key", &int_value)); | 31 EXPECT_TRUE(map.GetInteger("key", &int_value)); |
| 32 EXPECT_EQ(5, int_value); | 32 EXPECT_EQ(5, int_value); |
| 33 | 33 |
| 34 map.SetInteger("key", -14); | 34 map.SetInteger("key", -14); |
| 35 EXPECT_TRUE(map.GetInteger("key", &int_value)); | 35 EXPECT_TRUE(map.GetInteger("key", &int_value)); |
| 36 EXPECT_EQ(-14, int_value); | 36 EXPECT_EQ(-14, int_value); |
| 37 } | 37 } |
| 38 | 38 |
| 39 TEST_F(PrefValueMapTest, RemoveValue) { | 39 TEST_F(PrefValueMapTest, RemoveValue) { |
| 40 PrefValueMap map; | 40 PrefValueMap map; |
| 41 EXPECT_FALSE(map.RemoveValue("key")); | 41 EXPECT_FALSE(map.RemoveValue("key")); |
| 42 | 42 |
| 43 EXPECT_TRUE(map.SetValue("key", Value::CreateStringValue("test"))); | 43 EXPECT_TRUE(map.SetValue("key", base::StringValue::New("test"))); |
| 44 EXPECT_TRUE(map.GetValue("key", NULL)); | 44 EXPECT_TRUE(map.GetValue("key", NULL)); |
| 45 | 45 |
| 46 EXPECT_TRUE(map.RemoveValue("key")); | 46 EXPECT_TRUE(map.RemoveValue("key")); |
| 47 EXPECT_FALSE(map.GetValue("key", NULL)); | 47 EXPECT_FALSE(map.GetValue("key", NULL)); |
| 48 | 48 |
| 49 EXPECT_FALSE(map.RemoveValue("key")); | 49 EXPECT_FALSE(map.RemoveValue("key")); |
| 50 } | 50 } |
| 51 | 51 |
| 52 TEST_F(PrefValueMapTest, Clear) { | 52 TEST_F(PrefValueMapTest, Clear) { |
| 53 PrefValueMap map; | 53 PrefValueMap map; |
| 54 EXPECT_TRUE(map.SetValue("key", Value::CreateStringValue("test"))); | 54 EXPECT_TRUE(map.SetValue("key", base::StringValue::New("test"))); |
| 55 EXPECT_TRUE(map.GetValue("key", NULL)); | 55 EXPECT_TRUE(map.GetValue("key", NULL)); |
| 56 | 56 |
| 57 map.Clear(); | 57 map.Clear(); |
| 58 | 58 |
| 59 EXPECT_FALSE(map.GetValue("key", NULL)); | 59 EXPECT_FALSE(map.GetValue("key", NULL)); |
| 60 } | 60 } |
| 61 | 61 |
| 62 TEST_F(PrefValueMapTest, GetDifferingKeys) { | 62 TEST_F(PrefValueMapTest, GetDifferingKeys) { |
| 63 PrefValueMap reference; | 63 PrefValueMap reference; |
| 64 EXPECT_TRUE(reference.SetValue("b", Value::CreateStringValue("test"))); | 64 EXPECT_TRUE(reference.SetValue("b", base::StringValue::New("test"))); |
| 65 EXPECT_TRUE(reference.SetValue("c", Value::CreateStringValue("test"))); | 65 EXPECT_TRUE(reference.SetValue("c", base::StringValue::New("test"))); |
| 66 EXPECT_TRUE(reference.SetValue("e", Value::CreateStringValue("test"))); | 66 EXPECT_TRUE(reference.SetValue("e", base::StringValue::New("test"))); |
| 67 | 67 |
| 68 PrefValueMap check; | 68 PrefValueMap check; |
| 69 std::vector<std::string> differing_paths; | 69 std::vector<std::string> differing_paths; |
| 70 std::vector<std::string> expected_differing_paths; | 70 std::vector<std::string> expected_differing_paths; |
| 71 | 71 |
| 72 reference.GetDifferingKeys(&check, &differing_paths); | 72 reference.GetDifferingKeys(&check, &differing_paths); |
| 73 expected_differing_paths.push_back("b"); | 73 expected_differing_paths.push_back("b"); |
| 74 expected_differing_paths.push_back("c"); | 74 expected_differing_paths.push_back("c"); |
| 75 expected_differing_paths.push_back("e"); | 75 expected_differing_paths.push_back("e"); |
| 76 EXPECT_EQ(expected_differing_paths, differing_paths); | 76 EXPECT_EQ(expected_differing_paths, differing_paths); |
| 77 | 77 |
| 78 EXPECT_TRUE(check.SetValue("a", Value::CreateStringValue("test"))); | 78 EXPECT_TRUE(check.SetValue("a", base::StringValue::New("test"))); |
| 79 EXPECT_TRUE(check.SetValue("c", Value::CreateStringValue("test"))); | 79 EXPECT_TRUE(check.SetValue("c", base::StringValue::New("test"))); |
| 80 EXPECT_TRUE(check.SetValue("d", Value::CreateStringValue("test"))); | 80 EXPECT_TRUE(check.SetValue("d", base::StringValue::New("test"))); |
| 81 | 81 |
| 82 reference.GetDifferingKeys(&check, &differing_paths); | 82 reference.GetDifferingKeys(&check, &differing_paths); |
| 83 expected_differing_paths.clear(); | 83 expected_differing_paths.clear(); |
| 84 expected_differing_paths.push_back("a"); | 84 expected_differing_paths.push_back("a"); |
| 85 expected_differing_paths.push_back("b"); | 85 expected_differing_paths.push_back("b"); |
| 86 expected_differing_paths.push_back("d"); | 86 expected_differing_paths.push_back("d"); |
| 87 expected_differing_paths.push_back("e"); | 87 expected_differing_paths.push_back("e"); |
| 88 EXPECT_EQ(expected_differing_paths, differing_paths); | 88 EXPECT_EQ(expected_differing_paths, differing_paths); |
| 89 } | 89 } |
| OLD | NEW |