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

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

Issue 1915893002: [CacheStorage] Prioritize Size operations over other scheduled operations (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2704
Patch Set: Created 4 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
« 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 456 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 loop->Run(); 467 loop->Run();
468 return callback_closed_; 468 return callback_closed_;
469 } 469 }
470 470
471 int64_t Size() { 471 int64_t Size() {
472 // Storage notification happens after an operation completes. Let the any 472 // Storage notification happens after an operation completes. Let the any
473 // notifications complete before calling Size. 473 // notifications complete before calling Size.
474 base::RunLoop().RunUntilIdle(); 474 base::RunLoop().RunUntilIdle();
475 475
476 base::RunLoop run_loop; 476 base::RunLoop run_loop;
477 bool callback_called = false;
477 cache_->Size(base::Bind(&CacheStorageCacheTest::SizeCallback, 478 cache_->Size(base::Bind(&CacheStorageCacheTest::SizeCallback,
478 base::Unretained(this), &run_loop)); 479 base::Unretained(this), &run_loop,
480 &callback_called));
479 run_loop.Run(); 481 run_loop.Run();
482 EXPECT_TRUE(callback_called);
480 return callback_size_; 483 return callback_size_;
481 } 484 }
482 485
483 int64_t GetSizeThenClose() { 486 int64_t GetSizeThenClose() {
484 base::RunLoop run_loop; 487 base::RunLoop run_loop;
488 bool callback_called = false;
485 cache_->GetSizeThenClose(base::Bind(&CacheStorageCacheTest::SizeCallback, 489 cache_->GetSizeThenClose(base::Bind(&CacheStorageCacheTest::SizeCallback,
486 base::Unretained(this), &run_loop)); 490 base::Unretained(this), &run_loop,
491 &callback_called));
487 run_loop.Run(); 492 run_loop.Run();
493 EXPECT_TRUE(callback_called);
488 return callback_size_; 494 return callback_size_;
489 } 495 }
490 496
491 void RequestsCallback(base::RunLoop* run_loop, 497 void RequestsCallback(base::RunLoop* run_loop,
492 CacheStorageError error, 498 CacheStorageError error,
493 scoped_ptr<CacheStorageCache::Requests> requests) { 499 scoped_ptr<CacheStorageCache::Requests> requests) {
494 callback_error_ = error; 500 callback_error_ = error;
495 callback_strings_.clear(); 501 callback_strings_.clear();
496 if (requests) { 502 if (requests) {
497 for (size_t i = 0u; i < requests->size(); ++i) 503 for (size_t i = 0u; i < requests->size(); ++i)
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
545 quit_closure.Run(); 551 quit_closure.Run();
546 } 552 }
547 553
548 void CloseCallback(base::RunLoop* run_loop) { 554 void CloseCallback(base::RunLoop* run_loop) {
549 EXPECT_FALSE(callback_closed_); 555 EXPECT_FALSE(callback_closed_);
550 callback_closed_ = true; 556 callback_closed_ = true;
551 if (run_loop) 557 if (run_loop)
552 run_loop->Quit(); 558 run_loop->Quit();
553 } 559 }
554 560
555 void SizeCallback(base::RunLoop* run_loop, int64_t size) { 561 void SizeCallback(base::RunLoop* run_loop,
562 bool* callback_called,
563 int64_t size) {
564 *callback_called = true;
556 callback_size_ = size; 565 callback_size_ = size;
557 if (run_loop) 566 if (run_loop)
558 run_loop->Quit(); 567 run_loop->Quit();
559 } 568 }
560 569
561 bool VerifyKeys(const std::vector<std::string>& expected_keys) { 570 bool VerifyKeys(const std::vector<std::string>& expected_keys) {
562 if (expected_keys.size() != callback_strings_.size()) 571 if (expected_keys.size() != callback_strings_.size())
563 return false; 572 return false;
564 573
565 std::set<std::string> found_set; 574 std::set<std::string> found_set;
(...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after
1132 EXPECT_TRUE(Delete(no_body_request_)); 1141 EXPECT_TRUE(Delete(no_body_request_));
1133 EXPECT_EQ(0, Size()); 1142 EXPECT_EQ(0, Size());
1134 1143
1135 EXPECT_TRUE(Put(body_request_, body_response_)); 1144 EXPECT_TRUE(Put(body_request_, body_response_));
1136 EXPECT_LT(no_body_size, Size()); 1145 EXPECT_LT(no_body_size, Size());
1137 1146
1138 EXPECT_TRUE(Delete(body_request_)); 1147 EXPECT_TRUE(Delete(body_request_));
1139 EXPECT_EQ(0, Size()); 1148 EXPECT_EQ(0, Size());
1140 } 1149 }
1141 1150
1151 TEST_P(CacheStorageCacheTestP, SizeOperationsArePrioritized) {
1152 // Test that pending size operations (those waiting for initialization) run
1153 // before other scheduler operations.
1154 cache_->set_delay_backend_creation(true); // Delay cache initialization
1155
1156 CacheStorageBatchOperation operation;
1157 operation.operation_type = CACHE_STORAGE_CACHE_OPERATION_TYPE_PUT;
1158 operation.request = body_request_;
1159 operation.response = body_response_;
1160
1161 callback_error_ = CACHE_STORAGE_ERROR_NOT_FOUND;
1162 base::RunLoop run_loop;
1163 // Start a put operation that blocks on initialization.
1164 cache_->BatchOperation(std::vector<CacheStorageBatchOperation>(1, operation),
1165 base::Bind(&CacheStorageCacheTest::ErrorTypeCallback,
1166 base::Unretained(this), &run_loop));
1167
1168 // Next start a size operation that also blocks on initialization.
1169 bool size_callback_called = false;
1170 cache_->Size(base::Bind(&CacheStorageCacheTest::SizeCallback,
1171 base::Unretained(this), nullptr,
1172 &size_callback_called));
1173
1174 base::RunLoop().RunUntilIdle();
1175 EXPECT_FALSE(size_callback_called);
1176 EXPECT_EQ(CACHE_STORAGE_ERROR_NOT_FOUND, callback_error_);
1177
1178 // Finish initialization. The Size operation should complete before Put gets
1179 // to run as Size has priority. See crbug.com/605663.
1180 cache_->ContinueCreateBackend();
1181 run_loop.Run();
1182 EXPECT_TRUE(size_callback_called);
1183 EXPECT_EQ(CACHE_STORAGE_OK, callback_error_);
1184 }
1185
1142 TEST_P(CacheStorageCacheTestP, GetSizeThenClose) { 1186 TEST_P(CacheStorageCacheTestP, GetSizeThenClose) {
1143 EXPECT_TRUE(Put(body_request_, body_response_)); 1187 EXPECT_TRUE(Put(body_request_, body_response_));
1144 int64_t cache_size = Size(); 1188 int64_t cache_size = Size();
1145 EXPECT_EQ(cache_size, GetSizeThenClose()); 1189 EXPECT_EQ(cache_size, GetSizeThenClose());
1146 VerifyAllOpsFail(); 1190 VerifyAllOpsFail();
1147 } 1191 }
1148 1192
1149 TEST_P(CacheStorageCacheTestP, OpsFailOnClosedBackendNeverCreated) { 1193 TEST_P(CacheStorageCacheTestP, OpsFailOnClosedBackendNeverCreated) {
1150 cache_->set_delay_backend_creation( 1194 cache_->set_delay_backend_creation(
1151 true); // Will hang the test if a backend is created. 1195 true); // Will hang the test if a backend is created.
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1204 EXPECT_EQ(1, sequence_out); 1248 EXPECT_EQ(1, sequence_out);
1205 close_loop2->Run(); 1249 close_loop2->Run();
1206 EXPECT_EQ(2, sequence_out); 1250 EXPECT_EQ(2, sequence_out);
1207 } 1251 }
1208 1252
1209 INSTANTIATE_TEST_CASE_P(CacheStorageCacheTest, 1253 INSTANTIATE_TEST_CASE_P(CacheStorageCacheTest,
1210 CacheStorageCacheTestP, 1254 CacheStorageCacheTestP,
1211 ::testing::Values(false, true)); 1255 ::testing::Values(false, true));
1212 1256
1213 } // namespace content 1257 } // 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