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

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

Issue 6322003: net: Remove prefix net:: from some places that already are in namespace net. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 11 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
« no previous file with comments | « net/proxy/proxy_script_fetcher_impl.cc ('k') | net/proxy/proxy_service_unittest.cc » ('j') | 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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_impl.h" 5 #include "net/proxy/proxy_script_fetcher_impl.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/file_path.h" 9 #include "base/file_path.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 path = path.AppendASCII("net"); 69 path = path.AppendASCII("net");
70 path = path.AppendASCII("data"); 70 path = path.AppendASCII("data");
71 path = path.AppendASCII("proxy_script_fetcher_unittest"); 71 path = path.AppendASCII("proxy_script_fetcher_unittest");
72 GURL base_url = FilePathToFileURL(path); 72 GURL base_url = FilePathToFileURL(path);
73 return GURL(base_url.spec() + "/" + relpath); 73 return GURL(base_url.spec() + "/" + relpath);
74 } 74 }
75 75
76 class ProxyScriptFetcherImplTest : public PlatformTest { 76 class ProxyScriptFetcherImplTest : public PlatformTest {
77 public: 77 public:
78 ProxyScriptFetcherImplTest() 78 ProxyScriptFetcherImplTest()
79 : test_server_(net::TestServer::TYPE_HTTP, FilePath(kDocRoot)) { 79 : test_server_(TestServer::TYPE_HTTP, FilePath(kDocRoot)) {
80 } 80 }
81 81
82 static void SetUpTestCase() { 82 static void SetUpTestCase() {
83 net::URLRequest::AllowFileAccess(); 83 URLRequest::AllowFileAccess();
84 } 84 }
85 85
86 protected: 86 protected:
87 net::TestServer test_server_; 87 TestServer test_server_;
88 }; 88 };
89 89
90 TEST_F(ProxyScriptFetcherImplTest, FileUrl) { 90 TEST_F(ProxyScriptFetcherImplTest, FileUrl) {
91 scoped_refptr<net::URLRequestContext> context(new RequestContext); 91 scoped_refptr<URLRequestContext> context(new RequestContext);
92 ProxyScriptFetcherImpl pac_fetcher(context); 92 ProxyScriptFetcherImpl pac_fetcher(context);
93 93
94 { // Fetch a non-existent file. 94 { // Fetch a non-existent file.
95 string16 text; 95 string16 text;
96 TestCompletionCallback callback; 96 TestCompletionCallback callback;
97 int result = pac_fetcher.Fetch(GetTestFileUrl("does-not-exist"), 97 int result = pac_fetcher.Fetch(GetTestFileUrl("does-not-exist"),
98 &text, &callback); 98 &text, &callback);
99 EXPECT_EQ(ERR_IO_PENDING, result); 99 EXPECT_EQ(ERR_IO_PENDING, result);
100 EXPECT_EQ(ERR_FILE_NOT_FOUND, callback.WaitForResult()); 100 EXPECT_EQ(ERR_FILE_NOT_FOUND, callback.WaitForResult());
101 EXPECT_TRUE(text.empty()); 101 EXPECT_TRUE(text.empty());
102 } 102 }
103 { // Fetch a file that exists. 103 { // Fetch a file that exists.
104 string16 text; 104 string16 text;
105 TestCompletionCallback callback; 105 TestCompletionCallback callback;
106 int result = pac_fetcher.Fetch(GetTestFileUrl("pac.txt"), 106 int result = pac_fetcher.Fetch(GetTestFileUrl("pac.txt"),
107 &text, &callback); 107 &text, &callback);
108 EXPECT_EQ(ERR_IO_PENDING, result); 108 EXPECT_EQ(ERR_IO_PENDING, result);
109 EXPECT_EQ(OK, callback.WaitForResult()); 109 EXPECT_EQ(OK, callback.WaitForResult());
110 EXPECT_EQ(ASCIIToUTF16("-pac.txt-\n"), text); 110 EXPECT_EQ(ASCIIToUTF16("-pac.txt-\n"), text);
111 } 111 }
112 } 112 }
113 113
114 // Note that all mime types are allowed for PAC file, to be consistent 114 // Note that all mime types are allowed for PAC file, to be consistent
115 // with other browsers. 115 // with other browsers.
116 TEST_F(ProxyScriptFetcherImplTest, HttpMimeType) { 116 TEST_F(ProxyScriptFetcherImplTest, HttpMimeType) {
117 ASSERT_TRUE(test_server_.Start()); 117 ASSERT_TRUE(test_server_.Start());
118 118
119 scoped_refptr<net::URLRequestContext> context(new RequestContext); 119 scoped_refptr<URLRequestContext> context(new RequestContext);
120 ProxyScriptFetcherImpl pac_fetcher(context); 120 ProxyScriptFetcherImpl pac_fetcher(context);
121 121
122 { // Fetch a PAC with mime type "text/plain" 122 { // Fetch a PAC with mime type "text/plain"
123 GURL url(test_server_.GetURL("files/pac.txt")); 123 GURL url(test_server_.GetURL("files/pac.txt"));
124 string16 text; 124 string16 text;
125 TestCompletionCallback callback; 125 TestCompletionCallback callback;
126 int result = pac_fetcher.Fetch(url, &text, &callback); 126 int result = pac_fetcher.Fetch(url, &text, &callback);
127 EXPECT_EQ(ERR_IO_PENDING, result); 127 EXPECT_EQ(ERR_IO_PENDING, result);
128 EXPECT_EQ(OK, callback.WaitForResult()); 128 EXPECT_EQ(OK, callback.WaitForResult());
129 EXPECT_EQ(ASCIIToUTF16("-pac.txt-\n"), text); 129 EXPECT_EQ(ASCIIToUTF16("-pac.txt-\n"), text);
(...skipping 14 matching lines...) Expand all
144 int result = pac_fetcher.Fetch(url, &text, &callback); 144 int result = pac_fetcher.Fetch(url, &text, &callback);
145 EXPECT_EQ(ERR_IO_PENDING, result); 145 EXPECT_EQ(ERR_IO_PENDING, result);
146 EXPECT_EQ(OK, callback.WaitForResult()); 146 EXPECT_EQ(OK, callback.WaitForResult());
147 EXPECT_EQ(ASCIIToUTF16("-pac.nsproxy-\n"), text); 147 EXPECT_EQ(ASCIIToUTF16("-pac.nsproxy-\n"), text);
148 } 148 }
149 } 149 }
150 150
151 TEST_F(ProxyScriptFetcherImplTest, HttpStatusCode) { 151 TEST_F(ProxyScriptFetcherImplTest, HttpStatusCode) {
152 ASSERT_TRUE(test_server_.Start()); 152 ASSERT_TRUE(test_server_.Start());
153 153
154 scoped_refptr<net::URLRequestContext> context(new RequestContext); 154 scoped_refptr<URLRequestContext> context(new RequestContext);
155 ProxyScriptFetcherImpl pac_fetcher(context); 155 ProxyScriptFetcherImpl pac_fetcher(context);
156 156
157 { // Fetch a PAC which gives a 500 -- FAIL 157 { // Fetch a PAC which gives a 500 -- FAIL
158 GURL url(test_server_.GetURL("files/500.pac")); 158 GURL url(test_server_.GetURL("files/500.pac"));
159 string16 text; 159 string16 text;
160 TestCompletionCallback callback; 160 TestCompletionCallback callback;
161 int result = pac_fetcher.Fetch(url, &text, &callback); 161 int result = pac_fetcher.Fetch(url, &text, &callback);
162 EXPECT_EQ(ERR_IO_PENDING, result); 162 EXPECT_EQ(ERR_IO_PENDING, result);
163 EXPECT_EQ(ERR_PAC_STATUS_NOT_OK, callback.WaitForResult()); 163 EXPECT_EQ(ERR_PAC_STATUS_NOT_OK, callback.WaitForResult());
164 EXPECT_TRUE(text.empty()); 164 EXPECT_TRUE(text.empty());
165 } 165 }
166 { // Fetch a PAC which gives a 404 -- FAIL 166 { // Fetch a PAC which gives a 404 -- FAIL
167 GURL url(test_server_.GetURL("files/404.pac")); 167 GURL url(test_server_.GetURL("files/404.pac"));
168 string16 text; 168 string16 text;
169 TestCompletionCallback callback; 169 TestCompletionCallback callback;
170 int result = pac_fetcher.Fetch(url, &text, &callback); 170 int result = pac_fetcher.Fetch(url, &text, &callback);
171 EXPECT_EQ(ERR_IO_PENDING, result); 171 EXPECT_EQ(ERR_IO_PENDING, result);
172 EXPECT_EQ(ERR_PAC_STATUS_NOT_OK, callback.WaitForResult()); 172 EXPECT_EQ(ERR_PAC_STATUS_NOT_OK, callback.WaitForResult());
173 EXPECT_TRUE(text.empty()); 173 EXPECT_TRUE(text.empty());
174 } 174 }
175 } 175 }
176 176
177 TEST_F(ProxyScriptFetcherImplTest, ContentDisposition) { 177 TEST_F(ProxyScriptFetcherImplTest, ContentDisposition) {
178 ASSERT_TRUE(test_server_.Start()); 178 ASSERT_TRUE(test_server_.Start());
179 179
180 scoped_refptr<net::URLRequestContext> context(new RequestContext); 180 scoped_refptr<URLRequestContext> context(new RequestContext);
181 ProxyScriptFetcherImpl pac_fetcher(context); 181 ProxyScriptFetcherImpl pac_fetcher(context);
182 182
183 // Fetch PAC scripts via HTTP with a Content-Disposition header -- should 183 // Fetch PAC scripts via HTTP with a Content-Disposition header -- should
184 // have no effect. 184 // have no effect.
185 GURL url(test_server_.GetURL("files/downloadable.pac")); 185 GURL url(test_server_.GetURL("files/downloadable.pac"));
186 string16 text; 186 string16 text;
187 TestCompletionCallback callback; 187 TestCompletionCallback callback;
188 int result = pac_fetcher.Fetch(url, &text, &callback); 188 int result = pac_fetcher.Fetch(url, &text, &callback);
189 EXPECT_EQ(ERR_IO_PENDING, result); 189 EXPECT_EQ(ERR_IO_PENDING, result);
190 EXPECT_EQ(OK, callback.WaitForResult()); 190 EXPECT_EQ(OK, callback.WaitForResult());
191 EXPECT_EQ(ASCIIToUTF16("-downloadable.pac-\n"), text); 191 EXPECT_EQ(ASCIIToUTF16("-downloadable.pac-\n"), text);
192 } 192 }
193 193
194 TEST_F(ProxyScriptFetcherImplTest, NoCache) { 194 TEST_F(ProxyScriptFetcherImplTest, NoCache) {
195 ASSERT_TRUE(test_server_.Start()); 195 ASSERT_TRUE(test_server_.Start());
196 196
197 scoped_refptr<net::URLRequestContext> context(new RequestContext); 197 scoped_refptr<URLRequestContext> context(new RequestContext);
198 ProxyScriptFetcherImpl pac_fetcher(context); 198 ProxyScriptFetcherImpl pac_fetcher(context);
199 199
200 // Fetch a PAC script whose HTTP headers make it cacheable for 1 hour. 200 // Fetch a PAC script whose HTTP headers make it cacheable for 1 hour.
201 GURL url(test_server_.GetURL("files/cacheable_1hr.pac")); 201 GURL url(test_server_.GetURL("files/cacheable_1hr.pac"));
202 { 202 {
203 string16 text; 203 string16 text;
204 TestCompletionCallback callback; 204 TestCompletionCallback callback;
205 int result = pac_fetcher.Fetch(url, &text, &callback); 205 int result = pac_fetcher.Fetch(url, &text, &callback);
206 EXPECT_EQ(ERR_IO_PENDING, result); 206 EXPECT_EQ(ERR_IO_PENDING, result);
207 EXPECT_EQ(OK, callback.WaitForResult()); 207 EXPECT_EQ(OK, callback.WaitForResult());
(...skipping 11 matching lines...) Expand all
219 TestCompletionCallback callback; 219 TestCompletionCallback callback;
220 int result = pac_fetcher.Fetch(url, &text, &callback); 220 int result = pac_fetcher.Fetch(url, &text, &callback);
221 EXPECT_EQ(ERR_IO_PENDING, result); 221 EXPECT_EQ(ERR_IO_PENDING, result);
222 EXPECT_EQ(ERR_CONNECTION_REFUSED, callback.WaitForResult()); 222 EXPECT_EQ(ERR_CONNECTION_REFUSED, callback.WaitForResult());
223 } 223 }
224 } 224 }
225 225
226 TEST_F(ProxyScriptFetcherImplTest, TooLarge) { 226 TEST_F(ProxyScriptFetcherImplTest, TooLarge) {
227 ASSERT_TRUE(test_server_.Start()); 227 ASSERT_TRUE(test_server_.Start());
228 228
229 scoped_refptr<net::URLRequestContext> context(new RequestContext); 229 scoped_refptr<URLRequestContext> context(new RequestContext);
230 ProxyScriptFetcherImpl pac_fetcher(context); 230 ProxyScriptFetcherImpl pac_fetcher(context);
231 231
232 // Set the maximum response size to 50 bytes. 232 // Set the maximum response size to 50 bytes.
233 int prev_size = pac_fetcher.SetSizeConstraint(50); 233 int prev_size = pac_fetcher.SetSizeConstraint(50);
234 234
235 // These two URLs are the same file, but are http:// vs file:// 235 // These two URLs are the same file, but are http:// vs file://
236 GURL urls[] = { 236 GURL urls[] = {
237 test_server_.GetURL("files/large-pac.nsproxy"), 237 test_server_.GetURL("files/large-pac.nsproxy"),
238 GetTestFileUrl("large-pac.nsproxy") 238 GetTestFileUrl("large-pac.nsproxy")
239 }; 239 };
(...skipping 20 matching lines...) Expand all
260 int result = pac_fetcher.Fetch(url, &text, &callback); 260 int result = pac_fetcher.Fetch(url, &text, &callback);
261 EXPECT_EQ(ERR_IO_PENDING, result); 261 EXPECT_EQ(ERR_IO_PENDING, result);
262 EXPECT_EQ(OK, callback.WaitForResult()); 262 EXPECT_EQ(OK, callback.WaitForResult());
263 EXPECT_EQ(ASCIIToUTF16("-pac.nsproxy-\n"), text); 263 EXPECT_EQ(ASCIIToUTF16("-pac.nsproxy-\n"), text);
264 } 264 }
265 } 265 }
266 266
267 TEST_F(ProxyScriptFetcherImplTest, Hang) { 267 TEST_F(ProxyScriptFetcherImplTest, Hang) {
268 ASSERT_TRUE(test_server_.Start()); 268 ASSERT_TRUE(test_server_.Start());
269 269
270 scoped_refptr<net::URLRequestContext> context(new RequestContext); 270 scoped_refptr<URLRequestContext> context(new RequestContext);
271 ProxyScriptFetcherImpl pac_fetcher(context); 271 ProxyScriptFetcherImpl pac_fetcher(context);
272 272
273 // Set the timeout period to 0.5 seconds. 273 // Set the timeout period to 0.5 seconds.
274 base::TimeDelta prev_timeout = pac_fetcher.SetTimeoutConstraint( 274 base::TimeDelta prev_timeout = pac_fetcher.SetTimeoutConstraint(
275 base::TimeDelta::FromMilliseconds(500)); 275 base::TimeDelta::FromMilliseconds(500));
276 276
277 // Try fetching a URL which takes 1.2 seconds. We should abort the request 277 // Try fetching a URL which takes 1.2 seconds. We should abort the request
278 // after 500 ms, and fail with a timeout error. 278 // after 500 ms, and fail with a timeout error.
279 { GURL url(test_server_.GetURL("slow/proxy.pac?1.2")); 279 { GURL url(test_server_.GetURL("slow/proxy.pac?1.2"));
280 string16 text; 280 string16 text;
(...skipping 17 matching lines...) Expand all
298 EXPECT_EQ(ASCIIToUTF16("-pac.nsproxy-\n"), text); 298 EXPECT_EQ(ASCIIToUTF16("-pac.nsproxy-\n"), text);
299 } 299 }
300 } 300 }
301 301
302 // The ProxyScriptFetcher should decode any content-codings 302 // The ProxyScriptFetcher should decode any content-codings
303 // (like gzip, bzip, etc.), and apply any charset conversions to yield 303 // (like gzip, bzip, etc.), and apply any charset conversions to yield
304 // UTF8. 304 // UTF8.
305 TEST_F(ProxyScriptFetcherImplTest, Encodings) { 305 TEST_F(ProxyScriptFetcherImplTest, Encodings) {
306 ASSERT_TRUE(test_server_.Start()); 306 ASSERT_TRUE(test_server_.Start());
307 307
308 scoped_refptr<net::URLRequestContext> context(new RequestContext); 308 scoped_refptr<URLRequestContext> context(new RequestContext);
309 ProxyScriptFetcherImpl pac_fetcher(context); 309 ProxyScriptFetcherImpl pac_fetcher(context);
310 310
311 // Test a response that is gzip-encoded -- should get inflated. 311 // Test a response that is gzip-encoded -- should get inflated.
312 { 312 {
313 GURL url(test_server_.GetURL("files/gzipped_pac")); 313 GURL url(test_server_.GetURL("files/gzipped_pac"));
314 string16 text; 314 string16 text;
315 TestCompletionCallback callback; 315 TestCompletionCallback callback;
316 int result = pac_fetcher.Fetch(url, &text, &callback); 316 int result = pac_fetcher.Fetch(url, &text, &callback);
317 EXPECT_EQ(ERR_IO_PENDING, result); 317 EXPECT_EQ(ERR_IO_PENDING, result);
318 EXPECT_EQ(OK, callback.WaitForResult()); 318 EXPECT_EQ(OK, callback.WaitForResult());
319 EXPECT_EQ(ASCIIToUTF16("This data was gzipped.\n"), text); 319 EXPECT_EQ(ASCIIToUTF16("This data was gzipped.\n"), text);
320 } 320 }
321 321
322 // Test a response that was served as UTF-16 (BE). It should 322 // Test a response that was served as UTF-16 (BE). It should
323 // be converted to UTF8. 323 // be converted to UTF8.
324 { 324 {
325 GURL url(test_server_.GetURL("files/utf16be_pac")); 325 GURL url(test_server_.GetURL("files/utf16be_pac"));
326 string16 text; 326 string16 text;
327 TestCompletionCallback callback; 327 TestCompletionCallback callback;
328 int result = pac_fetcher.Fetch(url, &text, &callback); 328 int result = pac_fetcher.Fetch(url, &text, &callback);
329 EXPECT_EQ(ERR_IO_PENDING, result); 329 EXPECT_EQ(ERR_IO_PENDING, result);
330 EXPECT_EQ(OK, callback.WaitForResult()); 330 EXPECT_EQ(OK, callback.WaitForResult());
331 EXPECT_EQ(ASCIIToUTF16("This was encoded as UTF-16BE.\n"), text); 331 EXPECT_EQ(ASCIIToUTF16("This was encoded as UTF-16BE.\n"), text);
332 } 332 }
333 } 333 }
334 334
335 } // namespace net 335 } // namespace net
OLDNEW
« no previous file with comments | « net/proxy/proxy_script_fetcher_impl.cc ('k') | net/proxy/proxy_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698