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