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

Side by Side Diff: content/browser/cache_storage/cache_storage_unittest.cc

Issue 2056983004: [CacheStorage] Give ownership of all CacheStorageCaches to CacheStorage (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 6 months 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "content/browser/cache_storage/cache_storage.h" 5 #include "content/browser/cache_storage/cache_storage.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/files/scoped_temp_dir.h" 9 #include "base/files/scoped_temp_dir.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
11 #include "base/run_loop.h" 11 #include "base/run_loop.h"
12 #include "base/stl_util.h" 12 #include "base/stl_util.h"
13 #include "base/threading/thread_task_runner_handle.h" 13 #include "base/threading/thread_task_runner_handle.h"
14 #include "content/browser/cache_storage/cache_storage_cache_handle.h"
14 #include "content/browser/quota/mock_quota_manager_proxy.h" 15 #include "content/browser/quota/mock_quota_manager_proxy.h"
15 #include "content/public/test/mock_special_storage_policy.h" 16 #include "content/public/test/mock_special_storage_policy.h"
16 #include "content/public/test/test_browser_thread_bundle.h" 17 #include "content/public/test/test_browser_thread_bundle.h"
17 #include "net/url_request/url_request_context_getter.h" 18 #include "net/url_request/url_request_context_getter.h"
18 #include "storage/browser/quota/quota_manager_proxy.h" 19 #include "storage/browser/quota/quota_manager_proxy.h"
19 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
20 21
21 namespace content { 22 namespace content {
22 23
23 namespace { 24 namespace {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 bool callback_called = false; 90 bool callback_called = false;
90 test_cache_storage_->OpenCache( 91 test_cache_storage_->OpenCache(
91 cache_name, base::Bind(&CacheStorageTest::OpenCacheCallback, 92 cache_name, base::Bind(&CacheStorageTest::OpenCacheCallback,
92 base::Unretained(this), &callback_called)); 93 base::Unretained(this), &callback_called));
93 base::RunLoop().RunUntilIdle(); 94 base::RunLoop().RunUntilIdle();
94 EXPECT_TRUE(callback_called); 95 EXPECT_TRUE(callback_called);
95 return callback_error_ == CACHE_STORAGE_OK; 96 return callback_error_ == CACHE_STORAGE_OK;
96 } 97 }
97 98
98 void OpenCacheCallback(bool* callback_called, 99 void OpenCacheCallback(bool* callback_called,
99 scoped_refptr<CacheStorageCache> cache, 100 std::unique_ptr<CacheStorageCacheHandle> cache_handle,
100 CacheStorageError error) { 101 CacheStorageError error) {
101 *callback_called = true; 102 *callback_called = true;
102 callback_cache_ = cache; 103 callback_cache_handle_ = std::move(cache_handle);
103 callback_error_ = error; 104 callback_error_ = error;
104 } 105 }
105 106
106 base::ScopedTempDir temp_dir_; 107 base::ScopedTempDir temp_dir_;
107 TestBrowserThreadBundle browser_thread_bundle_; 108 TestBrowserThreadBundle browser_thread_bundle_;
108 scoped_refptr<MockSpecialStoragePolicy> quota_policy_; 109 scoped_refptr<MockSpecialStoragePolicy> quota_policy_;
109 scoped_refptr<MockQuotaManager> mock_quota_manager_; 110 scoped_refptr<MockQuotaManager> mock_quota_manager_;
110 scoped_refptr<MockQuotaManagerProxy> quota_manager_proxy_; 111 scoped_refptr<MockQuotaManagerProxy> quota_manager_proxy_;
111 std::unique_ptr<TestCacheStorage> test_cache_storage_; 112 std::unique_ptr<TestCacheStorage> test_cache_storage_;
112 113
113 scoped_refptr<CacheStorageCache> callback_cache_; 114 std::unique_ptr<CacheStorageCacheHandle> callback_cache_handle_;
114 CacheStorageError callback_error_; 115 CacheStorageError callback_error_;
115 }; 116 };
116 117
117 TEST_F(CacheStorageTest, PreserveCache) { 118 TEST_F(CacheStorageTest, PreserveCache) {
118 test_cache_storage_->set_delay_preserved_cache_callback(true); 119 test_cache_storage_->set_delay_preserved_cache_callback(true);
119 EXPECT_TRUE(OpenCache("foo")); 120 EXPECT_TRUE(OpenCache("foo"));
120 EXPECT_TRUE(test_cache_storage_->IsPreservingCache(callback_cache_.get())); 121 EXPECT_TRUE(
122 test_cache_storage_->IsPreservingCache(callback_cache_handle_->value()));
121 test_cache_storage_->RunPreservedCacheCallback(); 123 test_cache_storage_->RunPreservedCacheCallback();
122 EXPECT_FALSE(test_cache_storage_->IsPreservingCache(callback_cache_.get())); 124 EXPECT_FALSE(
125 test_cache_storage_->IsPreservingCache(callback_cache_handle_->value()));
123 126
124 // Try opening it again, since the cache is already open (callback_cache_ is 127 // Try opening it again, since the cache is already open
125 // referencing it) the cache shouldn't be preserved again. 128 // (callback_cache_handle_ is referencing it) the cache shouldn't be preserved
129 // again.
126 EXPECT_TRUE(OpenCache("foo")); 130 EXPECT_TRUE(OpenCache("foo"));
127 EXPECT_FALSE(test_cache_storage_->IsPreservingCache(callback_cache_.get())); 131 EXPECT_FALSE(
132 test_cache_storage_->IsPreservingCache(callback_cache_handle_->value()));
128 133
129 // Remove the reference to the cache so that it's deleted. After that, the 134 // Remove the reference to the cache so that it's deleted. After that, the
130 // next time it's opened will require the cache to be created again and 135 // next time it's opened will require the cache to be created again and
131 // preserved. 136 // preserved.
132 callback_cache_ = nullptr; 137 callback_cache_handle_.reset();
133 EXPECT_TRUE(OpenCache("foo")); 138 EXPECT_TRUE(OpenCache("foo"));
134 EXPECT_TRUE(test_cache_storage_->IsPreservingCache(callback_cache_.get())); 139 EXPECT_TRUE(
140 test_cache_storage_->IsPreservingCache(callback_cache_handle_->value()));
135 test_cache_storage_->RunPreservedCacheCallback(); 141 test_cache_storage_->RunPreservedCacheCallback();
136 EXPECT_FALSE(test_cache_storage_->IsPreservingCache(callback_cache_.get())); 142 EXPECT_FALSE(
143 test_cache_storage_->IsPreservingCache(callback_cache_handle_->value()));
137 } 144 }
138 145
139 } // namespace content 146 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/cache_storage/cache_storage_manager_unittest.cc ('k') | content/browser/renderer_host/render_message_filter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698