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

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

Issue 11368098: Draft change to use base::Closure instead of PrefObserver in PrefChangeRegistrar. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Respond to review comments. Created 8 years, 1 month 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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 prefs.SetUserPref(pref_name, Value::CreateStringValue("http://www.cnn.com")); 101 prefs.SetUserPref(pref_name, Value::CreateStringValue("http://www.cnn.com"));
102 prefs.RegisterStringPref(pref_name, std::string()); 102 prefs.RegisterStringPref(pref_name, std::string());
103 103
104 const char new_pref_value[] = "http://www.google.com/"; 104 const char new_pref_value[] = "http://www.google.com/";
105 const StringValue expected_new_pref_value(new_pref_value); 105 const StringValue expected_new_pref_value(new_pref_value);
106 PrefObserverMock obs; 106 PrefObserverMock obs;
107 PrefChangeRegistrar registrar; 107 PrefChangeRegistrar registrar;
108 registrar.Init(&prefs); 108 registrar.Init(&prefs);
109 registrar.Add(pref_name, &obs); 109 registrar.Add(pref_name, &obs);
110 110
111 PrefChangeRegistrar registrar_two;
112 registrar_two.Init(&prefs);
113
111 // This should fire the checks in PrefObserverMock::Observe. 114 // This should fire the checks in PrefObserverMock::Observe.
112 obs.Expect(&prefs, pref_name, &expected_new_pref_value); 115 obs.Expect(&prefs, pref_name, &expected_new_pref_value);
113 prefs.SetString(pref_name, new_pref_value); 116 prefs.SetString(pref_name, new_pref_value);
114 Mock::VerifyAndClearExpectations(&obs); 117 Mock::VerifyAndClearExpectations(&obs);
115 118
116 // Now try adding a second pref observer. 119 // Now try adding a second pref observer.
117 const char new_pref_value2[] = "http://www.youtube.com/"; 120 const char new_pref_value2[] = "http://www.youtube.com/";
118 const StringValue expected_new_pref_value2(new_pref_value2); 121 const StringValue expected_new_pref_value2(new_pref_value2);
119 PrefObserverMock obs2; 122 PrefObserverMock obs2;
120 obs.Expect(&prefs, pref_name, &expected_new_pref_value2); 123 obs.Expect(&prefs, pref_name, &expected_new_pref_value2);
121 obs2.Expect(&prefs, pref_name, &expected_new_pref_value2); 124 obs2.Expect(&prefs, pref_name, &expected_new_pref_value2);
122 registrar.Add(pref_name, &obs2); 125 registrar_two.Add(pref_name, &obs2);
123 // This should fire the checks in obs and obs2. 126 // This should fire the checks in obs and obs2.
124 prefs.SetString(pref_name, new_pref_value2); 127 prefs.SetString(pref_name, new_pref_value2);
125 Mock::VerifyAndClearExpectations(&obs); 128 Mock::VerifyAndClearExpectations(&obs);
126 Mock::VerifyAndClearExpectations(&obs2); 129 Mock::VerifyAndClearExpectations(&obs2);
127 130
128 // Set a recommended value. 131 // Set a recommended value.
129 const StringValue recommended_pref_value("http://www.gmail.com/"); 132 const StringValue recommended_pref_value("http://www.gmail.com/");
130 obs.Expect(&prefs, pref_name, &expected_new_pref_value2); 133 obs.Expect(&prefs, pref_name, &expected_new_pref_value2);
131 obs2.Expect(&prefs, pref_name, &expected_new_pref_value2); 134 obs2.Expect(&prefs, pref_name, &expected_new_pref_value2);
132 // This should fire the checks in obs and obs2 but with an unchanged value 135 // This should fire the checks in obs and obs2 but with an unchanged value
133 // as the recommended value is being overridden by the user-set value. 136 // as the recommended value is being overridden by the user-set value.
134 prefs.SetRecommendedPref(pref_name, recommended_pref_value.DeepCopy()); 137 prefs.SetRecommendedPref(pref_name, recommended_pref_value.DeepCopy());
135 Mock::VerifyAndClearExpectations(&obs); 138 Mock::VerifyAndClearExpectations(&obs);
136 Mock::VerifyAndClearExpectations(&obs2); 139 Mock::VerifyAndClearExpectations(&obs2);
137 140
138 // Make sure obs2 still works after removing obs. 141 // Make sure obs2 still works after removing obs.
139 registrar.Remove(pref_name, &obs); 142 registrar.Remove(pref_name);
140 EXPECT_CALL(obs, OnPreferenceChanged(_, _)).Times(0); 143 EXPECT_CALL(obs, OnPreferenceChanged(_, _)).Times(0);
141 obs2.Expect(&prefs, pref_name, &expected_new_pref_value); 144 obs2.Expect(&prefs, pref_name, &expected_new_pref_value);
142 // This should only fire the observer in obs2. 145 // This should only fire the observer in obs2.
143 prefs.SetString(pref_name, new_pref_value); 146 prefs.SetString(pref_name, new_pref_value);
144 Mock::VerifyAndClearExpectations(&obs); 147 Mock::VerifyAndClearExpectations(&obs);
145 Mock::VerifyAndClearExpectations(&obs2); 148 Mock::VerifyAndClearExpectations(&obs2);
146 } 149 }
147 150
148 // Make sure that if a preference changes type, so the wrong type is stored in 151 // Make sure that if a preference changes type, so the wrong type is stored in
149 // the user pref file, it uses the correct fallback value instead. 152 // the user pref file, it uses the correct fallback value instead.
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 const char kDefaultFont[] = "Times"; 494 const char kDefaultFont[] = "Times";
492 #elif defined(OS_CHROMEOS) 495 #elif defined(OS_CHROMEOS)
493 const char kDefaultFont[] = "Tinos"; 496 const char kDefaultFont[] = "Tinos";
494 #else 497 #else
495 const char kDefaultFont[] = "Times New Roman"; 498 const char kDefaultFont[] = "Times New Roman";
496 #endif 499 #endif
497 EXPECT_EQ(ASCIIToUTF16(kDefaultFont), 500 EXPECT_EQ(ASCIIToUTF16(kDefaultFont),
498 webkit_prefs.standard_font_family_map[prefs::kWebKitCommonScript]); 501 webkit_prefs.standard_font_family_map[prefs::kWebKitCommonScript]);
499 EXPECT_TRUE(webkit_prefs.javascript_enabled); 502 EXPECT_TRUE(webkit_prefs.javascript_enabled);
500 } 503 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_prefs_unittest.cc ('k') | chrome/browser/ui/ash/launcher/chrome_launcher_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698