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

Side by Side Diff: components/prefs/pref_change_registrar_unittest.cc

Issue 2782553004: Move TestingPrefService to use unique_ptr<Value> (Closed)
Patch Set: comments Created 3 years, 8 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
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "components/prefs/pref_change_registrar.h"
6
5 #include "base/bind.h" 7 #include "base/bind.h"
6 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
7 #include "components/prefs/pref_change_registrar.h" 9 #include "base/memory/ptr_util.h"
8 #include "components/prefs/pref_observer.h" 10 #include "components/prefs/pref_observer.h"
9 #include "components/prefs/pref_registry_simple.h" 11 #include "components/prefs/pref_registry_simple.h"
10 #include "components/prefs/testing_pref_service.h" 12 #include "components/prefs/testing_pref_service.h"
11 #include "testing/gmock/include/gmock/gmock.h" 13 #include "testing/gmock/include/gmock/gmock.h"
12 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
13 15
14 using testing::Mock; 16 using testing::Mock;
15 using testing::Eq; 17 using testing::Eq;
16 18
17 namespace base { 19 namespace base {
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 TEST_F(ObserveSetOfPreferencesTest, IsObserved) { 152 TEST_F(ObserveSetOfPreferencesTest, IsObserved) {
151 std::unique_ptr<PrefChangeRegistrar> pref_set(CreatePrefChangeRegistrar()); 153 std::unique_ptr<PrefChangeRegistrar> pref_set(CreatePrefChangeRegistrar());
152 EXPECT_TRUE(pref_set->IsObserved(kHomePage)); 154 EXPECT_TRUE(pref_set->IsObserved(kHomePage));
153 EXPECT_TRUE(pref_set->IsObserved(kHomePageIsNewTabPage)); 155 EXPECT_TRUE(pref_set->IsObserved(kHomePageIsNewTabPage));
154 EXPECT_FALSE(pref_set->IsObserved(kApplicationLocale)); 156 EXPECT_FALSE(pref_set->IsObserved(kApplicationLocale));
155 } 157 }
156 158
157 TEST_F(ObserveSetOfPreferencesTest, IsManaged) { 159 TEST_F(ObserveSetOfPreferencesTest, IsManaged) {
158 std::unique_ptr<PrefChangeRegistrar> pref_set(CreatePrefChangeRegistrar()); 160 std::unique_ptr<PrefChangeRegistrar> pref_set(CreatePrefChangeRegistrar());
159 EXPECT_FALSE(pref_set->IsManaged()); 161 EXPECT_FALSE(pref_set->IsManaged());
160 pref_service_->SetManagedPref(kHomePage, new Value("http://crbug.com")); 162 pref_service_->SetManagedPref(kHomePage,
163 base::MakeUnique<Value>("http://crbug.com"));
161 EXPECT_TRUE(pref_set->IsManaged()); 164 EXPECT_TRUE(pref_set->IsManaged());
162 pref_service_->SetManagedPref(kHomePageIsNewTabPage, new Value(true)); 165 pref_service_->SetManagedPref(kHomePageIsNewTabPage,
166 base::MakeUnique<Value>(true));
163 EXPECT_TRUE(pref_set->IsManaged()); 167 EXPECT_TRUE(pref_set->IsManaged());
164 pref_service_->RemoveManagedPref(kHomePage); 168 pref_service_->RemoveManagedPref(kHomePage);
165 EXPECT_TRUE(pref_set->IsManaged()); 169 EXPECT_TRUE(pref_set->IsManaged());
166 pref_service_->RemoveManagedPref(kHomePageIsNewTabPage); 170 pref_service_->RemoveManagedPref(kHomePageIsNewTabPage);
167 EXPECT_FALSE(pref_set->IsManaged()); 171 EXPECT_FALSE(pref_set->IsManaged());
168 } 172 }
169 173
170 TEST_F(ObserveSetOfPreferencesTest, Observe) { 174 TEST_F(ObserveSetOfPreferencesTest, Observe) {
171 using testing::_; 175 using testing::_;
172 using testing::Mock; 176 using testing::Mock;
173 177
174 PrefChangeRegistrar pref_set; 178 PrefChangeRegistrar pref_set;
175 PrefChangeRegistrar::NamedChangeCallback callback = base::Bind( 179 PrefChangeRegistrar::NamedChangeCallback callback = base::Bind(
176 &ObserveSetOfPreferencesTest::OnPreferenceChanged, 180 &ObserveSetOfPreferencesTest::OnPreferenceChanged,
177 base::Unretained(this)); 181 base::Unretained(this));
178 pref_set.Init(pref_service_.get()); 182 pref_set.Init(pref_service_.get());
179 pref_set.Add(kHomePage, callback); 183 pref_set.Add(kHomePage, callback);
180 pref_set.Add(kHomePageIsNewTabPage, callback); 184 pref_set.Add(kHomePageIsNewTabPage, callback);
181 185
182 EXPECT_CALL(*this, OnPreferenceChanged(kHomePage)); 186 EXPECT_CALL(*this, OnPreferenceChanged(kHomePage));
183 pref_service_->SetUserPref(kHomePage, new Value("http://crbug.com")); 187 pref_service_->SetUserPref(kHomePage,
188 base::MakeUnique<Value>("http://crbug.com"));
184 Mock::VerifyAndClearExpectations(this); 189 Mock::VerifyAndClearExpectations(this);
185 190
186 EXPECT_CALL(*this, OnPreferenceChanged(kHomePageIsNewTabPage)); 191 EXPECT_CALL(*this, OnPreferenceChanged(kHomePageIsNewTabPage));
187 pref_service_->SetUserPref(kHomePageIsNewTabPage, new Value(true)); 192 pref_service_->SetUserPref(kHomePageIsNewTabPage,
193 base::MakeUnique<Value>(true));
188 Mock::VerifyAndClearExpectations(this); 194 Mock::VerifyAndClearExpectations(this);
189 195
190 EXPECT_CALL(*this, OnPreferenceChanged(_)).Times(0); 196 EXPECT_CALL(*this, OnPreferenceChanged(_)).Times(0);
191 pref_service_->SetUserPref(kApplicationLocale, new Value("en_US.utf8")); 197 pref_service_->SetUserPref(kApplicationLocale,
198 base::MakeUnique<Value>("en_US.utf8"));
192 Mock::VerifyAndClearExpectations(this); 199 Mock::VerifyAndClearExpectations(this);
193 } 200 }
194 201
195 } // namespace base 202 } // namespace base
OLDNEW
« no previous file with comments | « components/policy/core/browser/url_blacklist_manager_unittest.cc ('k') | components/prefs/pref_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698