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

Side by Side Diff: net/proxy/proxy_script_fetcher_unittest.cc

Issue 14500: Temp experiment to confirm theory in crbug.com/5555.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 12 years 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
« no previous file with comments | « net/proxy/proxy_script_fetcher.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2008 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 "net/proxy/proxy_script_fetcher.h" 5 #include "net/proxy/proxy_script_fetcher.h"
6 6
7 #include "base/file_path.h" 7 #include "base/file_path.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "net/base/net_util.h" 10 #include "net/base/net_util.h"
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 GURL GetTestFileUrl(const std::string& relpath) { 153 GURL GetTestFileUrl(const std::string& relpath) {
154 FilePath path; 154 FilePath path;
155 PathService::Get(base::DIR_SOURCE_ROOT, &path); 155 PathService::Get(base::DIR_SOURCE_ROOT, &path);
156 path = path.Append(FILE_PATH_LITERAL("net")); 156 path = path.Append(FILE_PATH_LITERAL("net"));
157 path = path.Append(FILE_PATH_LITERAL("data")); 157 path = path.Append(FILE_PATH_LITERAL("data"));
158 path = path.Append(FILE_PATH_LITERAL("proxy_script_fetcher_unittest")); 158 path = path.Append(FILE_PATH_LITERAL("proxy_script_fetcher_unittest"));
159 GURL base_url = net::FilePathToFileURL(path); 159 GURL base_url = net::FilePathToFileURL(path);
160 return GURL(base_url.spec() + "/" + relpath); 160 return GURL(base_url.spec() + "/" + relpath);
161 } 161 }
162 162
163 TEST(ProxyScriptFetcherTest, DISABLED_FileUrl) { 163 TEST(ProxyScriptFetcherTest, FileUrl) {
164 SynchFetcher pac_fetcher; 164 SynchFetcher pac_fetcher;
165 165
166 { // Fetch a non-existent file. 166 { // Fetch a non-existent file.
167 FetchResult result = pac_fetcher.Fetch(GetTestFileUrl("does-not-exist")); 167 FetchResult result = pac_fetcher.Fetch(GetTestFileUrl("does-not-exist"));
168 EXPECT_EQ(net::ERR_FILE_NOT_FOUND, result.code); 168 EXPECT_EQ(net::ERR_FILE_NOT_FOUND, result.code);
169 EXPECT_TRUE(result.bytes.empty()); 169 EXPECT_TRUE(result.bytes.empty());
170 } 170 }
171 { // Fetch a file that exists. 171 { // Fetch a file that exists.
172 FetchResult result = pac_fetcher.Fetch(GetTestFileUrl("pac.txt")); 172 FetchResult result = pac_fetcher.Fetch(GetTestFileUrl("pac.txt"));
173 EXPECT_EQ(net::OK, result.code); 173 EXPECT_EQ(net::OK, result.code);
174 EXPECT_EQ("-pac.txt-\n", result.bytes); 174 EXPECT_EQ("-pac.txt-\n", result.bytes);
175 } 175 }
176 } 176 }
177 177
178 // Note that all mime types are allowed for PAC file, to be consistent 178 // Note that all mime types are allowed for PAC file, to be consistent
179 // with other browsers. 179 // with other browsers.
180 TEST(ProxyScriptFetcherTest, DISABLED_HttpMimeType) { 180 TEST(ProxyScriptFetcherTest, HttpMimeType) {
181 TestServer server(kDocRoot); 181 TestServer server(kDocRoot);
182 SynchFetcher pac_fetcher; 182 SynchFetcher pac_fetcher;
183 183
184 { // Fetch a PAC with mime type "text/plain" 184 { // Fetch a PAC with mime type "text/plain"
185 GURL url = server.TestServerPage("files/pac.txt"); 185 GURL url = server.TestServerPage("files/pac.txt");
186 FetchResult result = pac_fetcher.Fetch(url); 186 FetchResult result = pac_fetcher.Fetch(url);
187 EXPECT_EQ(net::OK, result.code); 187 EXPECT_EQ(net::OK, result.code);
188 EXPECT_EQ("-pac.txt-\n", result.bytes); 188 EXPECT_EQ("-pac.txt-\n", result.bytes);
189 } 189 }
190 { // Fetch a PAC with mime type "text/html" 190 { // Fetch a PAC with mime type "text/html"
191 GURL url = server.TestServerPage("files/pac.html"); 191 GURL url = server.TestServerPage("files/pac.html");
192 FetchResult result = pac_fetcher.Fetch(url); 192 FetchResult result = pac_fetcher.Fetch(url);
193 EXPECT_EQ(net::OK, result.code); 193 EXPECT_EQ(net::OK, result.code);
194 EXPECT_EQ("-pac.html-\n", result.bytes); 194 EXPECT_EQ("-pac.html-\n", result.bytes);
195 } 195 }
196 { // Fetch a PAC with mime type "application/x-ns-proxy-autoconfig" 196 { // Fetch a PAC with mime type "application/x-ns-proxy-autoconfig"
197 GURL url = server.TestServerPage("files/pac.nsproxy"); 197 GURL url = server.TestServerPage("files/pac.nsproxy");
198 FetchResult result = pac_fetcher.Fetch(url); 198 FetchResult result = pac_fetcher.Fetch(url);
199 EXPECT_EQ(net::OK, result.code); 199 EXPECT_EQ(net::OK, result.code);
200 EXPECT_EQ("-pac.nsproxy-\n", result.bytes); 200 EXPECT_EQ("-pac.nsproxy-\n", result.bytes);
201 } 201 }
202 } 202 }
203 203
204 TEST(ProxyScriptFetcherTest, DISABLED_HttpStatusCode) { 204 TEST(ProxyScriptFetcherTest, HttpStatusCode) {
205 TestServer server(kDocRoot); 205 TestServer server(kDocRoot);
206 SynchFetcher pac_fetcher; 206 SynchFetcher pac_fetcher;
207 207
208 { // Fetch a PAC which gives a 500 -- FAIL 208 { // Fetch a PAC which gives a 500 -- FAIL
209 GURL url = server.TestServerPage("files/500.pac"); 209 GURL url = server.TestServerPage("files/500.pac");
210 FetchResult result = pac_fetcher.Fetch(url); 210 FetchResult result = pac_fetcher.Fetch(url);
211 EXPECT_EQ(net::ERR_PAC_STATUS_NOT_OK, result.code); 211 EXPECT_EQ(net::ERR_PAC_STATUS_NOT_OK, result.code);
212 EXPECT_TRUE(result.bytes.empty()); 212 EXPECT_TRUE(result.bytes.empty());
213 } 213 }
214 { // Fetch a PAC which gives a 404 -- FAIL 214 { // Fetch a PAC which gives a 404 -- FAIL
215 GURL url = server.TestServerPage("files/404.pac"); 215 GURL url = server.TestServerPage("files/404.pac");
216 FetchResult result = pac_fetcher.Fetch(url); 216 FetchResult result = pac_fetcher.Fetch(url);
217 EXPECT_EQ(net::ERR_PAC_STATUS_NOT_OK, result.code); 217 EXPECT_EQ(net::ERR_PAC_STATUS_NOT_OK, result.code);
218 EXPECT_TRUE(result.bytes.empty()); 218 EXPECT_TRUE(result.bytes.empty());
219 } 219 }
220 } 220 }
221 221
222 TEST(ProxyScriptFetcherTest, DISABLED_ContentDisposition) { 222 TEST(ProxyScriptFetcherTest, ContentDisposition) {
223 TestServer server(kDocRoot); 223 TestServer server(kDocRoot);
224 SynchFetcher pac_fetcher; 224 SynchFetcher pac_fetcher;
225 225
226 // Fetch PAC scripts via HTTP with a Content-Disposition header -- should 226 // Fetch PAC scripts via HTTP with a Content-Disposition header -- should
227 // have no effect. 227 // have no effect.
228 GURL url = server.TestServerPage("files/downloadable.pac"); 228 GURL url = server.TestServerPage("files/downloadable.pac");
229 FetchResult result = pac_fetcher.Fetch(url); 229 FetchResult result = pac_fetcher.Fetch(url);
230 EXPECT_EQ(net::OK, result.code); 230 EXPECT_EQ(net::OK, result.code);
231 EXPECT_EQ("-downloadable.pac-\n", result.bytes); 231 EXPECT_EQ("-downloadable.pac-\n", result.bytes);
232 } 232 }
233 233
234 TEST(ProxyScriptFetcherTest, DISABLED_TooLarge) { 234 TEST(ProxyScriptFetcherTest, TooLarge) {
235 TestServer server(kDocRoot); 235 TestServer server(kDocRoot);
236 SynchFetcher pac_fetcher; 236 SynchFetcher pac_fetcher;
237 237
238 // Set the maximum response size to 50 bytes. 238 // Set the maximum response size to 50 bytes.
239 int prev_size = net::ProxyScriptFetcher::SetSizeConstraintForUnittest(50); 239 int prev_size = net::ProxyScriptFetcher::SetSizeConstraintForUnittest(50);
240 240
241 // These two URLs are the same file, but are http:// vs file:// 241 // These two URLs are the same file, but are http:// vs file://
242 GURL urls[] = { 242 GURL urls[] = {
243 server.TestServerPage("files/large-pac.nsproxy"), 243 server.TestServerPage("files/large-pac.nsproxy"),
244 GetTestFileUrl("large-pac.nsproxy") 244 GetTestFileUrl("large-pac.nsproxy")
(...skipping 12 matching lines...) Expand all
257 net::ProxyScriptFetcher::SetSizeConstraintForUnittest(prev_size); 257 net::ProxyScriptFetcher::SetSizeConstraintForUnittest(prev_size);
258 258
259 { // Make sure we can still fetch regular URLs. 259 { // Make sure we can still fetch regular URLs.
260 GURL url = server.TestServerPage("files/pac.nsproxy"); 260 GURL url = server.TestServerPage("files/pac.nsproxy");
261 FetchResult result = pac_fetcher.Fetch(url); 261 FetchResult result = pac_fetcher.Fetch(url);
262 EXPECT_EQ(net::OK, result.code); 262 EXPECT_EQ(net::OK, result.code);
263 EXPECT_EQ("-pac.nsproxy-\n", result.bytes); 263 EXPECT_EQ("-pac.nsproxy-\n", result.bytes);
264 } 264 }
265 } 265 }
266 266
267 TEST(ProxyScriptFetcherTest, DISABLED_Hang) { 267 TEST(ProxyScriptFetcherTest, Hang) {
268 TestServer server(kDocRoot); 268 TestServer server(kDocRoot);
269 SynchFetcher pac_fetcher; 269 SynchFetcher pac_fetcher;
270 270
271 // Set the timeout period to 0.5 seconds. 271 // Set the timeout period to 0.5 seconds.
272 int prev_timeout = 272 int prev_timeout =
273 net::ProxyScriptFetcher::SetTimeoutConstraintForUnittest(500); 273 net::ProxyScriptFetcher::SetTimeoutConstraintForUnittest(500);
274 274
275 // Try fetching a URL which takes 1.2 seconds. We should abort the request 275 // Try fetching a URL which takes 1.2 seconds. We should abort the request
276 // after 500 ms, and fail with a timeout error. 276 // after 500 ms, and fail with a timeout error.
277 { GURL url = server.TestServerPage("slow/proxy.pac?1.2"); 277 { GURL url = server.TestServerPage("slow/proxy.pac?1.2");
278 FetchResult result = pac_fetcher.Fetch(url); 278 FetchResult result = pac_fetcher.Fetch(url);
279 EXPECT_EQ(net::ERR_TIMED_OUT, result.code); 279 EXPECT_EQ(net::ERR_TIMED_OUT, result.code);
280 EXPECT_TRUE(result.bytes.empty()); 280 EXPECT_TRUE(result.bytes.empty());
281 } 281 }
282 282
283 // Restore the original timeout period. 283 // Restore the original timeout period.
284 net::ProxyScriptFetcher::SetTimeoutConstraintForUnittest(prev_timeout); 284 net::ProxyScriptFetcher::SetTimeoutConstraintForUnittest(prev_timeout);
285 285
286 { // Make sure we can still fetch regular URLs. 286 { // Make sure we can still fetch regular URLs.
287 GURL url = server.TestServerPage("files/pac.nsproxy"); 287 GURL url = server.TestServerPage("files/pac.nsproxy");
288 FetchResult result = pac_fetcher.Fetch(url); 288 FetchResult result = pac_fetcher.Fetch(url);
289 EXPECT_EQ(net::OK, result.code); 289 EXPECT_EQ(net::OK, result.code);
290 EXPECT_EQ("-pac.nsproxy-\n", result.bytes); 290 EXPECT_EQ("-pac.nsproxy-\n", result.bytes);
291 } 291 }
292 } 292 }
293 293
294 } // namespace net 294 } // namespace net
OLDNEW
« no previous file with comments | « net/proxy/proxy_script_fetcher.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698