| OLD | NEW | 
|     1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |     1 // Copyright (c) 2012 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 <algorithm> |     7 #include <algorithm> | 
|     8  |     8  | 
|     9 #include "base/bind.h" |     9 #include "base/bind.h" | 
|    10 #include "base/bind_helpers.h" |    10 #include "base/bind_helpers.h" | 
| (...skipping 7359 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  7370   EXPECT_EQ(1, cache.network_layer()->transaction_count()); |  7370   EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 
|  7371  |  7371  | 
|  7372   // Send the request again and check that Resource-Freshness header is absent. |  7372   // Send the request again and check that Resource-Freshness header is absent. | 
|  7373   stale_while_revalidate_transaction.handler = CheckResourceFreshnessAbsent; |  7373   stale_while_revalidate_transaction.handler = CheckResourceFreshnessAbsent; | 
|  7374  |  7374  | 
|  7375   RunTransactionTest(cache.http_cache(), stale_while_revalidate_transaction); |  7375   RunTransactionTest(cache.http_cache(), stale_while_revalidate_transaction); | 
|  7376  |  7376  | 
|  7377   EXPECT_EQ(2, cache.network_layer()->transaction_count()); |  7377   EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 
|  7378 } |  7378 } | 
|  7379  |  7379  | 
 |  7380 TEST(HttpCache, StaleContentNotUsedWhenLoadFlagNotSet) { | 
 |  7381   MockHttpCache cache; | 
 |  7382  | 
 |  7383   ScopedMockTransaction stale_while_revalidate_transaction( | 
 |  7384       kSimpleGET_Transaction); | 
 |  7385  | 
 |  7386   stale_while_revalidate_transaction.response_headers = | 
 |  7387       "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" | 
 |  7388       "Age: 10801\n" | 
 |  7389       "Cache-Control: max-age=0,stale-while-revalidate=86400\n"; | 
 |  7390  | 
 |  7391   // Write to the cache. | 
 |  7392   RunTransactionTest(cache.http_cache(), stale_while_revalidate_transaction); | 
 |  7393  | 
 |  7394   EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 
 |  7395  | 
 |  7396   // Send the request again and check that it is sent to the network again. | 
 |  7397   HttpResponseInfo response_info; | 
 |  7398   RunTransactionTestWithResponseInfo( | 
 |  7399       cache.http_cache(), stale_while_revalidate_transaction, &response_info); | 
 |  7400  | 
 |  7401   EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 
 |  7402   EXPECT_FALSE(response_info.async_revalidation_required); | 
 |  7403 } | 
 |  7404  | 
 |  7405 TEST(HttpCache, StaleContentUsedWhenLoadFlagSetAndUsable) { | 
 |  7406   MockHttpCache cache; | 
 |  7407  | 
 |  7408   ScopedMockTransaction stale_while_revalidate_transaction( | 
 |  7409       kSimpleGET_Transaction); | 
 |  7410   stale_while_revalidate_transaction.load_flags |= | 
 |  7411       LOAD_SUPPORT_ASYNC_REVALIDATION; | 
 |  7412   stale_while_revalidate_transaction.response_headers = | 
 |  7413       "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" | 
 |  7414       "Age: 10801\n" | 
 |  7415       "Cache-Control: max-age=0,stale-while-revalidate=86400\n"; | 
 |  7416  | 
 |  7417   // Write to the cache. | 
 |  7418   RunTransactionTest(cache.http_cache(), stale_while_revalidate_transaction); | 
 |  7419  | 
 |  7420   EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 
 |  7421  | 
 |  7422   // Send the request again and check that it is not sent to the network again. | 
 |  7423   HttpResponseInfo response_info; | 
 |  7424   RunTransactionTestWithResponseInfo( | 
 |  7425       cache.http_cache(), stale_while_revalidate_transaction, &response_info); | 
 |  7426  | 
 |  7427   EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 
 |  7428   EXPECT_TRUE(response_info.async_revalidation_required); | 
 |  7429 } | 
 |  7430  | 
 |  7431 TEST(HttpCache, StaleContentNotUsedWhenUnusable) { | 
 |  7432   MockHttpCache cache; | 
 |  7433  | 
 |  7434   ScopedMockTransaction stale_while_revalidate_transaction( | 
 |  7435       kSimpleGET_Transaction); | 
 |  7436   stale_while_revalidate_transaction.load_flags |= | 
 |  7437       LOAD_SUPPORT_ASYNC_REVALIDATION; | 
 |  7438   stale_while_revalidate_transaction.response_headers = | 
 |  7439       "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" | 
 |  7440       "Age: 10801\n" | 
 |  7441       "Cache-Control: max-age=0,stale-while-revalidate=1800\n"; | 
 |  7442  | 
 |  7443   // Write to the cache. | 
 |  7444   RunTransactionTest(cache.http_cache(), stale_while_revalidate_transaction); | 
 |  7445  | 
 |  7446   EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 
 |  7447  | 
 |  7448   // Send the request again and check that it is sent to the network again. | 
 |  7449   HttpResponseInfo response_info; | 
 |  7450   RunTransactionTestWithResponseInfo( | 
 |  7451       cache.http_cache(), stale_while_revalidate_transaction, &response_info); | 
 |  7452  | 
 |  7453   EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 
 |  7454   EXPECT_FALSE(response_info.async_revalidation_required); | 
 |  7455 } | 
 |  7456  | 
|  7380 // Tests that we allow multiple simultaneous, non-overlapping transactions to |  7457 // Tests that we allow multiple simultaneous, non-overlapping transactions to | 
|  7381 // take place on a sparse entry. |  7458 // take place on a sparse entry. | 
|  7382 TEST(HttpCache, RangeGET_MultipleRequests) { |  7459 TEST(HttpCache, RangeGET_MultipleRequests) { | 
|  7383   MockHttpCache cache; |  7460   MockHttpCache cache; | 
|  7384  |  7461  | 
|  7385   // Create a transaction for bytes 0-9. |  7462   // Create a transaction for bytes 0-9. | 
|  7386   MockHttpRequest request(kRangeGET_TransactionOK); |  7463   MockHttpRequest request(kRangeGET_TransactionOK); | 
|  7387   MockTransaction transaction(kRangeGET_TransactionOK); |  7464   MockTransaction transaction(kRangeGET_TransactionOK); | 
|  7388   transaction.request_headers = "Range: bytes = 0-9\r\n" EXTRA_HEADER; |  7465   transaction.request_headers = "Range: bytes = 0-9\r\n" EXTRA_HEADER; | 
|  7389   transaction.data = "rg: 00-09 "; |  7466   transaction.data = "rg: 00-09 "; | 
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  7554   EXPECT_EQ(1, cache.disk_cache()->open_count()); |  7631   EXPECT_EQ(1, cache.disk_cache()->open_count()); | 
|  7555   EXPECT_EQ(1, cache.disk_cache()->create_count()); |  7632   EXPECT_EQ(1, cache.disk_cache()->create_count()); | 
|  7556   EXPECT_TRUE(response_info.was_cached); |  7633   EXPECT_TRUE(response_info.was_cached); | 
|  7557  |  7634  | 
|  7558   // The new SSL state is reported. |  7635   // The new SSL state is reported. | 
|  7559   EXPECT_EQ(status2, response_info.ssl_info.connection_status); |  7636   EXPECT_EQ(status2, response_info.ssl_info.connection_status); | 
|  7560   EXPECT_TRUE(cert2->Equals(response_info.ssl_info.cert.get())); |  7637   EXPECT_TRUE(cert2->Equals(response_info.ssl_info.cert.get())); | 
|  7561 } |  7638 } | 
|  7562  |  7639  | 
|  7563 }  // namespace net |  7640 }  // namespace net | 
| OLD | NEW |