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

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: rebase 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"
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 294
295 void ClearDictionaryValue(PrefService* prefs, const char* key) { 295 void ClearDictionaryValue(PrefService* prefs, const char* key) {
296 DictionaryPrefUpdate updater(prefs, key); 296 DictionaryPrefUpdate updater(prefs, key);
297 updater->Clear(); 297 updater->Clear();
298 } 298 }
299 299
300 // The path to temporary directory used to contain the test operations. 300 // The path to temporary directory used to contain the test operations.
301 ScopedTempDir temp_dir_; 301 ScopedTempDir temp_dir_;
302 // The path to the directory where the test data is stored. 302 // The path to the directory where the test data is stored.
303 FilePath data_dir_; 303 FilePath data_dir_;
304 // A message loop that we can use as the file thread message loop. 304 // A message loop that we need for firing timers.
Mattias Nissler (ping if slow) 2012/10/22 17:28:21 It's not timers AFAICS.
zel 2012/10/24 02:20:11 Done.
305 MessageLoop message_loop_; 305 MessageLoop message_loop_;
306 }; 306 };
307 307
308 // Verifies that ListValue and DictionaryValue pref with non emtpy default 308 // Verifies that ListValue and DictionaryValue pref with non emtpy default
309 // preserves its empty value. 309 // preserves its empty value.
310 TEST_F(PrefServiceUserFilePrefsTest, PreserveEmptyValue) { 310 TEST_F(PrefServiceUserFilePrefsTest, PreserveEmptyValue) {
311 FilePath pref_file = temp_dir_.path().AppendASCII("write.json"); 311 FilePath pref_file = temp_dir_.path().AppendASCII("write.json");
312 312
313 ASSERT_TRUE(file_util::CopyFile( 313 ASSERT_TRUE(file_util::CopyFile(
314 data_dir_.AppendASCII("read.need_empty_value.json"), 314 data_dir_.AppendASCII("read.need_empty_value.json"),
315 pref_file)); 315 pref_file));
316 316
317 PrefServiceMockBuilder builder; 317 PrefServiceMockBuilder builder;
318 builder.WithUserFilePrefs(pref_file, base::MessageLoopProxy::current()); 318 builder.WithUserFilePrefs(pref_file, message_loop_.message_loop_proxy());
319 scoped_ptr<PrefService> prefs(builder.Create()); 319 scoped_ptr<PrefService> prefs(builder.Create());
320 320
321 // Register testing prefs. 321 // Register testing prefs.
322 prefs->RegisterListPref("list", 322 prefs->RegisterListPref("list",
323 PrefService::UNSYNCABLE_PREF); 323 PrefService::UNSYNCABLE_PREF);
324 prefs->RegisterDictionaryPref("dict", 324 prefs->RegisterDictionaryPref("dict",
325 PrefService::UNSYNCABLE_PREF); 325 PrefService::UNSYNCABLE_PREF);
326 326
327 base::ListValue* non_empty_list = new base::ListValue; 327 base::ListValue* non_empty_list = new base::ListValue;
328 non_empty_list->Append(base::Value::CreateStringValue("test")); 328 non_empty_list->Append(base::Value::CreateStringValue("test"));
329 prefs->RegisterListPref("list_needs_empty_value", 329 prefs->RegisterListPref("list_needs_empty_value",
330 non_empty_list, 330 non_empty_list,
331 PrefService::UNSYNCABLE_PREF); 331 PrefService::UNSYNCABLE_PREF);
332 332
333 base::DictionaryValue* non_empty_dict = new base::DictionaryValue; 333 base::DictionaryValue* non_empty_dict = new base::DictionaryValue;
334 non_empty_dict->SetString("dummy", "whatever"); 334 non_empty_dict->SetString("dummy", "whatever");
335 prefs->RegisterDictionaryPref("dict_needs_empty_value", 335 prefs->RegisterDictionaryPref("dict_needs_empty_value",
336 non_empty_dict, 336 non_empty_dict,
337 PrefService::UNSYNCABLE_PREF); 337 PrefService::UNSYNCABLE_PREF);
338 338
339 // Set all testing prefs to empty. 339 // Set all testing prefs to empty.
340 ClearListValue(prefs.get(), "list"); 340 ClearListValue(prefs.get(), "list");
341 ClearListValue(prefs.get(), "list_needs_empty_value"); 341 ClearListValue(prefs.get(), "list_needs_empty_value");
342 ClearDictionaryValue(prefs.get(), "dict"); 342 ClearDictionaryValue(prefs.get(), "dict");
343 ClearDictionaryValue(prefs.get(), "dict_needs_empty_value"); 343 ClearDictionaryValue(prefs.get(), "dict_needs_empty_value");
344 344
345 // Write to file. 345 // Write to file.
346 prefs->CommitPendingWrite(); 346 prefs->CommitPendingWrite();
347 MessageLoop::current()->RunAllPending(); 347 message_loop_.RunAllPending();
348 348
349 // Compare to expected output. 349 // Compare to expected output.
350 FilePath golden_output_file = 350 FilePath golden_output_file =
351 data_dir_.AppendASCII("write.golden.need_empty_value.json"); 351 data_dir_.AppendASCII("write.golden.need_empty_value.json");
352 ASSERT_TRUE(file_util::PathExists(golden_output_file)); 352 ASSERT_TRUE(file_util::PathExists(golden_output_file));
353 EXPECT_TRUE(file_util::TextContentsEqual(golden_output_file, pref_file)); 353 EXPECT_TRUE(file_util::TextContentsEqual(golden_output_file, pref_file));
354 } 354 }
355 355
356 class PrefServiceSetValueTest : public testing::Test { 356 class PrefServiceSetValueTest : public testing::Test {
357 protected: 357 protected:
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 const char kDefaultFont[] = "Times"; 491 const char kDefaultFont[] = "Times";
492 #elif defined(OS_CHROMEOS) 492 #elif defined(OS_CHROMEOS)
493 const char kDefaultFont[] = "Tinos"; 493 const char kDefaultFont[] = "Tinos";
494 #else 494 #else
495 const char kDefaultFont[] = "Times New Roman"; 495 const char kDefaultFont[] = "Times New Roman";
496 #endif 496 #endif
497 EXPECT_EQ(ASCIIToUTF16(kDefaultFont), 497 EXPECT_EQ(ASCIIToUTF16(kDefaultFont),
498 webkit_prefs.standard_font_family_map[prefs::kWebKitCommonScript]); 498 webkit_prefs.standard_font_family_map[prefs::kWebKitCommonScript]);
499 EXPECT_TRUE(webkit_prefs.javascript_enabled); 499 EXPECT_TRUE(webkit_prefs.javascript_enabled);
500 } 500 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698