| 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/scoped_vector.h" | 9 #include "base/scoped_vector.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 2485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2496 RunTransactionTestWithResponse(cache.http_cache(), transaction2, &headers); | 2496 RunTransactionTestWithResponse(cache.http_cache(), transaction2, &headers); |
| 2497 | 2497 |
| 2498 EXPECT_EQ(0U, headers.find("HTTP/1.1 200 OK\n")); | 2498 EXPECT_EQ(0U, headers.find("HTTP/1.1 200 OK\n")); |
| 2499 EXPECT_EQ(3, cache.network_layer()->transaction_count()); | 2499 EXPECT_EQ(3, cache.network_layer()->transaction_count()); |
| 2500 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 2500 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
| 2501 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 2501 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 2502 | 2502 |
| 2503 RemoveMockTransaction(&transaction); | 2503 RemoveMockTransaction(&transaction); |
| 2504 } | 2504 } |
| 2505 | 2505 |
| 2506 // Tests that we can handle a regular request to a sparse entry, that results in | |
| 2507 // new content provided by the server (206). | |
| 2508 TEST(HttpCache, GET_Previous206_NewContent) { | |
| 2509 MockHttpCache cache; | |
| 2510 cache.http_cache()->set_enable_range_support(true); | |
| 2511 AddMockTransaction(&kRangeGET_TransactionOK); | |
| 2512 std::string headers; | |
| 2513 | |
| 2514 // Write to the cache (0-9). | |
| 2515 MockTransaction transaction(kRangeGET_TransactionOK); | |
| 2516 transaction.request_headers = "Range: bytes = 0-9\r\n" EXTRA_HEADER; | |
| 2517 transaction.data = "rg: 00-09 "; | |
| 2518 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); | |
| 2519 | |
| 2520 EXPECT_TRUE(Verify206Response(headers, 0, 9)); | |
| 2521 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | |
| 2522 EXPECT_EQ(0, cache.disk_cache()->open_count()); | |
| 2523 EXPECT_EQ(1, cache.disk_cache()->create_count()); | |
| 2524 | |
| 2525 // Now we'll issue a request without any range that should result first in a | |
| 2526 // 206 (when revalidating), and then in a weird standard answer: the test | |
| 2527 // server will not modify the response so we'll get the default range... a | |
| 2528 // real server will answer with 200. | |
| 2529 MockTransaction transaction2(kRangeGET_TransactionOK); | |
| 2530 transaction2.request_headers = EXTRA_HEADER; | |
| 2531 transaction2.data = "rg: 40-49 "; | |
| 2532 RangeTransactionServer handler; | |
| 2533 handler.set_modified(true); | |
| 2534 RunTransactionTestWithResponse(cache.http_cache(), transaction2, &headers); | |
| 2535 | |
| 2536 EXPECT_EQ(0U, headers.find("HTTP/1.1 206 Partial Content\n")); | |
| 2537 EXPECT_EQ(3, cache.network_layer()->transaction_count()); | |
| 2538 EXPECT_EQ(1, cache.disk_cache()->open_count()); | |
| 2539 EXPECT_EQ(1, cache.disk_cache()->create_count()); | |
| 2540 | |
| 2541 // Verify that the previous request deleted the entry. | |
| 2542 RunTransactionTest(cache.http_cache(), transaction); | |
| 2543 EXPECT_EQ(2, cache.disk_cache()->create_count()); | |
| 2544 | |
| 2545 RemoveMockTransaction(&transaction); | |
| 2546 } | |
| 2547 | |
| 2548 // Tests that we can handle cached 206 responses that are not sparse. | 2506 // Tests that we can handle cached 206 responses that are not sparse. |
| 2549 TEST(HttpCache, GET_Previous206_NotSparse) { | 2507 TEST(HttpCache, GET_Previous206_NotSparse) { |
| 2550 MockHttpCache cache; | 2508 MockHttpCache cache; |
| 2551 cache.http_cache()->set_enable_range_support(true); | 2509 cache.http_cache()->set_enable_range_support(true); |
| 2552 | 2510 |
| 2553 // Create a disk cache entry that stores 206 headers while not being sparse. | 2511 // Create a disk cache entry that stores 206 headers while not being sparse. |
| 2554 disk_cache::Entry* entry; | 2512 disk_cache::Entry* entry; |
| 2555 ASSERT_TRUE(cache.disk_cache()->CreateEntry(kSimpleGET_Transaction.url, | 2513 ASSERT_TRUE(cache.disk_cache()->CreateEntry(kSimpleGET_Transaction.url, |
| 2556 &entry)); | 2514 &entry)); |
| 2557 | 2515 |
| (...skipping 1152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3710 std::string headers; | 3668 std::string headers; |
| 3711 response.headers->GetNormalizedHeaders(&headers); | 3669 response.headers->GetNormalizedHeaders(&headers); |
| 3712 | 3670 |
| 3713 EXPECT_EQ("HTTP/1.1 200 OK\n" | 3671 EXPECT_EQ("HTTP/1.1 200 OK\n" |
| 3714 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" | 3672 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" |
| 3715 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", | 3673 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", |
| 3716 headers); | 3674 headers); |
| 3717 | 3675 |
| 3718 RemoveMockTransaction(&mock_network_response); | 3676 RemoveMockTransaction(&mock_network_response); |
| 3719 } | 3677 } |
| OLD | NEW |