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

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

Issue 1039763002: Cache Storage: Move files to content/*/cache_storage, rename classes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: GN fix Created 5 years, 8 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/service_worker/service_worker_cache_storage_manager.h" 5 #include "content/browser/cache_storage/cache_storage_manager.h"
6 6
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/files/scoped_temp_dir.h" 9 #include "base/files/scoped_temp_dir.h"
10 #include "base/message_loop/message_loop_proxy.h" 10 #include "base/message_loop/message_loop_proxy.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 "content/browser/cache_storage/cache_storage_quota_client.h"
13 #include "content/browser/fileapi/chrome_blob_storage_context.h" 14 #include "content/browser/fileapi/chrome_blob_storage_context.h"
14 #include "content/browser/quota/mock_quota_manager_proxy.h" 15 #include "content/browser/quota/mock_quota_manager_proxy.h"
15 #include "content/browser/service_worker/service_worker_cache_quota_client.h"
16 #include "content/public/browser/browser_thread.h" 16 #include "content/public/browser/browser_thread.h"
17 #include "content/public/test/test_browser_context.h" 17 #include "content/public/test/test_browser_context.h"
18 #include "content/public/test/test_browser_thread_bundle.h" 18 #include "content/public/test/test_browser_thread_bundle.h"
19 #include "net/url_request/url_request_context_getter.h" 19 #include "net/url_request/url_request_context_getter.h"
20 #include "storage/browser/blob/blob_storage_context.h" 20 #include "storage/browser/blob/blob_storage_context.h"
21 #include "storage/browser/quota/quota_manager_proxy.h" 21 #include "storage/browser/quota/quota_manager_proxy.h"
22 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
23 23
24 namespace content { 24 namespace content {
25 25
26 class ServiceWorkerCacheStorageManagerTest : public testing::Test { 26 class CacheStorageManagerTest : public testing::Test {
27 public: 27 public:
28 ServiceWorkerCacheStorageManagerTest() 28 CacheStorageManagerTest()
29 : browser_thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP), 29 : browser_thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP),
30 callback_bool_(false), 30 callback_bool_(false),
31 callback_error_( 31 callback_error_(CacheStorage::CACHE_STORAGE_ERROR_NO_ERROR),
32 ServiceWorkerCacheStorage::CACHE_STORAGE_ERROR_NO_ERROR), 32 callback_cache_error_(CacheStorageCache::ERROR_TYPE_OK),
33 callback_cache_error_(ServiceWorkerCache::ERROR_TYPE_OK),
34 origin1_("http://example1.com"), 33 origin1_("http://example1.com"),
35 origin2_("http://example2.com") {} 34 origin2_("http://example2.com") {}
36 35
37 void SetUp() override { 36 void SetUp() override {
38 ChromeBlobStorageContext* blob_storage_context( 37 ChromeBlobStorageContext* blob_storage_context(
39 ChromeBlobStorageContext::GetFor(&browser_context_)); 38 ChromeBlobStorageContext::GetFor(&browser_context_));
40 // Wait for ChromeBlobStorageContext to finish initializing. 39 // Wait for ChromeBlobStorageContext to finish initializing.
41 base::RunLoop().RunUntilIdle(); 40 base::RunLoop().RunUntilIdle();
42 41
43 quota_manager_proxy_ = new MockQuotaManagerProxy( 42 quota_manager_proxy_ = new MockQuotaManagerProxy(
44 nullptr, base::MessageLoopProxy::current().get()); 43 nullptr, base::MessageLoopProxy::current().get());
45 44
46 net::URLRequestContext* url_request_context = 45 net::URLRequestContext* url_request_context =
47 browser_context_.GetRequestContext()->GetURLRequestContext(); 46 browser_context_.GetRequestContext()->GetURLRequestContext();
48 if (MemoryOnly()) { 47 if (MemoryOnly()) {
49 cache_manager_ = ServiceWorkerCacheStorageManager::Create( 48 cache_manager_ = CacheStorageManager::Create(
50 base::FilePath(), 49 base::FilePath(), base::MessageLoopProxy::current(),
51 base::MessageLoopProxy::current(),
52 quota_manager_proxy_); 50 quota_manager_proxy_);
53 } else { 51 } else {
54 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 52 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
55 cache_manager_ = ServiceWorkerCacheStorageManager::Create( 53 cache_manager_ = CacheStorageManager::Create(
56 temp_dir_.path(), 54 temp_dir_.path(), base::MessageLoopProxy::current(),
57 base::MessageLoopProxy::current(),
58 quota_manager_proxy_); 55 quota_manager_proxy_);
59 } 56 }
60 57
61 cache_manager_->SetBlobParametersForCache( 58 cache_manager_->SetBlobParametersForCache(
62 url_request_context, blob_storage_context->context()->AsWeakPtr()); 59 url_request_context, blob_storage_context->context()->AsWeakPtr());
63 } 60 }
64 61
65 void TearDown() override { 62 void TearDown() override {
66 quota_manager_proxy_->SimulateQuotaManagerDestroyed(); 63 quota_manager_proxy_->SimulateQuotaManagerDestroyed();
67 base::RunLoop().RunUntilIdle(); 64 base::RunLoop().RunUntilIdle();
68 } 65 }
69 66
70 virtual bool MemoryOnly() { return false; } 67 virtual bool MemoryOnly() { return false; }
71 68
72 void BoolAndErrorCallback( 69 void BoolAndErrorCallback(base::RunLoop* run_loop,
73 base::RunLoop* run_loop, 70 bool value,
74 bool value, 71 CacheStorage::CacheStorageError error) {
75 ServiceWorkerCacheStorage::CacheStorageError error) {
76 callback_bool_ = value; 72 callback_bool_ = value;
77 callback_error_ = error; 73 callback_error_ = error;
78 run_loop->Quit(); 74 run_loop->Quit();
79 } 75 }
80 76
81 void CacheAndErrorCallback( 77 void CacheAndErrorCallback(base::RunLoop* run_loop,
82 base::RunLoop* run_loop, 78 const scoped_refptr<CacheStorageCache>& cache,
83 const scoped_refptr<ServiceWorkerCache>& cache, 79 CacheStorage::CacheStorageError error) {
84 ServiceWorkerCacheStorage::CacheStorageError error) {
85 callback_cache_ = cache; 80 callback_cache_ = cache;
86 callback_error_ = error; 81 callback_error_ = error;
87 run_loop->Quit(); 82 run_loop->Quit();
88 } 83 }
89 84
90 void StringsAndErrorCallback( 85 void StringsAndErrorCallback(base::RunLoop* run_loop,
91 base::RunLoop* run_loop, 86 const std::vector<std::string>& strings,
92 const std::vector<std::string>& strings, 87 CacheStorage::CacheStorageError error) {
93 ServiceWorkerCacheStorage::CacheStorageError error) {
94 callback_strings_ = strings; 88 callback_strings_ = strings;
95 callback_error_ = error; 89 callback_error_ = error;
96 run_loop->Quit(); 90 run_loop->Quit();
97 } 91 }
98 92
99 void CachePutCallback(base::RunLoop* run_loop, 93 void CachePutCallback(base::RunLoop* run_loop,
100 ServiceWorkerCache::ErrorType error, 94 CacheStorageCache::ErrorType error,
101 scoped_ptr<ServiceWorkerResponse> response, 95 scoped_ptr<ServiceWorkerResponse> response,
102 scoped_ptr<storage::BlobDataHandle> blob_data_handle) { 96 scoped_ptr<storage::BlobDataHandle> blob_data_handle) {
103 callback_cache_error_ = error; 97 callback_cache_error_ = error;
104 run_loop->Quit(); 98 run_loop->Quit();
105 } 99 }
106 100
107 void CacheMatchCallback( 101 void CacheMatchCallback(
108 base::RunLoop* run_loop, 102 base::RunLoop* run_loop,
109 ServiceWorkerCache::ErrorType error, 103 CacheStorageCache::ErrorType error,
110 scoped_ptr<ServiceWorkerResponse> response, 104 scoped_ptr<ServiceWorkerResponse> response,
111 scoped_ptr<storage::BlobDataHandle> blob_data_handle) { 105 scoped_ptr<storage::BlobDataHandle> blob_data_handle) {
112 callback_cache_error_ = error; 106 callback_cache_error_ = error;
113 callback_cache_response_ = response.Pass(); 107 callback_cache_response_ = response.Pass();
114 // Deliberately drop the data handle as only the url is being tested. 108 // Deliberately drop the data handle as only the url is being tested.
115 run_loop->Quit(); 109 run_loop->Quit();
116 } 110 }
117 111
118 bool Open(const GURL& origin, const std::string& cache_name) { 112 bool Open(const GURL& origin, const std::string& cache_name) {
119 scoped_ptr<base::RunLoop> loop(new base::RunLoop()); 113 scoped_ptr<base::RunLoop> loop(new base::RunLoop());
120 cache_manager_->OpenCache( 114 cache_manager_->OpenCache(
121 origin, 115 origin, cache_name,
122 cache_name, 116 base::Bind(&CacheStorageManagerTest::CacheAndErrorCallback,
123 base::Bind(&ServiceWorkerCacheStorageManagerTest::CacheAndErrorCallback, 117 base::Unretained(this), base::Unretained(loop.get())));
124 base::Unretained(this),
125 base::Unretained(loop.get())));
126 loop->Run(); 118 loop->Run();
127 119
128 bool error = callback_error_ != 120 bool error = callback_error_ != CacheStorage::CACHE_STORAGE_ERROR_NO_ERROR;
129 ServiceWorkerCacheStorage::CACHE_STORAGE_ERROR_NO_ERROR;
130 if (error) 121 if (error)
131 EXPECT_TRUE(!callback_cache_.get()); 122 EXPECT_TRUE(!callback_cache_.get());
132 else 123 else
133 EXPECT_TRUE(callback_cache_.get()); 124 EXPECT_TRUE(callback_cache_.get());
134 return !error; 125 return !error;
135 } 126 }
136 127
137 bool Has(const GURL& origin, const std::string& cache_name) { 128 bool Has(const GURL& origin, const std::string& cache_name) {
138 scoped_ptr<base::RunLoop> loop(new base::RunLoop()); 129 scoped_ptr<base::RunLoop> loop(new base::RunLoop());
139 cache_manager_->HasCache( 130 cache_manager_->HasCache(
140 origin, 131 origin, cache_name,
141 cache_name, 132 base::Bind(&CacheStorageManagerTest::BoolAndErrorCallback,
142 base::Bind(&ServiceWorkerCacheStorageManagerTest::BoolAndErrorCallback, 133 base::Unretained(this), base::Unretained(loop.get())));
143 base::Unretained(this),
144 base::Unretained(loop.get())));
145 loop->Run(); 134 loop->Run();
146 135
147 return callback_bool_; 136 return callback_bool_;
148 } 137 }
149 138
150 bool Delete(const GURL& origin, const std::string& cache_name) { 139 bool Delete(const GURL& origin, const std::string& cache_name) {
151 scoped_ptr<base::RunLoop> loop(new base::RunLoop()); 140 scoped_ptr<base::RunLoop> loop(new base::RunLoop());
152 cache_manager_->DeleteCache( 141 cache_manager_->DeleteCache(
153 origin, 142 origin, cache_name,
154 cache_name, 143 base::Bind(&CacheStorageManagerTest::BoolAndErrorCallback,
155 base::Bind(&ServiceWorkerCacheStorageManagerTest::BoolAndErrorCallback, 144 base::Unretained(this), base::Unretained(loop.get())));
156 base::Unretained(this),
157 base::Unretained(loop.get())));
158 loop->Run(); 145 loop->Run();
159 146
160 return callback_bool_; 147 return callback_bool_;
161 } 148 }
162 149
163 bool Keys(const GURL& origin) { 150 bool Keys(const GURL& origin) {
164 scoped_ptr<base::RunLoop> loop(new base::RunLoop()); 151 scoped_ptr<base::RunLoop> loop(new base::RunLoop());
165 cache_manager_->EnumerateCaches( 152 cache_manager_->EnumerateCaches(
166 origin, 153 origin,
167 base::Bind( 154 base::Bind(&CacheStorageManagerTest::StringsAndErrorCallback,
168 &ServiceWorkerCacheStorageManagerTest::StringsAndErrorCallback, 155 base::Unretained(this), base::Unretained(loop.get())));
169 base::Unretained(this),
170 base::Unretained(loop.get())));
171 loop->Run(); 156 loop->Run();
172 157
173 bool error = callback_error_ != 158 bool error = callback_error_ != CacheStorage::CACHE_STORAGE_ERROR_NO_ERROR;
174 ServiceWorkerCacheStorage::CACHE_STORAGE_ERROR_NO_ERROR;
175 return !error; 159 return !error;
176 } 160 }
177 161
178 bool StorageMatch(const GURL& origin, 162 bool StorageMatch(const GURL& origin,
179 const std::string& cache_name, 163 const std::string& cache_name,
180 const GURL& url) { 164 const GURL& url) {
181 scoped_ptr<ServiceWorkerFetchRequest> request( 165 scoped_ptr<ServiceWorkerFetchRequest> request(
182 new ServiceWorkerFetchRequest()); 166 new ServiceWorkerFetchRequest());
183 request->url = url; 167 request->url = url;
184 scoped_ptr<base::RunLoop> loop(new base::RunLoop()); 168 scoped_ptr<base::RunLoop> loop(new base::RunLoop());
185 cache_manager_->MatchCache( 169 cache_manager_->MatchCache(
186 origin, cache_name, request.Pass(), 170 origin, cache_name, request.Pass(),
187 base::Bind(&ServiceWorkerCacheStorageManagerTest::CacheMatchCallback, 171 base::Bind(&CacheStorageManagerTest::CacheMatchCallback,
188 base::Unretained(this), base::Unretained(loop.get()))); 172 base::Unretained(this), base::Unretained(loop.get())));
189 loop->Run(); 173 loop->Run();
190 174
191 bool error = callback_cache_error_ != ServiceWorkerCache::ERROR_TYPE_OK; 175 bool error = callback_cache_error_ != CacheStorageCache::ERROR_TYPE_OK;
192 return !error; 176 return !error;
193 } 177 }
194 178
195 bool StorageMatchAll(const GURL& origin, const GURL& url) { 179 bool StorageMatchAll(const GURL& origin, const GURL& url) {
196 scoped_ptr<ServiceWorkerFetchRequest> request( 180 scoped_ptr<ServiceWorkerFetchRequest> request(
197 new ServiceWorkerFetchRequest()); 181 new ServiceWorkerFetchRequest());
198 request->url = url; 182 request->url = url;
199 scoped_ptr<base::RunLoop> loop(new base::RunLoop()); 183 scoped_ptr<base::RunLoop> loop(new base::RunLoop());
200 cache_manager_->MatchAllCaches( 184 cache_manager_->MatchAllCaches(
201 origin, request.Pass(), 185 origin, request.Pass(),
202 base::Bind(&ServiceWorkerCacheStorageManagerTest::CacheMatchCallback, 186 base::Bind(&CacheStorageManagerTest::CacheMatchCallback,
203 base::Unretained(this), base::Unretained(loop.get()))); 187 base::Unretained(this), base::Unretained(loop.get())));
204 loop->Run(); 188 loop->Run();
205 189
206 bool error = callback_cache_error_ != ServiceWorkerCache::ERROR_TYPE_OK; 190 bool error = callback_cache_error_ != CacheStorageCache::ERROR_TYPE_OK;
207 return !error; 191 return !error;
208 } 192 }
209 193
210 bool CachePut(const scoped_refptr<ServiceWorkerCache>& cache, 194 bool CachePut(const scoped_refptr<CacheStorageCache>& cache,
211 const GURL& url) { 195 const GURL& url) {
212 scoped_ptr<ServiceWorkerFetchRequest> request( 196 scoped_ptr<ServiceWorkerFetchRequest> request(
213 new ServiceWorkerFetchRequest()); 197 new ServiceWorkerFetchRequest());
214 scoped_ptr<ServiceWorkerResponse> response(new ServiceWorkerResponse()); 198 scoped_ptr<ServiceWorkerResponse> response(new ServiceWorkerResponse());
215 request->url = url; 199 request->url = url;
216 response->url = url; 200 response->url = url;
217 scoped_ptr<base::RunLoop> loop(new base::RunLoop()); 201 scoped_ptr<base::RunLoop> loop(new base::RunLoop());
218 cache->Put( 202 cache->Put(
219 request.Pass(), 203 request.Pass(), response.Pass(),
220 response.Pass(), 204 base::Bind(&CacheStorageManagerTest::CachePutCallback,
221 base::Bind(&ServiceWorkerCacheStorageManagerTest::CachePutCallback, 205 base::Unretained(this), base::Unretained(loop.get())));
222 base::Unretained(this),
223 base::Unretained(loop.get())));
224 loop->Run(); 206 loop->Run();
225 207
226 bool error = callback_cache_error_ != ServiceWorkerCache::ERROR_TYPE_OK; 208 bool error = callback_cache_error_ != CacheStorageCache::ERROR_TYPE_OK;
227 return !error; 209 return !error;
228 } 210 }
229 211
230 bool CacheMatch(const scoped_refptr<ServiceWorkerCache>& cache, 212 bool CacheMatch(const scoped_refptr<CacheStorageCache>& cache,
231 const GURL& url) { 213 const GURL& url) {
232 scoped_ptr<ServiceWorkerFetchRequest> request( 214 scoped_ptr<ServiceWorkerFetchRequest> request(
233 new ServiceWorkerFetchRequest()); 215 new ServiceWorkerFetchRequest());
234 request->url = url; 216 request->url = url;
235 scoped_ptr<base::RunLoop> loop(new base::RunLoop()); 217 scoped_ptr<base::RunLoop> loop(new base::RunLoop());
236 cache->Match( 218 cache->Match(
237 request.Pass(), 219 request.Pass(),
238 base::Bind(&ServiceWorkerCacheStorageManagerTest::CacheMatchCallback, 220 base::Bind(&CacheStorageManagerTest::CacheMatchCallback,
239 base::Unretained(this), 221 base::Unretained(this), base::Unretained(loop.get())));
240 base::Unretained(loop.get())));
241 loop->Run(); 222 loop->Run();
242 223
243 bool error = callback_cache_error_ != ServiceWorkerCache::ERROR_TYPE_OK; 224 bool error = callback_cache_error_ != CacheStorageCache::ERROR_TYPE_OK;
244 return !error; 225 return !error;
245 } 226 }
246 227
247 ServiceWorkerCacheStorage* CacheStorageForOrigin(const GURL& origin) { 228 CacheStorage* CacheStorageForOrigin(const GURL& origin) {
248 return cache_manager_->FindOrCreateServiceWorkerCacheManager(origin); 229 return cache_manager_->FindOrCreateCacheStorage(origin);
249 } 230 }
250 231
251 protected: 232 protected:
252 TestBrowserContext browser_context_; 233 TestBrowserContext browser_context_;
253 TestBrowserThreadBundle browser_thread_bundle_; 234 TestBrowserThreadBundle browser_thread_bundle_;
254 235
255 base::ScopedTempDir temp_dir_; 236 base::ScopedTempDir temp_dir_;
256 scoped_refptr<MockQuotaManagerProxy> quota_manager_proxy_; 237 scoped_refptr<MockQuotaManagerProxy> quota_manager_proxy_;
257 scoped_ptr<ServiceWorkerCacheStorageManager> cache_manager_; 238 scoped_ptr<CacheStorageManager> cache_manager_;
258 239
259 scoped_refptr<ServiceWorkerCache> callback_cache_; 240 scoped_refptr<CacheStorageCache> callback_cache_;
260 int callback_bool_; 241 int callback_bool_;
261 ServiceWorkerCacheStorage::CacheStorageError callback_error_; 242 CacheStorage::CacheStorageError callback_error_;
262 ServiceWorkerCache::ErrorType callback_cache_error_; 243 CacheStorageCache::ErrorType callback_cache_error_;
263 scoped_ptr<ServiceWorkerResponse> callback_cache_response_; 244 scoped_ptr<ServiceWorkerResponse> callback_cache_response_;
264 std::vector<std::string> callback_strings_; 245 std::vector<std::string> callback_strings_;
265 246
266 const GURL origin1_; 247 const GURL origin1_;
267 const GURL origin2_; 248 const GURL origin2_;
268 249
269 private: 250 private:
270 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerCacheStorageManagerTest); 251 DISALLOW_COPY_AND_ASSIGN(CacheStorageManagerTest);
271 }; 252 };
272 253
273 class ServiceWorkerCacheStorageManagerMemoryOnlyTest 254 class CacheStorageManagerMemoryOnlyTest : public CacheStorageManagerTest {
274 : public ServiceWorkerCacheStorageManagerTest {
275 bool MemoryOnly() override { return true; } 255 bool MemoryOnly() override { return true; }
276 }; 256 };
277 257
278 class ServiceWorkerCacheStorageManagerTestP 258 class CacheStorageManagerTestP : public CacheStorageManagerTest,
279 : public ServiceWorkerCacheStorageManagerTest, 259 public testing::WithParamInterface<bool> {
280 public testing::WithParamInterface<bool> {
281 bool MemoryOnly() override { return !GetParam(); } 260 bool MemoryOnly() override { return !GetParam(); }
282 }; 261 };
283 262
284 TEST_F(ServiceWorkerCacheStorageManagerTest, TestsRunOnIOThread) { 263 TEST_F(CacheStorageManagerTest, TestsRunOnIOThread) {
285 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); 264 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO));
286 } 265 }
287 266
288 TEST_P(ServiceWorkerCacheStorageManagerTestP, OpenCache) { 267 TEST_P(CacheStorageManagerTestP, OpenCache) {
289 EXPECT_TRUE(Open(origin1_, "foo")); 268 EXPECT_TRUE(Open(origin1_, "foo"));
290 } 269 }
291 270
292 TEST_P(ServiceWorkerCacheStorageManagerTestP, OpenTwoCaches) { 271 TEST_P(CacheStorageManagerTestP, OpenTwoCaches) {
293 EXPECT_TRUE(Open(origin1_, "foo")); 272 EXPECT_TRUE(Open(origin1_, "foo"));
294 EXPECT_TRUE(Open(origin1_, "bar")); 273 EXPECT_TRUE(Open(origin1_, "bar"));
295 } 274 }
296 275
297 TEST_P(ServiceWorkerCacheStorageManagerTestP, CachePointersDiffer) { 276 TEST_P(CacheStorageManagerTestP, CachePointersDiffer) {
298 EXPECT_TRUE(Open(origin1_, "foo")); 277 EXPECT_TRUE(Open(origin1_, "foo"));
299 scoped_refptr<ServiceWorkerCache> cache = callback_cache_; 278 scoped_refptr<CacheStorageCache> cache = callback_cache_;
300 EXPECT_TRUE(Open(origin1_, "bar")); 279 EXPECT_TRUE(Open(origin1_, "bar"));
301 EXPECT_NE(callback_cache_.get(), cache.get()); 280 EXPECT_NE(callback_cache_.get(), cache.get());
302 } 281 }
303 282
304 TEST_P(ServiceWorkerCacheStorageManagerTestP, Open2CachesSameNameDiffOrigins) { 283 TEST_P(CacheStorageManagerTestP, Open2CachesSameNameDiffOrigins) {
305 EXPECT_TRUE(Open(origin1_, "foo")); 284 EXPECT_TRUE(Open(origin1_, "foo"));
306 scoped_refptr<ServiceWorkerCache> cache = callback_cache_; 285 scoped_refptr<CacheStorageCache> cache = callback_cache_;
307 EXPECT_TRUE(Open(origin2_, "foo")); 286 EXPECT_TRUE(Open(origin2_, "foo"));
308 EXPECT_NE(cache.get(), callback_cache_.get()); 287 EXPECT_NE(cache.get(), callback_cache_.get());
309 } 288 }
310 289
311 TEST_P(ServiceWorkerCacheStorageManagerTestP, OpenExistingCache) { 290 TEST_P(CacheStorageManagerTestP, OpenExistingCache) {
312 EXPECT_TRUE(Open(origin1_, "foo")); 291 EXPECT_TRUE(Open(origin1_, "foo"));
313 scoped_refptr<ServiceWorkerCache> cache = callback_cache_; 292 scoped_refptr<CacheStorageCache> cache = callback_cache_;
314 EXPECT_TRUE(Open(origin1_, "foo")); 293 EXPECT_TRUE(Open(origin1_, "foo"));
315 EXPECT_EQ(callback_cache_.get(), cache.get()); 294 EXPECT_EQ(callback_cache_.get(), cache.get());
316 } 295 }
317 296
318 TEST_P(ServiceWorkerCacheStorageManagerTestP, HasCache) { 297 TEST_P(CacheStorageManagerTestP, HasCache) {
319 EXPECT_TRUE(Open(origin1_, "foo")); 298 EXPECT_TRUE(Open(origin1_, "foo"));
320 EXPECT_TRUE(Has(origin1_, "foo")); 299 EXPECT_TRUE(Has(origin1_, "foo"));
321 EXPECT_TRUE(callback_bool_); 300 EXPECT_TRUE(callback_bool_);
322 } 301 }
323 302
324 TEST_P(ServiceWorkerCacheStorageManagerTestP, HasNonExistent) { 303 TEST_P(CacheStorageManagerTestP, HasNonExistent) {
325 EXPECT_FALSE(Has(origin1_, "foo")); 304 EXPECT_FALSE(Has(origin1_, "foo"));
326 } 305 }
327 306
328 TEST_P(ServiceWorkerCacheStorageManagerTestP, DeleteCache) { 307 TEST_P(CacheStorageManagerTestP, DeleteCache) {
329 EXPECT_TRUE(Open(origin1_, "foo")); 308 EXPECT_TRUE(Open(origin1_, "foo"));
330 EXPECT_TRUE(Delete(origin1_, "foo")); 309 EXPECT_TRUE(Delete(origin1_, "foo"));
331 EXPECT_FALSE(Has(origin1_, "foo")); 310 EXPECT_FALSE(Has(origin1_, "foo"));
332 } 311 }
333 312
334 TEST_P(ServiceWorkerCacheStorageManagerTestP, DeleteTwice) { 313 TEST_P(CacheStorageManagerTestP, DeleteTwice) {
335 EXPECT_TRUE(Open(origin1_, "foo")); 314 EXPECT_TRUE(Open(origin1_, "foo"));
336 EXPECT_TRUE(Delete(origin1_, "foo")); 315 EXPECT_TRUE(Delete(origin1_, "foo"));
337 EXPECT_FALSE(Delete(origin1_, "foo")); 316 EXPECT_FALSE(Delete(origin1_, "foo"));
338 EXPECT_EQ(ServiceWorkerCacheStorage::CACHE_STORAGE_ERROR_NOT_FOUND, 317 EXPECT_EQ(CacheStorage::CACHE_STORAGE_ERROR_NOT_FOUND, callback_error_);
339 callback_error_);
340 } 318 }
341 319
342 TEST_P(ServiceWorkerCacheStorageManagerTestP, EmptyKeys) { 320 TEST_P(CacheStorageManagerTestP, EmptyKeys) {
343 EXPECT_TRUE(Keys(origin1_)); 321 EXPECT_TRUE(Keys(origin1_));
344 EXPECT_TRUE(callback_strings_.empty()); 322 EXPECT_TRUE(callback_strings_.empty());
345 } 323 }
346 324
347 TEST_P(ServiceWorkerCacheStorageManagerTestP, SomeKeys) { 325 TEST_P(CacheStorageManagerTestP, SomeKeys) {
348 EXPECT_TRUE(Open(origin1_, "foo")); 326 EXPECT_TRUE(Open(origin1_, "foo"));
349 EXPECT_TRUE(Open(origin1_, "bar")); 327 EXPECT_TRUE(Open(origin1_, "bar"));
350 EXPECT_TRUE(Open(origin2_, "baz")); 328 EXPECT_TRUE(Open(origin2_, "baz"));
351 EXPECT_TRUE(Keys(origin1_)); 329 EXPECT_TRUE(Keys(origin1_));
352 EXPECT_EQ(2u, callback_strings_.size()); 330 EXPECT_EQ(2u, callback_strings_.size());
353 std::vector<std::string> expected_keys; 331 std::vector<std::string> expected_keys;
354 expected_keys.push_back("foo"); 332 expected_keys.push_back("foo");
355 expected_keys.push_back("bar"); 333 expected_keys.push_back("bar");
356 EXPECT_EQ(expected_keys, callback_strings_); 334 EXPECT_EQ(expected_keys, callback_strings_);
357 EXPECT_TRUE(Keys(origin2_)); 335 EXPECT_TRUE(Keys(origin2_));
358 EXPECT_EQ(1u, callback_strings_.size()); 336 EXPECT_EQ(1u, callback_strings_.size());
359 EXPECT_STREQ("baz", callback_strings_[0].c_str()); 337 EXPECT_STREQ("baz", callback_strings_[0].c_str());
360 } 338 }
361 339
362 TEST_P(ServiceWorkerCacheStorageManagerTestP, DeletedKeysGone) { 340 TEST_P(CacheStorageManagerTestP, DeletedKeysGone) {
363 EXPECT_TRUE(Open(origin1_, "foo")); 341 EXPECT_TRUE(Open(origin1_, "foo"));
364 EXPECT_TRUE(Open(origin1_, "bar")); 342 EXPECT_TRUE(Open(origin1_, "bar"));
365 EXPECT_TRUE(Open(origin2_, "baz")); 343 EXPECT_TRUE(Open(origin2_, "baz"));
366 EXPECT_TRUE(Delete(origin1_, "bar")); 344 EXPECT_TRUE(Delete(origin1_, "bar"));
367 EXPECT_TRUE(Keys(origin1_)); 345 EXPECT_TRUE(Keys(origin1_));
368 EXPECT_EQ(1u, callback_strings_.size()); 346 EXPECT_EQ(1u, callback_strings_.size());
369 EXPECT_STREQ("foo", callback_strings_[0].c_str()); 347 EXPECT_STREQ("foo", callback_strings_[0].c_str());
370 } 348 }
371 349
372 TEST_P(ServiceWorkerCacheStorageManagerTestP, StorageMatchEntryExists) { 350 TEST_P(CacheStorageManagerTestP, StorageMatchEntryExists) {
373 EXPECT_TRUE(Open(origin1_, "foo")); 351 EXPECT_TRUE(Open(origin1_, "foo"));
374 EXPECT_TRUE(CachePut(callback_cache_, GURL("http://example.com/foo"))); 352 EXPECT_TRUE(CachePut(callback_cache_, GURL("http://example.com/foo")));
375 EXPECT_TRUE(StorageMatch(origin1_, "foo", GURL("http://example.com/foo"))); 353 EXPECT_TRUE(StorageMatch(origin1_, "foo", GURL("http://example.com/foo")));
376 } 354 }
377 355
378 TEST_P(ServiceWorkerCacheStorageManagerTestP, StorageMatchNoEntry) { 356 TEST_P(CacheStorageManagerTestP, StorageMatchNoEntry) {
379 EXPECT_TRUE(Open(origin1_, "foo")); 357 EXPECT_TRUE(Open(origin1_, "foo"));
380 EXPECT_TRUE(CachePut(callback_cache_, GURL("http://example.com/foo"))); 358 EXPECT_TRUE(CachePut(callback_cache_, GURL("http://example.com/foo")));
381 EXPECT_FALSE(StorageMatch(origin1_, "foo", GURL("http://example.com/bar"))); 359 EXPECT_FALSE(StorageMatch(origin1_, "foo", GURL("http://example.com/bar")));
382 EXPECT_EQ(ServiceWorkerCache::ERROR_TYPE_NOT_FOUND, callback_cache_error_); 360 EXPECT_EQ(CacheStorageCache::ERROR_TYPE_NOT_FOUND, callback_cache_error_);
383 } 361 }
384 362
385 TEST_P(ServiceWorkerCacheStorageManagerTestP, StorageMatchNoCache) { 363 TEST_P(CacheStorageManagerTestP, StorageMatchNoCache) {
386 EXPECT_TRUE(Open(origin1_, "foo")); 364 EXPECT_TRUE(Open(origin1_, "foo"));
387 EXPECT_TRUE(CachePut(callback_cache_, GURL("http://example.com/foo"))); 365 EXPECT_TRUE(CachePut(callback_cache_, GURL("http://example.com/foo")));
388 EXPECT_FALSE(StorageMatch(origin1_, "bar", GURL("http://example.com/foo"))); 366 EXPECT_FALSE(StorageMatch(origin1_, "bar", GURL("http://example.com/foo")));
389 EXPECT_EQ(ServiceWorkerCache::ERROR_TYPE_NOT_FOUND, callback_cache_error_); 367 EXPECT_EQ(CacheStorageCache::ERROR_TYPE_NOT_FOUND, callback_cache_error_);
390 } 368 }
391 369
392 TEST_P(ServiceWorkerCacheStorageManagerTestP, StorageMatchAllEntryExists) { 370 TEST_P(CacheStorageManagerTestP, StorageMatchAllEntryExists) {
393 EXPECT_TRUE(Open(origin1_, "foo")); 371 EXPECT_TRUE(Open(origin1_, "foo"));
394 EXPECT_TRUE(CachePut(callback_cache_, GURL("http://example.com/foo"))); 372 EXPECT_TRUE(CachePut(callback_cache_, GURL("http://example.com/foo")));
395 EXPECT_TRUE(StorageMatchAll(origin1_, GURL("http://example.com/foo"))); 373 EXPECT_TRUE(StorageMatchAll(origin1_, GURL("http://example.com/foo")));
396 } 374 }
397 375
398 TEST_P(ServiceWorkerCacheStorageManagerTestP, StorageMatchAllNoEntry) { 376 TEST_P(CacheStorageManagerTestP, StorageMatchAllNoEntry) {
399 EXPECT_TRUE(Open(origin1_, "foo")); 377 EXPECT_TRUE(Open(origin1_, "foo"));
400 EXPECT_TRUE(CachePut(callback_cache_, GURL("http://example.com/foo"))); 378 EXPECT_TRUE(CachePut(callback_cache_, GURL("http://example.com/foo")));
401 EXPECT_FALSE(StorageMatchAll(origin1_, GURL("http://example.com/bar"))); 379 EXPECT_FALSE(StorageMatchAll(origin1_, GURL("http://example.com/bar")));
402 EXPECT_EQ(ServiceWorkerCache::ERROR_TYPE_NOT_FOUND, callback_cache_error_); 380 EXPECT_EQ(CacheStorageCache::ERROR_TYPE_NOT_FOUND, callback_cache_error_);
403 } 381 }
404 382
405 TEST_P(ServiceWorkerCacheStorageManagerTestP, StorageMatchAllNoCaches) { 383 TEST_P(CacheStorageManagerTestP, StorageMatchAllNoCaches) {
406 EXPECT_FALSE(StorageMatchAll(origin1_, GURL("http://example.com/foo"))); 384 EXPECT_FALSE(StorageMatchAll(origin1_, GURL("http://example.com/foo")));
407 EXPECT_EQ(ServiceWorkerCache::ERROR_TYPE_NOT_FOUND, callback_cache_error_); 385 EXPECT_EQ(CacheStorageCache::ERROR_TYPE_NOT_FOUND, callback_cache_error_);
408 } 386 }
409 387
410 TEST_P(ServiceWorkerCacheStorageManagerTestP, StorageMatchAllEntryExistsTwice) { 388 TEST_P(CacheStorageManagerTestP, StorageMatchAllEntryExistsTwice) {
411 EXPECT_TRUE(Open(origin1_, "foo")); 389 EXPECT_TRUE(Open(origin1_, "foo"));
412 EXPECT_TRUE(CachePut(callback_cache_, GURL("http://example.com/foo"))); 390 EXPECT_TRUE(CachePut(callback_cache_, GURL("http://example.com/foo")));
413 EXPECT_TRUE(Open(origin1_, "bar")); 391 EXPECT_TRUE(Open(origin1_, "bar"));
414 EXPECT_TRUE(CachePut(callback_cache_, GURL("http://example.com/foo"))); 392 EXPECT_TRUE(CachePut(callback_cache_, GURL("http://example.com/foo")));
415 393
416 EXPECT_TRUE(StorageMatchAll(origin1_, GURL("http://example.com/foo"))); 394 EXPECT_TRUE(StorageMatchAll(origin1_, GURL("http://example.com/foo")));
417 } 395 }
418 396
419 TEST_P(ServiceWorkerCacheStorageManagerTestP, StorageMatchInOneOfMany) { 397 TEST_P(CacheStorageManagerTestP, StorageMatchInOneOfMany) {
420 EXPECT_TRUE(Open(origin1_, "foo")); 398 EXPECT_TRUE(Open(origin1_, "foo"));
421 EXPECT_TRUE(Open(origin1_, "bar")); 399 EXPECT_TRUE(Open(origin1_, "bar"));
422 EXPECT_TRUE(CachePut(callback_cache_, GURL("http://example.com/foo"))); 400 EXPECT_TRUE(CachePut(callback_cache_, GURL("http://example.com/foo")));
423 EXPECT_TRUE(Open(origin1_, "baz")); 401 EXPECT_TRUE(Open(origin1_, "baz"));
424 402
425 EXPECT_TRUE(StorageMatchAll(origin1_, GURL("http://example.com/foo"))); 403 EXPECT_TRUE(StorageMatchAll(origin1_, GURL("http://example.com/foo")));
426 } 404 }
427 405
428 TEST_P(ServiceWorkerCacheStorageManagerTestP, Chinese) { 406 TEST_P(CacheStorageManagerTestP, Chinese) {
429 EXPECT_TRUE(Open(origin1_, "你好")); 407 EXPECT_TRUE(Open(origin1_, "你好"));
430 scoped_refptr<ServiceWorkerCache> cache = callback_cache_; 408 scoped_refptr<CacheStorageCache> cache = callback_cache_;
431 EXPECT_TRUE(Open(origin1_, "你好")); 409 EXPECT_TRUE(Open(origin1_, "你好"));
432 EXPECT_EQ(callback_cache_.get(), cache.get()); 410 EXPECT_EQ(callback_cache_.get(), cache.get());
433 EXPECT_TRUE(Keys(origin1_)); 411 EXPECT_TRUE(Keys(origin1_));
434 EXPECT_EQ(1u, callback_strings_.size()); 412 EXPECT_EQ(1u, callback_strings_.size());
435 EXPECT_STREQ("你好", callback_strings_[0].c_str()); 413 EXPECT_STREQ("你好", callback_strings_[0].c_str());
436 } 414 }
437 415
438 TEST_F(ServiceWorkerCacheStorageManagerTest, EmptyKey) { 416 TEST_F(CacheStorageManagerTest, EmptyKey) {
439 EXPECT_TRUE(Open(origin1_, "")); 417 EXPECT_TRUE(Open(origin1_, ""));
440 scoped_refptr<ServiceWorkerCache> cache = callback_cache_; 418 scoped_refptr<CacheStorageCache> cache = callback_cache_;
441 EXPECT_TRUE(Open(origin1_, "")); 419 EXPECT_TRUE(Open(origin1_, ""));
442 EXPECT_EQ(cache.get(), callback_cache_.get()); 420 EXPECT_EQ(cache.get(), callback_cache_.get());
443 EXPECT_TRUE(Keys(origin1_)); 421 EXPECT_TRUE(Keys(origin1_));
444 EXPECT_EQ(1u, callback_strings_.size()); 422 EXPECT_EQ(1u, callback_strings_.size());
445 EXPECT_STREQ("", callback_strings_[0].c_str()); 423 EXPECT_STREQ("", callback_strings_[0].c_str());
446 EXPECT_TRUE(Has(origin1_, "")); 424 EXPECT_TRUE(Has(origin1_, ""));
447 EXPECT_TRUE(Delete(origin1_, "")); 425 EXPECT_TRUE(Delete(origin1_, ""));
448 EXPECT_TRUE(Keys(origin1_)); 426 EXPECT_TRUE(Keys(origin1_));
449 EXPECT_EQ(0u, callback_strings_.size()); 427 EXPECT_EQ(0u, callback_strings_.size());
450 } 428 }
451 429
452 TEST_F(ServiceWorkerCacheStorageManagerTest, DataPersists) { 430 TEST_F(CacheStorageManagerTest, DataPersists) {
453 EXPECT_TRUE(Open(origin1_, "foo")); 431 EXPECT_TRUE(Open(origin1_, "foo"));
454 EXPECT_TRUE(Open(origin1_, "bar")); 432 EXPECT_TRUE(Open(origin1_, "bar"));
455 EXPECT_TRUE(Open(origin1_, "baz")); 433 EXPECT_TRUE(Open(origin1_, "baz"));
456 EXPECT_TRUE(Open(origin2_, "raz")); 434 EXPECT_TRUE(Open(origin2_, "raz"));
457 EXPECT_TRUE(Delete(origin1_, "bar")); 435 EXPECT_TRUE(Delete(origin1_, "bar"));
458 quota_manager_proxy_->SimulateQuotaManagerDestroyed(); 436 quota_manager_proxy_->SimulateQuotaManagerDestroyed();
459 cache_manager_ = 437 cache_manager_ = CacheStorageManager::Create(cache_manager_.get());
460 ServiceWorkerCacheStorageManager::Create(cache_manager_.get());
461 EXPECT_TRUE(Keys(origin1_)); 438 EXPECT_TRUE(Keys(origin1_));
462 EXPECT_EQ(2u, callback_strings_.size()); 439 EXPECT_EQ(2u, callback_strings_.size());
463 std::vector<std::string> expected_keys; 440 std::vector<std::string> expected_keys;
464 expected_keys.push_back("foo"); 441 expected_keys.push_back("foo");
465 expected_keys.push_back("baz"); 442 expected_keys.push_back("baz");
466 EXPECT_EQ(expected_keys, callback_strings_); 443 EXPECT_EQ(expected_keys, callback_strings_);
467 } 444 }
468 445
469 TEST_F(ServiceWorkerCacheStorageManagerMemoryOnlyTest, DataLostWhenMemoryOnly) { 446 TEST_F(CacheStorageManagerMemoryOnlyTest, DataLostWhenMemoryOnly) {
470 EXPECT_TRUE(Open(origin1_, "foo")); 447 EXPECT_TRUE(Open(origin1_, "foo"));
471 EXPECT_TRUE(Open(origin2_, "baz")); 448 EXPECT_TRUE(Open(origin2_, "baz"));
472 quota_manager_proxy_->SimulateQuotaManagerDestroyed(); 449 quota_manager_proxy_->SimulateQuotaManagerDestroyed();
473 cache_manager_ = 450 cache_manager_ = CacheStorageManager::Create(cache_manager_.get());
474 ServiceWorkerCacheStorageManager::Create(cache_manager_.get());
475 EXPECT_TRUE(Keys(origin1_)); 451 EXPECT_TRUE(Keys(origin1_));
476 EXPECT_EQ(0u, callback_strings_.size()); 452 EXPECT_EQ(0u, callback_strings_.size());
477 } 453 }
478 454
479 TEST_F(ServiceWorkerCacheStorageManagerTest, BadCacheName) { 455 TEST_F(CacheStorageManagerTest, BadCacheName) {
480 // Since the implementation writes cache names to disk, ensure that we don't 456 // Since the implementation writes cache names to disk, ensure that we don't
481 // escape the directory. 457 // escape the directory.
482 const std::string bad_name = "../../../../../../../../../../../../../../foo"; 458 const std::string bad_name = "../../../../../../../../../../../../../../foo";
483 EXPECT_TRUE(Open(origin1_, bad_name)); 459 EXPECT_TRUE(Open(origin1_, bad_name));
484 EXPECT_TRUE(Keys(origin1_)); 460 EXPECT_TRUE(Keys(origin1_));
485 EXPECT_EQ(1u, callback_strings_.size()); 461 EXPECT_EQ(1u, callback_strings_.size());
486 EXPECT_STREQ(bad_name.c_str(), callback_strings_[0].c_str()); 462 EXPECT_STREQ(bad_name.c_str(), callback_strings_[0].c_str());
487 } 463 }
488 464
489 TEST_F(ServiceWorkerCacheStorageManagerTest, BadOriginName) { 465 TEST_F(CacheStorageManagerTest, BadOriginName) {
490 // Since the implementation writes origin names to disk, ensure that we don't 466 // Since the implementation writes origin names to disk, ensure that we don't
491 // escape the directory. 467 // escape the directory.
492 GURL bad_origin("http://../../../../../../../../../../../../../../foo"); 468 GURL bad_origin("http://../../../../../../../../../../../../../../foo");
493 EXPECT_TRUE(Open(bad_origin, "foo")); 469 EXPECT_TRUE(Open(bad_origin, "foo"));
494 EXPECT_TRUE(Keys(bad_origin)); 470 EXPECT_TRUE(Keys(bad_origin));
495 EXPECT_EQ(1u, callback_strings_.size()); 471 EXPECT_EQ(1u, callback_strings_.size());
496 EXPECT_STREQ("foo", callback_strings_[0].c_str()); 472 EXPECT_STREQ("foo", callback_strings_[0].c_str());
497 } 473 }
498 474
499 // With a persistent cache if the client drops its reference to a 475 // With a persistent cache if the client drops its reference to a
500 // ServiceWorkerCache 476 // CacheStorageCache
501 // it should be deleted. 477 // it should be deleted.
502 TEST_F(ServiceWorkerCacheStorageManagerTest, DropReference) { 478 TEST_F(CacheStorageManagerTest, DropReference) {
503 EXPECT_TRUE(Open(origin1_, "foo")); 479 EXPECT_TRUE(Open(origin1_, "foo"));
504 base::WeakPtr<ServiceWorkerCache> cache = callback_cache_->AsWeakPtr(); 480 base::WeakPtr<CacheStorageCache> cache = callback_cache_->AsWeakPtr();
505 callback_cache_ = NULL; 481 callback_cache_ = NULL;
506 EXPECT_TRUE(!cache); 482 EXPECT_TRUE(!cache);
507 } 483 }
508 484
509 // With a memory cache the cache can't be freed from memory until the client 485 // With a memory cache the cache can't be freed from memory until the client
510 // calls delete. 486 // calls delete.
511 TEST_F(ServiceWorkerCacheStorageManagerMemoryOnlyTest, 487 TEST_F(CacheStorageManagerMemoryOnlyTest, MemoryLosesReferenceOnlyAfterDelete) {
512 MemoryLosesReferenceOnlyAfterDelete) {
513 EXPECT_TRUE(Open(origin1_, "foo")); 488 EXPECT_TRUE(Open(origin1_, "foo"));
514 base::WeakPtr<ServiceWorkerCache> cache = callback_cache_->AsWeakPtr(); 489 base::WeakPtr<CacheStorageCache> cache = callback_cache_->AsWeakPtr();
515 callback_cache_ = NULL; 490 callback_cache_ = NULL;
516 EXPECT_TRUE(cache); 491 EXPECT_TRUE(cache);
517 EXPECT_TRUE(Delete(origin1_, "foo")); 492 EXPECT_TRUE(Delete(origin1_, "foo"));
518 EXPECT_FALSE(cache); 493 EXPECT_FALSE(cache);
519 } 494 }
520 495
521 TEST_P(ServiceWorkerCacheStorageManagerTestP, DeleteBeforeRelease) { 496 TEST_P(CacheStorageManagerTestP, DeleteBeforeRelease) {
522 EXPECT_TRUE(Open(origin1_, "foo")); 497 EXPECT_TRUE(Open(origin1_, "foo"));
523 EXPECT_TRUE(Delete(origin1_, "foo")); 498 EXPECT_TRUE(Delete(origin1_, "foo"));
524 EXPECT_TRUE(callback_cache_->AsWeakPtr()); 499 EXPECT_TRUE(callback_cache_->AsWeakPtr());
525 } 500 }
526 501
527 TEST_P(ServiceWorkerCacheStorageManagerTestP, OpenRunsSerially) { 502 TEST_P(CacheStorageManagerTestP, OpenRunsSerially) {
528 EXPECT_FALSE(Delete(origin1_, "tmp")); // Init storage. 503 EXPECT_FALSE(Delete(origin1_, "tmp")); // Init storage.
529 ServiceWorkerCacheStorage* cache_storage = CacheStorageForOrigin(origin1_); 504 CacheStorage* cache_storage = CacheStorageForOrigin(origin1_);
530 cache_storage->StartAsyncOperationForTesting(); 505 cache_storage->StartAsyncOperationForTesting();
531 506
532 scoped_ptr<base::RunLoop> open_loop(new base::RunLoop()); 507 scoped_ptr<base::RunLoop> open_loop(new base::RunLoop());
533 cache_manager_->OpenCache( 508 cache_manager_->OpenCache(
534 origin1_, "foo", 509 origin1_, "foo",
535 base::Bind(&ServiceWorkerCacheStorageManagerTest::CacheAndErrorCallback, 510 base::Bind(&CacheStorageManagerTest::CacheAndErrorCallback,
536 base::Unretained(this), base::Unretained(open_loop.get()))); 511 base::Unretained(this), base::Unretained(open_loop.get())));
537 512
538 base::RunLoop().RunUntilIdle(); 513 base::RunLoop().RunUntilIdle();
539 EXPECT_FALSE(callback_cache_); 514 EXPECT_FALSE(callback_cache_);
540 515
541 cache_storage->CompleteAsyncOperationForTesting(); 516 cache_storage->CompleteAsyncOperationForTesting();
542 open_loop->Run(); 517 open_loop->Run();
543 EXPECT_TRUE(callback_cache_); 518 EXPECT_TRUE(callback_cache_);
544 } 519 }
545 520
546 TEST_F(ServiceWorkerCacheStorageManagerMemoryOnlyTest, MemoryBackedSize) { 521 TEST_F(CacheStorageManagerMemoryOnlyTest, MemoryBackedSize) {
547 ServiceWorkerCacheStorage* cache_storage = CacheStorageForOrigin(origin1_); 522 CacheStorage* cache_storage = CacheStorageForOrigin(origin1_);
548 EXPECT_EQ(0, cache_storage->MemoryBackedSize()); 523 EXPECT_EQ(0, cache_storage->MemoryBackedSize());
549 524
550 EXPECT_TRUE(Open(origin1_, "foo")); 525 EXPECT_TRUE(Open(origin1_, "foo"));
551 scoped_refptr<ServiceWorkerCache> foo_cache = callback_cache_; 526 scoped_refptr<CacheStorageCache> foo_cache = callback_cache_;
552 EXPECT_TRUE(Open(origin1_, "bar")); 527 EXPECT_TRUE(Open(origin1_, "bar"));
553 scoped_refptr<ServiceWorkerCache> bar_cache = callback_cache_; 528 scoped_refptr<CacheStorageCache> bar_cache = callback_cache_;
554 EXPECT_EQ(0, cache_storage->MemoryBackedSize()); 529 EXPECT_EQ(0, cache_storage->MemoryBackedSize());
555 530
556 EXPECT_TRUE(CachePut(foo_cache, GURL("http://example.com/foo"))); 531 EXPECT_TRUE(CachePut(foo_cache, GURL("http://example.com/foo")));
557 EXPECT_LT(0, cache_storage->MemoryBackedSize()); 532 EXPECT_LT(0, cache_storage->MemoryBackedSize());
558 int64 foo_size = cache_storage->MemoryBackedSize(); 533 int64 foo_size = cache_storage->MemoryBackedSize();
559 534
560 EXPECT_TRUE(CachePut(bar_cache, GURL("http://example.com/foo"))); 535 EXPECT_TRUE(CachePut(bar_cache, GURL("http://example.com/foo")));
561 EXPECT_EQ(foo_size * 2, cache_storage->MemoryBackedSize()); 536 EXPECT_EQ(foo_size * 2, cache_storage->MemoryBackedSize());
562 } 537 }
563 538
564 TEST_F(ServiceWorkerCacheStorageManagerTest, MemoryBackedSizePersistent) { 539 TEST_F(CacheStorageManagerTest, MemoryBackedSizePersistent) {
565 ServiceWorkerCacheStorage* cache_storage = CacheStorageForOrigin(origin1_); 540 CacheStorage* cache_storage = CacheStorageForOrigin(origin1_);
566 EXPECT_EQ(0, cache_storage->MemoryBackedSize()); 541 EXPECT_EQ(0, cache_storage->MemoryBackedSize());
567 EXPECT_TRUE(Open(origin1_, "foo")); 542 EXPECT_TRUE(Open(origin1_, "foo"));
568 EXPECT_TRUE(CachePut(callback_cache_, GURL("http://example.com/foo"))); 543 EXPECT_TRUE(CachePut(callback_cache_, GURL("http://example.com/foo")));
569 EXPECT_EQ(0, cache_storage->MemoryBackedSize()); 544 EXPECT_EQ(0, cache_storage->MemoryBackedSize());
570 } 545 }
571 546
572 class ServiceWorkerCacheStorageMigrationTest 547 class CacheStorageMigrationTest : public CacheStorageManagerTest {
573 : public ServiceWorkerCacheStorageManagerTest {
574 protected: 548 protected:
575 ServiceWorkerCacheStorageMigrationTest() : cache1_("foo"), cache2_("bar") {} 549 CacheStorageMigrationTest() : cache1_("foo"), cache2_("bar") {}
576 550
577 void SetUp() override { 551 void SetUp() override {
578 ServiceWorkerCacheStorageManagerTest::SetUp(); 552 CacheStorageManagerTest::SetUp();
579 553
580 // Populate a cache, then move it to the "legacy" location 554 // Populate a cache, then move it to the "legacy" location
581 // so that tests can verify the results of migration. 555 // so that tests can verify the results of migration.
582 legacy_path_ = ServiceWorkerCacheStorageManager::ConstructLegacyOriginPath( 556 legacy_path_ = CacheStorageManager::ConstructLegacyOriginPath(
583 cache_manager_->root_path(), origin1_); 557 cache_manager_->root_path(), origin1_);
584 new_path_ = ServiceWorkerCacheStorageManager::ConstructOriginPath( 558 new_path_ = CacheStorageManager::ConstructOriginPath(
585 cache_manager_->root_path(), origin1_); 559 cache_manager_->root_path(), origin1_);
586 560
587 ASSERT_FALSE(base::DirectoryExists(legacy_path_)); 561 ASSERT_FALSE(base::DirectoryExists(legacy_path_));
588 ASSERT_FALSE(base::DirectoryExists(new_path_)); 562 ASSERT_FALSE(base::DirectoryExists(new_path_));
589 ASSERT_TRUE(Open(origin1_, cache1_)); 563 ASSERT_TRUE(Open(origin1_, cache1_));
590 ASSERT_TRUE(Open(origin1_, cache2_)); 564 ASSERT_TRUE(Open(origin1_, cache2_));
591 callback_cache_ = nullptr; 565 callback_cache_ = nullptr;
592 ASSERT_FALSE(base::DirectoryExists(legacy_path_)); 566 ASSERT_FALSE(base::DirectoryExists(legacy_path_));
593 ASSERT_TRUE(base::DirectoryExists(new_path_)); 567 ASSERT_TRUE(base::DirectoryExists(new_path_));
594 568
595 quota_manager_proxy_->SimulateQuotaManagerDestroyed(); 569 quota_manager_proxy_->SimulateQuotaManagerDestroyed();
596 cache_manager_ = 570 cache_manager_ = CacheStorageManager::Create(cache_manager_.get());
597 ServiceWorkerCacheStorageManager::Create(cache_manager_.get());
598 571
599 ASSERT_TRUE(base::Move(new_path_, legacy_path_)); 572 ASSERT_TRUE(base::Move(new_path_, legacy_path_));
600 ASSERT_TRUE(base::DirectoryExists(legacy_path_)); 573 ASSERT_TRUE(base::DirectoryExists(legacy_path_));
601 ASSERT_FALSE(base::DirectoryExists(new_path_)); 574 ASSERT_FALSE(base::DirectoryExists(new_path_));
602 } 575 }
603 576
604 int64 GetOriginUsage(const GURL& origin) { 577 int64 GetOriginUsage(const GURL& origin) {
605 scoped_ptr<base::RunLoop> loop(new base::RunLoop()); 578 scoped_ptr<base::RunLoop> loop(new base::RunLoop());
606 cache_manager_->GetOriginUsage( 579 cache_manager_->GetOriginUsage(
607 origin, 580 origin,
608 base::Bind(&ServiceWorkerCacheStorageMigrationTest::UsageCallback, 581 base::Bind(&CacheStorageMigrationTest::UsageCallback,
609 base::Unretained(this), base::Unretained(loop.get()))); 582 base::Unretained(this), base::Unretained(loop.get())));
610 loop->Run(); 583 loop->Run();
611 return callback_usage_; 584 return callback_usage_;
612 } 585 }
613 586
614 void UsageCallback(base::RunLoop* run_loop, int64 usage) { 587 void UsageCallback(base::RunLoop* run_loop, int64 usage) {
615 callback_usage_ = usage; 588 callback_usage_ = usage;
616 run_loop->Quit(); 589 run_loop->Quit();
617 } 590 }
618 591
619 base::FilePath legacy_path_; 592 base::FilePath legacy_path_;
620 base::FilePath new_path_; 593 base::FilePath new_path_;
621 594
622 const std::string cache1_; 595 const std::string cache1_;
623 const std::string cache2_; 596 const std::string cache2_;
624 597
625 int64 callback_usage_; 598 int64 callback_usage_;
626 599
627 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerCacheStorageMigrationTest); 600 DISALLOW_COPY_AND_ASSIGN(CacheStorageMigrationTest);
628 }; 601 };
629 602
630 TEST_F(ServiceWorkerCacheStorageMigrationTest, OpenCache) { 603 TEST_F(CacheStorageMigrationTest, OpenCache) {
631 EXPECT_TRUE(Open(origin1_, cache1_)); 604 EXPECT_TRUE(Open(origin1_, cache1_));
632 EXPECT_FALSE(base::DirectoryExists(legacy_path_)); 605 EXPECT_FALSE(base::DirectoryExists(legacy_path_));
633 EXPECT_TRUE(base::DirectoryExists(new_path_)); 606 EXPECT_TRUE(base::DirectoryExists(new_path_));
634 607
635 EXPECT_TRUE(Keys(origin1_)); 608 EXPECT_TRUE(Keys(origin1_));
636 std::vector<std::string> expected_keys; 609 std::vector<std::string> expected_keys;
637 expected_keys.push_back(cache1_); 610 expected_keys.push_back(cache1_);
638 expected_keys.push_back(cache2_); 611 expected_keys.push_back(cache2_);
639 EXPECT_EQ(expected_keys, callback_strings_); 612 EXPECT_EQ(expected_keys, callback_strings_);
640 } 613 }
641 614
642 TEST_F(ServiceWorkerCacheStorageMigrationTest, DeleteCache) { 615 TEST_F(CacheStorageMigrationTest, DeleteCache) {
643 EXPECT_TRUE(Delete(origin1_, cache1_)); 616 EXPECT_TRUE(Delete(origin1_, cache1_));
644 EXPECT_FALSE(base::DirectoryExists(legacy_path_)); 617 EXPECT_FALSE(base::DirectoryExists(legacy_path_));
645 EXPECT_TRUE(base::DirectoryExists(new_path_)); 618 EXPECT_TRUE(base::DirectoryExists(new_path_));
646 619
647 EXPECT_TRUE(Keys(origin1_)); 620 EXPECT_TRUE(Keys(origin1_));
648 std::vector<std::string> expected_keys; 621 std::vector<std::string> expected_keys;
649 expected_keys.push_back(cache2_); 622 expected_keys.push_back(cache2_);
650 EXPECT_EQ(expected_keys, callback_strings_); 623 EXPECT_EQ(expected_keys, callback_strings_);
651 } 624 }
652 625
653 TEST_F(ServiceWorkerCacheStorageMigrationTest, GetOriginUsage) { 626 TEST_F(CacheStorageMigrationTest, GetOriginUsage) {
654 EXPECT_GT(GetOriginUsage(origin1_), 0); 627 EXPECT_GT(GetOriginUsage(origin1_), 0);
655 EXPECT_FALSE(base::DirectoryExists(legacy_path_)); 628 EXPECT_FALSE(base::DirectoryExists(legacy_path_));
656 EXPECT_TRUE(base::DirectoryExists(new_path_)); 629 EXPECT_TRUE(base::DirectoryExists(new_path_));
657 } 630 }
658 631
659 TEST_F(ServiceWorkerCacheStorageMigrationTest, MoveFailure) { 632 TEST_F(CacheStorageMigrationTest, MoveFailure) {
660 // Revert the migration. 633 // Revert the migration.
661 ASSERT_TRUE(base::Move(legacy_path_, new_path_)); 634 ASSERT_TRUE(base::Move(legacy_path_, new_path_));
662 ASSERT_FALSE(base::DirectoryExists(legacy_path_)); 635 ASSERT_FALSE(base::DirectoryExists(legacy_path_));
663 ASSERT_TRUE(base::DirectoryExists(new_path_)); 636 ASSERT_TRUE(base::DirectoryExists(new_path_));
664 637
665 // Make a dummy legacy directory. 638 // Make a dummy legacy directory.
666 ASSERT_TRUE(base::CreateDirectory(legacy_path_)); 639 ASSERT_TRUE(base::CreateDirectory(legacy_path_));
667 640
668 // Ensure that migration doesn't stomp existing new directory, 641 // Ensure that migration doesn't stomp existing new directory,
669 // but does clean up old directory. 642 // but does clean up old directory.
670 EXPECT_TRUE(Open(origin1_, cache1_)); 643 EXPECT_TRUE(Open(origin1_, cache1_));
671 EXPECT_FALSE(base::DirectoryExists(legacy_path_)); 644 EXPECT_FALSE(base::DirectoryExists(legacy_path_));
672 EXPECT_TRUE(base::DirectoryExists(new_path_)); 645 EXPECT_TRUE(base::DirectoryExists(new_path_));
673 646
674 EXPECT_TRUE(Keys(origin1_)); 647 EXPECT_TRUE(Keys(origin1_));
675 std::vector<std::string> expected_keys; 648 std::vector<std::string> expected_keys;
676 expected_keys.push_back(cache1_); 649 expected_keys.push_back(cache1_);
677 expected_keys.push_back(cache2_); 650 expected_keys.push_back(cache2_);
678 EXPECT_EQ(expected_keys, callback_strings_); 651 EXPECT_EQ(expected_keys, callback_strings_);
679 } 652 }
680 653
681 class ServiceWorkerCacheQuotaClientTest 654 class CacheStorageQuotaClientTest : public CacheStorageManagerTest {
682 : public ServiceWorkerCacheStorageManagerTest {
683 protected: 655 protected:
684 ServiceWorkerCacheQuotaClientTest() {} 656 CacheStorageQuotaClientTest() {}
685 657
686 void SetUp() override { 658 void SetUp() override {
687 ServiceWorkerCacheStorageManagerTest::SetUp(); 659 CacheStorageManagerTest::SetUp();
688 quota_client_.reset( 660 quota_client_.reset(
689 new ServiceWorkerCacheQuotaClient(cache_manager_->AsWeakPtr())); 661 new CacheStorageQuotaClient(cache_manager_->AsWeakPtr()));
690 } 662 }
691 663
692 void UsageCallback(base::RunLoop* run_loop, int64 usage) { 664 void UsageCallback(base::RunLoop* run_loop, int64 usage) {
693 callback_usage_ = usage; 665 callback_usage_ = usage;
694 run_loop->Quit(); 666 run_loop->Quit();
695 } 667 }
696 668
697 void OriginsCallback(base::RunLoop* run_loop, const std::set<GURL>& origins) { 669 void OriginsCallback(base::RunLoop* run_loop, const std::set<GURL>& origins) {
698 callback_origins_ = origins; 670 callback_origins_ = origins;
699 run_loop->Quit(); 671 run_loop->Quit();
700 } 672 }
701 673
702 void DeleteOriginCallback(base::RunLoop* run_loop, 674 void DeleteOriginCallback(base::RunLoop* run_loop,
703 storage::QuotaStatusCode status) { 675 storage::QuotaStatusCode status) {
704 callback_status_ = status; 676 callback_status_ = status;
705 run_loop->Quit(); 677 run_loop->Quit();
706 } 678 }
707 679
708 int64 QuotaGetOriginUsage(const GURL& origin) { 680 int64 QuotaGetOriginUsage(const GURL& origin) {
709 scoped_ptr<base::RunLoop> loop(new base::RunLoop()); 681 scoped_ptr<base::RunLoop> loop(new base::RunLoop());
710 quota_client_->GetOriginUsage( 682 quota_client_->GetOriginUsage(
711 origin, 683 origin, storage::kStorageTypeTemporary,
712 storage::kStorageTypeTemporary, 684 base::Bind(&CacheStorageQuotaClientTest::UsageCallback,
713 base::Bind(&ServiceWorkerCacheQuotaClientTest::UsageCallback, 685 base::Unretained(this), base::Unretained(loop.get())));
714 base::Unretained(this),
715 base::Unretained(loop.get())));
716 loop->Run(); 686 loop->Run();
717 return callback_usage_; 687 return callback_usage_;
718 } 688 }
719 689
720 size_t QuotaGetOriginsForType() { 690 size_t QuotaGetOriginsForType() {
721 scoped_ptr<base::RunLoop> loop(new base::RunLoop()); 691 scoped_ptr<base::RunLoop> loop(new base::RunLoop());
722 quota_client_->GetOriginsForType( 692 quota_client_->GetOriginsForType(
723 storage::kStorageTypeTemporary, 693 storage::kStorageTypeTemporary,
724 base::Bind(&ServiceWorkerCacheQuotaClientTest::OriginsCallback, 694 base::Bind(&CacheStorageQuotaClientTest::OriginsCallback,
725 base::Unretained(this), 695 base::Unretained(this), base::Unretained(loop.get())));
726 base::Unretained(loop.get())));
727 loop->Run(); 696 loop->Run();
728 return callback_origins_.size(); 697 return callback_origins_.size();
729 } 698 }
730 699
731 size_t QuotaGetOriginsForHost(const std::string& host) { 700 size_t QuotaGetOriginsForHost(const std::string& host) {
732 scoped_ptr<base::RunLoop> loop(new base::RunLoop()); 701 scoped_ptr<base::RunLoop> loop(new base::RunLoop());
733 quota_client_->GetOriginsForHost( 702 quota_client_->GetOriginsForHost(
734 storage::kStorageTypeTemporary, 703 storage::kStorageTypeTemporary, host,
735 host, 704 base::Bind(&CacheStorageQuotaClientTest::OriginsCallback,
736 base::Bind(&ServiceWorkerCacheQuotaClientTest::OriginsCallback, 705 base::Unretained(this), base::Unretained(loop.get())));
737 base::Unretained(this),
738 base::Unretained(loop.get())));
739 loop->Run(); 706 loop->Run();
740 return callback_origins_.size(); 707 return callback_origins_.size();
741 } 708 }
742 709
743 bool QuotaDeleteOriginData(const GURL& origin) { 710 bool QuotaDeleteOriginData(const GURL& origin) {
744 scoped_ptr<base::RunLoop> loop(new base::RunLoop()); 711 scoped_ptr<base::RunLoop> loop(new base::RunLoop());
745 quota_client_->DeleteOriginData( 712 quota_client_->DeleteOriginData(
746 origin, 713 origin, storage::kStorageTypeTemporary,
747 storage::kStorageTypeTemporary, 714 base::Bind(&CacheStorageQuotaClientTest::DeleteOriginCallback,
748 base::Bind(&ServiceWorkerCacheQuotaClientTest::DeleteOriginCallback, 715 base::Unretained(this), base::Unretained(loop.get())));
749 base::Unretained(this),
750 base::Unretained(loop.get())));
751 loop->Run(); 716 loop->Run();
752 return callback_status_ == storage::kQuotaStatusOk; 717 return callback_status_ == storage::kQuotaStatusOk;
753 } 718 }
754 719
755 bool QuotaDoesSupport(storage::StorageType type) { 720 bool QuotaDoesSupport(storage::StorageType type) {
756 return quota_client_->DoesSupport(type); 721 return quota_client_->DoesSupport(type);
757 } 722 }
758 723
759 scoped_ptr<ServiceWorkerCacheQuotaClient> quota_client_; 724 scoped_ptr<CacheStorageQuotaClient> quota_client_;
760 725
761 storage::QuotaStatusCode callback_status_; 726 storage::QuotaStatusCode callback_status_;
762 int64 callback_usage_; 727 int64 callback_usage_;
763 std::set<GURL> callback_origins_; 728 std::set<GURL> callback_origins_;
764 729
765 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerCacheQuotaClientTest); 730 DISALLOW_COPY_AND_ASSIGN(CacheStorageQuotaClientTest);
766 }; 731 };
767 732
768 class ServiceWorkerCacheQuotaClientTestP 733 class CacheStorageQuotaClientTestP : public CacheStorageQuotaClientTest,
769 : public ServiceWorkerCacheQuotaClientTest, 734 public testing::WithParamInterface<bool> {
770 public testing::WithParamInterface<bool> {
771 bool MemoryOnly() override { return !GetParam(); } 735 bool MemoryOnly() override { return !GetParam(); }
772 }; 736 };
773 737
774 TEST_P(ServiceWorkerCacheQuotaClientTestP, QuotaID) { 738 TEST_P(CacheStorageQuotaClientTestP, QuotaID) {
775 EXPECT_EQ(storage::QuotaClient::kServiceWorkerCache, quota_client_->id()); 739 EXPECT_EQ(storage::QuotaClient::kServiceWorkerCache, quota_client_->id());
776 } 740 }
777 741
778 TEST_P(ServiceWorkerCacheQuotaClientTestP, QuotaGetOriginUsage) { 742 TEST_P(CacheStorageQuotaClientTestP, QuotaGetOriginUsage) {
779 EXPECT_EQ(0, QuotaGetOriginUsage(origin1_)); 743 EXPECT_EQ(0, QuotaGetOriginUsage(origin1_));
780 EXPECT_TRUE(Open(origin1_, "foo")); 744 EXPECT_TRUE(Open(origin1_, "foo"));
781 EXPECT_TRUE(CachePut(callback_cache_, GURL("http://example.com/foo"))); 745 EXPECT_TRUE(CachePut(callback_cache_, GURL("http://example.com/foo")));
782 EXPECT_LT(0, QuotaGetOriginUsage(origin1_)); 746 EXPECT_LT(0, QuotaGetOriginUsage(origin1_));
783 } 747 }
784 748
785 TEST_P(ServiceWorkerCacheQuotaClientTestP, QuotaGetOriginsForType) { 749 TEST_P(CacheStorageQuotaClientTestP, QuotaGetOriginsForType) {
786 EXPECT_EQ(0u, QuotaGetOriginsForType()); 750 EXPECT_EQ(0u, QuotaGetOriginsForType());
787 EXPECT_TRUE(Open(origin1_, "foo")); 751 EXPECT_TRUE(Open(origin1_, "foo"));
788 EXPECT_TRUE(Open(origin1_, "bar")); 752 EXPECT_TRUE(Open(origin1_, "bar"));
789 EXPECT_TRUE(Open(origin2_, "foo")); 753 EXPECT_TRUE(Open(origin2_, "foo"));
790 EXPECT_EQ(2u, QuotaGetOriginsForType()); 754 EXPECT_EQ(2u, QuotaGetOriginsForType());
791 } 755 }
792 756
793 TEST_P(ServiceWorkerCacheQuotaClientTestP, QuotaGetOriginsForHost) { 757 TEST_P(CacheStorageQuotaClientTestP, QuotaGetOriginsForHost) {
794 EXPECT_EQ(0u, QuotaGetOriginsForHost("example.com")); 758 EXPECT_EQ(0u, QuotaGetOriginsForHost("example.com"));
795 EXPECT_TRUE(Open(GURL("http://example.com:8080"), "foo")); 759 EXPECT_TRUE(Open(GURL("http://example.com:8080"), "foo"));
796 EXPECT_TRUE(Open(GURL("http://example.com:9000"), "foo")); 760 EXPECT_TRUE(Open(GURL("http://example.com:9000"), "foo"));
797 EXPECT_TRUE(Open(GURL("ftp://example.com"), "foo")); 761 EXPECT_TRUE(Open(GURL("ftp://example.com"), "foo"));
798 EXPECT_TRUE(Open(GURL("http://example2.com"), "foo")); 762 EXPECT_TRUE(Open(GURL("http://example2.com"), "foo"));
799 EXPECT_EQ(3u, QuotaGetOriginsForHost("example.com")); 763 EXPECT_EQ(3u, QuotaGetOriginsForHost("example.com"));
800 EXPECT_EQ(1u, QuotaGetOriginsForHost("example2.com")); 764 EXPECT_EQ(1u, QuotaGetOriginsForHost("example2.com"));
801 EXPECT_TRUE(callback_origins_.find(GURL("http://example2.com")) != 765 EXPECT_TRUE(callback_origins_.find(GURL("http://example2.com")) !=
802 callback_origins_.end()); 766 callback_origins_.end());
803 EXPECT_EQ(0u, QuotaGetOriginsForHost("unknown.com")); 767 EXPECT_EQ(0u, QuotaGetOriginsForHost("unknown.com"));
804 } 768 }
805 769
806 TEST_P(ServiceWorkerCacheQuotaClientTestP, QuotaDeleteOriginData) { 770 TEST_P(CacheStorageQuotaClientTestP, QuotaDeleteOriginData) {
807 EXPECT_TRUE(Open(origin1_, "foo")); 771 EXPECT_TRUE(Open(origin1_, "foo"));
808 // Call put to test that initialized caches are properly deleted too. 772 // Call put to test that initialized caches are properly deleted too.
809 EXPECT_TRUE(CachePut(callback_cache_, GURL("http://example.com/foo"))); 773 EXPECT_TRUE(CachePut(callback_cache_, GURL("http://example.com/foo")));
810 EXPECT_TRUE(Open(origin1_, "bar")); 774 EXPECT_TRUE(Open(origin1_, "bar"));
811 EXPECT_TRUE(Open(origin2_, "baz")); 775 EXPECT_TRUE(Open(origin2_, "baz"));
812 776
813 EXPECT_TRUE(QuotaDeleteOriginData(origin1_)); 777 EXPECT_TRUE(QuotaDeleteOriginData(origin1_));
814 778
815 EXPECT_FALSE(Has(origin1_, "foo")); 779 EXPECT_FALSE(Has(origin1_, "foo"));
816 EXPECT_FALSE(Has(origin1_, "bar")); 780 EXPECT_FALSE(Has(origin1_, "bar"));
817 EXPECT_TRUE(Has(origin2_, "baz")); 781 EXPECT_TRUE(Has(origin2_, "baz"));
818 EXPECT_TRUE(Open(origin1_, "foo")); 782 EXPECT_TRUE(Open(origin1_, "foo"));
819 } 783 }
820 784
821 TEST_P(ServiceWorkerCacheQuotaClientTestP, QuotaDeleteEmptyOrigin) { 785 TEST_P(CacheStorageQuotaClientTestP, QuotaDeleteEmptyOrigin) {
822 EXPECT_TRUE(QuotaDeleteOriginData(origin1_)); 786 EXPECT_TRUE(QuotaDeleteOriginData(origin1_));
823 } 787 }
824 788
825 TEST_P(ServiceWorkerCacheQuotaClientTestP, QuotaDoesSupport) { 789 TEST_P(CacheStorageQuotaClientTestP, QuotaDoesSupport) {
826 EXPECT_TRUE(QuotaDoesSupport(storage::kStorageTypeTemporary)); 790 EXPECT_TRUE(QuotaDoesSupport(storage::kStorageTypeTemporary));
827 EXPECT_FALSE(QuotaDoesSupport(storage::kStorageTypePersistent)); 791 EXPECT_FALSE(QuotaDoesSupport(storage::kStorageTypePersistent));
828 EXPECT_FALSE(QuotaDoesSupport(storage::kStorageTypeSyncable)); 792 EXPECT_FALSE(QuotaDoesSupport(storage::kStorageTypeSyncable));
829 EXPECT_FALSE(QuotaDoesSupport(storage::kStorageTypeQuotaNotManaged)); 793 EXPECT_FALSE(QuotaDoesSupport(storage::kStorageTypeQuotaNotManaged));
830 EXPECT_FALSE(QuotaDoesSupport(storage::kStorageTypeUnknown)); 794 EXPECT_FALSE(QuotaDoesSupport(storage::kStorageTypeUnknown));
831 } 795 }
832 796
833 INSTANTIATE_TEST_CASE_P(ServiceWorkerCacheStorageManagerTests, 797 INSTANTIATE_TEST_CASE_P(CacheStorageManagerTests,
834 ServiceWorkerCacheStorageManagerTestP, 798 CacheStorageManagerTestP,
835 ::testing::Values(false, true)); 799 ::testing::Values(false, true));
836 800
837 INSTANTIATE_TEST_CASE_P(ServiceWorkerCacheQuotaClientTests, 801 INSTANTIATE_TEST_CASE_P(CacheStorageQuotaClientTests,
838 ServiceWorkerCacheQuotaClientTestP, 802 CacheStorageQuotaClientTestP,
839 ::testing::Values(false, true)); 803 ::testing::Values(false, true));
840 804
841 } // namespace content 805 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/cache_storage/cache_storage_manager.cc ('k') | content/browser/cache_storage/cache_storage_proto.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698