OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/file_util.h" | 5 #include "base/file_util.h" |
6 #include "base/memory/ref_counted.h" | 6 #include "base/memory/ref_counted.h" |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/message_loop_proxy.h" | 9 #include "base/message_loop_proxy.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 void RunBasicJsonPrefStoreTest(JsonPrefStore *pref_store, | 91 void RunBasicJsonPrefStoreTest(JsonPrefStore *pref_store, |
92 const FilePath& output_file, | 92 const FilePath& output_file, |
93 const FilePath& golden_output_file) { | 93 const FilePath& golden_output_file) { |
94 const char kNewWindowsInTabs[] = "tabs.new_windows_in_tabs"; | 94 const char kNewWindowsInTabs[] = "tabs.new_windows_in_tabs"; |
95 const char kMaxTabs[] = "tabs.max_tabs"; | 95 const char kMaxTabs[] = "tabs.max_tabs"; |
96 const char kLongIntPref[] = "long_int.pref"; | 96 const char kLongIntPref[] = "long_int.pref"; |
97 | 97 |
98 std::string cnn("http://www.cnn.com"); | 98 std::string cnn("http://www.cnn.com"); |
99 | 99 |
100 const Value* actual; | 100 const Value* actual; |
101 EXPECT_EQ(PrefStore::READ_OK, | 101 EXPECT_TRUE(pref_store->GetValue(prefs::kHomePage, &actual)); |
102 pref_store->GetValue(prefs::kHomePage, &actual)); | |
103 std::string string_value; | 102 std::string string_value; |
104 EXPECT_TRUE(actual->GetAsString(&string_value)); | 103 EXPECT_TRUE(actual->GetAsString(&string_value)); |
105 EXPECT_EQ(cnn, string_value); | 104 EXPECT_EQ(cnn, string_value); |
106 | 105 |
107 const char kSomeDirectory[] = "some_directory"; | 106 const char kSomeDirectory[] = "some_directory"; |
108 | 107 |
109 EXPECT_EQ(PrefStore::READ_OK, pref_store->GetValue(kSomeDirectory, &actual)); | 108 EXPECT_TRUE(pref_store->GetValue(kSomeDirectory, &actual)); |
110 FilePath::StringType path; | 109 FilePath::StringType path; |
111 EXPECT_TRUE(actual->GetAsString(&path)); | 110 EXPECT_TRUE(actual->GetAsString(&path)); |
112 EXPECT_EQ(FilePath::StringType(FILE_PATH_LITERAL("/usr/local/")), path); | 111 EXPECT_EQ(FilePath::StringType(FILE_PATH_LITERAL("/usr/local/")), path); |
113 FilePath some_path(FILE_PATH_LITERAL("/usr/sbin/")); | 112 FilePath some_path(FILE_PATH_LITERAL("/usr/sbin/")); |
114 | 113 |
115 pref_store->SetValue(kSomeDirectory, | 114 pref_store->SetValue(kSomeDirectory, |
116 Value::CreateStringValue(some_path.value())); | 115 Value::CreateStringValue(some_path.value())); |
117 EXPECT_EQ(PrefStore::READ_OK, pref_store->GetValue(kSomeDirectory, &actual)); | 116 EXPECT_TRUE(pref_store->GetValue(kSomeDirectory, &actual)); |
118 EXPECT_TRUE(actual->GetAsString(&path)); | 117 EXPECT_TRUE(actual->GetAsString(&path)); |
119 EXPECT_EQ(some_path.value(), path); | 118 EXPECT_EQ(some_path.value(), path); |
120 | 119 |
121 // Test reading some other data types from sub-dictionaries. | 120 // Test reading some other data types from sub-dictionaries. |
122 EXPECT_EQ(PrefStore::READ_OK, | 121 EXPECT_TRUE(pref_store->GetValue(kNewWindowsInTabs, &actual)); |
123 pref_store->GetValue(kNewWindowsInTabs, &actual)); | |
124 bool boolean = false; | 122 bool boolean = false; |
125 EXPECT_TRUE(actual->GetAsBoolean(&boolean)); | 123 EXPECT_TRUE(actual->GetAsBoolean(&boolean)); |
126 EXPECT_TRUE(boolean); | 124 EXPECT_TRUE(boolean); |
127 | 125 |
128 pref_store->SetValue(kNewWindowsInTabs, | 126 pref_store->SetValue(kNewWindowsInTabs, |
129 Value::CreateBooleanValue(false)); | 127 Value::CreateBooleanValue(false)); |
130 EXPECT_EQ(PrefStore::READ_OK, | 128 EXPECT_TRUE(pref_store->GetValue(kNewWindowsInTabs, &actual)); |
131 pref_store->GetValue(kNewWindowsInTabs, &actual)); | |
132 EXPECT_TRUE(actual->GetAsBoolean(&boolean)); | 129 EXPECT_TRUE(actual->GetAsBoolean(&boolean)); |
133 EXPECT_FALSE(boolean); | 130 EXPECT_FALSE(boolean); |
134 | 131 |
135 EXPECT_EQ(PrefStore::READ_OK, pref_store->GetValue(kMaxTabs, &actual)); | 132 EXPECT_TRUE(pref_store->GetValue(kMaxTabs, &actual)); |
136 int integer = 0; | 133 int integer = 0; |
137 EXPECT_TRUE(actual->GetAsInteger(&integer)); | 134 EXPECT_TRUE(actual->GetAsInteger(&integer)); |
138 EXPECT_EQ(20, integer); | 135 EXPECT_EQ(20, integer); |
139 pref_store->SetValue(kMaxTabs, Value::CreateIntegerValue(10)); | 136 pref_store->SetValue(kMaxTabs, Value::CreateIntegerValue(10)); |
140 EXPECT_EQ(PrefStore::READ_OK, pref_store->GetValue(kMaxTabs, &actual)); | 137 EXPECT_TRUE(pref_store->GetValue(kMaxTabs, &actual)); |
141 EXPECT_TRUE(actual->GetAsInteger(&integer)); | 138 EXPECT_TRUE(actual->GetAsInteger(&integer)); |
142 EXPECT_EQ(10, integer); | 139 EXPECT_EQ(10, integer); |
143 | 140 |
144 pref_store->SetValue(kLongIntPref, | 141 pref_store->SetValue(kLongIntPref, |
145 Value::CreateStringValue( | 142 Value::CreateStringValue( |
146 base::Int64ToString(214748364842LL))); | 143 base::Int64ToString(214748364842LL))); |
147 EXPECT_EQ(PrefStore::READ_OK, pref_store->GetValue(kLongIntPref, &actual)); | 144 EXPECT_TRUE(pref_store->GetValue(kLongIntPref, &actual)); |
148 EXPECT_TRUE(actual->GetAsString(&string_value)); | 145 EXPECT_TRUE(actual->GetAsString(&string_value)); |
149 int64 value; | 146 int64 value; |
150 base::StringToInt64(string_value, &value); | 147 base::StringToInt64(string_value, &value); |
151 EXPECT_EQ(214748364842LL, value); | 148 EXPECT_EQ(214748364842LL, value); |
152 | 149 |
153 // Serialize and compare to expected output. | 150 // Serialize and compare to expected output. |
154 ASSERT_TRUE(file_util::PathExists(golden_output_file)); | 151 ASSERT_TRUE(file_util::PathExists(golden_output_file)); |
155 pref_store->CommitPendingWrite(); | 152 pref_store->CommitPendingWrite(); |
156 MessageLoop::current()->RunUntilIdle(); | 153 MessageLoop::current()->RunUntilIdle(); |
157 EXPECT_TRUE(file_util::TextContentsEqual(golden_output_file, output_file)); | 154 EXPECT_TRUE(file_util::TextContentsEqual(golden_output_file, output_file)); |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 // Write to file. | 281 // Write to file. |
285 pref_store->CommitPendingWrite(); | 282 pref_store->CommitPendingWrite(); |
286 MessageLoop::current()->RunUntilIdle(); | 283 MessageLoop::current()->RunUntilIdle(); |
287 | 284 |
288 // Compare to expected output. | 285 // Compare to expected output. |
289 FilePath golden_output_file = | 286 FilePath golden_output_file = |
290 data_dir_.AppendASCII("write.golden.need_empty_value.json"); | 287 data_dir_.AppendASCII("write.golden.need_empty_value.json"); |
291 ASSERT_TRUE(file_util::PathExists(golden_output_file)); | 288 ASSERT_TRUE(file_util::PathExists(golden_output_file)); |
292 EXPECT_TRUE(file_util::TextContentsEqual(golden_output_file, pref_file)); | 289 EXPECT_TRUE(file_util::TextContentsEqual(golden_output_file, pref_file)); |
293 } | 290 } |
OLD | NEW |