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

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

Issue 12092021: Remove PersistentPrefStore::MarkNeedsEmptyValue. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix some tests. Created 7 years, 10 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
« no previous file with comments | « chrome/browser/prefs/pref_service.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/files/scoped_temp_dir.h" 9 #include "base/files/scoped_temp_dir.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 19 matching lines...) Expand all
30 #include "chrome/test/base/testing_profile.h" 30 #include "chrome/test/base/testing_profile.h"
31 #include "content/public/test/test_browser_thread.h" 31 #include "content/public/test/test_browser_thread.h"
32 #include "content/public/test/web_contents_tester.h" 32 #include "content/public/test/web_contents_tester.h"
33 #include "testing/gmock/include/gmock/gmock.h" 33 #include "testing/gmock/include/gmock/gmock.h"
34 #include "testing/gtest/include/gtest/gtest.h" 34 #include "testing/gtest/include/gtest/gtest.h"
35 #include "ui/base/test/data/resource.h" 35 #include "ui/base/test/data/resource.h"
36 #include "webkit/glue/webpreferences.h" 36 #include "webkit/glue/webpreferences.h"
37 37
38 using content::BrowserThread; 38 using content::BrowserThread;
39 using content::WebContentsTester; 39 using content::WebContentsTester;
40 using testing::Mock;
40 using testing::_; 41 using testing::_;
41 using testing::Mock;
42 42
43 TEST(PrefServiceTest, NoObserverFire) { 43 TEST(PrefServiceTest, NoObserverFire) {
44 TestingPrefServiceSimple prefs; 44 TestingPrefServiceSimple prefs;
45 45
46 const char pref_name[] = "homepage"; 46 const char pref_name[] = "homepage";
47 prefs.RegisterStringPref(pref_name, std::string()); 47 prefs.RegisterStringPref(pref_name, std::string());
48 48
49 const char new_pref_value[] = "http://www.google.com/"; 49 const char new_pref_value[] = "http://www.google.com/";
50 MockPrefChangeCallback obs(&prefs); 50 MockPrefChangeCallback obs(&prefs);
51 PrefChangeRegistrar registrar; 51 PrefChangeRegistrar registrar;
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 // The path to temporary directory used to contain the test operations. 303 // The path to temporary directory used to contain the test operations.
304 base::ScopedTempDir temp_dir_; 304 base::ScopedTempDir temp_dir_;
305 // The path to the directory where the test data is stored. 305 // The path to the directory where the test data is stored.
306 FilePath data_dir_; 306 FilePath data_dir_;
307 // A message loop that we can use as the file thread message loop. 307 // A message loop that we can use as the file thread message loop.
308 MessageLoop message_loop_; 308 MessageLoop message_loop_;
309 }; 309 };
310 310
311 // Verifies that ListValue and DictionaryValue pref with non emtpy default 311 // Verifies that ListValue and DictionaryValue pref with non emtpy default
312 // preserves its empty value. 312 // preserves its empty value.
313 TEST_F(PrefServiceUserFilePrefsTest, PreserveEmptyValue) {
314 FilePath pref_file = temp_dir_.path().AppendASCII("write.json");
315
316 ASSERT_TRUE(file_util::CopyFile(
317 data_dir_.AppendASCII("read.need_empty_value.json"),
318 pref_file));
319
320 PrefServiceMockBuilder builder;
321 builder.WithUserFilePrefs(pref_file, message_loop_.message_loop_proxy());
322 scoped_ptr<PrefServiceSyncable> prefs(builder.CreateSyncable());
323
324 // Register testing prefs.
325 prefs->RegisterListPref("list",
326 PrefServiceSyncable::UNSYNCABLE_PREF);
327 prefs->RegisterDictionaryPref("dict",
328 PrefServiceSyncable::UNSYNCABLE_PREF);
329
330 base::ListValue* non_empty_list = new base::ListValue;
331 non_empty_list->Append(base::Value::CreateStringValue("test"));
332 prefs->RegisterListPref("list_needs_empty_value",
333 non_empty_list,
334 PrefServiceSyncable::UNSYNCABLE_PREF);
335
336 base::DictionaryValue* non_empty_dict = new base::DictionaryValue;
337 non_empty_dict->SetString("dummy", "whatever");
338 prefs->RegisterDictionaryPref("dict_needs_empty_value",
339 non_empty_dict,
340 PrefServiceSyncable::UNSYNCABLE_PREF);
341
342 // Set all testing prefs to empty.
343 ClearListValue(prefs.get(), "list");
344 ClearListValue(prefs.get(), "list_needs_empty_value");
345 ClearDictionaryValue(prefs.get(), "dict");
346 ClearDictionaryValue(prefs.get(), "dict_needs_empty_value");
347
348 // Write to file.
349 prefs->CommitPendingWrite();
350 message_loop_.RunUntilIdle();
351
352 // Compare to expected output.
353 FilePath golden_output_file =
354 data_dir_.AppendASCII("write.golden.need_empty_value.json");
355 ASSERT_TRUE(file_util::PathExists(golden_output_file));
356 EXPECT_TRUE(file_util::TextContentsEqual(golden_output_file, pref_file));
357 }
358
359 class PrefServiceSetValueTest : public testing::Test { 313 class PrefServiceSetValueTest : public testing::Test {
360 protected: 314 protected:
361 static const char kName[]; 315 static const char kName[];
362 static const char kValue[]; 316 static const char kValue[];
363 317
364 PrefServiceSetValueTest() : observer_(&prefs_) {} 318 PrefServiceSetValueTest() : observer_(&prefs_) {}
365 319
366 TestingPrefServiceSimple prefs_; 320 TestingPrefServiceSimple prefs_;
367 MockPrefChangeCallback observer_; 321 MockPrefChangeCallback observer_;
368 }; 322 };
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 const char kDefaultFont[] = "Times"; 451 const char kDefaultFont[] = "Times";
498 #elif defined(OS_CHROMEOS) 452 #elif defined(OS_CHROMEOS)
499 const char kDefaultFont[] = "Tinos"; 453 const char kDefaultFont[] = "Tinos";
500 #else 454 #else
501 const char kDefaultFont[] = "Times New Roman"; 455 const char kDefaultFont[] = "Times New Roman";
502 #endif 456 #endif
503 EXPECT_EQ(ASCIIToUTF16(kDefaultFont), 457 EXPECT_EQ(ASCIIToUTF16(kDefaultFont),
504 webkit_prefs.standard_font_family_map[prefs::kWebKitCommonScript]); 458 webkit_prefs.standard_font_family_map[prefs::kWebKitCommonScript]);
505 EXPECT_TRUE(webkit_prefs.javascript_enabled); 459 EXPECT_TRUE(webkit_prefs.javascript_enabled);
506 } 460 }
OLDNEW
« no previous file with comments | « chrome/browser/prefs/pref_service.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698