| 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/http/http_cache.h" | 5 #include "net/http/http_cache.h" |
| 6 | 6 |
| 7 #include "base/hash_tables.h" | 7 #include "base/hash_tables.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
| (...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 451 | 451 |
| 452 private: | 452 private: |
| 453 static bool no_store; | 453 static bool no_store; |
| 454 DISALLOW_COPY_AND_ASSIGN(FastTransactionServer); | 454 DISALLOW_COPY_AND_ASSIGN(FastTransactionServer); |
| 455 }; | 455 }; |
| 456 bool FastTransactionServer::no_store; | 456 bool FastTransactionServer::no_store; |
| 457 | 457 |
| 458 const MockTransaction kFastNoStoreGET_Transaction = { | 458 const MockTransaction kFastNoStoreGET_Transaction = { |
| 459 "http://www.google.com/nostore", | 459 "http://www.google.com/nostore", |
| 460 "GET", | 460 "GET", |
| 461 base::Time(), |
| 461 "", | 462 "", |
| 462 net::LOAD_VALIDATE_CACHE, | 463 net::LOAD_VALIDATE_CACHE, |
| 463 "HTTP/1.1 200 OK", | 464 "HTTP/1.1 200 OK", |
| 464 "Cache-Control: max-age=10000\n", | 465 "Cache-Control: max-age=10000\n", |
| 465 base::Time(), | 466 base::Time(), |
| 466 "<html><body>Google Blah Blah</body></html>", | 467 "<html><body>Google Blah Blah</body></html>", |
| 467 TEST_MODE_SYNC_NET_START, | 468 TEST_MODE_SYNC_NET_START, |
| 468 &FastTransactionServer::FastNoStoreHandler, | 469 &FastTransactionServer::FastNoStoreHandler, |
| 469 0 | 470 0 |
| 470 }; | 471 }; |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 555 } | 556 } |
| 556 } else { | 557 } else { |
| 557 response_status->assign("HTTP/1.1 304 Not Modified"); | 558 response_status->assign("HTTP/1.1 304 Not Modified"); |
| 558 response_data->clear(); | 559 response_data->clear(); |
| 559 } | 560 } |
| 560 } | 561 } |
| 561 | 562 |
| 562 const MockTransaction kRangeGET_TransactionOK = { | 563 const MockTransaction kRangeGET_TransactionOK = { |
| 563 "http://www.google.com/range", | 564 "http://www.google.com/range", |
| 564 "GET", | 565 "GET", |
| 566 base::Time(), |
| 565 "Range: bytes = 40-49\r\n", | 567 "Range: bytes = 40-49\r\n", |
| 566 net::LOAD_NORMAL, | 568 net::LOAD_NORMAL, |
| 567 "HTTP/1.1 206 Partial Content", | 569 "HTTP/1.1 206 Partial Content", |
| 568 "Last-Modified: Sat, 18 Apr 2009 01:10:43 GMT\n" | 570 "Last-Modified: Sat, 18 Apr 2009 01:10:43 GMT\n" |
| 569 "ETag: \"foo\"\n" | 571 "ETag: \"foo\"\n" |
| 570 "Accept-Ranges: bytes\n" | 572 "Accept-Ranges: bytes\n" |
| 571 "Content-Length: 10\n", | 573 "Content-Length: 10\n", |
| 572 base::Time(), | 574 base::Time(), |
| 573 "rg: 40-49 ", | 575 "rg: 40-49 ", |
| 574 TEST_MODE_NORMAL, | 576 TEST_MODE_NORMAL, |
| (...skipping 1916 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2491 | 2493 |
| 2492 RunTransactionTest(cache.http_cache(), transaction); | 2494 RunTransactionTest(cache.http_cache(), transaction); |
| 2493 | 2495 |
| 2494 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 2496 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
| 2495 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 2497 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| 2496 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 2498 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 2497 } | 2499 } |
| 2498 | 2500 |
| 2499 // Other tests check that the response headers of the cached response | 2501 // Other tests check that the response headers of the cached response |
| 2500 // get updated on 304. Here we specifically check that the | 2502 // get updated on 304. Here we specifically check that the |
| 2501 // HttpResponseHeaders::response_time field also gets updated. | 2503 // HttpResponseHeaders::request_time and HttpResponseHeaders::response_time |
| 2504 // fields also gets updated. |
| 2502 // http://crbug.com/20594. | 2505 // http://crbug.com/20594. |
| 2503 TEST(HttpCache, UpdatesResponseTimeOn304) { | 2506 TEST(HttpCache, UpdatesRequestResponseTimeOn304) { |
| 2504 MockHttpCache cache; | 2507 MockHttpCache cache; |
| 2505 | 2508 |
| 2506 const char* kUrl = "http://foobar"; | 2509 const char* kUrl = "http://foobar"; |
| 2507 const char* kData = "body"; | 2510 const char* kData = "body"; |
| 2508 | 2511 |
| 2509 MockTransaction mock_network_response = { 0 }; | 2512 MockTransaction mock_network_response = { 0 }; |
| 2510 mock_network_response.url = kUrl; | 2513 mock_network_response.url = kUrl; |
| 2511 | 2514 |
| 2512 AddMockTransaction(&mock_network_response); | 2515 AddMockTransaction(&mock_network_response); |
| 2513 | 2516 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 2536 request.load_flags = net::LOAD_VALIDATE_CACHE; | 2539 request.load_flags = net::LOAD_VALIDATE_CACHE; |
| 2537 | 2540 |
| 2538 static const Response kNetResponse2 = { | 2541 static const Response kNetResponse2 = { |
| 2539 "HTTP/1.1 304 Not Modified", | 2542 "HTTP/1.1 304 Not Modified", |
| 2540 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n", | 2543 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n", |
| 2541 "" | 2544 "" |
| 2542 }; | 2545 }; |
| 2543 | 2546 |
| 2544 kNetResponse2.AssignTo(&mock_network_response); | 2547 kNetResponse2.AssignTo(&mock_network_response); |
| 2545 | 2548 |
| 2546 base::Time t = base::Time() + base::TimeDelta::FromHours(1234); | 2549 base::Time request_time = base::Time() + base::TimeDelta::FromHours(1234); |
| 2547 mock_network_response.response_time = t; | 2550 base::Time response_time = base::Time() + base::TimeDelta::FromHours(1235); |
| 2551 |
| 2552 mock_network_response.request_time = request_time; |
| 2553 mock_network_response.response_time = response_time; |
| 2548 | 2554 |
| 2549 net::HttpResponseInfo response; | 2555 net::HttpResponseInfo response; |
| 2550 RunTransactionTestWithResponseInfo(cache.http_cache(), request, &response); | 2556 RunTransactionTestWithResponseInfo(cache.http_cache(), request, &response); |
| 2551 | 2557 |
| 2552 // The response time should have been updated. | 2558 // The request and response times should have been updated. |
| 2553 EXPECT_EQ(t.ToInternalValue(), | 2559 EXPECT_EQ(request_time.ToInternalValue(), |
| 2560 response.request_time.ToInternalValue()); |
| 2561 EXPECT_EQ(response_time.ToInternalValue(), |
| 2554 response.response_time.ToInternalValue()); | 2562 response.response_time.ToInternalValue()); |
| 2555 | 2563 |
| 2556 std::string headers; | 2564 std::string headers; |
| 2557 response.headers->GetNormalizedHeaders(&headers); | 2565 response.headers->GetNormalizedHeaders(&headers); |
| 2558 | 2566 |
| 2559 EXPECT_EQ("HTTP/1.1 200 OK\n" | 2567 EXPECT_EQ("HTTP/1.1 200 OK\n" |
| 2560 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" | 2568 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" |
| 2561 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", | 2569 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", |
| 2562 headers); | 2570 headers); |
| 2563 | 2571 |
| 2564 RemoveMockTransaction(&mock_network_response); | 2572 RemoveMockTransaction(&mock_network_response); |
| 2565 } | 2573 } |
| OLD | NEW |