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

Side by Side Diff: net/url_request/url_request_unittest.cc

Issue 21158: Fix a logic error in the handling the response to an HTTP... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 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
« no previous file with comments | « net/url_request/url_request_unittest.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) 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 } 48 }
49 49
50 virtual ~URLRequestHttpCacheContext() { 50 virtual ~URLRequestHttpCacheContext() {
51 delete http_transaction_factory_; 51 delete http_transaction_factory_;
52 delete proxy_service_; 52 delete proxy_service_;
53 } 53 }
54 }; 54 };
55 55
56 class TestURLRequest : public URLRequest { 56 class TestURLRequest : public URLRequest {
57 public: 57 public:
58 TestURLRequest(const GURL& url, Delegate* delegate) 58 TestURLRequest(const GURL& url, Delegate* delegate)
59 : URLRequest(url, delegate) { 59 : URLRequest(url, delegate) {
60 set_context(new URLRequestHttpCacheContext()); 60 set_context(new URLRequestHttpCacheContext());
61 } 61 }
62 }; 62 };
63 63
64 StringPiece TestNetResourceProvider(int key) { 64 StringPiece TestNetResourceProvider(int key) {
65 return "header"; 65 return "header";
66 } 66 }
67 67
68 // Do a case-insensitive search through |haystack| for |needle|. 68 // Do a case-insensitive search through |haystack| for |needle|.
69 bool ContainsString(const std::string& haystack, const char* needle) { 69 bool ContainsString(const std::string& haystack, const char* needle) {
70 std::string::const_iterator it = 70 std::string::const_iterator it =
71 std::search(haystack.begin(), 71 std::search(haystack.begin(),
72 haystack.end(), 72 haystack.end(),
73 needle, 73 needle,
74 needle + strlen(needle), 74 needle + strlen(needle),
75 CaseInsensitiveCompare<char>()); 75 CaseInsensitiveCompare<char>());
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, ProxyTunnelRedirectTest) {
86 // In this unit test, we're using the HTTPTestServer as a proxy server and
87 // issue a CONNECT request with the magic host name "www.redirect.com" to
88 // it. The HTTPTestServer will return a 302 response, which we should not
89 // follow.
90 scoped_refptr<HTTPTestServer> server =
91 HTTPTestServer::CreateServer(L"", NULL);
92 ASSERT_TRUE(NULL != server.get());
93 TestDelegate d;
94 {
95 URLRequest r(GURL("https://www.redirect.com/"), &d);
96 std::string proxy("localhost:");
97 proxy.append(IntToString(kHTTPDefaultPort));
98 r.set_context(new TestURLRequestContext(proxy));
99
100 r.Start();
101 EXPECT_TRUE(r.is_pending());
102
103 MessageLoop::current()->Run();
104
105 EXPECT_EQ(1, d.response_started_count());
106 // We should have rewritten the 302 response code as 500.
107 EXPECT_EQ(500, r.GetResponseCode());
108 // We should not have followed the redirect.
109 EXPECT_EQ(0, d.received_redirect_count());
110 }
111 }
112
85 TEST_F(URLRequestTest, GetTest_NoCache) { 113 TEST_F(URLRequestTest, GetTest_NoCache) {
86 scoped_refptr<HTTPTestServer> server = 114 scoped_refptr<HTTPTestServer> server =
87 HTTPTestServer::CreateServer(L"", NULL); 115 HTTPTestServer::CreateServer(L"", NULL);
88 ASSERT_TRUE(NULL != server.get()); 116 ASSERT_TRUE(NULL != server.get());
89 TestDelegate d; 117 TestDelegate d;
90 { 118 {
91 TestURLRequest r(server->TestServerPage(""), &d); 119 TestURLRequest r(server->TestServerPage(""), &d);
92 120
93 r.Start(); 121 r.Start();
94 EXPECT_TRUE(r.is_pending()); 122 EXPECT_TRUE(r.is_pending());
95 123
96 MessageLoop::current()->Run(); 124 MessageLoop::current()->Run();
97 125
98 EXPECT_EQ(1, d.response_started_count()); 126 EXPECT_EQ(1, d.response_started_count());
99 EXPECT_FALSE(d.received_data_before_response()); 127 EXPECT_FALSE(d.received_data_before_response());
100 EXPECT_NE(0, d.bytes_received()); 128 EXPECT_NE(0, d.bytes_received());
101 } 129 }
102 #ifndef NDEBUG 130 #ifndef NDEBUG
103 DCHECK_EQ(url_request_metrics.object_count,0); 131 DCHECK_EQ(url_request_metrics.object_count, 0);
104 #endif 132 #endif
105 } 133 }
106 134
107 TEST_F(URLRequestTest, GetTest) { 135 TEST_F(URLRequestTest, GetTest) {
108 scoped_refptr<HTTPTestServer> server = 136 scoped_refptr<HTTPTestServer> server =
109 HTTPTestServer::CreateServer(L"", NULL); 137 HTTPTestServer::CreateServer(L"", NULL);
110 ASSERT_TRUE(NULL != server.get()); 138 ASSERT_TRUE(NULL != server.get());
111 TestDelegate d; 139 TestDelegate d;
112 { 140 {
113 TestURLRequest r(server->TestServerPage(""), &d); 141 TestURLRequest r(server->TestServerPage(""), &d);
114 142
115 r.Start(); 143 r.Start();
116 EXPECT_TRUE(r.is_pending()); 144 EXPECT_TRUE(r.is_pending());
117 145
118 MessageLoop::current()->Run(); 146 MessageLoop::current()->Run();
119 147
120 EXPECT_EQ(1, d.response_started_count()); 148 EXPECT_EQ(1, d.response_started_count());
121 EXPECT_FALSE(d.received_data_before_response()); 149 EXPECT_FALSE(d.received_data_before_response());
122 EXPECT_NE(0, d.bytes_received()); 150 EXPECT_NE(0, d.bytes_received());
123 } 151 }
124 #ifndef NDEBUG 152 #ifndef NDEBUG
125 DCHECK_EQ(url_request_metrics.object_count,0); 153 DCHECK_EQ(url_request_metrics.object_count, 0);
126 #endif 154 #endif
127 } 155 }
128 156
129 class HTTPSRequestTest : public testing::Test { 157 class HTTPSRequestTest : public testing::Test {
130 protected: 158 protected:
131 HTTPSRequestTest() : util_() {}; 159 HTTPSRequestTest() : util_() {}
132 160
133 SSLTestUtil util_; 161 SSLTestUtil util_;
134 }; 162 };
135 163
136 #if defined(OS_MACOSX) 164 #if defined(OS_MACOSX)
137 // TODO(port): support temporary root cert on mac 165 // TODO(port): support temporary root cert on mac
138 #define MAYBE_HTTPSGetTest DISABLED_HTTPSGetTest 166 #define MAYBE_HTTPSGetTest DISABLED_HTTPSGetTest
139 #else 167 #else
140 #define MAYBE_HTTPSGetTest HTTPSGetTest 168 #define MAYBE_HTTPSGetTest HTTPSGetTest
141 #endif 169 #endif
142 170
143 TEST_F(HTTPSRequestTest, MAYBE_HTTPSGetTest) { 171 TEST_F(HTTPSRequestTest, MAYBE_HTTPSGetTest) {
(...skipping 14 matching lines...) Expand all
158 r.Start(); 186 r.Start();
159 EXPECT_TRUE(r.is_pending()); 187 EXPECT_TRUE(r.is_pending());
160 188
161 MessageLoop::current()->Run(); 189 MessageLoop::current()->Run();
162 190
163 EXPECT_EQ(1, d.response_started_count()); 191 EXPECT_EQ(1, d.response_started_count());
164 EXPECT_FALSE(d.received_data_before_response()); 192 EXPECT_FALSE(d.received_data_before_response());
165 EXPECT_NE(0, d.bytes_received()); 193 EXPECT_NE(0, d.bytes_received());
166 } 194 }
167 #ifndef NDEBUG 195 #ifndef NDEBUG
168 DCHECK_EQ(url_request_metrics.object_count,0); 196 DCHECK_EQ(url_request_metrics.object_count, 0);
169 #endif 197 #endif
170 } 198 }
171 199
172 TEST_F(URLRequestTest, CancelTest) { 200 TEST_F(URLRequestTest, CancelTest) {
173 TestDelegate d; 201 TestDelegate d;
174 { 202 {
175 TestURLRequest r(GURL("http://www.google.com/"), &d); 203 TestURLRequest r(GURL("http://www.google.com/"), &d);
176 204
177 r.Start(); 205 r.Start();
178 EXPECT_TRUE(r.is_pending()); 206 EXPECT_TRUE(r.is_pending());
179 207
180 r.Cancel(); 208 r.Cancel();
181 209
182 MessageLoop::current()->Run(); 210 MessageLoop::current()->Run();
183 211
184 // We expect to receive OnResponseStarted even though the request has been 212 // We expect to receive OnResponseStarted even though the request has been
185 // cancelled. 213 // cancelled.
186 EXPECT_EQ(1, d.response_started_count()); 214 EXPECT_EQ(1, d.response_started_count());
187 EXPECT_EQ(0, d.bytes_received()); 215 EXPECT_EQ(0, d.bytes_received());
188 EXPECT_FALSE(d.received_data_before_response()); 216 EXPECT_FALSE(d.received_data_before_response());
189 } 217 }
190 #ifndef NDEBUG 218 #ifndef NDEBUG
191 DCHECK_EQ(url_request_metrics.object_count,0); 219 DCHECK_EQ(url_request_metrics.object_count, 0);
192 #endif 220 #endif
193 } 221 }
194 222
195 TEST_F(URLRequestTest, CancelTest2) { 223 TEST_F(URLRequestTest, CancelTest2) {
196 scoped_refptr<HTTPTestServer> server = 224 scoped_refptr<HTTPTestServer> server =
197 HTTPTestServer::CreateServer(L"", NULL); 225 HTTPTestServer::CreateServer(L"", NULL);
198 ASSERT_TRUE(NULL != server.get()); 226 ASSERT_TRUE(NULL != server.get());
199 227
200 // error C2446: '!=' : no conversion from 'HTTPTestServer *const ' 228 // error C2446: '!=' : no conversion from 'HTTPTestServer *const '
201 // to 'const int' 229 // to 'const int'
202 230
203 TestDelegate d; 231 TestDelegate d;
204 { 232 {
205 TestURLRequest r(server->TestServerPage(""), &d); 233 TestURLRequest r(server->TestServerPage(""), &d);
206 234
207 d.set_cancel_in_response_started(true); 235 d.set_cancel_in_response_started(true);
208 236
209 r.Start(); 237 r.Start();
210 EXPECT_TRUE(r.is_pending()); 238 EXPECT_TRUE(r.is_pending());
211 239
212 MessageLoop::current()->Run(); 240 MessageLoop::current()->Run();
213 241
214 EXPECT_EQ(1, d.response_started_count()); 242 EXPECT_EQ(1, d.response_started_count());
215 EXPECT_EQ(0, d.bytes_received()); 243 EXPECT_EQ(0, d.bytes_received());
216 EXPECT_FALSE(d.received_data_before_response()); 244 EXPECT_FALSE(d.received_data_before_response());
217 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); 245 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status());
218 } 246 }
219 #ifndef NDEBUG 247 #ifndef NDEBUG
220 DCHECK_EQ(url_request_metrics.object_count,0); 248 DCHECK_EQ(url_request_metrics.object_count, 0);
221 #endif 249 #endif
222 } 250 }
223 251
224 TEST_F(URLRequestTest, CancelTest3) { 252 TEST_F(URLRequestTest, CancelTest3) {
225 scoped_refptr<HTTPTestServer> server = 253 scoped_refptr<HTTPTestServer> server =
226 HTTPTestServer::CreateServer(L"", NULL); 254 HTTPTestServer::CreateServer(L"", NULL);
227 ASSERT_TRUE(NULL != server.get()); 255 ASSERT_TRUE(NULL != server.get());
228 TestDelegate d; 256 TestDelegate d;
229 { 257 {
230 TestURLRequest r(server->TestServerPage(""), &d); 258 TestURLRequest r(server->TestServerPage(""), &d);
231 259
232 d.set_cancel_in_received_data(true); 260 d.set_cancel_in_received_data(true);
233 261
234 r.Start(); 262 r.Start();
235 EXPECT_TRUE(r.is_pending()); 263 EXPECT_TRUE(r.is_pending());
236 264
237 MessageLoop::current()->Run(); 265 MessageLoop::current()->Run();
238 266
239 EXPECT_EQ(1, d.response_started_count()); 267 EXPECT_EQ(1, d.response_started_count());
240 // There is no guarantee about how much data was received 268 // There is no guarantee about how much data was received
241 // before the cancel was issued. It could have been 0 bytes, 269 // before the cancel was issued. It could have been 0 bytes,
242 // or it could have been all the bytes. 270 // or it could have been all the bytes.
243 // EXPECT_EQ(0, d.bytes_received()); 271 // EXPECT_EQ(0, d.bytes_received());
244 EXPECT_FALSE(d.received_data_before_response()); 272 EXPECT_FALSE(d.received_data_before_response());
245 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); 273 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status());
246 } 274 }
247 #ifndef NDEBUG 275 #ifndef NDEBUG
248 DCHECK_EQ(url_request_metrics.object_count,0); 276 DCHECK_EQ(url_request_metrics.object_count, 0);
249 #endif 277 #endif
250 } 278 }
251 279
252 TEST_F(URLRequestTest, CancelTest4) { 280 TEST_F(URLRequestTest, CancelTest4) {
253 scoped_refptr<HTTPTestServer> server = 281 scoped_refptr<HTTPTestServer> server =
254 HTTPTestServer::CreateServer(L"", NULL); 282 HTTPTestServer::CreateServer(L"", NULL);
255 ASSERT_TRUE(NULL != server.get()); 283 ASSERT_TRUE(NULL != server.get());
256 TestDelegate d; 284 TestDelegate d;
257 { 285 {
258 TestURLRequest r(server->TestServerPage(""), &d); 286 TestURLRequest r(server->TestServerPage(""), &d);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 341
314 TEST_F(URLRequestTest, PostTest) { 342 TEST_F(URLRequestTest, PostTest) {
315 scoped_refptr<HTTPTestServer> server = 343 scoped_refptr<HTTPTestServer> server =
316 HTTPTestServer::CreateServer(L"net/data", NULL); 344 HTTPTestServer::CreateServer(L"net/data", NULL);
317 ASSERT_TRUE(NULL != server.get()); 345 ASSERT_TRUE(NULL != server.get());
318 const int kMsgSize = 20000; // multiple of 10 346 const int kMsgSize = 20000; // multiple of 10
319 const int kIterations = 50; 347 const int kIterations = 50;
320 char *uploadBytes = new char[kMsgSize+1]; 348 char *uploadBytes = new char[kMsgSize+1];
321 char *ptr = uploadBytes; 349 char *ptr = uploadBytes;
322 char marker = 'a'; 350 char marker = 'a';
323 for(int idx=0; idx<kMsgSize/10; idx++) { 351 for (int idx = 0; idx < kMsgSize/10; idx++) {
324 memcpy(ptr, "----------", 10); 352 memcpy(ptr, "----------", 10);
325 ptr += 10; 353 ptr += 10;
326 if (idx % 100 == 0) { 354 if (idx % 100 == 0) {
327 ptr--; 355 ptr--;
328 *ptr++ = marker; 356 *ptr++ = marker;
329 if (++marker > 'z') 357 if (++marker > 'z')
330 marker = 'a'; 358 marker = 'a';
331 } 359 }
332
333 } 360 }
334 uploadBytes[kMsgSize] = '\0'; 361 uploadBytes[kMsgSize] = '\0';
335 362
336 scoped_refptr<URLRequestContext> context = 363 scoped_refptr<URLRequestContext> context =
337 new URLRequestHttpCacheContext(); 364 new URLRequestHttpCacheContext();
338 365
339 for (int i = 0; i < kIterations; ++i) { 366 for (int i = 0; i < kIterations; ++i) {
340 TestDelegate d; 367 TestDelegate d;
341 URLRequest r(server->TestServerPage("echo"), &d); 368 URLRequest r(server->TestServerPage("echo"), &d);
342 r.set_context(context); 369 r.set_context(context);
343 r.set_method("POST"); 370 r.set_method("POST");
344 371
345 r.AppendBytesToUpload(uploadBytes, kMsgSize); 372 r.AppendBytesToUpload(uploadBytes, kMsgSize);
346 373
347 r.Start(); 374 r.Start();
348 EXPECT_TRUE(r.is_pending()); 375 EXPECT_TRUE(r.is_pending());
349 376
350 MessageLoop::current()->Run(); 377 MessageLoop::current()->Run();
351 378
352 ASSERT_EQ(1, d.response_started_count()) << "request failed: " << 379 ASSERT_EQ(1, d.response_started_count()) << "request failed: " <<
353 (int) r.status().status() << ", os error: " << r.status().os_error(); 380 (int) r.status().status() << ", os error: " << r.status().os_error();
354 381
355 EXPECT_FALSE(d.received_data_before_response()); 382 EXPECT_FALSE(d.received_data_before_response());
356 EXPECT_EQ(uploadBytes, d.data_received()); 383 EXPECT_EQ(uploadBytes, d.data_received());
357 EXPECT_EQ(memcmp(uploadBytes, d.data_received().c_str(), kMsgSize),0); 384 EXPECT_EQ(memcmp(uploadBytes, d.data_received().c_str(), kMsgSize), 0);
358 EXPECT_EQ(d.data_received().compare(uploadBytes), 0); 385 EXPECT_EQ(d.data_received().compare(uploadBytes), 0);
359 } 386 }
360 delete[] uploadBytes; 387 delete[] uploadBytes;
361 #ifndef NDEBUG 388 #ifndef NDEBUG
362 DCHECK_EQ(url_request_metrics.object_count,0); 389 DCHECK_EQ(url_request_metrics.object_count, 0);
363 #endif 390 #endif
364 } 391 }
365 392
366 TEST_F(URLRequestTest, PostEmptyTest) { 393 TEST_F(URLRequestTest, PostEmptyTest) {
367 scoped_refptr<HTTPTestServer> server = 394 scoped_refptr<HTTPTestServer> server =
368 HTTPTestServer::CreateServer(L"net/data", NULL); 395 HTTPTestServer::CreateServer(L"net/data", NULL);
369 ASSERT_TRUE(NULL != server.get()); 396 ASSERT_TRUE(NULL != server.get());
370 TestDelegate d; 397 TestDelegate d;
371 { 398 {
372 TestURLRequest r(server->TestServerPage("echo"), &d); 399 TestURLRequest r(server->TestServerPage("echo"), &d);
373 r.set_method("POST"); 400 r.set_method("POST");
374 401
375 r.Start(); 402 r.Start();
376 EXPECT_TRUE(r.is_pending()); 403 EXPECT_TRUE(r.is_pending());
377 404
378 MessageLoop::current()->Run(); 405 MessageLoop::current()->Run();
379 406
380 ASSERT_EQ(1, d.response_started_count()) << "request failed: " << 407 ASSERT_EQ(1, d.response_started_count()) << "request failed: " <<
381 (int) r.status().status() << ", os error: " << r.status().os_error(); 408 (int) r.status().status() << ", os error: " << r.status().os_error();
382 409
383 EXPECT_FALSE(d.received_data_before_response()); 410 EXPECT_FALSE(d.received_data_before_response());
384 EXPECT_TRUE(d.data_received().empty()); 411 EXPECT_TRUE(d.data_received().empty());
385 } 412 }
386 #ifndef NDEBUG 413 #ifndef NDEBUG
387 DCHECK_EQ(url_request_metrics.object_count,0); 414 DCHECK_EQ(url_request_metrics.object_count, 0);
388 #endif 415 #endif
389 } 416 }
390 417
391 TEST_F(URLRequestTest, PostFileTest) { 418 TEST_F(URLRequestTest, PostFileTest) {
392 scoped_refptr<HTTPTestServer> server = 419 scoped_refptr<HTTPTestServer> server =
393 HTTPTestServer::CreateServer(L"net/data", NULL); 420 HTTPTestServer::CreateServer(L"net/data", NULL);
394 ASSERT_TRUE(NULL != server.get()); 421 ASSERT_TRUE(NULL != server.get());
395 TestDelegate d; 422 TestDelegate d;
396 { 423 {
397 TestURLRequest r(server->TestServerPage("echo"), &d); 424 TestURLRequest r(server->TestServerPage("echo"), &d);
(...skipping 30 matching lines...) Expand all
428 455
429 ASSERT_EQ(1, d.response_started_count()) << "request failed: " << 456 ASSERT_EQ(1, d.response_started_count()) << "request failed: " <<
430 (int) r.status().status() << ", os error: " << r.status().os_error(); 457 (int) r.status().status() << ", os error: " << r.status().os_error();
431 458
432 EXPECT_FALSE(d.received_data_before_response()); 459 EXPECT_FALSE(d.received_data_before_response());
433 460
434 ASSERT_EQ(size, d.bytes_received()); 461 ASSERT_EQ(size, d.bytes_received());
435 EXPECT_EQ(0, memcmp(d.data_received().c_str(), buf.get(), size)); 462 EXPECT_EQ(0, memcmp(d.data_received().c_str(), buf.get(), size));
436 } 463 }
437 #ifndef NDEBUG 464 #ifndef NDEBUG
438 DCHECK_EQ(url_request_metrics.object_count,0); 465 DCHECK_EQ(url_request_metrics.object_count, 0);
439 #endif 466 #endif
440 } 467 }
441 468
442 TEST_F(URLRequestTest, AboutBlankTest) { 469 TEST_F(URLRequestTest, AboutBlankTest) {
443 TestDelegate d; 470 TestDelegate d;
444 { 471 {
445 TestURLRequest r(GURL("about:blank"), &d); 472 TestURLRequest r(GURL("about:blank"), &d);
446 473
447 r.Start(); 474 r.Start();
448 EXPECT_TRUE(r.is_pending()); 475 EXPECT_TRUE(r.is_pending());
449 476
450 MessageLoop::current()->Run(); 477 MessageLoop::current()->Run();
451 478
452 EXPECT_TRUE(!r.is_pending()); 479 EXPECT_TRUE(!r.is_pending());
453 EXPECT_FALSE(d.received_data_before_response()); 480 EXPECT_FALSE(d.received_data_before_response());
454 EXPECT_EQ(d.bytes_received(), 0); 481 EXPECT_EQ(d.bytes_received(), 0);
455 } 482 }
456 #ifndef NDEBUG 483 #ifndef NDEBUG
457 DCHECK_EQ(url_request_metrics.object_count,0); 484 DCHECK_EQ(url_request_metrics.object_count, 0);
458 #endif 485 #endif
459 } 486 }
460 487
461 TEST_F(URLRequestTest, FileTest) { 488 TEST_F(URLRequestTest, FileTest) {
462 FilePath app_path; 489 FilePath app_path;
463 PathService::Get(base::FILE_EXE, &app_path); 490 PathService::Get(base::FILE_EXE, &app_path);
464 GURL app_url = net::FilePathToFileURL(app_path.ToWStringHack()); 491 GURL app_url = net::FilePathToFileURL(app_path.ToWStringHack());
465 492
466 TestDelegate d; 493 TestDelegate d;
467 { 494 {
468 TestURLRequest r(app_url, &d); 495 TestURLRequest r(app_url, &d);
469 496
470 r.Start(); 497 r.Start();
471 EXPECT_TRUE(r.is_pending()); 498 EXPECT_TRUE(r.is_pending());
472 499
473 MessageLoop::current()->Run(); 500 MessageLoop::current()->Run();
474 501
475 int64 file_size; 502 int64 file_size;
476 file_util::GetFileSize(app_path, &file_size); 503 file_util::GetFileSize(app_path, &file_size);
477 504
478 EXPECT_TRUE(!r.is_pending()); 505 EXPECT_TRUE(!r.is_pending());
479 EXPECT_EQ(1, d.response_started_count()); 506 EXPECT_EQ(1, d.response_started_count());
480 EXPECT_FALSE(d.received_data_before_response()); 507 EXPECT_FALSE(d.received_data_before_response());
481 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size)); 508 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size));
482 } 509 }
483 #ifndef NDEBUG 510 #ifndef NDEBUG
484 DCHECK_EQ(url_request_metrics.object_count,0); 511 DCHECK_EQ(url_request_metrics.object_count, 0);
485 #endif 512 #endif
486 } 513 }
487 514
488 TEST_F(URLRequestTest, InvalidUrlTest) { 515 TEST_F(URLRequestTest, InvalidUrlTest) {
489 TestDelegate d; 516 TestDelegate d;
490 { 517 {
491 TestURLRequest r(GURL("invalid url"), &d); 518 TestURLRequest r(GURL("invalid url"), &d);
492 519
493 r.Start(); 520 r.Start();
494 EXPECT_TRUE(r.is_pending()); 521 EXPECT_TRUE(r.is_pending());
495 522
496 MessageLoop::current()->Run(); 523 MessageLoop::current()->Run();
497 EXPECT_TRUE(d.request_failed()); 524 EXPECT_TRUE(d.request_failed());
498 } 525 }
499 #ifndef NDEBUG 526 #ifndef NDEBUG
500 DCHECK_EQ(url_request_metrics.object_count,0); 527 DCHECK_EQ(url_request_metrics.object_count, 0);
501 #endif 528 #endif
502 } 529 }
503 530
504 // This test is disabled because it fails on some computers due to proxies 531 // This test is disabled because it fails on some computers due to proxies
505 // returning a page in response to this request rather than reporting failure. 532 // returning a page in response to this request rather than reporting failure.
506 TEST_F(URLRequestTest, DISABLED_DnsFailureTest) { 533 TEST_F(URLRequestTest, DISABLED_DnsFailureTest) {
507 TestDelegate d; 534 TestDelegate d;
508 { 535 {
509 URLRequest r(GURL("http://thisisnotavalidurl0123456789foo.com/"), &d); 536 URLRequest r(GURL("http://thisisnotavalidurl0123456789foo.com/"), &d);
510 537
511 r.Start(); 538 r.Start();
512 EXPECT_TRUE(r.is_pending()); 539 EXPECT_TRUE(r.is_pending());
513 540
514 MessageLoop::current()->Run(); 541 MessageLoop::current()->Run();
515 EXPECT_TRUE(d.request_failed()); 542 EXPECT_TRUE(d.request_failed());
516 } 543 }
517 #ifndef NDEBUG 544 #ifndef NDEBUG
518 DCHECK_EQ(url_request_metrics.object_count,0); 545 DCHECK_EQ(url_request_metrics.object_count, 0);
519 #endif 546 #endif
520 } 547 }
521 548
522 TEST_F(URLRequestTest, ResponseHeadersTest) { 549 TEST_F(URLRequestTest, ResponseHeadersTest) {
523 scoped_refptr<HTTPTestServer> server = 550 scoped_refptr<HTTPTestServer> server =
524 HTTPTestServer::CreateServer(L"net/data/url_request_unittest", NULL); 551 HTTPTestServer::CreateServer(L"net/data/url_request_unittest", NULL);
525 ASSERT_TRUE(NULL != server.get()); 552 ASSERT_TRUE(NULL != server.get());
526 TestDelegate d; 553 TestDelegate d;
527 TestURLRequest req(server->TestServerPage("files/with-headers.html"), &d); 554 TestURLRequest req(server->TestServerPage("files/with-headers.html"), &d);
528 req.Start(); 555 req.Start();
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
659 EXPECT_TRUE(!r.is_pending()); 686 EXPECT_TRUE(!r.is_pending());
660 EXPECT_EQ(1, d.received_redirect_count()); 687 EXPECT_EQ(1, d.received_redirect_count());
661 EXPECT_EQ(content, d.data_received()); 688 EXPECT_EQ(content, d.data_received());
662 } 689 }
663 690
664 // Clean the shortcut 691 // Clean the shortcut
665 DeleteFile(lnk_path.c_str()); 692 DeleteFile(lnk_path.c_str());
666 CoUninitialize(); 693 CoUninitialize();
667 694
668 #ifndef NDEBUG 695 #ifndef NDEBUG
669 DCHECK_EQ(url_request_metrics.object_count,0); 696 DCHECK_EQ(url_request_metrics.object_count, 0);
670 #endif 697 #endif
671 } 698 }
672 #endif // defined(OS_WIN) 699 #endif // defined(OS_WIN)
673 700
674 TEST_F(URLRequestTest, ContentTypeNormalizationTest) { 701 TEST_F(URLRequestTest, ContentTypeNormalizationTest) {
675 scoped_refptr<HTTPTestServer> server = 702 scoped_refptr<HTTPTestServer> server =
676 HTTPTestServer::CreateServer(L"net/data/url_request_unittest", NULL); 703 HTTPTestServer::CreateServer(L"net/data/url_request_unittest", NULL);
677 ASSERT_TRUE(NULL != server.get()); 704 ASSERT_TRUE(NULL != server.get());
678 705
679 TestDelegate d; 706 TestDelegate d;
(...skipping 26 matching lines...) Expand all
706 733
707 TestURLRequest req(net::FilePathToFileURL(file_path), &d); 734 TestURLRequest req(net::FilePathToFileURL(file_path), &d);
708 req.Start(); 735 req.Start();
709 EXPECT_TRUE(req.is_pending()); 736 EXPECT_TRUE(req.is_pending());
710 737
711 d.set_cancel_in_received_data_pending(true); 738 d.set_cancel_in_received_data_pending(true);
712 739
713 MessageLoop::current()->Run(); 740 MessageLoop::current()->Run();
714 } 741 }
715 #ifndef NDEBUG 742 #ifndef NDEBUG
716 DCHECK_EQ(url_request_metrics.object_count,0); 743 DCHECK_EQ(url_request_metrics.object_count, 0);
717 #endif 744 #endif
718 745
719 // Take out mock resource provider. 746 // Take out mock resource provider.
720 net::NetModule::SetResourceProvider(NULL); 747 net::NetModule::SetResourceProvider(NULL);
721 } 748 }
722 749
723 TEST_F(URLRequestTest, RestrictRedirects) { 750 TEST_F(URLRequestTest, RestrictRedirects) {
724 scoped_refptr<HTTPTestServer> server = 751 scoped_refptr<HTTPTestServer> server =
725 HTTPTestServer::CreateServer(L"net/data/url_request_unittest", NULL); 752 HTTPTestServer::CreateServer(L"net/data/url_request_unittest", NULL);
726 ASSERT_TRUE(NULL != server.get()); 753 ASSERT_TRUE(NULL != server.get());
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
1032 int64 file_size = 0; 1059 int64 file_size = 0;
1033 file_util::GetFileSize(app_path, &file_size); 1060 file_util::GetFileSize(app_path, &file_size);
1034 1061
1035 EXPECT_TRUE(!r.is_pending()); 1062 EXPECT_TRUE(!r.is_pending());
1036 EXPECT_EQ(1, d.response_started_count()); 1063 EXPECT_EQ(1, d.response_started_count());
1037 EXPECT_FALSE(d.received_data_before_response()); 1064 EXPECT_FALSE(d.received_data_before_response());
1038 EXPECT_EQ(d.bytes_received(), 0); 1065 EXPECT_EQ(d.bytes_received(), 0);
1039 } 1066 }
1040 } 1067 }
1041 1068
OLDNEW
« no previous file with comments | « net/url_request/url_request_unittest.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698