Chromium Code Reviews

Side by Side Diff: chrome/browser/extensions/extension_proxy_apitest.cc

Issue 5701003: Intorduce a separate preference for 'proxy server mode' (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix indentation nit Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | | Annotate | Revision Log
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 "chrome/browser/extensions/extension_apitest.h" 5 #include "chrome/browser/extensions/extension_apitest.h"
6 #include "chrome/browser/prefs/pref_service.h" 6 #include "chrome/browser/prefs/pref_service.h"
7 #include "chrome/browser/prefs/proxy_prefs.h"
7 #include "chrome/browser/profiles/profile.h" 8 #include "chrome/browser/profiles/profile.h"
8 #include "chrome/browser/ui/browser.h" 9 #include "chrome/browser/ui/browser.h"
9 #include "chrome/common/chrome_switches.h" 10 #include "chrome/common/chrome_switches.h"
10 #include "chrome/common/extensions/extension.h" 11 #include "chrome/common/extensions/extension.h"
11 #include "chrome/common/pref_names.h" 12 #include "chrome/common/pref_names.h"
12 13
13 // Tests auto-detect and PAC proxy settings. 14 // Tests auto-detect and PAC proxy settings.
14 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ProxyAutoSettings) { 15 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ProxyAutoSettings) {
15 CommandLine::ForCurrentProcess()->AppendSwitch( 16 CommandLine::ForCurrentProcess()->AppendSwitch(
16 switches::kEnableExperimentalExtensionApis); 17 switches::kEnableExperimentalExtensionApis);
17 18
18 ASSERT_TRUE(RunExtensionTest("proxy/auto")) << message_; 19 ASSERT_TRUE(RunExtensionTest("proxy/auto")) << message_;
19 const Extension* extension = GetSingleLoadedExtension(); 20 const Extension* extension = GetSingleLoadedExtension();
20 ASSERT_TRUE(extension); 21 ASSERT_TRUE(extension);
21 22
22 PrefService* pref_service = browser()->profile()->GetPrefs(); 23 PrefService* pref_service = browser()->profile()->GetPrefs();
23 24
24 const PrefService::Preference* pref = 25 const PrefService::Preference* pref =
25 pref_service->FindPreference(prefs::kProxyAutoDetect); 26 pref_service->FindPreference(prefs::kProxyServerMode);
Pam (message me for reviews) 2010/12/18 08:29:55 Not to quibble, but I don't understand the naming
battre (please use the other) 2010/12/20 12:57:23 Done. I discussed this with Danno. We agree that
26 ASSERT_TRUE(pref != NULL); 27 ASSERT_TRUE(pref != NULL);
27 ASSERT_TRUE(pref->IsExtensionControlled()); 28 ASSERT_TRUE(pref->IsExtensionControlled());
28 bool auto_detect = pref_service->GetBoolean(prefs::kProxyAutoDetect); 29 int mode = pref_service->GetInteger(prefs::kProxyServerMode);
29 EXPECT_TRUE(auto_detect); 30 EXPECT_EQ(ProxyPrefs::AUTO_DETECT, mode);
30 31
31 pref = pref_service->FindPreference(prefs::kProxyPacUrl); 32 pref = pref_service->FindPreference(prefs::kProxyPacUrl);
32 ASSERT_TRUE(pref != NULL); 33 ASSERT_TRUE(pref != NULL);
33 ASSERT_TRUE(pref->IsExtensionControlled()); 34 ASSERT_TRUE(pref->IsExtensionControlled());
34 std::string pac_url = pref_service->GetString(prefs::kProxyPacUrl); 35 std::string pac_url = pref_service->GetString(prefs::kProxyPacUrl);
35 EXPECT_EQ("http://wpad/windows.pac", pac_url); 36 EXPECT_EQ("http://wpad/windows.pac", pac_url);
36 37
37 // No manual proxy prefs were set. 38 // No manual proxy prefs were set.
38 pref = pref_service->FindPreference(prefs::kProxyServer); 39 pref = pref_service->FindPreference(prefs::kProxyServer);
39 ASSERT_TRUE(pref != NULL); 40 ASSERT_TRUE(pref != NULL);
(...skipping 17 matching lines...)
57 ASSERT_TRUE(pref != NULL); 58 ASSERT_TRUE(pref != NULL);
58 ASSERT_TRUE(pref->IsExtensionControlled()); 59 ASSERT_TRUE(pref->IsExtensionControlled());
59 std::string proxy_server = pref_service->GetString(prefs::kProxyServer); 60 std::string proxy_server = pref_service->GetString(prefs::kProxyServer);
60 EXPECT_EQ("http=http://127.0.0.1:100;" 61 EXPECT_EQ("http=http://127.0.0.1:100;"
61 "https=http://127.0.0.1:100;" 62 "https=http://127.0.0.1:100;"
62 "ftp=http://127.0.0.1:100;" 63 "ftp=http://127.0.0.1:100;"
63 "socks=http://9.9.9.9", proxy_server); 64 "socks=http://9.9.9.9", proxy_server);
64 65
65 // Other proxy prefs should also be set, so they're all controlled from one 66 // Other proxy prefs should also be set, so they're all controlled from one
66 // place. 67 // place.
67 pref = pref_service->FindPreference(prefs::kProxyAutoDetect); 68 pref = pref_service->FindPreference(prefs::kProxyServerMode);
68 ASSERT_TRUE(pref != NULL); 69 ASSERT_TRUE(pref != NULL);
69 EXPECT_TRUE(pref->IsExtensionControlled()); 70 EXPECT_TRUE(pref->IsExtensionControlled());
70 EXPECT_FALSE(pref_service->GetBoolean(prefs::kProxyAutoDetect)); 71 EXPECT_EQ(ProxyPrefs::MANUAL,
72 pref_service->GetInteger(prefs::kProxyServerMode));
71 73
72 pref = pref_service->FindPreference(prefs::kProxyPacUrl); 74 pref = pref_service->FindPreference(prefs::kProxyPacUrl);
73 ASSERT_TRUE(pref != NULL); 75 ASSERT_TRUE(pref != NULL);
74 EXPECT_TRUE(pref->IsExtensionControlled()); 76 EXPECT_TRUE(pref->IsExtensionControlled());
75 EXPECT_EQ("", pref_service->GetString(prefs::kProxyPacUrl)); 77 EXPECT_EQ("", pref_service->GetString(prefs::kProxyPacUrl));
76 } 78 }
77 79
80 // Tests setting to use the systems's proxy settings.
Pam (message me for reviews) 2010/12/18 08:29:55 typo -> system's
battre (please use the other) 2010/12/20 12:57:23 Done.
81 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ProxySystem) {
82 CommandLine::ForCurrentProcess()->AppendSwitch(
83 switches::kEnableExperimentalExtensionApis);
84
85 ASSERT_TRUE(RunExtensionTest("proxy/system")) << message_;
86 const Extension* extension = GetSingleLoadedExtension();
87 ASSERT_TRUE(extension);
88
89 PrefService* pref_service = browser()->profile()->GetPrefs();
90
91 // There should be no values superseding the extension-set proxy in this test.
92 const PrefService::Preference* pref =
93 pref_service->FindPreference(prefs::kProxyServerMode);
94 ASSERT_TRUE(pref != NULL);
95 ASSERT_TRUE(pref->IsExtensionControlled());
96 int proxy_server_mode = pref_service->GetInteger(prefs::kProxyServerMode);
97 EXPECT_EQ(ProxyPrefs::SYSTEM, proxy_server_mode);
98
99 // Other proxy prefs should also be set, so they're all controlled from one
100 // place.
101 pref = pref_service->FindPreference(prefs::kProxyPacUrl);
102 ASSERT_TRUE(pref != NULL);
103 EXPECT_TRUE(pref->IsExtensionControlled());
104 EXPECT_EQ("", pref_service->GetString(prefs::kProxyPacUrl));
105 }
106
78 // Tests setting separate proxies for each scheme. 107 // Tests setting separate proxies for each scheme.
79 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ProxyManualIndividual) { 108 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ProxyManualIndividual) {
80 CommandLine::ForCurrentProcess()->AppendSwitch( 109 CommandLine::ForCurrentProcess()->AppendSwitch(
81 switches::kEnableExperimentalExtensionApis); 110 switches::kEnableExperimentalExtensionApis);
82 111
83 ASSERT_TRUE(RunExtensionTest("proxy/individual")) << message_; 112 ASSERT_TRUE(RunExtensionTest("proxy/individual")) << message_;
84 const Extension* extension = GetSingleLoadedExtension(); 113 const Extension* extension = GetSingleLoadedExtension();
85 ASSERT_TRUE(extension); 114 ASSERT_TRUE(extension);
86 115
87 PrefService* pref_service = browser()->profile()->GetPrefs(); 116 PrefService* pref_service = browser()->profile()->GetPrefs();
88 117
89 // There should be no values superseding the extension-set proxy in this test. 118 // There should be no values superseding the extension-set proxy in this test.
90 const PrefService::Preference* pref = 119 const PrefService::Preference* pref =
91 pref_service->FindPreference(prefs::kProxyServer); 120 pref_service->FindPreference(prefs::kProxyServer);
92 ASSERT_TRUE(pref != NULL); 121 ASSERT_TRUE(pref != NULL);
93 ASSERT_TRUE(pref->IsExtensionControlled()); 122 ASSERT_TRUE(pref->IsExtensionControlled());
94 123
95 std::string proxy_server = pref_service->GetString(prefs::kProxyServer); 124 std::string proxy_server = pref_service->GetString(prefs::kProxyServer);
96 EXPECT_EQ("http=http://1.1.1.1;" 125 EXPECT_EQ("http=http://1.1.1.1;"
97 "https=socks://2.2.2.2;" 126 "https=socks://2.2.2.2;"
98 "ftp=http://3.3.3.3:9000;" 127 "ftp=http://3.3.3.3:9000;"
99 "socks=socks4://4.4.4.4:9090", proxy_server); 128 "socks=socks4://4.4.4.4:9090", proxy_server);
100 129
101 // Other proxy prefs should also be set, so they're all controlled from one 130 // Other proxy prefs should also be set, so they're all controlled from one
102 // place. 131 // place.
103 pref = pref_service->FindPreference(prefs::kProxyAutoDetect); 132 pref = pref_service->FindPreference(prefs::kProxyServerMode);
104 ASSERT_TRUE(pref != NULL); 133 ASSERT_TRUE(pref != NULL);
105 EXPECT_TRUE(pref->IsExtensionControlled()); 134 EXPECT_TRUE(pref->IsExtensionControlled());
106 EXPECT_FALSE(pref_service->GetBoolean(prefs::kProxyAutoDetect)); 135 EXPECT_EQ(ProxyPrefs::MANUAL,
136 pref_service->GetInteger(prefs::kProxyServerMode));
107 137
108 pref = pref_service->FindPreference(prefs::kProxyPacUrl); 138 pref = pref_service->FindPreference(prefs::kProxyPacUrl);
109 ASSERT_TRUE(pref != NULL); 139 ASSERT_TRUE(pref != NULL);
110 EXPECT_TRUE(pref->IsExtensionControlled()); 140 EXPECT_TRUE(pref->IsExtensionControlled());
111 EXPECT_EQ("", pref_service->GetString(prefs::kProxyPacUrl)); 141 EXPECT_EQ("", pref_service->GetString(prefs::kProxyPacUrl));
112 } 142 }
OLDNEW

Powered by Google App Engine