OLD | NEW |
1 // Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2010 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 649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
660 block_ = false; | 660 block_ = false; |
661 if (callback_) { | 661 if (callback_) { |
662 if (!fail_) | 662 if (!fail_) |
663 *backend_ = new MockDiskCache(); | 663 *backend_ = new MockDiskCache(); |
664 net::CompletionCallback* cb = callback_; | 664 net::CompletionCallback* cb = callback_; |
665 callback_ = NULL; | 665 callback_ = NULL; |
666 cb->Run(Result()); // This object can be deleted here. | 666 cb->Run(Result()); // This object can be deleted here. |
667 } | 667 } |
668 } | 668 } |
669 | 669 |
| 670 disk_cache::Backend** backend() { return backend_; } |
670 void set_fail(bool fail) { fail_ = fail; } | 671 void set_fail(bool fail) { fail_ = fail; } |
671 | 672 |
672 net::CompletionCallback* callback() { return callback_; } | 673 net::CompletionCallback* callback() { return callback_; } |
673 | 674 |
674 private: | 675 private: |
675 int Result() { return fail_ ? net::ERR_FAILED : net::OK; } | 676 int Result() { return fail_ ? net::ERR_FAILED : net::OK; } |
676 | 677 |
677 disk_cache::Backend** backend_; | 678 disk_cache::Backend** backend_; |
678 net::CompletionCallback* callback_; | 679 net::CompletionCallback* callback_; |
679 bool block_; | 680 bool block_; |
(...skipping 1332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2012 | 2013 |
2013 // Just to make sure that everything is still pending. | 2014 // Just to make sure that everything is still pending. |
2014 MessageLoop::current()->RunAllPending(); | 2015 MessageLoop::current()->RunAllPending(); |
2015 | 2016 |
2016 // The request should be creating the disk cache. | 2017 // The request should be creating the disk cache. |
2017 EXPECT_FALSE(c->callback.have_result()); | 2018 EXPECT_FALSE(c->callback.have_result()); |
2018 | 2019 |
2019 // We cannot call FinishCreation because the factory itself will go away with | 2020 // We cannot call FinishCreation because the factory itself will go away with |
2020 // the cache, so grab the callback and attempt to use it. | 2021 // the cache, so grab the callback and attempt to use it. |
2021 net::CompletionCallback* callback = factory->callback(); | 2022 net::CompletionCallback* callback = factory->callback(); |
| 2023 disk_cache::Backend** backend = factory->backend(); |
2022 | 2024 |
2023 cache.reset(); | 2025 cache.reset(); |
2024 MessageLoop::current()->RunAllPending(); | 2026 MessageLoop::current()->RunAllPending(); |
2025 | 2027 |
| 2028 *backend = NULL; |
2026 callback->Run(net::ERR_ABORTED); | 2029 callback->Run(net::ERR_ABORTED); |
2027 } | 2030 } |
2028 | 2031 |
2029 // Tests that we can delete the cache while creating the backend, from within | 2032 // Tests that we can delete the cache while creating the backend, from within |
2030 // one of the callbacks. | 2033 // one of the callbacks. |
2031 TEST(HttpCache, DeleteCacheWaitingForBackend2) { | 2034 TEST(HttpCache, DeleteCacheWaitingForBackend2) { |
2032 MockBlockingBackendFactory* factory = new MockBlockingBackendFactory(); | 2035 MockBlockingBackendFactory* factory = new MockBlockingBackendFactory(); |
2033 MockHttpCache* cache = new MockHttpCache(factory); | 2036 MockHttpCache* cache = new MockHttpCache(factory); |
2034 | 2037 |
2035 DeleteCacheCompletionCallback cb(cache); | 2038 DeleteCacheCompletionCallback cb(cache); |
(...skipping 2776 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4812 // Now return 200 when validating the entry so the metadata will be lost. | 4815 // Now return 200 when validating the entry so the metadata will be lost. |
4813 MockTransaction trans2(kTypicalGET_Transaction); | 4816 MockTransaction trans2(kTypicalGET_Transaction); |
4814 trans2.load_flags = net::LOAD_VALIDATE_CACHE; | 4817 trans2.load_flags = net::LOAD_VALIDATE_CACHE; |
4815 RunTransactionTestWithResponseInfo(cache.http_cache(), trans2, &response); | 4818 RunTransactionTestWithResponseInfo(cache.http_cache(), trans2, &response); |
4816 EXPECT_TRUE(response.metadata.get() == NULL); | 4819 EXPECT_TRUE(response.metadata.get() == NULL); |
4817 | 4820 |
4818 EXPECT_EQ(3, cache.network_layer()->transaction_count()); | 4821 EXPECT_EQ(3, cache.network_layer()->transaction_count()); |
4819 EXPECT_EQ(4, cache.disk_cache()->open_count()); | 4822 EXPECT_EQ(4, cache.disk_cache()->open_count()); |
4820 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 4823 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
4821 } | 4824 } |
OLD | NEW |