| OLD | NEW |
| 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/bind_helpers.h" | 6 #include "base/bind_helpers.h" |
| 7 #include "components/prefs/pref_change_registrar.h" | 7 #include "components/prefs/pref_change_registrar.h" |
| 8 #include "components/prefs/pref_observer.h" | 8 #include "components/prefs/pref_observer.h" |
| 9 #include "components/prefs/pref_registry_simple.h" | 9 #include "components/prefs/pref_registry_simple.h" |
| 10 #include "components/prefs/testing_pref_service.h" | 10 #include "components/prefs/testing_pref_service.h" |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 EXPECT_FALSE(pref_set->IsObserved(kApplicationLocale)); | 154 EXPECT_FALSE(pref_set->IsObserved(kApplicationLocale)); |
| 155 } | 155 } |
| 156 | 156 |
| 157 TEST_F(ObserveSetOfPreferencesTest, IsManaged) { | 157 TEST_F(ObserveSetOfPreferencesTest, IsManaged) { |
| 158 std::unique_ptr<PrefChangeRegistrar> pref_set(CreatePrefChangeRegistrar()); | 158 std::unique_ptr<PrefChangeRegistrar> pref_set(CreatePrefChangeRegistrar()); |
| 159 EXPECT_FALSE(pref_set->IsManaged()); | 159 EXPECT_FALSE(pref_set->IsManaged()); |
| 160 pref_service_->SetManagedPref(kHomePage, | 160 pref_service_->SetManagedPref(kHomePage, |
| 161 new StringValue("http://crbug.com")); | 161 new StringValue("http://crbug.com")); |
| 162 EXPECT_TRUE(pref_set->IsManaged()); | 162 EXPECT_TRUE(pref_set->IsManaged()); |
| 163 pref_service_->SetManagedPref(kHomePageIsNewTabPage, | 163 pref_service_->SetManagedPref(kHomePageIsNewTabPage, |
| 164 new FundamentalValue(true)); | 164 new Value(true)); |
| 165 EXPECT_TRUE(pref_set->IsManaged()); | 165 EXPECT_TRUE(pref_set->IsManaged()); |
| 166 pref_service_->RemoveManagedPref(kHomePage); | 166 pref_service_->RemoveManagedPref(kHomePage); |
| 167 EXPECT_TRUE(pref_set->IsManaged()); | 167 EXPECT_TRUE(pref_set->IsManaged()); |
| 168 pref_service_->RemoveManagedPref(kHomePageIsNewTabPage); | 168 pref_service_->RemoveManagedPref(kHomePageIsNewTabPage); |
| 169 EXPECT_FALSE(pref_set->IsManaged()); | 169 EXPECT_FALSE(pref_set->IsManaged()); |
| 170 } | 170 } |
| 171 | 171 |
| 172 TEST_F(ObserveSetOfPreferencesTest, Observe) { | 172 TEST_F(ObserveSetOfPreferencesTest, Observe) { |
| 173 using testing::_; | 173 using testing::_; |
| 174 using testing::Mock; | 174 using testing::Mock; |
| 175 | 175 |
| 176 PrefChangeRegistrar pref_set; | 176 PrefChangeRegistrar pref_set; |
| 177 PrefChangeRegistrar::NamedChangeCallback callback = base::Bind( | 177 PrefChangeRegistrar::NamedChangeCallback callback = base::Bind( |
| 178 &ObserveSetOfPreferencesTest::OnPreferenceChanged, | 178 &ObserveSetOfPreferencesTest::OnPreferenceChanged, |
| 179 base::Unretained(this)); | 179 base::Unretained(this)); |
| 180 pref_set.Init(pref_service_.get()); | 180 pref_set.Init(pref_service_.get()); |
| 181 pref_set.Add(kHomePage, callback); | 181 pref_set.Add(kHomePage, callback); |
| 182 pref_set.Add(kHomePageIsNewTabPage, callback); | 182 pref_set.Add(kHomePageIsNewTabPage, callback); |
| 183 | 183 |
| 184 EXPECT_CALL(*this, OnPreferenceChanged(kHomePage)); | 184 EXPECT_CALL(*this, OnPreferenceChanged(kHomePage)); |
| 185 pref_service_->SetUserPref(kHomePage, new StringValue("http://crbug.com")); | 185 pref_service_->SetUserPref(kHomePage, new StringValue("http://crbug.com")); |
| 186 Mock::VerifyAndClearExpectations(this); | 186 Mock::VerifyAndClearExpectations(this); |
| 187 | 187 |
| 188 EXPECT_CALL(*this, OnPreferenceChanged(kHomePageIsNewTabPage)); | 188 EXPECT_CALL(*this, OnPreferenceChanged(kHomePageIsNewTabPage)); |
| 189 pref_service_->SetUserPref(kHomePageIsNewTabPage, | 189 pref_service_->SetUserPref(kHomePageIsNewTabPage, |
| 190 new FundamentalValue(true)); | 190 new Value(true)); |
| 191 Mock::VerifyAndClearExpectations(this); | 191 Mock::VerifyAndClearExpectations(this); |
| 192 | 192 |
| 193 EXPECT_CALL(*this, OnPreferenceChanged(_)).Times(0); | 193 EXPECT_CALL(*this, OnPreferenceChanged(_)).Times(0); |
| 194 pref_service_->SetUserPref(kApplicationLocale, new StringValue("en_US.utf8")); | 194 pref_service_->SetUserPref(kApplicationLocale, new StringValue("en_US.utf8")); |
| 195 Mock::VerifyAndClearExpectations(this); | 195 Mock::VerifyAndClearExpectations(this); |
| 196 } | 196 } |
| 197 | 197 |
| 198 } // namespace base | 198 } // namespace base |
| OLD | NEW |