| 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 <stdint.h> | 7 #include <stdint.h> |
| 8 | |
| 9 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/bind_helpers.h" | 13 #include "base/bind_helpers.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
| 17 #include "base/run_loop.h" | 17 #include "base/run_loop.h" |
| 18 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
| 19 #include "base/strings/stringprintf.h" | 19 #include "base/strings/stringprintf.h" |
| (...skipping 681 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 701 EXPECT_EQ(0, cache.disk_cache()->create_count()); | 701 EXPECT_EQ(0, cache.disk_cache()->create_count()); |
| 702 TestLoadTimingNetworkRequest(load_timing_info); | 702 TestLoadTimingNetworkRequest(load_timing_info); |
| 703 } | 703 } |
| 704 | 704 |
| 705 TEST(HttpCache, SimpleGETNoDiskCache2) { | 705 TEST(HttpCache, SimpleGETNoDiskCache2) { |
| 706 // This will initialize a cache object with NULL backend. | 706 // This will initialize a cache object with NULL backend. |
| 707 scoped_ptr<MockBlockingBackendFactory> factory( | 707 scoped_ptr<MockBlockingBackendFactory> factory( |
| 708 new MockBlockingBackendFactory()); | 708 new MockBlockingBackendFactory()); |
| 709 factory->set_fail(true); | 709 factory->set_fail(true); |
| 710 factory->FinishCreation(); // We'll complete synchronously. | 710 factory->FinishCreation(); // We'll complete synchronously. |
| 711 MockHttpCache cache(factory.Pass()); | 711 MockHttpCache cache(std::move(factory)); |
| 712 | 712 |
| 713 // Read from the network, and don't use the cache. | 713 // Read from the network, and don't use the cache. |
| 714 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); | 714 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); |
| 715 | 715 |
| 716 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 716 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 717 EXPECT_FALSE(cache.http_cache()->GetCurrentBackend()); | 717 EXPECT_FALSE(cache.http_cache()->GetCurrentBackend()); |
| 718 } | 718 } |
| 719 | 719 |
| 720 // Tests that IOBuffers are not referenced after IO completes. | 720 // Tests that IOBuffers are not referenced after IO completes. |
| 721 TEST(HttpCache, ReleaseBuffer) { | 721 TEST(HttpCache, ReleaseBuffer) { |
| (...skipping 2363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3085 RemoveMockTransaction(&transaction); | 3085 RemoveMockTransaction(&transaction); |
| 3086 } | 3086 } |
| 3087 | 3087 |
| 3088 // Tests that processing a POST before creating the backend doesn't crash. | 3088 // Tests that processing a POST before creating the backend doesn't crash. |
| 3089 TEST(HttpCache, SimplePOST_NoUploadId_NoBackend) { | 3089 TEST(HttpCache, SimplePOST_NoUploadId_NoBackend) { |
| 3090 // This will initialize a cache object with NULL backend. | 3090 // This will initialize a cache object with NULL backend. |
| 3091 scoped_ptr<MockBlockingBackendFactory> factory( | 3091 scoped_ptr<MockBlockingBackendFactory> factory( |
| 3092 new MockBlockingBackendFactory()); | 3092 new MockBlockingBackendFactory()); |
| 3093 factory->set_fail(true); | 3093 factory->set_fail(true); |
| 3094 factory->FinishCreation(); | 3094 factory->FinishCreation(); |
| 3095 MockHttpCache cache(factory.Pass()); | 3095 MockHttpCache cache(std::move(factory)); |
| 3096 | 3096 |
| 3097 std::vector<scoped_ptr<UploadElementReader>> element_readers; | 3097 std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 3098 element_readers.push_back( | 3098 element_readers.push_back( |
| 3099 make_scoped_ptr(new UploadBytesElementReader("hello", 5))); | 3099 make_scoped_ptr(new UploadBytesElementReader("hello", 5))); |
| 3100 ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); | 3100 ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
| 3101 | 3101 |
| 3102 MockTransaction transaction(kSimplePOST_Transaction); | 3102 MockTransaction transaction(kSimplePOST_Transaction); |
| 3103 AddMockTransaction(&transaction); | 3103 AddMockTransaction(&transaction); |
| 3104 MockHttpRequest req(transaction); | 3104 MockHttpRequest req(transaction); |
| 3105 req.upload_data_stream = &upload_data_stream; | 3105 req.upload_data_stream = &upload_data_stream; |
| (...skipping 2324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5430 RemoveMockTransaction(&kRangeGET_TransactionOK); | 5430 RemoveMockTransaction(&kRangeGET_TransactionOK); |
| 5431 } | 5431 } |
| 5432 | 5432 |
| 5433 // Tests that we don't crash with a range request if the disk cache was not | 5433 // Tests that we don't crash with a range request if the disk cache was not |
| 5434 // initialized properly. | 5434 // initialized properly. |
| 5435 TEST(HttpCache, RangeGET_NoDiskCache) { | 5435 TEST(HttpCache, RangeGET_NoDiskCache) { |
| 5436 scoped_ptr<MockBlockingBackendFactory> factory( | 5436 scoped_ptr<MockBlockingBackendFactory> factory( |
| 5437 new MockBlockingBackendFactory()); | 5437 new MockBlockingBackendFactory()); |
| 5438 factory->set_fail(true); | 5438 factory->set_fail(true); |
| 5439 factory->FinishCreation(); // We'll complete synchronously. | 5439 factory->FinishCreation(); // We'll complete synchronously. |
| 5440 MockHttpCache cache(factory.Pass()); | 5440 MockHttpCache cache(std::move(factory)); |
| 5441 | 5441 |
| 5442 AddMockTransaction(&kRangeGET_TransactionOK); | 5442 AddMockTransaction(&kRangeGET_TransactionOK); |
| 5443 | 5443 |
| 5444 RunTransactionTest(cache.http_cache(), kRangeGET_TransactionOK); | 5444 RunTransactionTest(cache.http_cache(), kRangeGET_TransactionOK); |
| 5445 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 5445 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 5446 | 5446 |
| 5447 RemoveMockTransaction(&kRangeGET_TransactionOK); | 5447 RemoveMockTransaction(&kRangeGET_TransactionOK); |
| 5448 } | 5448 } |
| 5449 | 5449 |
| 5450 // Tests that we handle byte range requests that skip the cache. | 5450 // Tests that we handle byte range requests that skip the cache. |
| (...skipping 2281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7732 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 7732 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
| 7733 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 7733 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 7734 EXPECT_TRUE(response_info.was_cached); | 7734 EXPECT_TRUE(response_info.was_cached); |
| 7735 | 7735 |
| 7736 // The new SSL state is reported. | 7736 // The new SSL state is reported. |
| 7737 EXPECT_EQ(status2, response_info.ssl_info.connection_status); | 7737 EXPECT_EQ(status2, response_info.ssl_info.connection_status); |
| 7738 EXPECT_TRUE(cert2->Equals(response_info.ssl_info.cert.get())); | 7738 EXPECT_TRUE(cert2->Equals(response_info.ssl_info.cert.get())); |
| 7739 } | 7739 } |
| 7740 | 7740 |
| 7741 } // namespace net | 7741 } // namespace net |
| OLD | NEW |