OLD | NEW |
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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 27 matching lines...) Expand all Loading... |
38 #include "testing/gtest/include/gtest/gtest.h" | 38 #include "testing/gtest/include/gtest/gtest.h" |
39 #include "testing/platform_test.h" | 39 #include "testing/platform_test.h" |
40 | 40 |
41 using base::Time; | 41 using base::Time; |
42 | 42 |
43 namespace { | 43 namespace { |
44 | 44 |
45 class URLRequestHttpCacheContext : public URLRequestContext { | 45 class URLRequestHttpCacheContext : public URLRequestContext { |
46 public: | 46 public: |
47 URLRequestHttpCacheContext() { | 47 URLRequestHttpCacheContext() { |
48 host_resolver_ = new net::HostResolver; | 48 // TODO(eroman): we turn off host caching to see if synchronous |
| 49 // host resolving interacts poorly with client socket pool. [experiment] |
| 50 // http://crbug.com/13952 |
| 51 host_resolver_ = new net::HostResolver(0, 0); |
49 proxy_service_ = net::ProxyService::CreateNull(); | 52 proxy_service_ = net::ProxyService::CreateNull(); |
50 http_transaction_factory_ = | 53 http_transaction_factory_ = |
51 new net::HttpCache( | 54 new net::HttpCache( |
52 net::HttpNetworkLayer::CreateFactory(host_resolver_, proxy_service_), | 55 net::HttpNetworkLayer::CreateFactory(host_resolver_, proxy_service_), |
53 disk_cache::CreateInMemoryCacheBackend(0)); | 56 disk_cache::CreateInMemoryCacheBackend(0)); |
54 // In-memory cookie store. | 57 // In-memory cookie store. |
55 cookie_store_ = new net::CookieMonster(); | 58 cookie_store_ = new net::CookieMonster(); |
56 } | 59 } |
57 | 60 |
58 virtual ~URLRequestHttpCacheContext() { | 61 virtual ~URLRequestHttpCacheContext() { |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 EXPECT_FALSE(d.received_data_before_response()); | 311 EXPECT_FALSE(d.received_data_before_response()); |
309 EXPECT_TRUE(d.have_certificate_errors()); | 312 EXPECT_TRUE(d.have_certificate_errors()); |
310 if (err_allowed) | 313 if (err_allowed) |
311 EXPECT_NE(0, d.bytes_received()); | 314 EXPECT_NE(0, d.bytes_received()); |
312 else | 315 else |
313 EXPECT_EQ(0, d.bytes_received()); | 316 EXPECT_EQ(0, d.bytes_received()); |
314 } | 317 } |
315 } | 318 } |
316 } | 319 } |
317 | 320 |
318 TEST_F(URLRequestTest, CancelTest) { | 321 // http://crbug.com/13952 |
| 322 TEST_F(URLRequestTest, DISABLED_CancelTest) { |
319 TestDelegate d; | 323 TestDelegate d; |
320 { | 324 { |
321 TestURLRequest r(GURL("http://www.google.com/"), &d); | 325 TestURLRequest r(GURL("http://www.google.com/"), &d); |
322 | 326 |
323 r.Start(); | 327 r.Start(); |
324 EXPECT_TRUE(r.is_pending()); | 328 EXPECT_TRUE(r.is_pending()); |
325 | 329 |
326 r.Cancel(); | 330 r.Cancel(); |
327 | 331 |
328 MessageLoop::current()->Run(); | 332 MessageLoop::current()->Run(); |
329 | 333 |
330 // We expect to receive OnResponseStarted even though the request has been | 334 // We expect to receive OnResponseStarted even though the request has been |
331 // cancelled. | 335 // cancelled. |
332 EXPECT_EQ(1, d.response_started_count()); | 336 EXPECT_EQ(1, d.response_started_count()); |
333 EXPECT_EQ(0, d.bytes_received()); | 337 EXPECT_EQ(0, d.bytes_received()); |
334 EXPECT_FALSE(d.received_data_before_response()); | 338 EXPECT_FALSE(d.received_data_before_response()); |
335 } | 339 } |
336 #ifndef NDEBUG | 340 #ifndef NDEBUG |
337 DCHECK_EQ(url_request_metrics.object_count, 0); | 341 DCHECK_EQ(url_request_metrics.object_count, 0); |
338 #endif | 342 #endif |
339 } | 343 } |
340 | 344 |
341 TEST_F(URLRequestTest, CancelTest2) { | 345 // http://crbug.com/13952 |
| 346 TEST_F(URLRequestTest, DISABLED_CancelTest2) { |
342 scoped_refptr<HTTPTestServer> server = | 347 scoped_refptr<HTTPTestServer> server = |
343 HTTPTestServer::CreateServer(L"", NULL); | 348 HTTPTestServer::CreateServer(L"", NULL); |
344 ASSERT_TRUE(NULL != server.get()); | 349 ASSERT_TRUE(NULL != server.get()); |
345 | 350 |
346 // error C2446: '!=' : no conversion from 'HTTPTestServer *const ' | 351 // error C2446: '!=' : no conversion from 'HTTPTestServer *const ' |
347 // to 'const int' | 352 // to 'const int' |
348 | 353 |
349 TestDelegate d; | 354 TestDelegate d; |
350 { | 355 { |
351 TestURLRequest r(server->TestServerPage(""), &d); | 356 TestURLRequest r(server->TestServerPage(""), &d); |
352 | 357 |
353 d.set_cancel_in_response_started(true); | 358 d.set_cancel_in_response_started(true); |
354 | 359 |
355 r.Start(); | 360 r.Start(); |
356 EXPECT_TRUE(r.is_pending()); | 361 EXPECT_TRUE(r.is_pending()); |
357 | 362 |
358 MessageLoop::current()->Run(); | 363 MessageLoop::current()->Run(); |
359 | 364 |
360 EXPECT_EQ(1, d.response_started_count()); | 365 EXPECT_EQ(1, d.response_started_count()); |
361 EXPECT_EQ(0, d.bytes_received()); | 366 EXPECT_EQ(0, d.bytes_received()); |
362 EXPECT_FALSE(d.received_data_before_response()); | 367 EXPECT_FALSE(d.received_data_before_response()); |
363 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); | 368 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); |
364 } | 369 } |
365 #ifndef NDEBUG | 370 #ifndef NDEBUG |
366 DCHECK_EQ(url_request_metrics.object_count, 0); | 371 DCHECK_EQ(url_request_metrics.object_count, 0); |
367 #endif | 372 #endif |
368 } | 373 } |
369 | 374 |
370 TEST_F(URLRequestTest, CancelTest3) { | 375 // http://crbug.com/13952 |
| 376 TEST_F(URLRequestTest, DISABLED_CancelTest3) { |
371 scoped_refptr<HTTPTestServer> server = | 377 scoped_refptr<HTTPTestServer> server = |
372 HTTPTestServer::CreateServer(L"", NULL); | 378 HTTPTestServer::CreateServer(L"", NULL); |
373 ASSERT_TRUE(NULL != server.get()); | 379 ASSERT_TRUE(NULL != server.get()); |
374 TestDelegate d; | 380 TestDelegate d; |
375 { | 381 { |
376 TestURLRequest r(server->TestServerPage(""), &d); | 382 TestURLRequest r(server->TestServerPage(""), &d); |
377 | 383 |
378 d.set_cancel_in_received_data(true); | 384 d.set_cancel_in_received_data(true); |
379 | 385 |
380 r.Start(); | 386 r.Start(); |
381 EXPECT_TRUE(r.is_pending()); | 387 EXPECT_TRUE(r.is_pending()); |
382 | 388 |
383 MessageLoop::current()->Run(); | 389 MessageLoop::current()->Run(); |
384 | 390 |
385 EXPECT_EQ(1, d.response_started_count()); | 391 EXPECT_EQ(1, d.response_started_count()); |
386 // There is no guarantee about how much data was received | 392 // There is no guarantee about how much data was received |
387 // before the cancel was issued. It could have been 0 bytes, | 393 // before the cancel was issued. It could have been 0 bytes, |
388 // or it could have been all the bytes. | 394 // or it could have been all the bytes. |
389 // EXPECT_EQ(0, d.bytes_received()); | 395 // EXPECT_EQ(0, d.bytes_received()); |
390 EXPECT_FALSE(d.received_data_before_response()); | 396 EXPECT_FALSE(d.received_data_before_response()); |
391 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); | 397 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); |
392 } | 398 } |
393 #ifndef NDEBUG | 399 #ifndef NDEBUG |
394 DCHECK_EQ(url_request_metrics.object_count, 0); | 400 DCHECK_EQ(url_request_metrics.object_count, 0); |
395 #endif | 401 #endif |
396 } | 402 } |
397 | 403 |
398 TEST_F(URLRequestTest, CancelTest4) { | 404 // http://crbug.com/13952 |
| 405 TEST_F(URLRequestTest, DISABLED_CancelTest4) { |
399 scoped_refptr<HTTPTestServer> server = | 406 scoped_refptr<HTTPTestServer> server = |
400 HTTPTestServer::CreateServer(L"", NULL); | 407 HTTPTestServer::CreateServer(L"", NULL); |
401 ASSERT_TRUE(NULL != server.get()); | 408 ASSERT_TRUE(NULL != server.get()); |
402 TestDelegate d; | 409 TestDelegate d; |
403 { | 410 { |
404 TestURLRequest r(server->TestServerPage(""), &d); | 411 TestURLRequest r(server->TestServerPage(""), &d); |
405 | 412 |
406 r.Start(); | 413 r.Start(); |
407 EXPECT_TRUE(r.is_pending()); | 414 EXPECT_TRUE(r.is_pending()); |
408 | 415 |
(...skipping 1390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1799 | 1806 |
1800 int64 file_size = 0; | 1807 int64 file_size = 0; |
1801 file_util::GetFileSize(app_path, &file_size); | 1808 file_util::GetFileSize(app_path, &file_size); |
1802 | 1809 |
1803 EXPECT_TRUE(!r.is_pending()); | 1810 EXPECT_TRUE(!r.is_pending()); |
1804 EXPECT_EQ(1, d.response_started_count()); | 1811 EXPECT_EQ(1, d.response_started_count()); |
1805 EXPECT_FALSE(d.received_data_before_response()); | 1812 EXPECT_FALSE(d.received_data_before_response()); |
1806 EXPECT_EQ(d.bytes_received(), 0); | 1813 EXPECT_EQ(d.bytes_received(), 0); |
1807 } | 1814 } |
1808 } | 1815 } |
OLD | NEW |