| 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/callback.h" | 10 #include "base/callback.h" |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 const std::vector<base::Value*>& values) { | 224 const std::vector<base::Value*>& values) { |
| 225 for (size_t i = 0; i < names.size(); ++i) | 225 for (size_t i = 0; i < names.size(); ++i) |
| 226 pref_service_->Set(names[i].c_str(), *values[i]); | 226 pref_service_->Set(names[i].c_str(), *values[i]); |
| 227 } | 227 } |
| 228 | 228 |
| 229 void PreferencesBrowserTest::VerifyKeyValue(const base::DictionaryValue& dict, | 229 void PreferencesBrowserTest::VerifyKeyValue(const base::DictionaryValue& dict, |
| 230 const std::string& key, | 230 const std::string& key, |
| 231 const base::Value& expected) { | 231 const base::Value& expected) { |
| 232 const base::Value* actual = NULL; | 232 const base::Value* actual = NULL; |
| 233 EXPECT_TRUE(dict.Get(key, &actual)) << "Was checking key: " << key; | 233 EXPECT_TRUE(dict.Get(key, &actual)) << "Was checking key: " << key; |
| 234 EXPECT_EQ(expected, *actual) << "Was checking key: " << key; | 234 if (actual) |
| 235 EXPECT_EQ(expected, *actual) << "Was checking key: " << key; |
| 235 } | 236 } |
| 236 | 237 |
| 237 void PreferencesBrowserTest::VerifyPref(const base::DictionaryValue* prefs, | 238 void PreferencesBrowserTest::VerifyPref(const base::DictionaryValue* prefs, |
| 238 const std::string& name, | 239 const std::string& name, |
| 239 const base::Value* value, | 240 const base::Value* value, |
| 240 const std::string& controlledBy, | 241 const std::string& controlledBy, |
| 241 bool disabled, | 242 bool disabled, |
| 242 bool uncommitted) { | 243 bool uncommitted) { |
| 243 const base::Value* pref; | 244 const base::Value* pref = NULL; |
| 244 const base::DictionaryValue* dict; | 245 const base::DictionaryValue* dict = NULL; |
| 245 ASSERT_TRUE(prefs->GetWithoutPathExpansion(name, &pref)); | 246 ASSERT_TRUE(prefs->GetWithoutPathExpansion(name, &pref)); |
| 246 ASSERT_TRUE(pref->GetAsDictionary(&dict)); | 247 ASSERT_TRUE(pref->GetAsDictionary(&dict)); |
| 247 VerifyKeyValue(*dict, "value", *value); | 248 VerifyKeyValue(*dict, "value", *value); |
| 248 if (!controlledBy.empty()) { | 249 if (!controlledBy.empty()) |
| 249 VerifyKeyValue(*dict, "controlledBy", base::StringValue(controlledBy)); | 250 VerifyKeyValue(*dict, "controlledBy", base::StringValue(controlledBy)); |
| 250 } else { | 251 else |
| 251 EXPECT_FALSE(dict->HasKey("controlledBy")); | 252 EXPECT_FALSE(dict->HasKey("controlledBy")); |
| 252 } | 253 |
| 253 if (disabled) | 254 if (disabled) |
| 254 VerifyKeyValue(*dict, "disabled", base::FundamentalValue(true)); | 255 VerifyKeyValue(*dict, "disabled", base::FundamentalValue(true)); |
| 255 else if (dict->HasKey("disabled")) | 256 else if (dict->HasKey("disabled")) |
| 256 VerifyKeyValue(*dict, "disabled", base::FundamentalValue(false)); | 257 VerifyKeyValue(*dict, "disabled", base::FundamentalValue(false)); |
| 258 |
| 257 if (uncommitted) | 259 if (uncommitted) |
| 258 VerifyKeyValue(*dict, "uncommitted", base::FundamentalValue(true)); | 260 VerifyKeyValue(*dict, "uncommitted", base::FundamentalValue(true)); |
| 259 else if (dict->HasKey("uncommitted")) | 261 else if (dict->HasKey("uncommitted")) |
| 260 VerifyKeyValue(*dict, "uncommitted", base::FundamentalValue(false)); | 262 VerifyKeyValue(*dict, "uncommitted", base::FundamentalValue(false)); |
| 261 } | 263 } |
| 262 | 264 |
| 263 void PreferencesBrowserTest::VerifyObservedPref(const std::string& json, | 265 void PreferencesBrowserTest::VerifyObservedPref(const std::string& json, |
| 264 const std::string& name, | 266 const std::string& name, |
| 265 const base::Value* value, | 267 const base::Value* value, |
| 266 const std::string& controlledBy, | 268 const std::string& controlledBy, |
| (...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 834 chromeos::onc::ONCSource expected_source) { | 836 chromeos::onc::ONCSource expected_source) { |
| 835 const chromeos::FavoriteState* network = GetDefaultFavoriteNetwork(); | 837 const chromeos::FavoriteState* network = GetDefaultFavoriteNetwork(); |
| 836 ASSERT_TRUE(network); | 838 ASSERT_TRUE(network); |
| 837 chromeos::onc::ONCSource actual_source; | 839 chromeos::onc::ONCSource actual_source; |
| 838 scoped_ptr<ProxyConfigDictionary> proxy_dict = | 840 scoped_ptr<ProxyConfigDictionary> proxy_dict = |
| 839 chromeos::proxy_config::GetProxyConfigForFavoriteNetwork( | 841 chromeos::proxy_config::GetProxyConfigForFavoriteNetwork( |
| 840 pref_service_, | 842 pref_service_, |
| 841 g_browser_process->local_state(), | 843 g_browser_process->local_state(), |
| 842 *network, | 844 *network, |
| 843 &actual_source); | 845 &actual_source); |
| 846 ASSERT_TRUE(proxy_dict); |
| 844 std::string actual_proxy_server; | 847 std::string actual_proxy_server; |
| 845 EXPECT_TRUE(proxy_dict->GetProxyServer(&actual_proxy_server)); | 848 EXPECT_TRUE(proxy_dict->GetProxyServer(&actual_proxy_server)); |
| 846 EXPECT_EQ(expected_server, actual_proxy_server); | 849 EXPECT_EQ(expected_server, actual_proxy_server); |
| 847 EXPECT_EQ(expected_source, actual_source); | 850 EXPECT_EQ(expected_source, actual_source); |
| 848 } | 851 } |
| 849 }; | 852 }; |
| 850 | 853 |
| 851 // Verifies that proxy settings are correctly pushed to JavaScript during | 854 // Verifies that proxy settings are correctly pushed to JavaScript during |
| 852 // initialization of the proxy settings page. | 855 // initialization of the proxy settings page. |
| 853 IN_PROC_BROWSER_TEST_F(ProxyPreferencesBrowserTest, ChromeOSInitializeProxy) { | 856 IN_PROC_BROWSER_TEST_F(ProxyPreferencesBrowserTest, ChromeOSInitializeProxy) { |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 993 SetProxyPref(chromeos::kProxyHttpsPort, base::FundamentalValue(2)); | 996 SetProxyPref(chromeos::kProxyHttpsPort, base::FundamentalValue(2)); |
| 994 SetProxyPref(chromeos::kProxyFtpPort, base::FundamentalValue(3)); | 997 SetProxyPref(chromeos::kProxyFtpPort, base::FundamentalValue(3)); |
| 995 SetProxyPref(chromeos::kProxySocksPort, base::FundamentalValue(4)); | 998 SetProxyPref(chromeos::kProxySocksPort, base::FundamentalValue(4)); |
| 996 | 999 |
| 997 VerifyCurrentProxyServer( | 1000 VerifyCurrentProxyServer( |
| 998 "http=a.com:1;https=4.3.2.1:2;ftp=c.com:3;socks=socks4://d.com:4", | 1001 "http=a.com:1;https=4.3.2.1:2;ftp=c.com:3;socks=socks4://d.com:4", |
| 999 chromeos::onc::ONC_SOURCE_NONE); | 1002 chromeos::onc::ONC_SOURCE_NONE); |
| 1000 } | 1003 } |
| 1001 | 1004 |
| 1002 #endif | 1005 #endif |
| OLD | NEW |