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

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

Issue 1832863002: [CacheStorage] Make CacheStorage::MatchAllCaches return in order (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add layout test Created 4 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/cache_storage/cache_storage_manager.h" 5 #include "content/browser/cache_storage/cache_storage_manager.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 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 cache_manager_->MatchAllCaches( 220 cache_manager_->MatchAllCaches(
221 origin, std::move(request), 221 origin, std::move(request),
222 base::Bind(&CacheStorageManagerTest::CacheMatchCallback, 222 base::Bind(&CacheStorageManagerTest::CacheMatchCallback,
223 base::Unretained(this), base::Unretained(&loop))); 223 base::Unretained(this), base::Unretained(&loop)));
224 loop.Run(); 224 loop.Run();
225 225
226 return callback_error_ == CACHE_STORAGE_OK; 226 return callback_error_ == CACHE_STORAGE_OK;
227 } 227 }
228 228
229 bool CachePut(CacheStorageCache* cache, const GURL& url) { 229 bool CachePut(CacheStorageCache* cache, const GURL& url) {
230 return CachePutWithStatusCode(cache, url, 200);
231 }
232
233 bool CachePutWithStatusCode(CacheStorageCache* cache,
234 const GURL& url,
235 int status_code) {
230 ServiceWorkerFetchRequest request; 236 ServiceWorkerFetchRequest request;
231 request.url = url; 237 request.url = url;
232 238
233 scoped_ptr<storage::BlobDataBuilder> blob_data( 239 scoped_ptr<storage::BlobDataBuilder> blob_data(
234 new storage::BlobDataBuilder(base::GenerateGUID())); 240 new storage::BlobDataBuilder(base::GenerateGUID()));
235 blob_data->AppendData(url.spec()); 241 blob_data->AppendData(url.spec());
236 242
237 scoped_ptr<storage::BlobDataHandle> blob_handle = 243 scoped_ptr<storage::BlobDataHandle> blob_handle =
238 blob_storage_context_->AddFinishedBlob(blob_data.get()); 244 blob_storage_context_->AddFinishedBlob(blob_data.get());
239 ServiceWorkerResponse response( 245 ServiceWorkerResponse response(
240 url, 200, "OK", blink::WebServiceWorkerResponseTypeDefault, 246 url, status_code, "OK", blink::WebServiceWorkerResponseTypeDefault,
241 ServiceWorkerHeaderMap(), blob_handle->uuid(), url.spec().size(), 247 ServiceWorkerHeaderMap(), blob_handle->uuid(), url.spec().size(),
242 GURL(), blink::WebServiceWorkerResponseErrorUnknown, base::Time()); 248 GURL(), blink::WebServiceWorkerResponseErrorUnknown, base::Time());
243 249
244 CacheStorageBatchOperation operation; 250 CacheStorageBatchOperation operation;
245 operation.operation_type = CACHE_STORAGE_CACHE_OPERATION_TYPE_PUT; 251 operation.operation_type = CACHE_STORAGE_CACHE_OPERATION_TYPE_PUT;
246 operation.request = request; 252 operation.request = request;
247 operation.response = response; 253 operation.response = response;
248 254
249 base::RunLoop loop; 255 base::RunLoop loop;
250 cache->BatchOperation( 256 cache->BatchOperation(
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 519
514 EXPECT_TRUE(Delete(origin1_, "foo")); 520 EXPECT_TRUE(Delete(origin1_, "foo"));
515 // The cache is deleted but the handle to one of its entries is still 521 // The cache is deleted but the handle to one of its entries is still
516 // open. Creating a new cache in the same directory would fail on Windows. 522 // open. Creating a new cache in the same directory would fail on Windows.
517 EXPECT_TRUE(Open(origin1_, "foo")); 523 EXPECT_TRUE(Open(origin1_, "foo"));
518 EXPECT_TRUE(CachePut(callback_cache_.get(), kTestURL)); 524 EXPECT_TRUE(CachePut(callback_cache_.get(), kTestURL));
519 } 525 }
520 526
521 TEST_P(CacheStorageManagerTestP, StorageMatchAllEntryExistsTwice) { 527 TEST_P(CacheStorageManagerTestP, StorageMatchAllEntryExistsTwice) {
522 EXPECT_TRUE(Open(origin1_, "foo")); 528 EXPECT_TRUE(Open(origin1_, "foo"));
523 EXPECT_TRUE(CachePut(callback_cache_.get(), GURL("http://example.com/foo"))); 529 EXPECT_TRUE(CachePutWithStatusCode(callback_cache_.get(),
530 GURL("http://example.com/foo"), 200));
524 EXPECT_TRUE(Open(origin1_, "bar")); 531 EXPECT_TRUE(Open(origin1_, "bar"));
525 EXPECT_TRUE(CachePut(callback_cache_.get(), GURL("http://example.com/foo"))); 532 EXPECT_TRUE(CachePutWithStatusCode(callback_cache_.get(),
533 GURL("http://example.com/foo"), 201));
526 534
527 EXPECT_TRUE(StorageMatchAll(origin1_, GURL("http://example.com/foo"))); 535 EXPECT_TRUE(StorageMatchAll(origin1_, GURL("http://example.com/foo")));
536
537 // The caches need to be searched in order of creation, so verify that the
538 // response came from the first cache.
539 EXPECT_EQ(200, callback_cache_response_->status_code);
528 } 540 }
529 541
530 TEST_P(CacheStorageManagerTestP, StorageMatchInOneOfMany) { 542 TEST_P(CacheStorageManagerTestP, StorageMatchInOneOfMany) {
531 EXPECT_TRUE(Open(origin1_, "foo")); 543 EXPECT_TRUE(Open(origin1_, "foo"));
532 EXPECT_TRUE(Open(origin1_, "bar")); 544 EXPECT_TRUE(Open(origin1_, "bar"));
533 EXPECT_TRUE(CachePut(callback_cache_.get(), GURL("http://example.com/foo"))); 545 EXPECT_TRUE(CachePut(callback_cache_.get(), GURL("http://example.com/foo")));
534 EXPECT_TRUE(Open(origin1_, "baz")); 546 EXPECT_TRUE(Open(origin1_, "baz"));
535 547
536 EXPECT_TRUE(StorageMatchAll(origin1_, GURL("http://example.com/foo"))); 548 EXPECT_TRUE(StorageMatchAll(origin1_, GURL("http://example.com/foo")));
537 } 549 }
(...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after
1127 1139
1128 INSTANTIATE_TEST_CASE_P(CacheStorageManagerTests, 1140 INSTANTIATE_TEST_CASE_P(CacheStorageManagerTests,
1129 CacheStorageManagerTestP, 1141 CacheStorageManagerTestP,
1130 ::testing::Values(false, true)); 1142 ::testing::Values(false, true));
1131 1143
1132 INSTANTIATE_TEST_CASE_P(CacheStorageQuotaClientTests, 1144 INSTANTIATE_TEST_CASE_P(CacheStorageQuotaClientTests,
1133 CacheStorageQuotaClientTestP, 1145 CacheStorageQuotaClientTestP,
1134 ::testing::Values(false, true)); 1146 ::testing::Values(false, true));
1135 1147
1136 } // namespace content 1148 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698