Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(505)

Side by Side Diff: chrome/browser/prefs/pref_service_unittest.cc

Issue 11027070: Moved JsonPrefStore to use SequencedWorkerPool (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 <string> 5 #include <string>
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
11 #include "base/scoped_temp_dir.h" 11 #include "base/scoped_temp_dir.h"
12 #include "base/threading/sequenced_worker_pool.h"
12 #include "base/utf_string_conversions.h" 13 #include "base/utf_string_conversions.h"
13 #include "base/values.h" 14 #include "base/values.h"
14 #include "chrome/browser/api/prefs/pref_change_registrar.h" 15 #include "chrome/browser/api/prefs/pref_change_registrar.h"
15 #include "chrome/browser/policy/configuration_policy_pref_store.h" 16 #include "chrome/browser/policy/configuration_policy_pref_store.h"
16 #include "chrome/browser/policy/mock_configuration_policy_provider.h" 17 #include "chrome/browser/policy/mock_configuration_policy_provider.h"
17 #include "chrome/browser/prefs/browser_prefs.h" 18 #include "chrome/browser/prefs/browser_prefs.h"
18 #include "chrome/browser/prefs/command_line_pref_store.h" 19 #include "chrome/browser/prefs/command_line_pref_store.h"
19 #include "chrome/browser/prefs/pref_observer_mock.h" 20 #include "chrome/browser/prefs/pref_observer_mock.h"
20 #include "chrome/browser/prefs/pref_service_mock_builder.h" 21 #include "chrome/browser/prefs/pref_service_mock_builder.h"
21 #include "chrome/browser/prefs/pref_value_store.h" 22 #include "chrome/browser/prefs/pref_value_store.h"
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 } 279 }
279 280
280 class PrefServiceUserFilePrefsTest : public testing::Test { 281 class PrefServiceUserFilePrefsTest : public testing::Test {
281 protected: 282 protected:
282 virtual void SetUp() { 283 virtual void SetUp() {
283 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 284 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
284 285
285 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_dir_)); 286 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_dir_));
286 data_dir_ = data_dir_.AppendASCII("pref_service"); 287 data_dir_ = data_dir_.AppendASCII("pref_service");
287 ASSERT_TRUE(file_util::PathExists(data_dir_)); 288 ASSERT_TRUE(file_util::PathExists(data_dir_));
289
290 blocking_pool_ = new base::SequencedWorkerPool(1, "TestBlocking");
288 } 291 }
289 292
290 void ClearListValue(PrefService* prefs, const char* key) { 293 void ClearListValue(PrefService* prefs, const char* key) {
291 ListPrefUpdate updater(prefs, key); 294 ListPrefUpdate updater(prefs, key);
292 updater->Clear(); 295 updater->Clear();
293 } 296 }
294 297
295 void ClearDictionaryValue(PrefService* prefs, const char* key) { 298 void ClearDictionaryValue(PrefService* prefs, const char* key) {
296 DictionaryPrefUpdate updater(prefs, key); 299 DictionaryPrefUpdate updater(prefs, key);
297 updater->Clear(); 300 updater->Clear();
298 } 301 }
299 302
300 // The path to temporary directory used to contain the test operations. 303 // The path to temporary directory used to contain the test operations.
301 ScopedTempDir temp_dir_; 304 ScopedTempDir temp_dir_;
302 // The path to the directory where the test data is stored. 305 // The path to the directory where the test data is stored.
303 FilePath data_dir_; 306 FilePath data_dir_;
307 // A message loop that we need for firing timers.
308 MessageLoop message_loop_;
304 // A message loop that we can use as the file thread message loop. 309 // A message loop that we can use as the file thread message loop.
305 MessageLoop message_loop_; 310 scoped_refptr<base::SequencedWorkerPool> blocking_pool_;
306 }; 311 };
307 312
308 // Verifies that ListValue and DictionaryValue pref with non emtpy default 313 // Verifies that ListValue and DictionaryValue pref with non emtpy default
309 // preserves its empty value. 314 // preserves its empty value.
310 TEST_F(PrefServiceUserFilePrefsTest, PreserveEmptyValue) { 315 TEST_F(PrefServiceUserFilePrefsTest, PreserveEmptyValue) {
311 FilePath pref_file = temp_dir_.path().AppendASCII("write.json"); 316 FilePath pref_file = temp_dir_.path().AppendASCII("write.json");
312 317
313 ASSERT_TRUE(file_util::CopyFile( 318 ASSERT_TRUE(file_util::CopyFile(
314 data_dir_.AppendASCII("read.need_empty_value.json"), 319 data_dir_.AppendASCII("read.need_empty_value.json"),
315 pref_file)); 320 pref_file));
316 321
317 PrefServiceMockBuilder builder; 322 PrefServiceMockBuilder builder;
318 builder.WithUserFilePrefs(pref_file, base::MessageLoopProxy::current()); 323 builder.WithUserFilePrefs(pref_file, blocking_pool_.get());
319 scoped_ptr<PrefService> prefs(builder.Create()); 324 scoped_ptr<PrefService> prefs(builder.Create());
320 325
321 // Register testing prefs. 326 // Register testing prefs.
322 prefs->RegisterListPref("list", 327 prefs->RegisterListPref("list",
323 PrefService::UNSYNCABLE_PREF); 328 PrefService::UNSYNCABLE_PREF);
324 prefs->RegisterDictionaryPref("dict", 329 prefs->RegisterDictionaryPref("dict",
325 PrefService::UNSYNCABLE_PREF); 330 PrefService::UNSYNCABLE_PREF);
326 331
327 base::ListValue* non_empty_list = new base::ListValue; 332 base::ListValue* non_empty_list = new base::ListValue;
328 non_empty_list->Append(base::Value::CreateStringValue("test")); 333 non_empty_list->Append(base::Value::CreateStringValue("test"));
329 prefs->RegisterListPref("list_needs_empty_value", 334 prefs->RegisterListPref("list_needs_empty_value",
330 non_empty_list, 335 non_empty_list,
331 PrefService::UNSYNCABLE_PREF); 336 PrefService::UNSYNCABLE_PREF);
332 337
333 base::DictionaryValue* non_empty_dict = new base::DictionaryValue; 338 base::DictionaryValue* non_empty_dict = new base::DictionaryValue;
334 non_empty_dict->SetString("dummy", "whatever"); 339 non_empty_dict->SetString("dummy", "whatever");
335 prefs->RegisterDictionaryPref("dict_needs_empty_value", 340 prefs->RegisterDictionaryPref("dict_needs_empty_value",
336 non_empty_dict, 341 non_empty_dict,
337 PrefService::UNSYNCABLE_PREF); 342 PrefService::UNSYNCABLE_PREF);
338 343
339 // Set all testing prefs to empty. 344 // Set all testing prefs to empty.
340 ClearListValue(prefs.get(), "list"); 345 ClearListValue(prefs.get(), "list");
341 ClearListValue(prefs.get(), "list_needs_empty_value"); 346 ClearListValue(prefs.get(), "list_needs_empty_value");
342 ClearDictionaryValue(prefs.get(), "dict"); 347 ClearDictionaryValue(prefs.get(), "dict");
343 ClearDictionaryValue(prefs.get(), "dict_needs_empty_value"); 348 ClearDictionaryValue(prefs.get(), "dict_needs_empty_value");
344 349
345 // Write to file. 350 // Write to file.
346 prefs->CommitPendingWrite(); 351 prefs->CommitPendingWrite();
347 MessageLoop::current()->RunAllPending(); 352 blocking_pool_->Shutdown();
348 353
349 // Compare to expected output. 354 // Compare to expected output.
350 FilePath golden_output_file = 355 FilePath golden_output_file =
351 data_dir_.AppendASCII("write.golden.need_empty_value.json"); 356 data_dir_.AppendASCII("write.golden.need_empty_value.json");
352 ASSERT_TRUE(file_util::PathExists(golden_output_file)); 357 ASSERT_TRUE(file_util::PathExists(golden_output_file));
353 EXPECT_TRUE(file_util::TextContentsEqual(golden_output_file, pref_file)); 358 EXPECT_TRUE(file_util::TextContentsEqual(golden_output_file, pref_file));
354 } 359 }
355 360
356 class PrefServiceSetValueTest : public testing::Test { 361 class PrefServiceSetValueTest : public testing::Test {
357 protected: 362 protected:
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 const char kDefaultFont[] = "Times"; 496 const char kDefaultFont[] = "Times";
492 #elif defined(OS_CHROMEOS) 497 #elif defined(OS_CHROMEOS)
493 const char kDefaultFont[] = "Tinos"; 498 const char kDefaultFont[] = "Tinos";
494 #else 499 #else
495 const char kDefaultFont[] = "Times New Roman"; 500 const char kDefaultFont[] = "Times New Roman";
496 #endif 501 #endif
497 EXPECT_EQ(ASCIIToUTF16(kDefaultFont), 502 EXPECT_EQ(ASCIIToUTF16(kDefaultFont),
498 webkit_prefs.standard_font_family_map[prefs::kWebKitCommonScript]); 503 webkit_prefs.standard_font_family_map[prefs::kWebKitCommonScript]);
499 EXPECT_TRUE(webkit_prefs.javascript_enabled); 504 EXPECT_TRUE(webkit_prefs.javascript_enabled);
500 } 505 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698