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

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

Issue 1113303003: CacheStorage: Support multiple batch operations (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@remove_responses
Patch Set: 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 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 blink::WebServiceWorkerResponseTypeDefault, headers, "", 0, GURL()); 245 blink::WebServiceWorkerResponseTypeDefault, headers, "", 0, GURL());
246 } 246 }
247 247
248 scoped_ptr<ServiceWorkerFetchRequest> CopyFetchRequest( 248 scoped_ptr<ServiceWorkerFetchRequest> CopyFetchRequest(
249 const ServiceWorkerFetchRequest& request) { 249 const ServiceWorkerFetchRequest& request) {
250 return make_scoped_ptr(new ServiceWorkerFetchRequest( 250 return make_scoped_ptr(new ServiceWorkerFetchRequest(
251 request.url, request.method, request.headers, request.referrer, 251 request.url, request.method, request.headers, request.referrer,
252 request.is_reload)); 252 request.is_reload));
253 } 253 }
254 254
255 scoped_ptr<ServiceWorkerResponse> CopyFetchResponse(
256 const ServiceWorkerResponse& response) {
257 scoped_ptr<ServiceWorkerResponse> sw_response(new ServiceWorkerResponse(
258 response.url, response.status_code, response.status_text,
259 response.response_type, response.headers, response.blob_uuid,
260 response.blob_size, response.stream_url));
261 return sw_response.Pass();
262 }
263
264 bool Put(const ServiceWorkerFetchRequest& request, 255 bool Put(const ServiceWorkerFetchRequest& request,
265 const ServiceWorkerResponse& response) { 256 const ServiceWorkerResponse& response) {
257 CacheStorageBatchOperation operation;
258 operation.operation_type = CACHE_STORAGE_CACHE_OPERATION_TYPE_PUT;
259 operation.request = request;
260 operation.response = response;
261
266 scoped_ptr<base::RunLoop> loop(new base::RunLoop()); 262 scoped_ptr<base::RunLoop> loop(new base::RunLoop());
267 263
268 cache_->Put( 264 cache_->BatchOperation(
269 CopyFetchRequest(request), CopyFetchResponse(response), 265 std::vector<CacheStorageBatchOperation>(1, operation),
270 base::Bind(&CacheStorageCacheTest::ErrorTypeCallback, 266 base::Bind(&CacheStorageCacheTest::ErrorTypeCallback,
271 base::Unretained(this), base::Unretained(loop.get()))); 267 base::Unretained(this), base::Unretained(loop.get())));
272 // TODO(jkarlin): These functions should use base::RunLoop().RunUntilIdle() 268 // TODO(jkarlin): These functions should use base::RunLoop().RunUntilIdle()
273 // once the cache uses a passed in MessageLoopProxy instead of the CACHE 269 // once the cache uses a passed in MessageLoopProxy instead of the CACHE
274 // thread. 270 // thread.
275 loop->Run(); 271 loop->Run();
276 272
277 return callback_error_ == CacheStorageCache::ERROR_TYPE_OK; 273 return callback_error_ == CacheStorageCache::ERROR_TYPE_OK;
278 } 274 }
279 275
280 bool Match(const ServiceWorkerFetchRequest& request) { 276 bool Match(const ServiceWorkerFetchRequest& request) {
281 scoped_ptr<base::RunLoop> loop(new base::RunLoop()); 277 scoped_ptr<base::RunLoop> loop(new base::RunLoop());
282 278
283 cache_->Match( 279 cache_->Match(
284 CopyFetchRequest(request), 280 CopyFetchRequest(request),
285 base::Bind(&CacheStorageCacheTest::ResponseAndErrorCallback, 281 base::Bind(&CacheStorageCacheTest::ResponseAndErrorCallback,
286 base::Unretained(this), base::Unretained(loop.get()))); 282 base::Unretained(this), base::Unretained(loop.get())));
287 loop->Run(); 283 loop->Run();
288 284
289 return callback_error_ == CacheStorageCache::ERROR_TYPE_OK; 285 return callback_error_ == CacheStorageCache::ERROR_TYPE_OK;
290 } 286 }
291 287
292 bool Delete(const ServiceWorkerFetchRequest& request) { 288 bool Delete(const ServiceWorkerFetchRequest& request) {
289 CacheStorageBatchOperation operation;
290 operation.operation_type = CACHE_STORAGE_CACHE_OPERATION_TYPE_DELETE;
291 operation.request = request;
292
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_->BatchOperation(
296 CopyFetchRequest(request), 296 std::vector<CacheStorageBatchOperation>(1, operation),
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_ == CacheStorageCache::ERROR_TYPE_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
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 471
472 TEST_P(CacheStorageCacheTestP, ResponseURLEmpty) { 472 TEST_P(CacheStorageCacheTestP, ResponseURLEmpty) {
473 no_body_response_.url = GURL(); 473 no_body_response_.url = GURL();
474 EXPECT_STRNE("", no_body_request_.url.spec().c_str()); 474 EXPECT_STRNE("", no_body_request_.url.spec().c_str());
475 EXPECT_TRUE(Put(no_body_request_, no_body_response_)); 475 EXPECT_TRUE(Put(no_body_request_, no_body_response_));
476 EXPECT_TRUE(Match(no_body_request_)); 476 EXPECT_TRUE(Match(no_body_request_));
477 EXPECT_STREQ("", callback_response_->url.spec().c_str()); 477 EXPECT_STREQ("", callback_response_->url.spec().c_str());
478 } 478 }
479 479
480 TEST_F(CacheStorageCacheTest, PutBodyDropBlobRef) { 480 TEST_F(CacheStorageCacheTest, PutBodyDropBlobRef) {
481 CacheStorageBatchOperation operation;
482 operation.operation_type = CACHE_STORAGE_CACHE_OPERATION_TYPE_PUT;
483 operation.request = body_request_;
484 operation.response = body_response_;
485
481 scoped_ptr<base::RunLoop> loop(new base::RunLoop()); 486 scoped_ptr<base::RunLoop> loop(new base::RunLoop());
482 cache_->Put(CopyFetchRequest(body_request_), 487 cache_->BatchOperation(
483 CopyFetchResponse(body_response_), 488 std::vector<CacheStorageBatchOperation>(1, operation),
484 base::Bind(&CacheStorageCacheTestP::ErrorTypeCallback, 489 base::Bind(&CacheStorageCacheTestP::ErrorTypeCallback,
485 base::Unretained(this), base::Unretained(loop.get()))); 490 base::Unretained(this), base::Unretained(loop.get())));
486 // The handle should be held by the cache now so the deref here should be 491 // The handle should be held by the cache now so the deref here should be
487 // okay. 492 // okay.
488 blob_handle_.reset(); 493 blob_handle_.reset();
489 loop->Run(); 494 loop->Run();
490 495
491 EXPECT_EQ(CacheStorageCache::ERROR_TYPE_OK, callback_error_); 496 EXPECT_EQ(CacheStorageCache::ERROR_TYPE_OK, callback_error_);
492 } 497 }
493 498
494 TEST_P(CacheStorageCacheTestP, PutReplace) { 499 TEST_P(CacheStorageCacheTestP, PutReplace) {
495 EXPECT_TRUE(Put(body_request_, no_body_response_)); 500 EXPECT_TRUE(Put(body_request_, no_body_response_));
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
757 762
758 TEST_P(CacheStorageCacheTestP, VerifySerialScheduling) { 763 TEST_P(CacheStorageCacheTestP, VerifySerialScheduling) {
759 // Start two operations, the first one is delayed but the second isn't. The 764 // Start two operations, the first one is delayed but the second isn't. The
760 // second should wait for the first. 765 // second should wait for the first.
761 EXPECT_TRUE(Keys()); // Opens the backend. 766 EXPECT_TRUE(Keys()); // Opens the backend.
762 DelayableBackend* delayable_backend = cache_->UseDelayableBackend(); 767 DelayableBackend* delayable_backend = cache_->UseDelayableBackend();
763 delayable_backend->set_delay_open(true); 768 delayable_backend->set_delay_open(true);
764 769
765 int sequence_out = -1; 770 int sequence_out = -1;
766 771
767 scoped_ptr<ServiceWorkerResponse> response1 = 772 CacheStorageBatchOperation operation1;
768 CopyFetchResponse(body_response_); 773 operation1.operation_type = CACHE_STORAGE_CACHE_OPERATION_TYPE_PUT;
774 operation1.request = body_request_;
775 operation1.response = body_response_;
776
769 scoped_ptr<base::RunLoop> close_loop1(new base::RunLoop()); 777 scoped_ptr<base::RunLoop> close_loop1(new base::RunLoop());
770 cache_->Put( 778 cache_->BatchOperation(
771 CopyFetchRequest(body_request_), response1.Pass(), 779 std::vector<CacheStorageBatchOperation>(1, operation1),
772 base::Bind(&CacheStorageCacheTest::SequenceCallback, 780 base::Bind(&CacheStorageCacheTest::SequenceCallback,
773 base::Unretained(this), 1, &sequence_out, close_loop1.get())); 781 base::Unretained(this), 1, &sequence_out, close_loop1.get()));
774 782
775 // Blocks on opening the cache entry. 783 // Blocks on opening the cache entry.
776 base::RunLoop().RunUntilIdle(); 784 base::RunLoop().RunUntilIdle();
777 785
786 CacheStorageBatchOperation operation2;
787 operation2.operation_type = CACHE_STORAGE_CACHE_OPERATION_TYPE_PUT;
788 operation2.request = body_request_;
789 operation2.response = body_response_;
790
778 delayable_backend->set_delay_open(false); 791 delayable_backend->set_delay_open(false);
779 scoped_ptr<ServiceWorkerResponse> response2 =
780 CopyFetchResponse(body_response_);
781 scoped_ptr<base::RunLoop> close_loop2(new base::RunLoop()); 792 scoped_ptr<base::RunLoop> close_loop2(new base::RunLoop());
782 cache_->Put( 793 cache_->BatchOperation(
783 CopyFetchRequest(body_request_), response2.Pass(), 794 std::vector<CacheStorageBatchOperation>(1, operation2),
784 base::Bind(&CacheStorageCacheTest::SequenceCallback, 795 base::Bind(&CacheStorageCacheTest::SequenceCallback,
785 base::Unretained(this), 2, &sequence_out, close_loop2.get())); 796 base::Unretained(this), 2, &sequence_out, close_loop2.get()));
786 797
787 // The second put operation should wait for the first to complete. 798 // The second put operation should wait for the first to complete.
788 base::RunLoop().RunUntilIdle(); 799 base::RunLoop().RunUntilIdle();
789 EXPECT_FALSE(callback_response_); 800 EXPECT_FALSE(callback_response_);
790 801
791 delayable_backend->OpenEntryContinue(); 802 delayable_backend->OpenEntryContinue();
792 close_loop1->Run(); 803 close_loop1->Run();
793 EXPECT_EQ(1, sequence_out); 804 EXPECT_EQ(1, sequence_out);
794 close_loop2->Run(); 805 close_loop2->Run();
795 EXPECT_EQ(2, sequence_out); 806 EXPECT_EQ(2, sequence_out);
796 } 807 }
797 808
798 INSTANTIATE_TEST_CASE_P(CacheStorageCacheTest, 809 INSTANTIATE_TEST_CASE_P(CacheStorageCacheTest,
799 CacheStorageCacheTestP, 810 CacheStorageCacheTestP,
800 ::testing::Values(false, true)); 811 ::testing::Values(false, true));
801 812
802 } // namespace content 813 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698