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

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

Issue 6240013: Make proxy settings one atomic dictionary in the PrefStores such that modifications are atomic. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/out/Debug
Patch Set: Updated to ToT and addressed Matt's comments in base-CL Created 9 years, 10 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 | 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/prefs/proxy_prefs.h"
8 #include "chrome/browser/profiles/profile.h" 8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/ui/browser.h" 9 #include "chrome/browser/ui/browser.h"
10 #include "chrome/common/chrome_switches.h" 10 #include "chrome/common/chrome_switches.h"
11 #include "chrome/common/extensions/extension.h" 11 #include "chrome/common/extensions/extension.h"
12 #include "chrome/common/pref_names.h" 12 #include "chrome/common/pref_names.h"
13 13
14 namespace {
15
16 const char NO_SERVER[] = "";
17 const char NO_PAC[] = "";
18
19 } // namespace
20
14 class ProxySettingsApiTest : public ExtensionApiTest { 21 class ProxySettingsApiTest : public ExtensionApiTest {
15 protected: 22 protected:
16 void AssertSettings(int expected_mode, 23 void ExpectSettings(int expected_mode,
danno 2011/02/04 10:32:13 s/Expect/Validate/g
battre 2011/02/07 14:13:47 Done.
17 const char* expected_server, 24 const std::string& expected_server,
18 const char* expected_pac_url, 25 const std::string& expected_pac_url,
19 PrefService* pref_service) { 26 PrefService* pref_service) {
20 AssertExtensionControlled(prefs::kProxyMode, pref_service); 27 const PrefService::Preference* pref =
21 int mode = pref_service->GetInteger(prefs::kProxyMode); 28 pref_service->FindPreference(prefs::kProxy);
29 ASSERT_TRUE(pref != NULL);
30 EXPECT_TRUE(pref->IsExtensionControlled());
31
32 ProxyPrefsDictionary dict(pref_service->GetDictionary(prefs::kProxy));
33
34 ProxyPrefs::ProxyMode mode;
35 ASSERT_TRUE(dict.GetMode(&mode));
22 EXPECT_EQ(expected_mode, mode); 36 EXPECT_EQ(expected_mode, mode);
23 37
24 AssertExtensionControlled(prefs::kProxyPacUrl, pref_service); 38 std::string value;
25 EXPECT_EQ(expected_pac_url, pref_service->GetString(prefs::kProxyPacUrl)); 39 if (!expected_pac_url.empty()) {
40 ASSERT_TRUE(dict.GetPacUrl(&value));
41 EXPECT_EQ(expected_pac_url, value);
42 } else {
43 EXPECT_FALSE(dict.GetPacUrl(&value));
44 }
26 45
27 AssertExtensionControlled(prefs::kProxyServer, pref_service); 46 if (!expected_server.empty()) {
28 EXPECT_EQ(expected_server, pref_service->GetString(prefs::kProxyServer)); 47 ASSERT_TRUE(dict.GetProxyServer(&value));
48 EXPECT_EQ(expected_server, value);
49 } else {
50 EXPECT_FALSE(dict.GetProxyServer(&value));
51 }
29 } 52 }
30 53
31 void AssertNoSettings(PrefService* pref_service) { 54 void ExpectNoSettings(PrefService* pref_service) {
32 AssertNotExtensionControlled(prefs::kProxyServer, pref_service);
33 AssertNotExtensionControlled(prefs::kProxyMode, pref_service);
34 AssertNotExtensionControlled(prefs::kProxyPacUrl, pref_service);
35 }
36 private:
37 void AssertExtensionControlled(const char* pref_key,
38 PrefService* pref_service) {
39 const PrefService::Preference* pref = 55 const PrefService::Preference* pref =
40 pref_service->FindPreference(pref_key); 56 pref_service->FindPreference(prefs::kProxy);
41 ASSERT_TRUE(pref != NULL);
42 EXPECT_TRUE(pref->IsExtensionControlled());
43 }
44
45 void AssertNotExtensionControlled(const char* pref_key,
46 PrefService* pref_service) {
47 const PrefService::Preference* pref =
48 pref_service->FindPreference(pref_key);
49 ASSERT_TRUE(pref != NULL); 57 ASSERT_TRUE(pref != NULL);
50 EXPECT_FALSE(pref->IsExtensionControlled()); 58 EXPECT_FALSE(pref->IsExtensionControlled());
51 } 59 }
52 }; 60 };
53 61
54 namespace { 62 namespace {
55 63
56 const char kNoServer[] = ""; 64 const char kNoServer[] = "";
57 const char kNoPac[] = ""; 65 const char kNoPac[] = "";
58 66
59 } // namespace 67 } // namespace
60 68
61 // Tests direct connection settings. 69 // Tests direct connection settings.
62 IN_PROC_BROWSER_TEST_F(ProxySettingsApiTest, ProxyDirectSettings) { 70 IN_PROC_BROWSER_TEST_F(ProxySettingsApiTest, ProxyDirectSettings) {
63 CommandLine::ForCurrentProcess()->AppendSwitch( 71 CommandLine::ForCurrentProcess()->AppendSwitch(
64 switches::kEnableExperimentalExtensionApis); 72 switches::kEnableExperimentalExtensionApis);
65 73
66 ASSERT_TRUE(RunExtensionTest("proxy/direct")) << message_; 74 ASSERT_TRUE(RunExtensionTest("proxy/direct")) << message_;
67 const Extension* extension = GetSingleLoadedExtension(); 75 const Extension* extension = GetSingleLoadedExtension();
68 ASSERT_TRUE(extension); 76 ASSERT_TRUE(extension);
69 77
70 PrefService* pref_service = browser()->profile()->GetPrefs(); 78 PrefService* pref_service = browser()->profile()->GetPrefs();
71 AssertSettings(ProxyPrefs::MODE_DIRECT, kNoServer, kNoPac, pref_service); 79 ExpectSettings(ProxyPrefs::MODE_DIRECT, kNoServer, kNoPac, pref_service);
72 } 80 }
73 81
74 // Tests auto-detect settings. 82 // Tests auto-detect settings.
75 IN_PROC_BROWSER_TEST_F(ProxySettingsApiTest, ProxyAutoSettings) { 83 IN_PROC_BROWSER_TEST_F(ProxySettingsApiTest, ProxyAutoSettings) {
76 CommandLine::ForCurrentProcess()->AppendSwitch( 84 CommandLine::ForCurrentProcess()->AppendSwitch(
77 switches::kEnableExperimentalExtensionApis); 85 switches::kEnableExperimentalExtensionApis);
78 86
79 ASSERT_TRUE(RunExtensionTest("proxy/auto")) << message_; 87 ASSERT_TRUE(RunExtensionTest("proxy/auto")) << message_;
80 const Extension* extension = GetSingleLoadedExtension(); 88 const Extension* extension = GetSingleLoadedExtension();
81 ASSERT_TRUE(extension); 89 ASSERT_TRUE(extension);
82 90
83 PrefService* pref_service = browser()->profile()->GetPrefs(); 91 PrefService* pref_service = browser()->profile()->GetPrefs();
84 AssertSettings(ProxyPrefs::MODE_AUTO_DETECT, kNoServer, kNoPac, pref_service); 92 ExpectSettings(ProxyPrefs::MODE_AUTO_DETECT, kNoServer, kNoPac, pref_service);
85 } 93 }
86 94
87 // Tests PAC proxy settings. 95 // Tests PAC proxy settings.
88 IN_PROC_BROWSER_TEST_F(ProxySettingsApiTest, ProxyPacScript) { 96 IN_PROC_BROWSER_TEST_F(ProxySettingsApiTest, ProxyPacScript) {
89 CommandLine::ForCurrentProcess()->AppendSwitch( 97 CommandLine::ForCurrentProcess()->AppendSwitch(
90 switches::kEnableExperimentalExtensionApis); 98 switches::kEnableExperimentalExtensionApis);
91 99
92 ASSERT_TRUE(RunExtensionTest("proxy/pac")) << message_; 100 ASSERT_TRUE(RunExtensionTest("proxy/pac")) << message_;
93 const Extension* extension = GetSingleLoadedExtension(); 101 const Extension* extension = GetSingleLoadedExtension();
94 ASSERT_TRUE(extension); 102 ASSERT_TRUE(extension);
95 103
96 PrefService* pref_service = browser()->profile()->GetPrefs(); 104 PrefService* pref_service = browser()->profile()->GetPrefs();
97 AssertSettings(ProxyPrefs::MODE_PAC_SCRIPT, kNoServer, 105 ExpectSettings(ProxyPrefs::MODE_PAC_SCRIPT, kNoServer,
98 "http://wpad/windows.pac", pref_service); 106 "http://wpad/windows.pac", pref_service);
99 } 107 }
100 108
101 // Tests setting a single proxy to cover all schemes. 109 // Tests setting a single proxy to cover all schemes.
102 IN_PROC_BROWSER_TEST_F(ProxySettingsApiTest, ProxyFixedSingle) { 110 IN_PROC_BROWSER_TEST_F(ProxySettingsApiTest, ProxyFixedSingle) {
103 CommandLine::ForCurrentProcess()->AppendSwitch( 111 CommandLine::ForCurrentProcess()->AppendSwitch(
104 switches::kEnableExperimentalExtensionApis); 112 switches::kEnableExperimentalExtensionApis);
105 113
106 ASSERT_TRUE(RunExtensionTest("proxy/single")) << message_; 114 ASSERT_TRUE(RunExtensionTest("proxy/single")) << message_;
107 const Extension* extension = GetSingleLoadedExtension(); 115 const Extension* extension = GetSingleLoadedExtension();
108 ASSERT_TRUE(extension); 116 ASSERT_TRUE(extension);
109 117
110 PrefService* pref_service = browser()->profile()->GetPrefs(); 118 PrefService* pref_service = browser()->profile()->GetPrefs();
111 AssertSettings(ProxyPrefs::MODE_FIXED_SERVERS, 119 ExpectSettings(ProxyPrefs::MODE_FIXED_SERVERS,
112 "http=http://127.0.0.1:100;" 120 "http=http://127.0.0.1:100;"
113 "https=http://127.0.0.1:100;" 121 "https=http://127.0.0.1:100;"
114 "ftp=http://127.0.0.1:100;" 122 "ftp=http://127.0.0.1:100;"
115 "socks=http://9.9.9.9", 123 "socks=http://9.9.9.9",
116 kNoPac, 124 kNoPac,
117 pref_service); 125 pref_service);
118 } 126 }
119 127
120 // Tests setting to use the system's proxy settings. 128 // Tests setting to use the system's proxy settings.
121 IN_PROC_BROWSER_TEST_F(ProxySettingsApiTest, ProxySystem) { 129 IN_PROC_BROWSER_TEST_F(ProxySettingsApiTest, ProxySystem) {
122 CommandLine::ForCurrentProcess()->AppendSwitch( 130 CommandLine::ForCurrentProcess()->AppendSwitch(
123 switches::kEnableExperimentalExtensionApis); 131 switches::kEnableExperimentalExtensionApis);
124 132
125 ASSERT_TRUE(RunExtensionTest("proxy/system")) << message_; 133 ASSERT_TRUE(RunExtensionTest("proxy/system")) << message_;
126 const Extension* extension = GetSingleLoadedExtension(); 134 const Extension* extension = GetSingleLoadedExtension();
127 ASSERT_TRUE(extension); 135 ASSERT_TRUE(extension);
128 136
129 PrefService* pref_service = browser()->profile()->GetPrefs(); 137 PrefService* pref_service = browser()->profile()->GetPrefs();
130 AssertSettings(ProxyPrefs::MODE_SYSTEM, kNoServer, kNoPac, pref_service); 138 ExpectSettings(ProxyPrefs::MODE_SYSTEM, kNoServer, kNoPac, pref_service);
131 } 139 }
132 140
133 // Tests setting separate proxies for each scheme. 141 // Tests setting separate proxies for each scheme.
134 IN_PROC_BROWSER_TEST_F(ProxySettingsApiTest, ProxyFixedIndividual) { 142 IN_PROC_BROWSER_TEST_F(ProxySettingsApiTest, ProxyFixedIndividual) {
135 CommandLine::ForCurrentProcess()->AppendSwitch( 143 CommandLine::ForCurrentProcess()->AppendSwitch(
136 switches::kEnableExperimentalExtensionApis); 144 switches::kEnableExperimentalExtensionApis);
137 145
138 ASSERT_TRUE(RunExtensionTest("proxy/individual")) << message_; 146 ASSERT_TRUE(RunExtensionTest("proxy/individual")) << message_;
139 const Extension* extension = GetSingleLoadedExtension(); 147 const Extension* extension = GetSingleLoadedExtension();
140 ASSERT_TRUE(extension); 148 ASSERT_TRUE(extension);
141 149
142 PrefService* pref_service = browser()->profile()->GetPrefs(); 150 PrefService* pref_service = browser()->profile()->GetPrefs();
143 AssertSettings(ProxyPrefs::MODE_FIXED_SERVERS, 151 ExpectSettings(ProxyPrefs::MODE_FIXED_SERVERS,
144 "http=http://1.1.1.1;" 152 "http=http://1.1.1.1;"
145 "https=socks://2.2.2.2;" 153 "https=socks://2.2.2.2;"
146 "ftp=http://3.3.3.3:9000;" 154 "ftp=http://3.3.3.3:9000;"
147 "socks=socks4://4.4.4.4:9090", 155 "socks=socks4://4.4.4.4:9090",
148 kNoPac, 156 kNoPac,
149 pref_service); 157 pref_service);
150 158
151 // Now check the incognito preferences. 159 // Now check the incognito preferences.
152 pref_service = browser()->profile()->GetOffTheRecordProfile()->GetPrefs(); 160 pref_service = browser()->profile()->GetOffTheRecordProfile()->GetPrefs();
153 AssertSettings(ProxyPrefs::MODE_FIXED_SERVERS, 161 ExpectSettings(ProxyPrefs::MODE_FIXED_SERVERS,
154 "http=http://1.1.1.1;" 162 "http=http://1.1.1.1;"
155 "https=socks://2.2.2.2;" 163 "https=socks://2.2.2.2;"
156 "ftp=http://3.3.3.3:9000;" 164 "ftp=http://3.3.3.3:9000;"
157 "socks=socks4://4.4.4.4:9090", 165 "socks=socks4://4.4.4.4:9090",
158 kNoPac, 166 kNoPac,
159 pref_service); 167 pref_service);
160 } 168 }
161 169
162 // Tests setting values only for incognito mode 170 // Tests setting values only for incognito mode
163 IN_PROC_BROWSER_TEST_F(ProxySettingsApiTest, 171 IN_PROC_BROWSER_TEST_F(ProxySettingsApiTest,
164 ProxyFixedIndividualIncognitoOnly) { 172 ProxyFixedIndividualIncognitoOnly) {
165 CommandLine::ForCurrentProcess()->AppendSwitch( 173 CommandLine::ForCurrentProcess()->AppendSwitch(
166 switches::kEnableExperimentalExtensionApis); 174 switches::kEnableExperimentalExtensionApis);
167 175
168 ASSERT_TRUE(RunExtensionTest("proxy/individual_incognito_only")) << message_; 176 ASSERT_TRUE(RunExtensionTest("proxy/individual_incognito_only")) << message_;
169 const Extension* extension = GetSingleLoadedExtension(); 177 const Extension* extension = GetSingleLoadedExtension();
170 ASSERT_TRUE(extension); 178 ASSERT_TRUE(extension);
171 179
172 PrefService* pref_service = browser()->profile()->GetPrefs(); 180 PrefService* pref_service = browser()->profile()->GetPrefs();
173 AssertNoSettings(pref_service); 181 ExpectNoSettings(pref_service);
174 182
175 // Now check the incognito preferences. 183 // Now check the incognito preferences.
176 pref_service = browser()->profile()->GetOffTheRecordProfile()->GetPrefs(); 184 pref_service = browser()->profile()->GetOffTheRecordProfile()->GetPrefs();
177 AssertSettings(ProxyPrefs::MODE_FIXED_SERVERS, 185 ExpectSettings(ProxyPrefs::MODE_FIXED_SERVERS,
178 "http=http://1.1.1.1;" 186 "http=http://1.1.1.1;"
179 "https=socks://2.2.2.2;" 187 "https=socks://2.2.2.2;"
180 "ftp=http://3.3.3.3:9000;" 188 "ftp=http://3.3.3.3:9000;"
181 "socks=socks4://4.4.4.4:9090", 189 "socks=socks4://4.4.4.4:9090",
182 kNoPac, 190 kNoPac,
183 pref_service); 191 pref_service);
184 } 192 }
185 193
186 // Tests setting values also for incognito mode 194 // Tests setting values also for incognito mode
187 IN_PROC_BROWSER_TEST_F(ProxySettingsApiTest, 195 IN_PROC_BROWSER_TEST_F(ProxySettingsApiTest,
188 ProxyFixedIndividualIncognitoAlso) { 196 ProxyFixedIndividualIncognitoAlso) {
189 CommandLine::ForCurrentProcess()->AppendSwitch( 197 CommandLine::ForCurrentProcess()->AppendSwitch(
190 switches::kEnableExperimentalExtensionApis); 198 switches::kEnableExperimentalExtensionApis);
191 199
192 ASSERT_TRUE(RunExtensionTest("proxy/individual_incognito_also")) << message_; 200 ASSERT_TRUE(RunExtensionTest("proxy/individual_incognito_also")) << message_;
193 const Extension* extension = GetSingleLoadedExtension(); 201 const Extension* extension = GetSingleLoadedExtension();
194 ASSERT_TRUE(extension); 202 ASSERT_TRUE(extension);
195 203
196 PrefService* pref_service = browser()->profile()->GetPrefs(); 204 PrefService* pref_service = browser()->profile()->GetPrefs();
197 AssertSettings(ProxyPrefs::MODE_FIXED_SERVERS, 205 ExpectSettings(ProxyPrefs::MODE_FIXED_SERVERS,
198 "http=http://1.1.1.1;" 206 "http=http://1.1.1.1;"
199 "https=socks://2.2.2.2;" 207 "https=socks://2.2.2.2;"
200 "ftp=http://3.3.3.3:9000;" 208 "ftp=http://3.3.3.3:9000;"
201 "socks=socks4://4.4.4.4:9090", 209 "socks=socks4://4.4.4.4:9090",
202 kNoPac, 210 kNoPac,
203 pref_service); 211 pref_service);
204 212
205 // Now check the incognito preferences. 213 // Now check the incognito preferences.
206 pref_service = browser()->profile()->GetOffTheRecordProfile()->GetPrefs(); 214 pref_service = browser()->profile()->GetOffTheRecordProfile()->GetPrefs();
207 AssertSettings(ProxyPrefs::MODE_FIXED_SERVERS, 215 ExpectSettings(ProxyPrefs::MODE_FIXED_SERVERS,
208 "http=http://5.5.5.5;" 216 "http=http://5.5.5.5;"
209 "https=socks://6.6.6.6;" 217 "https=socks://6.6.6.6;"
210 "ftp=http://7.7.7.7:9000;" 218 "ftp=http://7.7.7.7:9000;"
211 "socks=socks4://8.8.8.8:9090", 219 "socks=socks4://8.8.8.8:9090",
212 kNoPac, 220 kNoPac,
213 pref_service); 221 pref_service);
214 } 222 }
215 223
216 // Tests setting and unsetting values 224 // Tests setting and unsetting values
217 IN_PROC_BROWSER_TEST_F(ProxySettingsApiTest, ProxyFixedIndividualRemove) { 225 IN_PROC_BROWSER_TEST_F(ProxySettingsApiTest, ProxyFixedIndividualRemove) {
218 CommandLine::ForCurrentProcess()->AppendSwitch( 226 CommandLine::ForCurrentProcess()->AppendSwitch(
219 switches::kEnableExperimentalExtensionApis); 227 switches::kEnableExperimentalExtensionApis);
220 228
221 ASSERT_TRUE(RunExtensionTest("proxy/individual_remove")) << message_; 229 ASSERT_TRUE(RunExtensionTest("proxy/individual_remove")) << message_;
222 const Extension* extension = GetSingleLoadedExtension(); 230 const Extension* extension = GetSingleLoadedExtension();
223 ASSERT_TRUE(extension); 231 ASSERT_TRUE(extension);
224 232
225 PrefService* pref_service = browser()->profile()->GetPrefs(); 233 PrefService* pref_service = browser()->profile()->GetPrefs();
226 AssertNoSettings(pref_service); 234 ExpectNoSettings(pref_service);
227 } 235 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698