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 3313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3324 handler.set_bad_200(true); | 3324 handler.set_bad_200(true); |
3325 RunTransactionTest(cache.http_cache(), transaction); | 3325 RunTransactionTest(cache.http_cache(), transaction); |
3326 | 3326 |
3327 EXPECT_EQ(3, cache.network_layer()->transaction_count()); | 3327 EXPECT_EQ(3, cache.network_layer()->transaction_count()); |
3328 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 3328 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
3329 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 3329 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
3330 | 3330 |
3331 RemoveMockTransaction(&transaction); | 3331 RemoveMockTransaction(&transaction); |
3332 } | 3332 } |
3333 | 3333 |
| 3334 // Tests that when the server gives us less data than expected, we don't keep |
| 3335 // asking for more data. |
| 3336 TEST(HttpCache, RangeGET_FastFlakyServer2) { |
| 3337 MockHttpCache cache; |
| 3338 cache.http_cache()->set_enable_range_support(true); |
| 3339 |
| 3340 // First, check with an empty cache (WRITE mode). |
| 3341 MockTransaction transaction(kRangeGET_TransactionOK); |
| 3342 transaction.request_headers = "Range: bytes = 40-49\r\n" EXTRA_HEADER; |
| 3343 transaction.data = "rg: 40-"; // Less than expected. |
| 3344 transaction.handler = NULL; |
| 3345 std::string headers(transaction.response_headers); |
| 3346 headers.append("Content-Range: bytes 40-49/80\n"); |
| 3347 transaction.response_headers = headers.c_str(); |
| 3348 |
| 3349 AddMockTransaction(&transaction); |
| 3350 |
| 3351 // Write to the cache. |
| 3352 RunTransactionTest(cache.http_cache(), transaction); |
| 3353 |
| 3354 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 3355 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| 3356 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 3357 |
| 3358 // Now verify that even in READ_WRITE mode, we forward the bad response to |
| 3359 // the caller. |
| 3360 transaction.request_headers = "Range: bytes = 60-69\r\n" EXTRA_HEADER; |
| 3361 transaction.data = "rg: 60-"; // Less than expected. |
| 3362 headers = kRangeGET_TransactionOK.response_headers; |
| 3363 headers.append("Content-Range: bytes 60-69/80\n"); |
| 3364 transaction.response_headers = headers.c_str(); |
| 3365 |
| 3366 RunTransactionTest(cache.http_cache(), transaction); |
| 3367 |
| 3368 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
| 3369 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
| 3370 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 3371 |
| 3372 RemoveMockTransaction(&transaction); |
| 3373 } |
| 3374 |
3334 #ifdef NDEBUG | 3375 #ifdef NDEBUG |
3335 // This test hits a NOTREACHED so it is a release mode only test. | 3376 // This test hits a NOTREACHED so it is a release mode only test. |
3336 TEST(HttpCache, RangeGET_OK_LoadOnlyFromCache) { | 3377 TEST(HttpCache, RangeGET_OK_LoadOnlyFromCache) { |
3337 MockHttpCache cache; | 3378 MockHttpCache cache; |
3338 cache.http_cache()->set_enable_range_support(true); | 3379 cache.http_cache()->set_enable_range_support(true); |
3339 AddMockTransaction(&kRangeGET_TransactionOK); | 3380 AddMockTransaction(&kRangeGET_TransactionOK); |
3340 | 3381 |
3341 // Write to the cache (40-49). | 3382 // Write to the cache (40-49). |
3342 RunTransactionTest(cache.http_cache(), kRangeGET_TransactionOK); | 3383 RunTransactionTest(cache.http_cache(), kRangeGET_TransactionOK); |
3343 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 3384 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
(...skipping 781 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4125 std::string headers; | 4166 std::string headers; |
4126 response.headers->GetNormalizedHeaders(&headers); | 4167 response.headers->GetNormalizedHeaders(&headers); |
4127 | 4168 |
4128 EXPECT_EQ("HTTP/1.1 200 OK\n" | 4169 EXPECT_EQ("HTTP/1.1 200 OK\n" |
4129 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" | 4170 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" |
4130 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", | 4171 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", |
4131 headers); | 4172 headers); |
4132 | 4173 |
4133 RemoveMockTransaction(&mock_network_response); | 4174 RemoveMockTransaction(&mock_network_response); |
4134 } | 4175 } |
OLD | NEW |