| OLD | NEW |
| 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 "chrome/browser/ui/webui/options/preferences_browsertest.h" | 5 #include "chrome/browser/ui/webui/options/preferences_browsertest.h" |
| 6 | 6 |
| 7 #include <iostream> | 7 #include <iostream> |
| 8 #include <sstream> | 8 #include <sstream> |
| 9 | 9 |
| 10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 L"" | 155 L"" |
| 156 L" finishObservingAndReply: function() {" | 156 L" finishObservingAndReply: function() {" |
| 157 L" this.sentinelValue_ = !this.sentinelValue_;" | 157 L" this.sentinelValue_ = !this.sentinelValue_;" |
| 158 L" Preferences.setBooleanPref(this.sentinelName_, this.sentinelValue_," | 158 L" Preferences.setBooleanPref(this.sentinelName_, this.sentinelValue_," |
| 159 L" true);" | 159 L" true);" |
| 160 L" }" | 160 L" }" |
| 161 L"};")); | 161 L"};")); |
| 162 } | 162 } |
| 163 | 163 |
| 164 // Forwards notifications received when pref values change in the backend. | 164 // Forwards notifications received when pref values change in the backend. |
| 165 void PreferencesBrowserTest::OnPreferenceChanged(PrefServiceBase* service, | 165 void PreferencesBrowserTest::OnPreferenceChanged(const std::string& pref_name) { |
| 166 const std::string& pref_name) { | |
| 167 ASSERT_EQ(pref_service_, service); | |
| 168 OnCommit(pref_service_->FindPreference(pref_name.c_str())); | 166 OnCommit(pref_service_->FindPreference(pref_name.c_str())); |
| 169 } | 167 } |
| 170 | 168 |
| 171 // Sets up a mock user policy provider. | 169 // Sets up a mock user policy provider. |
| 172 void PreferencesBrowserTest::SetUpInProcessBrowserTestFixture() { | 170 void PreferencesBrowserTest::SetUpInProcessBrowserTestFixture() { |
| 173 EXPECT_CALL(policy_provider_, IsInitializationComplete()) | 171 EXPECT_CALL(policy_provider_, IsInitializationComplete()) |
| 174 .WillRepeatedly(Return(true)); | 172 .WillRepeatedly(Return(true)); |
| 175 policy::BrowserPolicyConnector::SetPolicyProviderForTesting( | 173 policy::BrowserPolicyConnector::SetPolicyProviderForTesting( |
| 176 &policy_provider_); | 174 &policy_provider_); |
| 177 }; | 175 }; |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 scoped_ptr<base::Value> observed_value_ptr(base::JSONReader::Read(json)); | 260 scoped_ptr<base::Value> observed_value_ptr(base::JSONReader::Read(json)); |
| 263 const base::DictionaryValue* observed_dict; | 261 const base::DictionaryValue* observed_dict; |
| 264 ASSERT_TRUE(observed_value_ptr.get()); | 262 ASSERT_TRUE(observed_value_ptr.get()); |
| 265 ASSERT_TRUE(observed_value_ptr->GetAsDictionary(&observed_dict)); | 263 ASSERT_TRUE(observed_value_ptr->GetAsDictionary(&observed_dict)); |
| 266 for (size_t i = 0; i < names.size(); ++i) | 264 for (size_t i = 0; i < names.size(); ++i) |
| 267 VerifyPref(observed_dict, names[i], values[i], controlledBy, disabled, | 265 VerifyPref(observed_dict, names[i], values[i], controlledBy, disabled, |
| 268 uncommitted); | 266 uncommitted); |
| 269 } | 267 } |
| 270 | 268 |
| 271 void PreferencesBrowserTest::ExpectNoCommit(const std::string& name) { | 269 void PreferencesBrowserTest::ExpectNoCommit(const std::string& name) { |
| 272 pref_change_registrar_.Add(name.c_str(), this); | 270 pref_change_registrar_.Add( |
| 271 name.c_str(), |
| 272 base::Bind(&PreferencesBrowserTest::OnPreferenceChanged, |
| 273 base::Unretained(this))); |
| 273 EXPECT_CALL(*this, OnCommit(Property(&PrefService::Preference::name, name))) | 274 EXPECT_CALL(*this, OnCommit(Property(&PrefService::Preference::name, name))) |
| 274 .Times(0); | 275 .Times(0); |
| 275 } | 276 } |
| 276 | 277 |
| 277 void PreferencesBrowserTest::ExpectSetCommit(const std::string& name, | 278 void PreferencesBrowserTest::ExpectSetCommit(const std::string& name, |
| 278 const base::Value* value) { | 279 const base::Value* value) { |
| 279 pref_change_registrar_.Add(name.c_str(), this); | 280 pref_change_registrar_.Add( |
| 281 name.c_str(), |
| 282 base::Bind(&PreferencesBrowserTest::OnPreferenceChanged, |
| 283 base::Unretained(this))); |
| 280 EXPECT_CALL(*this, OnCommit(AllOf( | 284 EXPECT_CALL(*this, OnCommit(AllOf( |
| 281 Property(&PrefService::Preference::name, name), | 285 Property(&PrefService::Preference::name, name), |
| 282 Property(&PrefService::Preference::IsUserControlled, true), | 286 Property(&PrefService::Preference::IsUserControlled, true), |
| 283 Property(&PrefService::Preference::GetValue, EqualsValue(value))))); | 287 Property(&PrefService::Preference::GetValue, EqualsValue(value))))); |
| 284 } | 288 } |
| 285 | 289 |
| 286 void PreferencesBrowserTest::ExpectClearCommit(const std::string& name) { | 290 void PreferencesBrowserTest::ExpectClearCommit(const std::string& name) { |
| 287 pref_change_registrar_.Add(name.c_str(), this); | 291 pref_change_registrar_.Add( |
| 292 name.c_str(), |
| 293 base::Bind(&PreferencesBrowserTest::OnPreferenceChanged, |
| 294 base::Unretained(this))); |
| 288 EXPECT_CALL(*this, OnCommit(AllOf( | 295 EXPECT_CALL(*this, OnCommit(AllOf( |
| 289 Property(&PrefService::Preference::name, name), | 296 Property(&PrefService::Preference::name, name), |
| 290 Property(&PrefService::Preference::IsUserControlled, false)))); | 297 Property(&PrefService::Preference::IsUserControlled, false)))); |
| 291 } | 298 } |
| 292 | 299 |
| 293 void PreferencesBrowserTest::VerifyAndClearExpectations() { | 300 void PreferencesBrowserTest::VerifyAndClearExpectations() { |
| 294 Mock::VerifyAndClearExpectations(this); | 301 Mock::VerifyAndClearExpectations(this); |
| 295 pref_change_registrar_.RemoveAll(); | 302 pref_change_registrar_.RemoveAll(); |
| 296 } | 303 } |
| 297 | 304 |
| (...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 728 // Do not set the Boolean pref. It will toogle automatically. | 735 // Do not set the Boolean pref. It will toogle automatically. |
| 729 for (size_t i = 1; i < pref_names_.size(); ++i) | 736 for (size_t i = 1; i < pref_names_.size(); ++i) |
| 730 chromeos::proxy_cros_settings_parser::SetProxyPrefValue( | 737 chromeos::proxy_cros_settings_parser::SetProxyPrefValue( |
| 731 profile, pref_names_[i], non_default_values_[i]->DeepCopy()); | 738 profile, pref_names_[i], non_default_values_[i]->DeepCopy()); |
| 732 SetupJavaScriptTestEnvironment(pref_names_, &observed_json); | 739 SetupJavaScriptTestEnvironment(pref_names_, &observed_json); |
| 733 VerifyObservedPrefs(observed_json, pref_names_, non_default_values_, | 740 VerifyObservedPrefs(observed_json, pref_names_, non_default_values_, |
| 734 "", false, false); | 741 "", false, false); |
| 735 } | 742 } |
| 736 | 743 |
| 737 #endif | 744 #endif |
| OLD | NEW |