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

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

Issue 1829663002: test Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
« 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 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 381
382 cache_->Match( 382 cache_->Match(
383 CopyFetchRequest(request), 383 CopyFetchRequest(request),
384 base::Bind(&CacheStorageCacheTest::ResponseAndErrorCallback, 384 base::Bind(&CacheStorageCacheTest::ResponseAndErrorCallback,
385 base::Unretained(this), base::Unretained(loop.get()))); 385 base::Unretained(this), base::Unretained(loop.get())));
386 loop->Run(); 386 loop->Run();
387 387
388 return callback_error_ == CACHE_STORAGE_OK; 388 return callback_error_ == CACHE_STORAGE_OK;
389 } 389 }
390 390
391 bool QueryCache(const ServiceWorkerFetchRequest& request,
392 const CacheStorageCacheQueryParams& options) {
393 base::RunLoop loop;
394 cache_->QueryCache(CopyFetchRequest(request), options);
395 loop.Run();
396 return true;
397 }
398
391 bool MatchAll(const ServiceWorkerFetchRequest& request, 399 bool MatchAll(const ServiceWorkerFetchRequest& request,
392 const CacheStorageCacheQueryParams& match_params, 400 const CacheStorageCacheQueryParams& match_params,
393 scoped_ptr<CacheStorageCache::Responses>* responses, 401 scoped_ptr<CacheStorageCache::Responses>* responses,
394 scoped_ptr<CacheStorageCache::BlobDataHandles>* body_handles) { 402 scoped_ptr<CacheStorageCache::BlobDataHandles>* body_handles) {
395 base::RunLoop loop; 403 base::RunLoop loop;
396 cache_->MatchAll( 404 cache_->MatchAll(
397 CopyFetchRequest(request), match_params, 405 CopyFetchRequest(request), match_params,
398 base::Bind(&CacheStorageCacheTest::ResponsesAndErrorCallback, 406 base::Bind(&CacheStorageCacheTest::ResponsesAndErrorCallback,
399 base::Unretained(this), loop.QuitClosure(), responses, 407 base::Unretained(this), loop.QuitClosure(), responses,
400 body_handles)); 408 body_handles));
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after
822 EXPECT_TRUE(ResponseMetadataEqual(body_response_with_query_, response)); 830 EXPECT_TRUE(ResponseMetadataEqual(body_response_with_query_, response));
823 matched_set.insert(response.url.spec()); 831 matched_set.insert(response.url.spec());
824 } else if (response.url.spec() == "http://example.com/body.html") { 832 } else if (response.url.spec() == "http://example.com/body.html") {
825 EXPECT_TRUE(ResponseMetadataEqual(body_response_, response)); 833 EXPECT_TRUE(ResponseMetadataEqual(body_response_, response));
826 matched_set.insert(response.url.spec()); 834 matched_set.insert(response.url.spec());
827 } 835 }
828 } 836 }
829 EXPECT_EQ(2u, matched_set.size()); 837 EXPECT_EQ(2u, matched_set.size());
830 } 838 }
831 839
840 TEST_P(CacheStorageCacheTestP, QueryCache) {
841 EXPECT_TRUE(Put(body_request_, body_response_));
842 EXPECT_TRUE(Put(body_request_with_query_, body_response_with_query_));
843 EXPECT_TRUE(Put(no_body_request_, no_body_response_));
844
845 CacheStorageCacheQueryParams match_params;
846 EXPECT_TRUE(QueryCache(body_request_, match_params));
847
848 /* scoped_ptr<CacheStorageCache::Responses> responses;
849 scoped_ptr<CacheStorageCache::BlobDataHandles> body_handles;
850 CacheStorageCacheQueryParams match_params;
851 match_params.ignore_search = true;
852 EXPECT_TRUE(MatchAll(body_request_, match_params, &responses, &body_handles));
853
854 ASSERT_EQ(2u, responses->size());
855 ASSERT_EQ(2u, body_handles->size());
856
857 // Order of returned responses is not guaranteed.
858 std::set<std::string> matched_set;
859 for (const ServiceWorkerResponse& response : *responses) {
860 if (response.url.spec() == "http://example.com/body.html?query=test") {
861 EXPECT_TRUE(ResponseMetadataEqual(body_response_with_query_, response));
862 matched_set.insert(response.url.spec());
863 } else if (response.url.spec() == "http://example.com/body.html") {
864 EXPECT_TRUE(ResponseMetadataEqual(body_response_, response));
865 matched_set.insert(response.url.spec());
866 }
867 }
868 EXPECT_EQ(2u, matched_set.size());*/
869 }
870
871
832 TEST_P(CacheStorageCacheTestP, Vary) { 872 TEST_P(CacheStorageCacheTestP, Vary) {
833 body_request_.headers["vary_foo"] = "foo"; 873 body_request_.headers["vary_foo"] = "foo";
834 body_response_.headers["vary"] = "vary_foo"; 874 body_response_.headers["vary"] = "vary_foo";
835 EXPECT_TRUE(Put(body_request_, body_response_)); 875 EXPECT_TRUE(Put(body_request_, body_response_));
836 EXPECT_TRUE(Match(body_request_)); 876 EXPECT_TRUE(Match(body_request_));
837 877
838 body_request_.headers["vary_foo"] = "bar"; 878 body_request_.headers["vary_foo"] = "bar";
839 EXPECT_FALSE(Match(body_request_)); 879 EXPECT_FALSE(Match(body_request_));
840 880
841 body_request_.headers.erase("vary_foo"); 881 body_request_.headers.erase("vary_foo");
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
1167 EXPECT_EQ(1, sequence_out); 1207 EXPECT_EQ(1, sequence_out);
1168 close_loop2->Run(); 1208 close_loop2->Run();
1169 EXPECT_EQ(2, sequence_out); 1209 EXPECT_EQ(2, sequence_out);
1170 } 1210 }
1171 1211
1172 INSTANTIATE_TEST_CASE_P(CacheStorageCacheTest, 1212 INSTANTIATE_TEST_CASE_P(CacheStorageCacheTest,
1173 CacheStorageCacheTestP, 1213 CacheStorageCacheTestP,
1174 ::testing::Values(false, true)); 1214 ::testing::Values(false, true));
1175 1215
1176 } // namespace content 1216 } // 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