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

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

Issue 1957663004: [CacheStorage] Prioritize Size operations over other scheduled operations (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2661
Patch Set: Merge conflict fix Created 4 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
« no previous file with comments | « content/browser/cache_storage/cache_storage_cache.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 loop->Run(); 441 loop->Run();
442 return callback_closed_; 442 return callback_closed_;
443 } 443 }
444 444
445 int64_t Size() { 445 int64_t Size() {
446 // Storage notification happens after an operation completes. Let the any 446 // Storage notification happens after an operation completes. Let the any
447 // notifications complete before calling Size. 447 // notifications complete before calling Size.
448 base::RunLoop().RunUntilIdle(); 448 base::RunLoop().RunUntilIdle();
449 449
450 base::RunLoop run_loop; 450 base::RunLoop run_loop;
451 bool callback_called = false;
451 cache_->Size(base::Bind(&CacheStorageCacheTest::SizeCallback, 452 cache_->Size(base::Bind(&CacheStorageCacheTest::SizeCallback,
452 base::Unretained(this), &run_loop)); 453 base::Unretained(this), &run_loop,
454 &callback_called));
453 run_loop.Run(); 455 run_loop.Run();
456 EXPECT_TRUE(callback_called);
454 return callback_size_; 457 return callback_size_;
455 } 458 }
456 459
457 int64_t GetSizeThenClose() { 460 int64_t GetSizeThenClose() {
458 base::RunLoop run_loop; 461 base::RunLoop run_loop;
462 bool callback_called = false;
459 cache_->GetSizeThenClose(base::Bind(&CacheStorageCacheTest::SizeCallback, 463 cache_->GetSizeThenClose(base::Bind(&CacheStorageCacheTest::SizeCallback,
460 base::Unretained(this), &run_loop)); 464 base::Unretained(this), &run_loop,
465 &callback_called));
461 run_loop.Run(); 466 run_loop.Run();
467 EXPECT_TRUE(callback_called);
462 return callback_size_; 468 return callback_size_;
463 } 469 }
464 470
465 void RequestsCallback(base::RunLoop* run_loop, 471 void RequestsCallback(base::RunLoop* run_loop,
466 CacheStorageError error, 472 CacheStorageError error,
467 scoped_ptr<CacheStorageCache::Requests> requests) { 473 scoped_ptr<CacheStorageCache::Requests> requests) {
468 callback_error_ = error; 474 callback_error_ = error;
469 callback_strings_.clear(); 475 callback_strings_.clear();
470 if (requests) { 476 if (requests) {
471 for (size_t i = 0u; i < requests->size(); ++i) 477 for (size_t i = 0u; i < requests->size(); ++i)
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 quit_closure.Run(); 525 quit_closure.Run();
520 } 526 }
521 527
522 void CloseCallback(base::RunLoop* run_loop) { 528 void CloseCallback(base::RunLoop* run_loop) {
523 EXPECT_FALSE(callback_closed_); 529 EXPECT_FALSE(callback_closed_);
524 callback_closed_ = true; 530 callback_closed_ = true;
525 if (run_loop) 531 if (run_loop)
526 run_loop->Quit(); 532 run_loop->Quit();
527 } 533 }
528 534
529 void SizeCallback(base::RunLoop* run_loop, int64_t size) { 535 void SizeCallback(base::RunLoop* run_loop,
536 bool* callback_called,
537 int64_t size) {
538 *callback_called = true;
530 callback_size_ = size; 539 callback_size_ = size;
531 if (run_loop) 540 if (run_loop)
532 run_loop->Quit(); 541 run_loop->Quit();
533 } 542 }
534 543
535 bool VerifyKeys(const std::vector<std::string>& expected_keys) { 544 bool VerifyKeys(const std::vector<std::string>& expected_keys) {
536 if (expected_keys.size() != callback_strings_.size()) 545 if (expected_keys.size() != callback_strings_.size())
537 return false; 546 return false;
538 547
539 std::set<std::string> found_set; 548 std::set<std::string> found_set;
(...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after
1095 EXPECT_TRUE(Delete(no_body_request_)); 1104 EXPECT_TRUE(Delete(no_body_request_));
1096 EXPECT_EQ(0, Size()); 1105 EXPECT_EQ(0, Size());
1097 1106
1098 EXPECT_TRUE(Put(body_request_, body_response_)); 1107 EXPECT_TRUE(Put(body_request_, body_response_));
1099 EXPECT_LT(no_body_size, Size()); 1108 EXPECT_LT(no_body_size, Size());
1100 1109
1101 EXPECT_TRUE(Delete(body_request_)); 1110 EXPECT_TRUE(Delete(body_request_));
1102 EXPECT_EQ(0, Size()); 1111 EXPECT_EQ(0, Size());
1103 } 1112 }
1104 1113
1114 TEST_P(CacheStorageCacheTestP, SizeOperationsArePrioritized) {
1115 // Test that pending size operations (those waiting for initialization) run
1116 // before other scheduler operations.
1117 cache_->set_delay_backend_creation(true); // Delay cache initialization
1118
1119 CacheStorageBatchOperation operation;
1120 operation.operation_type = CACHE_STORAGE_CACHE_OPERATION_TYPE_PUT;
1121 operation.request = body_request_;
1122 operation.response = body_response_;
1123
1124 callback_error_ = CACHE_STORAGE_ERROR_NOT_FOUND;
1125 base::RunLoop run_loop;
1126 // Start a put operation that blocks on initialization.
1127 cache_->BatchOperation(std::vector<CacheStorageBatchOperation>(1, operation),
1128 base::Bind(&CacheStorageCacheTest::ErrorTypeCallback,
1129 base::Unretained(this), &run_loop));
1130
1131 // Next start a size operation that also blocks on initialization.
1132 bool size_callback_called = false;
1133 cache_->Size(base::Bind(&CacheStorageCacheTest::SizeCallback,
1134 base::Unretained(this), nullptr,
1135 &size_callback_called));
1136
1137 base::RunLoop().RunUntilIdle();
1138 EXPECT_FALSE(size_callback_called);
1139 EXPECT_EQ(CACHE_STORAGE_ERROR_NOT_FOUND, callback_error_);
1140
1141 // Finish initialization. The Size operation should complete before Put gets
1142 // to run as Size has priority. See crbug.com/605663.
1143 cache_->ContinueCreateBackend();
1144 run_loop.Run();
1145 EXPECT_TRUE(size_callback_called);
1146 EXPECT_EQ(CACHE_STORAGE_OK, callback_error_);
1147 }
1148
1105 TEST_P(CacheStorageCacheTestP, GetSizeThenClose) { 1149 TEST_P(CacheStorageCacheTestP, GetSizeThenClose) {
1106 EXPECT_TRUE(Put(body_request_, body_response_)); 1150 EXPECT_TRUE(Put(body_request_, body_response_));
1107 int64_t cache_size = Size(); 1151 int64_t cache_size = Size();
1108 EXPECT_EQ(cache_size, GetSizeThenClose()); 1152 EXPECT_EQ(cache_size, GetSizeThenClose());
1109 VerifyAllOpsFail(); 1153 VerifyAllOpsFail();
1110 } 1154 }
1111 1155
1112 TEST_P(CacheStorageCacheTestP, OpsFailOnClosedBackendNeverCreated) { 1156 TEST_P(CacheStorageCacheTestP, OpsFailOnClosedBackendNeverCreated) {
1113 cache_->set_delay_backend_creation( 1157 cache_->set_delay_backend_creation(
1114 true); // Will hang the test if a backend is created. 1158 true); // Will hang the test if a backend is created.
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1167 EXPECT_EQ(1, sequence_out); 1211 EXPECT_EQ(1, sequence_out);
1168 close_loop2->Run(); 1212 close_loop2->Run();
1169 EXPECT_EQ(2, sequence_out); 1213 EXPECT_EQ(2, sequence_out);
1170 } 1214 }
1171 1215
1172 INSTANTIATE_TEST_CASE_P(CacheStorageCacheTest, 1216 INSTANTIATE_TEST_CASE_P(CacheStorageCacheTest,
1173 CacheStorageCacheTestP, 1217 CacheStorageCacheTestP,
1174 ::testing::Values(false, true)); 1218 ::testing::Values(false, true));
1175 1219
1176 } // namespace content 1220 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/cache_storage/cache_storage_cache.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698