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

Side by Side Diff: net/http/http_cache_unittest.cc

Issue 434052: Http cache: Add code to restart a network request when the... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years 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/http/http_cache_transaction.cc ('k') | net/http/partial_data.h » ('j') | 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-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
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
2506 // Tests that we can handle cached 206 responses that are not sparse. 2548 // Tests that we can handle cached 206 responses that are not sparse.
2507 TEST(HttpCache, GET_Previous206_NotSparse) { 2549 TEST(HttpCache, GET_Previous206_NotSparse) {
2508 MockHttpCache cache; 2550 MockHttpCache cache;
2509 cache.http_cache()->set_enable_range_support(true); 2551 cache.http_cache()->set_enable_range_support(true);
2510 2552
2511 // Create a disk cache entry that stores 206 headers while not being sparse. 2553 // Create a disk cache entry that stores 206 headers while not being sparse.
2512 disk_cache::Entry* entry; 2554 disk_cache::Entry* entry;
2513 ASSERT_TRUE(cache.disk_cache()->CreateEntry(kSimpleGET_Transaction.url, 2555 ASSERT_TRUE(cache.disk_cache()->CreateEntry(kSimpleGET_Transaction.url,
2514 &entry)); 2556 &entry));
2515 2557
(...skipping 1152 matching lines...) Expand 10 before | Expand all | Expand 10 after
3668 std::string headers; 3710 std::string headers;
3669 response.headers->GetNormalizedHeaders(&headers); 3711 response.headers->GetNormalizedHeaders(&headers);
3670 3712
3671 EXPECT_EQ("HTTP/1.1 200 OK\n" 3713 EXPECT_EQ("HTTP/1.1 200 OK\n"
3672 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" 3714 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n"
3673 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", 3715 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n",
3674 headers); 3716 headers);
3675 3717
3676 RemoveMockTransaction(&mock_network_response); 3718 RemoveMockTransaction(&mock_network_response);
3677 } 3719 }
OLDNEW
« no previous file with comments | « net/http/http_cache_transaction.cc ('k') | net/http/partial_data.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698