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

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

Issue 1132683003: CacheStorage: Merge CacheStorage::CacheStorageError and CacheStorageCache::ErrorType (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix more Created 5 years, 7 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/cache_storage/cache_storage_cache.h" 5 #include "content/browser/cache_storage/cache_storage_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 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 bool delay_backend_creation_; 168 bool delay_backend_creation_;
169 ErrorCallback backend_creation_callback_; 169 ErrorCallback backend_creation_callback_;
170 170
171 DISALLOW_COPY_AND_ASSIGN(TestCacheStorageCache); 171 DISALLOW_COPY_AND_ASSIGN(TestCacheStorageCache);
172 }; 172 };
173 173
174 class CacheStorageCacheTest : public testing::Test { 174 class CacheStorageCacheTest : public testing::Test {
175 public: 175 public:
176 CacheStorageCacheTest() 176 CacheStorageCacheTest()
177 : browser_thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP), 177 : browser_thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP),
178 callback_error_(CacheStorageCache::ERROR_TYPE_OK), 178 callback_error_(CACHE_STORAGE_OK),
179 callback_closed_(false) {} 179 callback_closed_(false) {}
180 180
181 void SetUp() override { 181 void SetUp() override {
182 ChromeBlobStorageContext* blob_storage_context = 182 ChromeBlobStorageContext* blob_storage_context =
183 ChromeBlobStorageContext::GetFor(&browser_context_); 183 ChromeBlobStorageContext::GetFor(&browser_context_);
184 // Wait for chrome_blob_storage_context to finish initializing. 184 // Wait for chrome_blob_storage_context to finish initializing.
185 base::RunLoop().RunUntilIdle(); 185 base::RunLoop().RunUntilIdle();
186 blob_storage_context_ = blob_storage_context->context(); 186 blob_storage_context_ = blob_storage_context->context();
187 187
188 quota_manager_proxy_ = new MockQuotaManagerProxy( 188 quota_manager_proxy_ = new MockQuotaManagerProxy(
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 267
268 cache_->Put( 268 cache_->Put(
269 CopyFetchRequest(request), CopyFetchResponse(response), 269 CopyFetchRequest(request), CopyFetchResponse(response),
270 base::Bind(&CacheStorageCacheTest::ErrorTypeCallback, 270 base::Bind(&CacheStorageCacheTest::ErrorTypeCallback,
271 base::Unretained(this), base::Unretained(loop.get()))); 271 base::Unretained(this), base::Unretained(loop.get())));
272 // TODO(jkarlin): These functions should use base::RunLoop().RunUntilIdle() 272 // TODO(jkarlin): These functions should use base::RunLoop().RunUntilIdle()
273 // once the cache uses a passed in MessageLoopProxy instead of the CACHE 273 // once the cache uses a passed in MessageLoopProxy instead of the CACHE
274 // thread. 274 // thread.
275 loop->Run(); 275 loop->Run();
276 276
277 return callback_error_ == CacheStorageCache::ERROR_TYPE_OK; 277 return callback_error_ == CACHE_STORAGE_OK;
278 } 278 }
279 279
280 bool Match(const ServiceWorkerFetchRequest& request) { 280 bool Match(const ServiceWorkerFetchRequest& request) {
281 scoped_ptr<base::RunLoop> loop(new base::RunLoop()); 281 scoped_ptr<base::RunLoop> loop(new base::RunLoop());
282 282
283 cache_->Match( 283 cache_->Match(
284 CopyFetchRequest(request), 284 CopyFetchRequest(request),
285 base::Bind(&CacheStorageCacheTest::ResponseAndErrorCallback, 285 base::Bind(&CacheStorageCacheTest::ResponseAndErrorCallback,
286 base::Unretained(this), base::Unretained(loop.get()))); 286 base::Unretained(this), base::Unretained(loop.get())));
287 loop->Run(); 287 loop->Run();
288 288
289 return callback_error_ == CacheStorageCache::ERROR_TYPE_OK; 289 return callback_error_ == CACHE_STORAGE_OK;
290 } 290 }
291 291
292 bool Delete(const ServiceWorkerFetchRequest& request) { 292 bool Delete(const ServiceWorkerFetchRequest& request) {
293 scoped_ptr<base::RunLoop> loop(new base::RunLoop()); 293 scoped_ptr<base::RunLoop> loop(new base::RunLoop());
294 294
295 cache_->Delete( 295 cache_->Delete(
296 CopyFetchRequest(request), 296 CopyFetchRequest(request),
297 base::Bind(&CacheStorageCacheTest::ErrorTypeCallback, 297 base::Bind(&CacheStorageCacheTest::ErrorTypeCallback,
298 base::Unretained(this), base::Unretained(loop.get()))); 298 base::Unretained(this), base::Unretained(loop.get())));
299 loop->Run(); 299 loop->Run();
300 300
301 return callback_error_ == CacheStorageCache::ERROR_TYPE_OK; 301 return callback_error_ == CACHE_STORAGE_OK;
302 } 302 }
303 303
304 bool Keys() { 304 bool Keys() {
305 scoped_ptr<base::RunLoop> loop(new base::RunLoop()); 305 scoped_ptr<base::RunLoop> loop(new base::RunLoop());
306 306
307 cache_->Keys(base::Bind(&CacheStorageCacheTest::RequestsCallback, 307 cache_->Keys(base::Bind(&CacheStorageCacheTest::RequestsCallback,
308 base::Unretained(this), 308 base::Unretained(this),
309 base::Unretained(loop.get()))); 309 base::Unretained(loop.get())));
310 loop->Run(); 310 loop->Run();
311 311
312 return callback_error_ == CacheStorageCache::ERROR_TYPE_OK; 312 return callback_error_ == CACHE_STORAGE_OK;
313 } 313 }
314 314
315 bool Close() { 315 bool Close() {
316 scoped_ptr<base::RunLoop> loop(new base::RunLoop()); 316 scoped_ptr<base::RunLoop> loop(new base::RunLoop());
317 317
318 cache_->Close(base::Bind(&CacheStorageCacheTest::CloseCallback, 318 cache_->Close(base::Bind(&CacheStorageCacheTest::CloseCallback,
319 base::Unretained(this), 319 base::Unretained(this),
320 base::Unretained(loop.get()))); 320 base::Unretained(loop.get())));
321 loop->Run(); 321 loop->Run();
322 return callback_closed_; 322 return callback_closed_;
323 } 323 }
324 324
325 void RequestsCallback(base::RunLoop* run_loop, 325 void RequestsCallback(base::RunLoop* run_loop,
326 CacheStorageCache::ErrorType error, 326 CacheStorageError error,
327 scoped_ptr<CacheStorageCache::Requests> requests) { 327 scoped_ptr<CacheStorageCache::Requests> requests) {
328 callback_error_ = error; 328 callback_error_ = error;
329 callback_strings_.clear(); 329 callback_strings_.clear();
330 if (requests) { 330 if (requests) {
331 for (size_t i = 0u; i < requests->size(); ++i) 331 for (size_t i = 0u; i < requests->size(); ++i)
332 callback_strings_.push_back(requests->at(i).url.spec()); 332 callback_strings_.push_back(requests->at(i).url.spec());
333 } 333 }
334 if (run_loop) 334 if (run_loop)
335 run_loop->Quit(); 335 run_loop->Quit();
336 } 336 }
337 337
338 void ErrorTypeCallback(base::RunLoop* run_loop, 338 void ErrorTypeCallback(base::RunLoop* run_loop, CacheStorageError error) {
339 CacheStorageCache::ErrorType error) {
340 callback_error_ = error; 339 callback_error_ = error;
341 if (run_loop) 340 if (run_loop)
342 run_loop->Quit(); 341 run_loop->Quit();
343 } 342 }
344 343
345 void SequenceCallback(int sequence, 344 void SequenceCallback(int sequence,
346 int* sequence_out, 345 int* sequence_out,
347 base::RunLoop* run_loop, 346 base::RunLoop* run_loop,
348 CacheStorageCache::ErrorType error) { 347 CacheStorageError error) {
349 *sequence_out = sequence; 348 *sequence_out = sequence;
350 callback_error_ = error; 349 callback_error_ = error;
351 if (run_loop) 350 if (run_loop)
352 run_loop->Quit(); 351 run_loop->Quit();
353 } 352 }
354 353
355 void ResponseAndErrorCallback( 354 void ResponseAndErrorCallback(
356 base::RunLoop* run_loop, 355 base::RunLoop* run_loop,
357 CacheStorageCache::ErrorType error, 356 CacheStorageError error,
358 scoped_ptr<ServiceWorkerResponse> response, 357 scoped_ptr<ServiceWorkerResponse> response,
359 scoped_ptr<storage::BlobDataHandle> body_handle) { 358 scoped_ptr<storage::BlobDataHandle> body_handle) {
360 callback_error_ = error; 359 callback_error_ = error;
361 callback_response_ = response.Pass(); 360 callback_response_ = response.Pass();
362 callback_response_data_.reset(); 361 callback_response_data_.reset();
363 if (error == CacheStorageCache::ERROR_TYPE_OK && 362 if (error == CACHE_STORAGE_OK && !callback_response_->blob_uuid.empty())
364 !callback_response_->blob_uuid.empty()) {
365 callback_response_data_ = body_handle.Pass(); 363 callback_response_data_ = body_handle.Pass();
366 }
367 364
368 if (run_loop) 365 if (run_loop)
369 run_loop->Quit(); 366 run_loop->Quit();
370 } 367 }
371 368
372 void CloseCallback(base::RunLoop* run_loop) { 369 void CloseCallback(base::RunLoop* run_loop) {
373 EXPECT_FALSE(callback_closed_); 370 EXPECT_FALSE(callback_closed_);
374 callback_closed_ = true; 371 callback_closed_ = true;
375 if (run_loop) 372 if (run_loop)
376 run_loop->Quit(); 373 run_loop->Quit();
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 base::ScopedTempDir temp_dir_; 423 base::ScopedTempDir temp_dir_;
427 scoped_refptr<TestCacheStorageCache> cache_; 424 scoped_refptr<TestCacheStorageCache> cache_;
428 425
429 ServiceWorkerFetchRequest body_request_; 426 ServiceWorkerFetchRequest body_request_;
430 ServiceWorkerResponse body_response_; 427 ServiceWorkerResponse body_response_;
431 ServiceWorkerFetchRequest no_body_request_; 428 ServiceWorkerFetchRequest no_body_request_;
432 ServiceWorkerResponse no_body_response_; 429 ServiceWorkerResponse no_body_response_;
433 scoped_ptr<storage::BlobDataHandle> blob_handle_; 430 scoped_ptr<storage::BlobDataHandle> blob_handle_;
434 std::string expected_blob_data_; 431 std::string expected_blob_data_;
435 432
436 CacheStorageCache::ErrorType callback_error_; 433 CacheStorageError callback_error_;
437 scoped_ptr<ServiceWorkerResponse> callback_response_; 434 scoped_ptr<ServiceWorkerResponse> callback_response_;
438 scoped_ptr<storage::BlobDataHandle> callback_response_data_; 435 scoped_ptr<storage::BlobDataHandle> callback_response_data_;
439 std::vector<std::string> callback_strings_; 436 std::vector<std::string> callback_strings_;
440 bool callback_closed_; 437 bool callback_closed_;
441 }; 438 };
442 439
443 class CacheStorageCacheTestP : public CacheStorageCacheTest, 440 class CacheStorageCacheTestP : public CacheStorageCacheTest,
444 public testing::WithParamInterface<bool> { 441 public testing::WithParamInterface<bool> {
445 bool MemoryOnly() override { return !GetParam(); } 442 bool MemoryOnly() override { return !GetParam(); }
446 }; 443 };
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 scoped_ptr<base::RunLoop> loop(new base::RunLoop()); 478 scoped_ptr<base::RunLoop> loop(new base::RunLoop());
482 cache_->Put(CopyFetchRequest(body_request_), 479 cache_->Put(CopyFetchRequest(body_request_),
483 CopyFetchResponse(body_response_), 480 CopyFetchResponse(body_response_),
484 base::Bind(&CacheStorageCacheTestP::ErrorTypeCallback, 481 base::Bind(&CacheStorageCacheTestP::ErrorTypeCallback,
485 base::Unretained(this), base::Unretained(loop.get()))); 482 base::Unretained(this), base::Unretained(loop.get())));
486 // The handle should be held by the cache now so the deref here should be 483 // The handle should be held by the cache now so the deref here should be
487 // okay. 484 // okay.
488 blob_handle_.reset(); 485 blob_handle_.reset();
489 loop->Run(); 486 loop->Run();
490 487
491 EXPECT_EQ(CacheStorageCache::ERROR_TYPE_OK, callback_error_); 488 EXPECT_EQ(CACHE_STORAGE_OK, callback_error_);
492 } 489 }
493 490
494 TEST_P(CacheStorageCacheTestP, PutReplace) { 491 TEST_P(CacheStorageCacheTestP, PutReplace) {
495 EXPECT_TRUE(Put(body_request_, no_body_response_)); 492 EXPECT_TRUE(Put(body_request_, no_body_response_));
496 EXPECT_TRUE(Match(body_request_)); 493 EXPECT_TRUE(Match(body_request_));
497 EXPECT_FALSE(callback_response_data_); 494 EXPECT_FALSE(callback_response_data_);
498 495
499 EXPECT_TRUE(Put(body_request_, body_response_)); 496 EXPECT_TRUE(Put(body_request_, body_response_));
500 EXPECT_TRUE(Match(body_request_)); 497 EXPECT_TRUE(Match(body_request_));
501 EXPECT_TRUE(callback_response_data_); 498 EXPECT_TRUE(callback_response_data_);
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
793 EXPECT_EQ(1, sequence_out); 790 EXPECT_EQ(1, sequence_out);
794 close_loop2->Run(); 791 close_loop2->Run();
795 EXPECT_EQ(2, sequence_out); 792 EXPECT_EQ(2, sequence_out);
796 } 793 }
797 794
798 INSTANTIATE_TEST_CASE_P(CacheStorageCacheTest, 795 INSTANTIATE_TEST_CASE_P(CacheStorageCacheTest,
799 CacheStorageCacheTestP, 796 CacheStorageCacheTestP,
800 ::testing::Values(false, true)); 797 ::testing::Values(false, true));
801 798
802 } // namespace content 799 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/cache_storage/cache_storage_cache.cc ('k') | content/browser/cache_storage/cache_storage_dispatcher_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698