OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-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/url_request/url_request_unittest.h" | 5 #include "net/url_request/url_request_unittest.h" |
6 | 6 |
7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
8 | 8 |
9 #if defined(OS_WIN) | 9 #if defined(OS_WIN) |
10 #include <windows.h> | 10 #include <windows.h> |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 return it != haystack.end(); | 76 return it != haystack.end(); |
77 } | 77 } |
78 | 78 |
79 } // namespace | 79 } // namespace |
80 | 80 |
81 // Inherit PlatformTest since we require the autorelease pool on Mac OS X.f | 81 // Inherit PlatformTest since we require the autorelease pool on Mac OS X.f |
82 class URLRequestTest : public PlatformTest { | 82 class URLRequestTest : public PlatformTest { |
83 }; | 83 }; |
84 | 84 |
85 TEST_F(URLRequestTest, GetTest_NoCache) { | 85 TEST_F(URLRequestTest, GetTest_NoCache) { |
86 TestServer server(L""); | 86 scoped_refptr<HTTPTestServer> server = |
87 ASSERT_TRUE(server.init_successful()); | 87 HTTPTestServer::CreateServer(L""); |
| 88 ASSERT_TRUE(NULL != server.get()); |
88 TestDelegate d; | 89 TestDelegate d; |
89 { | 90 { |
90 TestURLRequest r(server.TestServerPage(""), &d); | 91 TestURLRequest r(server->TestServerPage(""), &d); |
91 | 92 |
92 r.Start(); | 93 r.Start(); |
93 EXPECT_TRUE(r.is_pending()); | 94 EXPECT_TRUE(r.is_pending()); |
94 | 95 |
95 MessageLoop::current()->Run(); | 96 MessageLoop::current()->Run(); |
96 | 97 |
97 EXPECT_EQ(1, d.response_started_count()); | 98 EXPECT_EQ(1, d.response_started_count()); |
98 EXPECT_FALSE(d.received_data_before_response()); | 99 EXPECT_FALSE(d.received_data_before_response()); |
99 EXPECT_NE(0, d.bytes_received()); | 100 EXPECT_NE(0, d.bytes_received()); |
100 } | 101 } |
101 #ifndef NDEBUG | 102 #ifndef NDEBUG |
102 DCHECK_EQ(url_request_metrics.object_count,0); | 103 DCHECK_EQ(url_request_metrics.object_count,0); |
103 #endif | 104 #endif |
104 } | 105 } |
105 | 106 |
106 TEST_F(URLRequestTest, GetTest) { | 107 TEST_F(URLRequestTest, GetTest) { |
107 TestServer server(L""); | 108 scoped_refptr<HTTPTestServer> server = |
108 ASSERT_TRUE(server.init_successful()); | 109 HTTPTestServer::CreateServer(L""); |
| 110 ASSERT_TRUE(NULL != server.get()); |
109 TestDelegate d; | 111 TestDelegate d; |
110 { | 112 { |
111 TestURLRequest r(server.TestServerPage(""), &d); | 113 TestURLRequest r(server->TestServerPage(""), &d); |
112 | 114 |
113 r.Start(); | 115 r.Start(); |
114 EXPECT_TRUE(r.is_pending()); | 116 EXPECT_TRUE(r.is_pending()); |
115 | 117 |
116 MessageLoop::current()->Run(); | 118 MessageLoop::current()->Run(); |
117 | 119 |
118 EXPECT_EQ(1, d.response_started_count()); | 120 EXPECT_EQ(1, d.response_started_count()); |
119 EXPECT_FALSE(d.received_data_before_response()); | 121 EXPECT_FALSE(d.received_data_before_response()); |
120 EXPECT_NE(0, d.bytes_received()); | 122 EXPECT_NE(0, d.bytes_received()); |
121 } | 123 } |
122 #ifndef NDEBUG | 124 #ifndef NDEBUG |
123 DCHECK_EQ(url_request_metrics.object_count,0); | 125 DCHECK_EQ(url_request_metrics.object_count,0); |
124 #endif | 126 #endif |
125 } | 127 } |
126 | 128 |
127 class HTTPSRequestTest : public testing::Test { | 129 class HTTPSRequestTest : public testing::Test { |
128 protected: | 130 protected: |
129 HTTPSRequestTest() : util_() {}; | 131 HTTPSRequestTest() : util_() {}; |
130 | 132 |
131 SSLTestUtil util_; | 133 SSLTestUtil util_; |
132 }; | 134 }; |
133 | 135 |
134 #if defined(OS_MACOSX) | 136 #if defined(OS_MACOSX) |
135 // TODO(port): support temporary root cert on mac | 137 // TODO(port): support temporary root cert on mac |
136 #define MAYBE_HTTPSGetTest DISABLED_HTTPSGetTest | 138 #define MAYBE_HTTPSGetTest DISABLED_HTTPSGetTest |
137 #else | 139 #else |
138 #define MAYBE_HTTPSGetTest HTTPSGetTest | 140 #define MAYBE_HTTPSGetTest HTTPSGetTest |
139 #endif | 141 #endif |
140 | 142 |
141 TEST_F(HTTPSRequestTest, MAYBE_HTTPSGetTest) { | 143 TEST_F(HTTPSRequestTest, MAYBE_HTTPSGetTest) { |
142 // Note: tools/testserver/testserver.py does not need | 144 // Note: tools/testserver/testserver.py does not need |
143 // a working document root to server the pages / and /hello.html, | 145 // a working document root to server the pages / and /hello.html, |
144 // so this test doesn't really need to specify a document root. | 146 // so this test doesn't really need to specify a document root. |
145 // But if it did, a good one would be net/data/ssl. | 147 // But if it did, a good one would be net/data/ssl. |
146 HTTPSTestServer https_server(util_.kHostName, util_.kOKHTTPSPort, | 148 scoped_refptr<HTTPSTestServer> server = |
147 L"net/data/ssl", | 149 HTTPSTestServer::CreateServer(util_.kHostName, util_.kOKHTTPSPort, |
148 util_.GetOKCertPath().ToWStringHack()); | 150 L"net/data/ssl", util_.GetOKCertPath().ToWStringHack()); |
| 151 ASSERT_TRUE(NULL != server.get()); |
149 | 152 |
150 EXPECT_TRUE(util_.CheckCATrusted()); | 153 EXPECT_TRUE(util_.CheckCATrusted()); |
151 TestDelegate d; | 154 TestDelegate d; |
152 { | 155 { |
153 TestURLRequest r(https_server.TestServerPage(""), &d); | 156 TestURLRequest r(server->TestServerPage(""), &d); |
154 | 157 |
155 r.Start(); | 158 r.Start(); |
156 EXPECT_TRUE(r.is_pending()); | 159 EXPECT_TRUE(r.is_pending()); |
157 | 160 |
158 MessageLoop::current()->Run(); | 161 MessageLoop::current()->Run(); |
159 | 162 |
160 EXPECT_EQ(1, d.response_started_count()); | 163 EXPECT_EQ(1, d.response_started_count()); |
161 EXPECT_FALSE(d.received_data_before_response()); | 164 EXPECT_FALSE(d.received_data_before_response()); |
162 EXPECT_NE(0, d.bytes_received()); | 165 EXPECT_NE(0, d.bytes_received()); |
163 } | 166 } |
(...skipping 19 matching lines...) Expand all Loading... |
183 EXPECT_EQ(1, d.response_started_count()); | 186 EXPECT_EQ(1, d.response_started_count()); |
184 EXPECT_EQ(0, d.bytes_received()); | 187 EXPECT_EQ(0, d.bytes_received()); |
185 EXPECT_FALSE(d.received_data_before_response()); | 188 EXPECT_FALSE(d.received_data_before_response()); |
186 } | 189 } |
187 #ifndef NDEBUG | 190 #ifndef NDEBUG |
188 DCHECK_EQ(url_request_metrics.object_count,0); | 191 DCHECK_EQ(url_request_metrics.object_count,0); |
189 #endif | 192 #endif |
190 } | 193 } |
191 | 194 |
192 TEST_F(URLRequestTest, CancelTest2) { | 195 TEST_F(URLRequestTest, CancelTest2) { |
193 TestServer server(L""); | 196 scoped_refptr<HTTPTestServer> server = |
194 ASSERT_TRUE(server.init_successful()); | 197 HTTPTestServer::CreateServer(L""); |
| 198 ASSERT_TRUE(NULL != server.get()); |
| 199 |
| 200 // error C2446: '!=' : no conversion from 'HTTPTestServer *const ' |
| 201 // to 'const int' |
| 202 |
195 TestDelegate d; | 203 TestDelegate d; |
196 { | 204 { |
197 TestURLRequest r(server.TestServerPage(""), &d); | 205 TestURLRequest r(server->TestServerPage(""), &d); |
198 | 206 |
199 d.set_cancel_in_response_started(true); | 207 d.set_cancel_in_response_started(true); |
200 | 208 |
201 r.Start(); | 209 r.Start(); |
202 EXPECT_TRUE(r.is_pending()); | 210 EXPECT_TRUE(r.is_pending()); |
203 | 211 |
204 MessageLoop::current()->Run(); | 212 MessageLoop::current()->Run(); |
205 | 213 |
206 EXPECT_EQ(1, d.response_started_count()); | 214 EXPECT_EQ(1, d.response_started_count()); |
207 EXPECT_EQ(0, d.bytes_received()); | 215 EXPECT_EQ(0, d.bytes_received()); |
208 EXPECT_FALSE(d.received_data_before_response()); | 216 EXPECT_FALSE(d.received_data_before_response()); |
209 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); | 217 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); |
210 } | 218 } |
211 #ifndef NDEBUG | 219 #ifndef NDEBUG |
212 DCHECK_EQ(url_request_metrics.object_count,0); | 220 DCHECK_EQ(url_request_metrics.object_count,0); |
213 #endif | 221 #endif |
214 } | 222 } |
215 | 223 |
216 TEST_F(URLRequestTest, CancelTest3) { | 224 TEST_F(URLRequestTest, CancelTest3) { |
217 TestServer server(L""); | 225 scoped_refptr<HTTPTestServer> server = |
218 ASSERT_TRUE(server.init_successful()); | 226 HTTPTestServer::CreateServer(L""); |
| 227 ASSERT_TRUE(NULL != server.get()); |
219 TestDelegate d; | 228 TestDelegate d; |
220 { | 229 { |
221 TestURLRequest r(server.TestServerPage(""), &d); | 230 TestURLRequest r(server->TestServerPage(""), &d); |
222 | 231 |
223 d.set_cancel_in_received_data(true); | 232 d.set_cancel_in_received_data(true); |
224 | 233 |
225 r.Start(); | 234 r.Start(); |
226 EXPECT_TRUE(r.is_pending()); | 235 EXPECT_TRUE(r.is_pending()); |
227 | 236 |
228 MessageLoop::current()->Run(); | 237 MessageLoop::current()->Run(); |
229 | 238 |
230 EXPECT_EQ(1, d.response_started_count()); | 239 EXPECT_EQ(1, d.response_started_count()); |
231 // There is no guarantee about how much data was received | 240 // There is no guarantee about how much data was received |
232 // before the cancel was issued. It could have been 0 bytes, | 241 // before the cancel was issued. It could have been 0 bytes, |
233 // or it could have been all the bytes. | 242 // or it could have been all the bytes. |
234 // EXPECT_EQ(0, d.bytes_received()); | 243 // EXPECT_EQ(0, d.bytes_received()); |
235 EXPECT_FALSE(d.received_data_before_response()); | 244 EXPECT_FALSE(d.received_data_before_response()); |
236 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); | 245 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); |
237 } | 246 } |
238 #ifndef NDEBUG | 247 #ifndef NDEBUG |
239 DCHECK_EQ(url_request_metrics.object_count,0); | 248 DCHECK_EQ(url_request_metrics.object_count,0); |
240 #endif | 249 #endif |
241 } | 250 } |
242 | 251 |
243 TEST_F(URLRequestTest, CancelTest4) { | 252 TEST_F(URLRequestTest, CancelTest4) { |
244 TestServer server(L""); | 253 scoped_refptr<HTTPTestServer> server = |
245 ASSERT_TRUE(server.init_successful()); | 254 HTTPTestServer::CreateServer(L""); |
| 255 ASSERT_TRUE(NULL != server.get()); |
246 TestDelegate d; | 256 TestDelegate d; |
247 { | 257 { |
248 TestURLRequest r(server.TestServerPage(""), &d); | 258 TestURLRequest r(server->TestServerPage(""), &d); |
249 | 259 |
250 r.Start(); | 260 r.Start(); |
251 EXPECT_TRUE(r.is_pending()); | 261 EXPECT_TRUE(r.is_pending()); |
252 | 262 |
253 // The request will be implicitly canceled when it is destroyed. The | 263 // The request will be implicitly canceled when it is destroyed. The |
254 // test delegate must not post a quit message when this happens because | 264 // test delegate must not post a quit message when this happens because |
255 // this test doesn't actually have a message loop. The quit message would | 265 // this test doesn't actually have a message loop. The quit message would |
256 // get put on this thread's message queue and the next test would exit | 266 // get put on this thread's message queue and the next test would exit |
257 // early, causing problems. | 267 // early, causing problems. |
258 d.set_quit_on_complete(false); | 268 d.set_quit_on_complete(false); |
259 } | 269 } |
260 // expect things to just cleanup properly. | 270 // expect things to just cleanup properly. |
261 | 271 |
262 // we won't actually get a received reponse here because we've never run the | 272 // we won't actually get a received reponse here because we've never run the |
263 // message loop | 273 // message loop |
264 EXPECT_FALSE(d.received_data_before_response()); | 274 EXPECT_FALSE(d.received_data_before_response()); |
265 EXPECT_EQ(0, d.bytes_received()); | 275 EXPECT_EQ(0, d.bytes_received()); |
266 } | 276 } |
267 | 277 |
268 TEST_F(URLRequestTest, CancelTest5) { | 278 TEST_F(URLRequestTest, CancelTest5) { |
269 TestServer server(L""); | 279 scoped_refptr<HTTPTestServer> server = |
270 ASSERT_TRUE(server.init_successful()); | 280 HTTPTestServer::CreateServer(L""); |
| 281 ASSERT_TRUE(NULL != server.get()); |
271 scoped_refptr<URLRequestContext> context = new URLRequestHttpCacheContext(); | 282 scoped_refptr<URLRequestContext> context = new URLRequestHttpCacheContext(); |
272 | 283 |
273 // populate cache | 284 // populate cache |
274 { | 285 { |
275 TestDelegate d; | 286 TestDelegate d; |
276 URLRequest r(server.TestServerPage("cachetime"), &d); | 287 URLRequest r(server->TestServerPage("cachetime"), &d); |
277 r.set_context(context); | 288 r.set_context(context); |
278 r.Start(); | 289 r.Start(); |
279 MessageLoop::current()->Run(); | 290 MessageLoop::current()->Run(); |
280 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 291 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); |
281 } | 292 } |
282 | 293 |
283 // cancel read from cache (see bug 990242) | 294 // cancel read from cache (see bug 990242) |
284 { | 295 { |
285 TestDelegate d; | 296 TestDelegate d; |
286 URLRequest r(server.TestServerPage("cachetime"), &d); | 297 URLRequest r(server->TestServerPage("cachetime"), &d); |
287 r.set_context(context); | 298 r.set_context(context); |
288 r.Start(); | 299 r.Start(); |
289 r.Cancel(); | 300 r.Cancel(); |
290 MessageLoop::current()->Run(); | 301 MessageLoop::current()->Run(); |
291 | 302 |
292 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); | 303 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); |
293 EXPECT_EQ(1, d.response_started_count()); | 304 EXPECT_EQ(1, d.response_started_count()); |
294 EXPECT_EQ(0, d.bytes_received()); | 305 EXPECT_EQ(0, d.bytes_received()); |
295 EXPECT_FALSE(d.received_data_before_response()); | 306 EXPECT_FALSE(d.received_data_before_response()); |
296 } | 307 } |
297 | 308 |
298 #ifndef NDEBUG | 309 #ifndef NDEBUG |
299 DCHECK_EQ(url_request_metrics.object_count, 0); | 310 DCHECK_EQ(url_request_metrics.object_count, 0); |
300 #endif | 311 #endif |
301 } | 312 } |
302 | 313 |
303 TEST_F(URLRequestTest, PostTest) { | 314 TEST_F(URLRequestTest, PostTest) { |
304 TestServer server(L"net/data"); | 315 scoped_refptr<HTTPTestServer> server = |
305 ASSERT_TRUE(server.init_successful()); | 316 HTTPTestServer::CreateServer(L"net/data"); |
306 | 317 ASSERT_TRUE(NULL != server.get()); |
307 const int kMsgSize = 20000; // multiple of 10 | 318 const int kMsgSize = 20000; // multiple of 10 |
308 const int kIterations = 50; | 319 const int kIterations = 50; |
309 char *uploadBytes = new char[kMsgSize+1]; | 320 char *uploadBytes = new char[kMsgSize+1]; |
310 char *ptr = uploadBytes; | 321 char *ptr = uploadBytes; |
311 char marker = 'a'; | 322 char marker = 'a'; |
312 for(int idx=0; idx<kMsgSize/10; idx++) { | 323 for(int idx=0; idx<kMsgSize/10; idx++) { |
313 memcpy(ptr, "----------", 10); | 324 memcpy(ptr, "----------", 10); |
314 ptr += 10; | 325 ptr += 10; |
315 if (idx % 100 == 0) { | 326 if (idx % 100 == 0) { |
316 ptr--; | 327 ptr--; |
317 *ptr++ = marker; | 328 *ptr++ = marker; |
318 if (++marker > 'z') | 329 if (++marker > 'z') |
319 marker = 'a'; | 330 marker = 'a'; |
320 } | 331 } |
321 | 332 |
322 } | 333 } |
323 uploadBytes[kMsgSize] = '\0'; | 334 uploadBytes[kMsgSize] = '\0'; |
324 | 335 |
325 scoped_refptr<URLRequestContext> context = | 336 scoped_refptr<URLRequestContext> context = |
326 new URLRequestHttpCacheContext(); | 337 new URLRequestHttpCacheContext(); |
327 | 338 |
328 for (int i = 0; i < kIterations; ++i) { | 339 for (int i = 0; i < kIterations; ++i) { |
329 TestDelegate d; | 340 TestDelegate d; |
330 URLRequest r(server.TestServerPage("echo"), &d); | 341 URLRequest r(server->TestServerPage("echo"), &d); |
331 r.set_context(context); | 342 r.set_context(context); |
332 r.set_method("POST"); | 343 r.set_method("POST"); |
333 | 344 |
334 r.AppendBytesToUpload(uploadBytes, kMsgSize); | 345 r.AppendBytesToUpload(uploadBytes, kMsgSize); |
335 | 346 |
336 r.Start(); | 347 r.Start(); |
337 EXPECT_TRUE(r.is_pending()); | 348 EXPECT_TRUE(r.is_pending()); |
338 | 349 |
339 MessageLoop::current()->Run(); | 350 MessageLoop::current()->Run(); |
340 | 351 |
341 ASSERT_EQ(1, d.response_started_count()) << "request failed: " << | 352 ASSERT_EQ(1, d.response_started_count()) << "request failed: " << |
342 (int) r.status().status() << ", os error: " << r.status().os_error(); | 353 (int) r.status().status() << ", os error: " << r.status().os_error(); |
343 | 354 |
344 EXPECT_FALSE(d.received_data_before_response()); | 355 EXPECT_FALSE(d.received_data_before_response()); |
345 EXPECT_EQ(uploadBytes, d.data_received()); | 356 EXPECT_EQ(uploadBytes, d.data_received()); |
346 EXPECT_EQ(memcmp(uploadBytes, d.data_received().c_str(), kMsgSize),0); | 357 EXPECT_EQ(memcmp(uploadBytes, d.data_received().c_str(), kMsgSize),0); |
347 EXPECT_EQ(d.data_received().compare(uploadBytes), 0); | 358 EXPECT_EQ(d.data_received().compare(uploadBytes), 0); |
348 } | 359 } |
349 delete[] uploadBytes; | 360 delete[] uploadBytes; |
350 #ifndef NDEBUG | 361 #ifndef NDEBUG |
351 DCHECK_EQ(url_request_metrics.object_count,0); | 362 DCHECK_EQ(url_request_metrics.object_count,0); |
352 #endif | 363 #endif |
353 } | 364 } |
354 | 365 |
355 TEST_F(URLRequestTest, PostEmptyTest) { | 366 TEST_F(URLRequestTest, PostEmptyTest) { |
356 TestServer server(L"net/data"); | 367 scoped_refptr<HTTPTestServer> server = |
357 ASSERT_TRUE(server.init_successful()); | 368 HTTPTestServer::CreateServer(L"net/data"); |
| 369 ASSERT_TRUE(NULL != server.get()); |
358 TestDelegate d; | 370 TestDelegate d; |
359 { | 371 { |
360 TestURLRequest r(server.TestServerPage("echo"), &d); | 372 TestURLRequest r(server->TestServerPage("echo"), &d); |
361 r.set_method("POST"); | 373 r.set_method("POST"); |
362 | 374 |
363 r.Start(); | 375 r.Start(); |
364 EXPECT_TRUE(r.is_pending()); | 376 EXPECT_TRUE(r.is_pending()); |
365 | 377 |
366 MessageLoop::current()->Run(); | 378 MessageLoop::current()->Run(); |
367 | 379 |
368 ASSERT_EQ(1, d.response_started_count()) << "request failed: " << | 380 ASSERT_EQ(1, d.response_started_count()) << "request failed: " << |
369 (int) r.status().status() << ", os error: " << r.status().os_error(); | 381 (int) r.status().status() << ", os error: " << r.status().os_error(); |
370 | 382 |
371 EXPECT_FALSE(d.received_data_before_response()); | 383 EXPECT_FALSE(d.received_data_before_response()); |
372 EXPECT_TRUE(d.data_received().empty()); | 384 EXPECT_TRUE(d.data_received().empty()); |
373 } | 385 } |
374 #ifndef NDEBUG | 386 #ifndef NDEBUG |
375 DCHECK_EQ(url_request_metrics.object_count,0); | 387 DCHECK_EQ(url_request_metrics.object_count,0); |
376 #endif | 388 #endif |
377 } | 389 } |
378 | 390 |
379 TEST_F(URLRequestTest, PostFileTest) { | 391 TEST_F(URLRequestTest, PostFileTest) { |
380 TestServer server(L"net/data"); | 392 scoped_refptr<HTTPTestServer> server = |
381 ASSERT_TRUE(server.init_successful()); | 393 HTTPTestServer::CreateServer(L"net/data"); |
| 394 ASSERT_TRUE(NULL != server.get()); |
382 TestDelegate d; | 395 TestDelegate d; |
383 { | 396 { |
384 TestURLRequest r(server.TestServerPage("echo"), &d); | 397 TestURLRequest r(server->TestServerPage("echo"), &d); |
385 r.set_method("POST"); | 398 r.set_method("POST"); |
386 | 399 |
387 std::wstring dir; | 400 std::wstring dir; |
388 PathService::Get(base::DIR_EXE, &dir); | 401 PathService::Get(base::DIR_EXE, &dir); |
389 file_util::SetCurrentDirectory(dir); | 402 file_util::SetCurrentDirectory(dir); |
390 | 403 |
391 std::wstring path; | 404 std::wstring path; |
392 PathService::Get(base::DIR_SOURCE_ROOT, &path); | 405 PathService::Get(base::DIR_SOURCE_ROOT, &path); |
393 file_util::AppendToPath(&path, L"net"); | 406 file_util::AppendToPath(&path, L"net"); |
394 file_util::AppendToPath(&path, L"data"); | 407 file_util::AppendToPath(&path, L"data"); |
395 file_util::AppendToPath(&path, L"url_request_unittest"); | 408 file_util::AppendToPath(&path, L"url_request_unittest"); |
396 file_util::AppendToPath(&path, L"with-headers.html"); | 409 file_util::AppendToPath(&path, L"with-headers.html"); |
397 r.AppendFileToUpload(path); | 410 r.AppendFileToUpload(path); |
398 | 411 |
399 // This file should just be ignored in the upload stream. | 412 // This file should just be ignored in the upload stream. |
400 r.AppendFileToUpload(L"c:\\path\\to\\non\\existant\\file.randomness.12345"); | 413 r.AppendFileToUpload(L"c:\\path\\to\\non\\existant\\file.randomness.12345"); |
401 | 414 |
402 r.Start(); | 415 r.Start(); |
403 EXPECT_TRUE(r.is_pending()); | 416 EXPECT_TRUE(r.is_pending()); |
404 | 417 |
405 MessageLoop::current()->Run(); | 418 MessageLoop::current()->Run(); |
406 | 419 |
407 int64 longsize; | 420 int64 longsize; |
408 ASSERT_EQ(true, file_util::GetFileSize(path, &longsize)); | 421 ASSERT_EQ(true, file_util::GetFileSize(path, &longsize)); |
409 int size = static_cast<int>(longsize); | 422 int size = static_cast<int>(longsize); |
410 scoped_array<char> buf(new char[size]); | 423 scoped_array<char> buf(new char[size]); |
411 | 424 |
412 int size_read = static_cast<int>(file_util::ReadFile(path, buf.get(), size))
; | 425 int size_read = static_cast<int>(file_util::ReadFile(path, |
| 426 buf.get(), size)); |
413 ASSERT_EQ(size, size_read); | 427 ASSERT_EQ(size, size_read); |
414 | 428 |
415 ASSERT_EQ(1, d.response_started_count()) << "request failed: " << | 429 ASSERT_EQ(1, d.response_started_count()) << "request failed: " << |
416 (int) r.status().status() << ", os error: " << r.status().os_error(); | 430 (int) r.status().status() << ", os error: " << r.status().os_error(); |
417 | 431 |
418 EXPECT_FALSE(d.received_data_before_response()); | 432 EXPECT_FALSE(d.received_data_before_response()); |
419 | 433 |
420 ASSERT_EQ(size, d.bytes_received()); | 434 ASSERT_EQ(size, d.bytes_received()); |
421 EXPECT_EQ(0, memcmp(d.data_received().c_str(), buf.get(), size)); | 435 EXPECT_EQ(0, memcmp(d.data_received().c_str(), buf.get(), size)); |
422 } | 436 } |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
499 | 513 |
500 MessageLoop::current()->Run(); | 514 MessageLoop::current()->Run(); |
501 EXPECT_TRUE(d.request_failed()); | 515 EXPECT_TRUE(d.request_failed()); |
502 } | 516 } |
503 #ifndef NDEBUG | 517 #ifndef NDEBUG |
504 DCHECK_EQ(url_request_metrics.object_count,0); | 518 DCHECK_EQ(url_request_metrics.object_count,0); |
505 #endif | 519 #endif |
506 } | 520 } |
507 | 521 |
508 TEST_F(URLRequestTest, ResponseHeadersTest) { | 522 TEST_F(URLRequestTest, ResponseHeadersTest) { |
509 TestServer server(L"net/data/url_request_unittest"); | 523 scoped_refptr<HTTPTestServer> server = |
510 ASSERT_TRUE(server.init_successful()); | 524 HTTPTestServer::CreateServer(L"net/data/url_request_unittest"); |
| 525 ASSERT_TRUE(NULL != server.get()); |
511 TestDelegate d; | 526 TestDelegate d; |
512 TestURLRequest req(server.TestServerPage("files/with-headers.html"), &d); | 527 TestURLRequest req(server->TestServerPage("files/with-headers.html"), &d); |
513 req.Start(); | 528 req.Start(); |
514 MessageLoop::current()->Run(); | 529 MessageLoop::current()->Run(); |
515 | 530 |
516 const net::HttpResponseHeaders* headers = req.response_headers(); | 531 const net::HttpResponseHeaders* headers = req.response_headers(); |
517 std::string header; | 532 std::string header; |
518 EXPECT_TRUE(headers->GetNormalizedHeader("cache-control", &header)); | 533 EXPECT_TRUE(headers->GetNormalizedHeader("cache-control", &header)); |
519 EXPECT_EQ("private", header); | 534 EXPECT_EQ("private", header); |
520 | 535 |
521 header.clear(); | 536 header.clear(); |
522 EXPECT_TRUE(headers->GetNormalizedHeader("content-type", &header)); | 537 EXPECT_TRUE(headers->GetNormalizedHeader("content-type", &header)); |
523 EXPECT_EQ("text/html; charset=ISO-8859-1", header); | 538 EXPECT_EQ("text/html; charset=ISO-8859-1", header); |
524 | 539 |
525 // The response has two "X-Multiple-Entries" headers. | 540 // The response has two "X-Multiple-Entries" headers. |
526 // This verfies our output has them concatenated together. | 541 // This verfies our output has them concatenated together. |
527 header.clear(); | 542 header.clear(); |
528 EXPECT_TRUE(headers->GetNormalizedHeader("x-multiple-entries", &header)); | 543 EXPECT_TRUE(headers->GetNormalizedHeader("x-multiple-entries", &header)); |
529 EXPECT_EQ("a, b", header); | 544 EXPECT_EQ("a, b", header); |
530 } | 545 } |
531 | 546 |
532 TEST_F(URLRequestTest, BZip2ContentTest) { | 547 TEST_F(URLRequestTest, BZip2ContentTest) { |
533 TestServer server(L"net/data/filter_unittests"); | 548 scoped_refptr<HTTPTestServer> server = |
534 ASSERT_TRUE(server.init_successful()); | 549 HTTPTestServer::CreateServer(L"net/data/filter_unittests"); |
| 550 ASSERT_TRUE(NULL != server.get()); |
535 | 551 |
536 // for localhost domain, we also should support bzip2 encoding | 552 // for localhost domain, we also should support bzip2 encoding |
537 // first, get the original file | 553 // first, get the original file |
538 TestDelegate d1; | 554 TestDelegate d1; |
539 TestURLRequest req1(server.TestServerPage("realfiles/google.txt"), &d1); | 555 TestURLRequest req1(server->TestServerPage("realfiles/google.txt"), &d1); |
540 req1.Start(); | 556 req1.Start(); |
541 MessageLoop::current()->Run(); | 557 MessageLoop::current()->Run(); |
542 | 558 |
543 const std::string& got_content = d1.data_received(); | 559 const std::string& got_content = d1.data_received(); |
544 | 560 |
545 // second, get bzip2 content | 561 // second, get bzip2 content |
546 TestDelegate d2; | 562 TestDelegate d2; |
547 TestURLRequest req2(server.TestServerPage("realbz2files/google.txt"), &d2); | 563 TestURLRequest req2(server->TestServerPage("realbz2files/google.txt"), &d2); |
548 req2.Start(); | 564 req2.Start(); |
549 MessageLoop::current()->Run(); | 565 MessageLoop::current()->Run(); |
550 | 566 |
551 const std::string& got_bz2_content = d2.data_received(); | 567 const std::string& got_bz2_content = d2.data_received(); |
552 | 568 |
553 // compare those two results | 569 // compare those two results |
554 EXPECT_EQ(got_content, got_bz2_content); | 570 EXPECT_EQ(got_content, got_bz2_content); |
555 } | 571 } |
556 | 572 |
557 TEST_F(URLRequestTest, BZip2ContentTest_IncrementalHeader) { | 573 TEST_F(URLRequestTest, BZip2ContentTest_IncrementalHeader) { |
558 TestServer server(L"net/data/filter_unittests"); | 574 scoped_refptr<HTTPTestServer> server = |
559 ASSERT_TRUE(server.init_successful()); | 575 HTTPTestServer::CreateServer(L"net/data/filter_unittests"); |
| 576 ASSERT_TRUE(NULL != server.get()); |
560 | 577 |
561 // for localhost domain, we also should support bzip2 encoding | 578 // for localhost domain, we also should support bzip2 encoding |
562 // first, get the original file | 579 // first, get the original file |
563 TestDelegate d1; | 580 TestDelegate d1; |
564 TestURLRequest req1(server.TestServerPage("realfiles/google.txt"), &d1); | 581 TestURLRequest req1(server->TestServerPage("realfiles/google.txt"), &d1); |
565 req1.Start(); | 582 req1.Start(); |
566 MessageLoop::current()->Run(); | 583 MessageLoop::current()->Run(); |
567 | 584 |
568 const std::string& got_content = d1.data_received(); | 585 const std::string& got_content = d1.data_received(); |
569 | 586 |
570 // second, get bzip2 content. ask the testserver to send the BZ2 header in | 587 // second, get bzip2 content. ask the testserver to send the BZ2 header in |
571 // two chunks with a delay between them. this tests our fix for bug 867161. | 588 // two chunks with a delay between them. this tests our fix for bug 867161. |
572 TestDelegate d2; | 589 TestDelegate d2; |
573 TestURLRequest req2(server.TestServerPage("realbz2files/google.txt?incremental
-header"), &d2); | 590 TestURLRequest req2(server->TestServerPage( |
| 591 "realbz2files/google.txt?incremental-header"), &d2); |
574 req2.Start(); | 592 req2.Start(); |
575 MessageLoop::current()->Run(); | 593 MessageLoop::current()->Run(); |
576 | 594 |
577 const std::string& got_bz2_content = d2.data_received(); | 595 const std::string& got_bz2_content = d2.data_received(); |
578 | 596 |
579 // compare those two results | 597 // compare those two results |
580 EXPECT_EQ(got_content, got_bz2_content); | 598 EXPECT_EQ(got_content, got_bz2_content); |
581 } | 599 } |
582 | 600 |
583 #if defined(OS_WIN) | 601 #if defined(OS_WIN) |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
647 DeleteFile(lnk_path.c_str()); | 665 DeleteFile(lnk_path.c_str()); |
648 CoUninitialize(); | 666 CoUninitialize(); |
649 | 667 |
650 #ifndef NDEBUG | 668 #ifndef NDEBUG |
651 DCHECK_EQ(url_request_metrics.object_count,0); | 669 DCHECK_EQ(url_request_metrics.object_count,0); |
652 #endif | 670 #endif |
653 } | 671 } |
654 #endif // defined(OS_WIN) | 672 #endif // defined(OS_WIN) |
655 | 673 |
656 TEST_F(URLRequestTest, ContentTypeNormalizationTest) { | 674 TEST_F(URLRequestTest, ContentTypeNormalizationTest) { |
657 TestServer server(L"net/data/url_request_unittest"); | 675 scoped_refptr<HTTPTestServer> server = |
658 ASSERT_TRUE(server.init_successful()); | 676 HTTPTestServer::CreateServer(L"net/data/url_request_unittest"); |
| 677 ASSERT_TRUE(NULL != server.get()); |
| 678 |
659 TestDelegate d; | 679 TestDelegate d; |
660 TestURLRequest req(server.TestServerPage( | 680 TestURLRequest req(server->TestServerPage( |
661 "files/content-type-normalization.html"), &d); | 681 "files/content-type-normalization.html"), &d); |
662 req.Start(); | 682 req.Start(); |
663 MessageLoop::current()->Run(); | 683 MessageLoop::current()->Run(); |
664 | 684 |
665 std::string mime_type; | 685 std::string mime_type; |
666 req.GetMimeType(&mime_type); | 686 req.GetMimeType(&mime_type); |
667 EXPECT_EQ("text/html", mime_type); | 687 EXPECT_EQ("text/html", mime_type); |
668 | 688 |
669 std::string charset; | 689 std::string charset; |
670 req.GetCharset(&charset); | 690 req.GetCharset(&charset); |
(...skipping 23 matching lines...) Expand all Loading... |
694 } | 714 } |
695 #ifndef NDEBUG | 715 #ifndef NDEBUG |
696 DCHECK_EQ(url_request_metrics.object_count,0); | 716 DCHECK_EQ(url_request_metrics.object_count,0); |
697 #endif | 717 #endif |
698 | 718 |
699 // Take out mock resource provider. | 719 // Take out mock resource provider. |
700 net::NetModule::SetResourceProvider(NULL); | 720 net::NetModule::SetResourceProvider(NULL); |
701 } | 721 } |
702 | 722 |
703 TEST_F(URLRequestTest, RestrictRedirects) { | 723 TEST_F(URLRequestTest, RestrictRedirects) { |
704 TestServer server(L"net/data/url_request_unittest"); | 724 scoped_refptr<HTTPTestServer> server = |
705 ASSERT_TRUE(server.init_successful()); | 725 HTTPTestServer::CreateServer(L"net/data/url_request_unittest"); |
| 726 ASSERT_TRUE(NULL != server.get()); |
| 727 |
706 TestDelegate d; | 728 TestDelegate d; |
707 TestURLRequest req(server.TestServerPage( | 729 TestURLRequest req(server->TestServerPage( |
708 "files/redirect-to-file.html"), &d); | 730 "files/redirect-to-file.html"), &d); |
709 req.Start(); | 731 req.Start(); |
710 MessageLoop::current()->Run(); | 732 MessageLoop::current()->Run(); |
711 | 733 |
712 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status()); | 734 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status()); |
713 EXPECT_EQ(net::ERR_UNSAFE_REDIRECT, req.status().os_error()); | 735 EXPECT_EQ(net::ERR_UNSAFE_REDIRECT, req.status().os_error()); |
714 } | 736 } |
715 | 737 |
716 TEST_F(URLRequestTest, NoUserPassInReferrer) { | 738 TEST_F(URLRequestTest, NoUserPassInReferrer) { |
717 TestServer server(L"net/data/url_request_unittest"); | 739 scoped_refptr<HTTPTestServer> server = |
718 ASSERT_TRUE(server.init_successful()); | 740 HTTPTestServer::CreateServer(L"net/data/url_request_unittest"); |
| 741 ASSERT_TRUE(NULL != server.get()); |
719 TestDelegate d; | 742 TestDelegate d; |
720 TestURLRequest req(server.TestServerPage( | 743 TestURLRequest req(server->TestServerPage( |
721 "echoheader?Referer"), &d); | 744 "echoheader?Referer"), &d); |
722 req.set_referrer("http://user:pass@foo.com/"); | 745 req.set_referrer("http://user:pass@foo.com/"); |
723 req.Start(); | 746 req.Start(); |
724 MessageLoop::current()->Run(); | 747 MessageLoop::current()->Run(); |
725 | 748 |
726 EXPECT_EQ(std::string("http://foo.com/"), d.data_received()); | 749 EXPECT_EQ(std::string("http://foo.com/"), d.data_received()); |
727 } | 750 } |
728 | 751 |
729 TEST_F(URLRequestTest, CancelRedirect) { | 752 TEST_F(URLRequestTest, CancelRedirect) { |
730 TestServer server(L"net/data/url_request_unittest"); | 753 scoped_refptr<HTTPTestServer> server = |
731 ASSERT_TRUE(server.init_successful()); | 754 HTTPTestServer::CreateServer(L"net/data/url_request_unittest"); |
| 755 ASSERT_TRUE(NULL != server.get()); |
732 TestDelegate d; | 756 TestDelegate d; |
733 { | 757 { |
734 d.set_cancel_in_received_redirect(true); | 758 d.set_cancel_in_received_redirect(true); |
735 TestURLRequest req(server.TestServerPage( | 759 TestURLRequest req(server->TestServerPage( |
736 "files/redirect-test.html"), &d); | 760 "files/redirect-test.html"), &d); |
737 req.Start(); | 761 req.Start(); |
738 MessageLoop::current()->Run(); | 762 MessageLoop::current()->Run(); |
739 | 763 |
740 EXPECT_EQ(1, d.response_started_count()); | 764 EXPECT_EQ(1, d.response_started_count()); |
741 EXPECT_EQ(0, d.bytes_received()); | 765 EXPECT_EQ(0, d.bytes_received()); |
742 EXPECT_FALSE(d.received_data_before_response()); | 766 EXPECT_FALSE(d.received_data_before_response()); |
743 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); | 767 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); |
744 } | 768 } |
745 } | 769 } |
746 | 770 |
747 TEST_F(URLRequestTest, VaryHeader) { | 771 TEST_F(URLRequestTest, VaryHeader) { |
748 TestServer server(L"net/data/url_request_unittest"); | 772 scoped_refptr<HTTPTestServer> server = |
749 ASSERT_TRUE(server.init_successful()); | 773 HTTPTestServer::CreateServer(L"net/data/url_request_unittest"); |
| 774 ASSERT_TRUE(NULL != server.get()); |
750 | 775 |
751 scoped_refptr<URLRequestContext> context = new URLRequestHttpCacheContext(); | 776 scoped_refptr<URLRequestContext> context = new URLRequestHttpCacheContext(); |
752 | 777 |
753 Time response_time; | 778 Time response_time; |
754 | 779 |
755 // populate the cache | 780 // populate the cache |
756 { | 781 { |
757 TestDelegate d; | 782 TestDelegate d; |
758 URLRequest req(server.TestServerPage("echoheader?foo"), &d); | 783 URLRequest req(server->TestServerPage("echoheader?foo"), &d); |
759 req.set_context(context); | 784 req.set_context(context); |
760 req.SetExtraRequestHeaders("foo:1"); | 785 req.SetExtraRequestHeaders("foo:1"); |
761 req.Start(); | 786 req.Start(); |
762 MessageLoop::current()->Run(); | 787 MessageLoop::current()->Run(); |
763 | 788 |
764 response_time = req.response_time(); | 789 response_time = req.response_time(); |
765 } | 790 } |
766 | 791 |
767 // Make sure that the response time of a future response will be in the | 792 // Make sure that the response time of a future response will be in the |
768 // future! | 793 // future! |
769 PlatformThread::Sleep(10); | 794 PlatformThread::Sleep(10); |
770 | 795 |
771 // expect a cache hit | 796 // expect a cache hit |
772 { | 797 { |
773 TestDelegate d; | 798 TestDelegate d; |
774 URLRequest req(server.TestServerPage("echoheader?foo"), &d); | 799 URLRequest req(server->TestServerPage("echoheader?foo"), &d); |
775 req.set_context(context); | 800 req.set_context(context); |
776 req.SetExtraRequestHeaders("foo:1"); | 801 req.SetExtraRequestHeaders("foo:1"); |
777 req.Start(); | 802 req.Start(); |
778 MessageLoop::current()->Run(); | 803 MessageLoop::current()->Run(); |
779 | 804 |
780 EXPECT_TRUE(req.response_time() == response_time); | 805 EXPECT_TRUE(req.response_time() == response_time); |
781 } | 806 } |
782 | 807 |
783 // expect a cache miss | 808 // expect a cache miss |
784 { | 809 { |
785 TestDelegate d; | 810 TestDelegate d; |
786 URLRequest req(server.TestServerPage("echoheader?foo"), &d); | 811 URLRequest req(server->TestServerPage("echoheader?foo"), &d); |
787 req.set_context(context); | 812 req.set_context(context); |
788 req.SetExtraRequestHeaders("foo:2"); | 813 req.SetExtraRequestHeaders("foo:2"); |
789 req.Start(); | 814 req.Start(); |
790 MessageLoop::current()->Run(); | 815 MessageLoop::current()->Run(); |
791 | 816 |
792 EXPECT_FALSE(req.response_time() == response_time); | 817 EXPECT_FALSE(req.response_time() == response_time); |
793 } | 818 } |
794 } | 819 } |
795 | 820 |
796 TEST_F(URLRequestTest, BasicAuth) { | 821 TEST_F(URLRequestTest, BasicAuth) { |
797 scoped_refptr<URLRequestContext> context = new URLRequestHttpCacheContext(); | 822 scoped_refptr<URLRequestContext> context = new URLRequestHttpCacheContext(); |
798 TestServer server(L""); | 823 scoped_refptr<HTTPTestServer> server = |
799 ASSERT_TRUE(server.init_successful()); | 824 HTTPTestServer::CreateServer(L""); |
| 825 ASSERT_TRUE(NULL != server.get()); |
800 | 826 |
801 Time response_time; | 827 Time response_time; |
802 | 828 |
803 // populate the cache | 829 // populate the cache |
804 { | 830 { |
805 TestDelegate d; | 831 TestDelegate d; |
806 d.set_username(L"user"); | 832 d.set_username(L"user"); |
807 d.set_password(L"secret"); | 833 d.set_password(L"secret"); |
808 | 834 |
809 URLRequest r(server.TestServerPage("auth-basic"), &d); | 835 URLRequest r(server->TestServerPage("auth-basic"), &d); |
810 r.set_context(context); | 836 r.set_context(context); |
811 r.Start(); | 837 r.Start(); |
812 | 838 |
813 MessageLoop::current()->Run(); | 839 MessageLoop::current()->Run(); |
814 | 840 |
815 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); | 841 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); |
816 | 842 |
817 response_time = r.response_time(); | 843 response_time = r.response_time(); |
818 } | 844 } |
819 | 845 |
820 // Let some time pass so we can ensure that a future response will have a | 846 // Let some time pass so we can ensure that a future response will have a |
821 // response time value in the future. | 847 // response time value in the future. |
822 PlatformThread::Sleep(10 /* milliseconds */); | 848 PlatformThread::Sleep(10 /* milliseconds */); |
823 | 849 |
824 // repeat request with end-to-end validation. since auth-basic results in a | 850 // repeat request with end-to-end validation. since auth-basic results in a |
825 // cachable page, we expect this test to result in a 304. in which case, the | 851 // cachable page, we expect this test to result in a 304. in which case, the |
826 // response should be fetched from the cache. | 852 // response should be fetched from the cache. |
827 { | 853 { |
828 TestDelegate d; | 854 TestDelegate d; |
829 d.set_username(L"user"); | 855 d.set_username(L"user"); |
830 d.set_password(L"secret"); | 856 d.set_password(L"secret"); |
831 | 857 |
832 URLRequest r(server.TestServerPage("auth-basic"), &d); | 858 URLRequest r(server->TestServerPage("auth-basic"), &d); |
833 r.set_context(context); | 859 r.set_context(context); |
834 r.set_load_flags(net::LOAD_VALIDATE_CACHE); | 860 r.set_load_flags(net::LOAD_VALIDATE_CACHE); |
835 r.Start(); | 861 r.Start(); |
836 | 862 |
837 MessageLoop::current()->Run(); | 863 MessageLoop::current()->Run(); |
838 | 864 |
839 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); | 865 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); |
840 | 866 |
841 // Should be the same cached document, which means that the response time | 867 // Should be the same cached document, which means that the response time |
842 // should not have changed. | 868 // should not have changed. |
843 EXPECT_TRUE(response_time == r.response_time()); | 869 EXPECT_TRUE(response_time == r.response_time()); |
844 } | 870 } |
845 } | 871 } |
846 | 872 |
847 // In this test, we do a POST which the server will 302 redirect. | 873 // In this test, we do a POST which the server will 302 redirect. |
848 // The subsequent transaction should use GET, and should not send the | 874 // The subsequent transaction should use GET, and should not send the |
849 // Content-Type header. | 875 // Content-Type header. |
850 // http://code.google.com/p/chromium/issues/detail?id=843 | 876 // http://code.google.com/p/chromium/issues/detail?id=843 |
851 TEST_F(URLRequestTest, Post302RedirectGet) { | 877 TEST_F(URLRequestTest, Post302RedirectGet) { |
852 TestServer server(L"net/data/url_request_unittest"); | 878 scoped_refptr<HTTPTestServer> server = |
| 879 HTTPTestServer::CreateServer(L"net/data/url_request_unittest"); |
| 880 ASSERT_TRUE(NULL != server.get()); |
853 TestDelegate d; | 881 TestDelegate d; |
854 TestURLRequest req(server.TestServerPage("files/redirect-to-echoall"), &d); | 882 TestURLRequest req(server->TestServerPage("files/redirect-to-echoall"), &d); |
855 req.set_method("POST"); | 883 req.set_method("POST"); |
856 | 884 |
857 // Set headers (some of which are specific to the POST). | 885 // Set headers (some of which are specific to the POST). |
858 // ("Content-Length: 10" is just a junk value to make sure it gets stripped). | 886 // ("Content-Length: 10" is just a junk value to make sure it gets stripped). |
859 req.SetExtraRequestHeaders( | 887 req.SetExtraRequestHeaders( |
860 "Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryAADeAA+NA
AWMAAwZ\r\n" | 888 "Content-Type: multipart/form-data; " |
861 "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text
/plain;q=0.8,image/png,*/*;q=0.5\r\n" | 889 "boundary=----WebKitFormBoundaryAADeAA+NAAWMAAwZ\r\n" |
| 890 "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9," |
| 891 "text/plain;q=0.8,image/png,*/*;q=0.5\r\n" |
862 "Accept-Language: en-US,en\r\n" | 892 "Accept-Language: en-US,en\r\n" |
863 "Accept-Charset: ISO-8859-1,*,utf-8\r\n" | 893 "Accept-Charset: ISO-8859-1,*,utf-8\r\n" |
864 "Content-Length: 10\r\n" | 894 "Content-Length: 10\r\n" |
865 "Origin: http://localhost:1337/" | 895 "Origin: http://localhost:1337/" |
866 ); | 896 ); |
867 req.Start(); | 897 req.Start(); |
868 MessageLoop::current()->Run(); | 898 MessageLoop::current()->Run(); |
869 | 899 |
870 std::string mime_type; | 900 std::string mime_type; |
871 req.GetMimeType(&mime_type); | 901 req.GetMimeType(&mime_type); |
872 EXPECT_EQ("text/html", mime_type); | 902 EXPECT_EQ("text/html", mime_type); |
873 | 903 |
874 const std::string& data = d.data_received(); | 904 const std::string& data = d.data_received(); |
875 | 905 |
876 // Check that the post-specific headers were stripped: | 906 // Check that the post-specific headers were stripped: |
877 EXPECT_FALSE(ContainsString(data, "Content-Length:")); | 907 EXPECT_FALSE(ContainsString(data, "Content-Length:")); |
878 EXPECT_FALSE(ContainsString(data, "Content-Type:")); | 908 EXPECT_FALSE(ContainsString(data, "Content-Type:")); |
879 EXPECT_FALSE(ContainsString(data, "Origin:")); | 909 EXPECT_FALSE(ContainsString(data, "Origin:")); |
880 | 910 |
881 // These extra request headers should not have been stripped. | 911 // These extra request headers should not have been stripped. |
882 EXPECT_TRUE(ContainsString(data, "Accept:")); | 912 EXPECT_TRUE(ContainsString(data, "Accept:")); |
883 EXPECT_TRUE(ContainsString(data, "Accept-Language:")); | 913 EXPECT_TRUE(ContainsString(data, "Accept-Language:")); |
884 EXPECT_TRUE(ContainsString(data, "Accept-Charset:")); | 914 EXPECT_TRUE(ContainsString(data, "Accept-Charset:")); |
885 } | 915 } |
886 | 916 |
887 TEST_F(URLRequestTest, Post307RedirectPost) { | 917 TEST_F(URLRequestTest, Post307RedirectPost) { |
888 TestServer server(L"net/data/url_request_unittest"); | 918 scoped_refptr<HTTPTestServer> server = |
| 919 HTTPTestServer::CreateServer(L"net/data/url_request_unittest"); |
| 920 ASSERT_TRUE(NULL != server.get()); |
889 TestDelegate d; | 921 TestDelegate d; |
890 TestURLRequest req(server.TestServerPage("files/redirect307-to-echoall"), &d); | 922 TestURLRequest req(server->TestServerPage("files/redirect307-to-echoall"), |
| 923 &d); |
891 req.set_method("POST"); | 924 req.set_method("POST"); |
892 req.Start(); | 925 req.Start(); |
893 MessageLoop::current()->Run(); | 926 MessageLoop::current()->Run(); |
894 EXPECT_EQ(req.method(), "POST"); | 927 EXPECT_EQ(req.method(), "POST"); |
895 } | 928 } |
| 929 |
| 930 #if !defined(OS_WIN) |
| 931 #define MAYBE_FTPGetTestAnonymous DISABLED_FTPGetTestAnonymous |
| 932 #define MAYBE_FTPCheckWrongPassword DISABLED_FTPCheckWrongPassword |
| 933 #define MAYBE_FTPCheckWrongUser DISABLED_FTPCheckWrongUser |
| 934 #define MAYBE_FTPGetTest DISABLED_FTPGetTest |
| 935 #else |
| 936 #define MAYBE_FTPGetTestAnonymous FTPGetTestAnonymous |
| 937 #define MAYBE_FTPCheckWrongPassword FTPCheckWrongPassword |
| 938 #define MAYBE_FTPCheckWrongUser FTPCheckWrongUser |
| 939 #define MAYBE_FTPGetTest FTPGetTest |
| 940 #endif |
| 941 |
| 942 TEST_F(URLRequestTest, MAYBE_FTPGetTestAnonymous) { |
| 943 scoped_refptr<FTPTestServer> server = FTPTestServer::CreateServer(L""); |
| 944 ASSERT_TRUE(NULL != server.get()); |
| 945 std::wstring app_path; |
| 946 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); |
| 947 app_path.append(L"\\LICENSE"); |
| 948 TestDelegate d; |
| 949 { |
| 950 TestURLRequest r(server->TestServerPage("/LICENSE"), &d); |
| 951 r.Start(); |
| 952 EXPECT_TRUE(r.is_pending()); |
| 953 |
| 954 MessageLoop::current()->Run(); |
| 955 |
| 956 int64 file_size = 0; |
| 957 file_util::GetFileSize(app_path, &file_size); |
| 958 |
| 959 EXPECT_TRUE(!r.is_pending()); |
| 960 EXPECT_EQ(1, d.response_started_count()); |
| 961 EXPECT_FALSE(d.received_data_before_response()); |
| 962 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size)); |
| 963 } |
| 964 } |
| 965 |
| 966 TEST_F(URLRequestTest, MAYBE_FTPGetTest) { |
| 967 scoped_refptr<FTPTestServer> server = |
| 968 FTPTestServer::CreateServer(L"", "chrome", "chrome"); |
| 969 ASSERT_TRUE(NULL != server.get()); |
| 970 std::wstring app_path; |
| 971 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); |
| 972 app_path.append(L"\\LICENSE"); |
| 973 TestDelegate d; |
| 974 { |
| 975 TestURLRequest r(server->TestServerPage("/LICENSE"), &d); |
| 976 r.Start(); |
| 977 EXPECT_TRUE(r.is_pending()); |
| 978 |
| 979 MessageLoop::current()->Run(); |
| 980 |
| 981 int64 file_size = 0; |
| 982 file_util::GetFileSize(app_path, &file_size); |
| 983 |
| 984 EXPECT_TRUE(!r.is_pending()); |
| 985 EXPECT_EQ(1, d.response_started_count()); |
| 986 EXPECT_FALSE(d.received_data_before_response()); |
| 987 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size)); |
| 988 } |
| 989 } |
| 990 |
| 991 TEST_F(URLRequestTest, MAYBE_FTPCheckWrongPassword) { |
| 992 scoped_refptr<FTPTestServer> server = |
| 993 FTPTestServer::CreateServer(L"", "chrome", "wrong_password"); |
| 994 ASSERT_TRUE(NULL != server.get()); |
| 995 std::wstring app_path; |
| 996 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); |
| 997 app_path.append(L"\\LICENSE"); |
| 998 TestDelegate d; |
| 999 { |
| 1000 TestURLRequest r(server->TestServerPage("/LICENSE"), &d); |
| 1001 r.Start(); |
| 1002 EXPECT_TRUE(r.is_pending()); |
| 1003 |
| 1004 MessageLoop::current()->Run(); |
| 1005 |
| 1006 int64 file_size = 0; |
| 1007 file_util::GetFileSize(app_path, &file_size); |
| 1008 |
| 1009 EXPECT_TRUE(!r.is_pending()); |
| 1010 EXPECT_EQ(1, d.response_started_count()); |
| 1011 EXPECT_FALSE(d.received_data_before_response()); |
| 1012 EXPECT_EQ(d.bytes_received(), 0); |
| 1013 } |
| 1014 } |
| 1015 |
| 1016 TEST_F(URLRequestTest, MAYBE_FTPCheckWrongUser) { |
| 1017 scoped_refptr<FTPTestServer> server = |
| 1018 FTPTestServer::CreateServer(L"", "wrong_user", "chrome"); |
| 1019 ASSERT_TRUE(NULL != server.get()); |
| 1020 std::wstring app_path; |
| 1021 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); |
| 1022 app_path.append(L"\\LICENSE"); |
| 1023 TestDelegate d; |
| 1024 { |
| 1025 TestURLRequest r(server->TestServerPage("/LICENSE"), &d); |
| 1026 r.Start(); |
| 1027 EXPECT_TRUE(r.is_pending()); |
| 1028 |
| 1029 MessageLoop::current()->Run(); |
| 1030 |
| 1031 int64 file_size = 0; |
| 1032 file_util::GetFileSize(app_path, &file_size); |
| 1033 |
| 1034 EXPECT_TRUE(!r.is_pending()); |
| 1035 EXPECT_EQ(1, d.response_started_count()); |
| 1036 EXPECT_FALSE(d.received_data_before_response()); |
| 1037 EXPECT_EQ(d.bytes_received(), 0); |
| 1038 } |
| 1039 } |
| 1040 |
OLD | NEW |