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

Side by Side Diff: content/browser/service_worker/service_worker_cache_unittest.cc

Issue 985053002: [ServiceWorkerCache] Cache and CacheStorage creation UMA (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Also monitor cache storage creation Created 5 years, 9 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.h" 5 #include "content/browser/service_worker/service_worker_cache.h"
6 6
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/files/scoped_temp_dir.h" 8 #include "base/files/scoped_temp_dir.h"
9 #include "base/message_loop/message_loop_proxy.h" 9 #include "base/message_loop/message_loop_proxy.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 bool delay_backend_creation_; 167 bool delay_backend_creation_;
168 ErrorCallback backend_creation_callback_; 168 ErrorCallback backend_creation_callback_;
169 169
170 DISALLOW_COPY_AND_ASSIGN(TestServiceWorkerCache); 170 DISALLOW_COPY_AND_ASSIGN(TestServiceWorkerCache);
171 }; 171 };
172 172
173 class ServiceWorkerCacheTest : public testing::Test { 173 class ServiceWorkerCacheTest : public testing::Test {
174 public: 174 public:
175 ServiceWorkerCacheTest() 175 ServiceWorkerCacheTest()
176 : browser_thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP), 176 : browser_thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP),
177 callback_error_(ServiceWorkerCache::ErrorTypeOK), 177 callback_error_(ServiceWorkerCache::ERROR_TYPE_OK),
178 callback_closed_(false) {} 178 callback_closed_(false) {}
179 179
180 void SetUp() override { 180 void SetUp() override {
181 ChromeBlobStorageContext* blob_storage_context = 181 ChromeBlobStorageContext* blob_storage_context =
182 ChromeBlobStorageContext::GetFor(&browser_context_); 182 ChromeBlobStorageContext::GetFor(&browser_context_);
183 // Wait for chrome_blob_storage_context to finish initializing. 183 // Wait for chrome_blob_storage_context to finish initializing.
184 base::RunLoop().RunUntilIdle(); 184 base::RunLoop().RunUntilIdle();
185 blob_storage_context_ = blob_storage_context->context(); 185 blob_storage_context_ = blob_storage_context->context();
186 186
187 quota_manager_proxy_ = new MockQuotaManagerProxy( 187 quota_manager_proxy_ = new MockQuotaManagerProxy(
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 cache_->Put(CopyFetchRequest(request), 288 cache_->Put(CopyFetchRequest(request),
289 CopyFetchResponse(response), 289 CopyFetchResponse(response),
290 base::Bind(&ServiceWorkerCacheTest::ResponseAndErrorCallback, 290 base::Bind(&ServiceWorkerCacheTest::ResponseAndErrorCallback,
291 base::Unretained(this), 291 base::Unretained(this),
292 base::Unretained(loop.get()))); 292 base::Unretained(loop.get())));
293 // TODO(jkarlin): These functions should use base::RunLoop().RunUntilIdle() 293 // TODO(jkarlin): These functions should use base::RunLoop().RunUntilIdle()
294 // once the cache uses a passed in MessageLoopProxy instead of the CACHE 294 // once the cache uses a passed in MessageLoopProxy instead of the CACHE
295 // thread. 295 // thread.
296 loop->Run(); 296 loop->Run();
297 297
298 return callback_error_ == ServiceWorkerCache::ErrorTypeOK; 298 return callback_error_ == ServiceWorkerCache::ERROR_TYPE_OK;
299 } 299 }
300 300
301 bool Match(const ServiceWorkerFetchRequest& request) { 301 bool Match(const ServiceWorkerFetchRequest& request) {
302 scoped_ptr<base::RunLoop> loop(new base::RunLoop()); 302 scoped_ptr<base::RunLoop> loop(new base::RunLoop());
303 303
304 cache_->Match(CopyFetchRequest(request), 304 cache_->Match(CopyFetchRequest(request),
305 base::Bind(&ServiceWorkerCacheTest::ResponseAndErrorCallback, 305 base::Bind(&ServiceWorkerCacheTest::ResponseAndErrorCallback,
306 base::Unretained(this), 306 base::Unretained(this),
307 base::Unretained(loop.get()))); 307 base::Unretained(loop.get())));
308 loop->Run(); 308 loop->Run();
309 309
310 return callback_error_ == ServiceWorkerCache::ErrorTypeOK; 310 return callback_error_ == ServiceWorkerCache::ERROR_TYPE_OK;
311 } 311 }
312 312
313 bool Delete(const ServiceWorkerFetchRequest& request) { 313 bool Delete(const ServiceWorkerFetchRequest& request) {
314 scoped_ptr<base::RunLoop> loop(new base::RunLoop()); 314 scoped_ptr<base::RunLoop> loop(new base::RunLoop());
315 315
316 cache_->Delete(CopyFetchRequest(request), 316 cache_->Delete(CopyFetchRequest(request),
317 base::Bind(&ServiceWorkerCacheTest::ErrorTypeCallback, 317 base::Bind(&ServiceWorkerCacheTest::ErrorTypeCallback,
318 base::Unretained(this), 318 base::Unretained(this),
319 base::Unretained(loop.get()))); 319 base::Unretained(loop.get())));
320 loop->Run(); 320 loop->Run();
321 321
322 return callback_error_ == ServiceWorkerCache::ErrorTypeOK; 322 return callback_error_ == ServiceWorkerCache::ERROR_TYPE_OK;
323 } 323 }
324 324
325 bool Keys() { 325 bool Keys() {
326 scoped_ptr<base::RunLoop> loop(new base::RunLoop()); 326 scoped_ptr<base::RunLoop> loop(new base::RunLoop());
327 327
328 cache_->Keys(base::Bind(&ServiceWorkerCacheTest::RequestsCallback, 328 cache_->Keys(base::Bind(&ServiceWorkerCacheTest::RequestsCallback,
329 base::Unretained(this), 329 base::Unretained(this),
330 base::Unretained(loop.get()))); 330 base::Unretained(loop.get())));
331 loop->Run(); 331 loop->Run();
332 332
333 return callback_error_ == ServiceWorkerCache::ErrorTypeOK; 333 return callback_error_ == ServiceWorkerCache::ERROR_TYPE_OK;
334 } 334 }
335 335
336 bool Close() { 336 bool Close() {
337 scoped_ptr<base::RunLoop> loop(new base::RunLoop()); 337 scoped_ptr<base::RunLoop> loop(new base::RunLoop());
338 338
339 cache_->Close(base::Bind(&ServiceWorkerCacheTest::CloseCallback, 339 cache_->Close(base::Bind(&ServiceWorkerCacheTest::CloseCallback,
340 base::Unretained(this), 340 base::Unretained(this),
341 base::Unretained(loop.get()))); 341 base::Unretained(loop.get())));
342 loop->Run(); 342 loop->Run();
343 return callback_closed_; 343 return callback_closed_;
(...skipping 20 matching lines...) Expand all
364 } 364 }
365 365
366 void ResponseAndErrorCallback( 366 void ResponseAndErrorCallback(
367 base::RunLoop* run_loop, 367 base::RunLoop* run_loop,
368 ServiceWorkerCache::ErrorType error, 368 ServiceWorkerCache::ErrorType error,
369 scoped_ptr<ServiceWorkerResponse> response, 369 scoped_ptr<ServiceWorkerResponse> response,
370 scoped_ptr<storage::BlobDataHandle> body_handle) { 370 scoped_ptr<storage::BlobDataHandle> body_handle) {
371 callback_error_ = error; 371 callback_error_ = error;
372 callback_response_ = response.Pass(); 372 callback_response_ = response.Pass();
373 callback_response_data_.reset(); 373 callback_response_data_.reset();
374 if (error == ServiceWorkerCache::ErrorTypeOK && 374 if (error == ServiceWorkerCache::ERROR_TYPE_OK &&
375 !callback_response_->blob_uuid.empty()) { 375 !callback_response_->blob_uuid.empty()) {
376 callback_response_data_ = body_handle.Pass(); 376 callback_response_data_ = body_handle.Pass();
377 } 377 }
378 378
379 if (run_loop) 379 if (run_loop)
380 run_loop->Quit(); 380 run_loop->Quit();
381 } 381 }
382 382
383 void CloseCallback(base::RunLoop* run_loop) { 383 void CloseCallback(base::RunLoop* run_loop) {
384 EXPECT_FALSE(callback_closed_); 384 EXPECT_FALSE(callback_closed_);
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 cache_->Put(CopyFetchRequest(body_request_), 509 cache_->Put(CopyFetchRequest(body_request_),
510 CopyFetchResponse(body_response_), 510 CopyFetchResponse(body_response_),
511 base::Bind(&ServiceWorkerCacheTestP::ResponseAndErrorCallback, 511 base::Bind(&ServiceWorkerCacheTestP::ResponseAndErrorCallback,
512 base::Unretained(this), 512 base::Unretained(this),
513 base::Unretained(loop.get()))); 513 base::Unretained(loop.get())));
514 // The handle should be held by the cache now so the deref here should be 514 // The handle should be held by the cache now so the deref here should be
515 // okay. 515 // okay.
516 blob_handle_.reset(); 516 blob_handle_.reset();
517 loop->Run(); 517 loop->Run();
518 518
519 EXPECT_EQ(ServiceWorkerCache::ErrorTypeOK, callback_error_); 519 EXPECT_EQ(ServiceWorkerCache::ERROR_TYPE_OK, callback_error_);
520 } 520 }
521 521
522 TEST_P(ServiceWorkerCacheTestP, PutReplace) { 522 TEST_P(ServiceWorkerCacheTestP, PutReplace) {
523 EXPECT_TRUE(Put(body_request_, no_body_response_)); 523 EXPECT_TRUE(Put(body_request_, no_body_response_));
524 EXPECT_TRUE(Match(body_request_)); 524 EXPECT_TRUE(Match(body_request_));
525 EXPECT_FALSE(callback_response_data_); 525 EXPECT_FALSE(callback_response_data_);
526 526
527 EXPECT_TRUE(Put(body_request_, body_response_)); 527 EXPECT_TRUE(Put(body_request_, body_response_));
528 EXPECT_TRUE(Match(body_request_)); 528 EXPECT_TRUE(Match(body_request_));
529 EXPECT_TRUE(callback_response_data_); 529 EXPECT_TRUE(callback_response_data_);
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
827 EXPECT_EQ(1, callback_response_->status_code); 827 EXPECT_EQ(1, callback_response_->status_code);
828 close_loop2->Run(); 828 close_loop2->Run();
829 EXPECT_EQ(2, callback_response_->status_code); 829 EXPECT_EQ(2, callback_response_->status_code);
830 } 830 }
831 831
832 INSTANTIATE_TEST_CASE_P(ServiceWorkerCacheTest, 832 INSTANTIATE_TEST_CASE_P(ServiceWorkerCacheTest,
833 ServiceWorkerCacheTestP, 833 ServiceWorkerCacheTestP,
834 ::testing::Values(false, true)); 834 ::testing::Values(false, true));
835 835
836 } // namespace content 836 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698