Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 377 headers.insert(std::make_pair("b", "b")); | 377 headers.insert(std::make_pair("b", "b")); |
| 378 body_request_ = | 378 body_request_ = |
| 379 ServiceWorkerFetchRequest(GURL("http://example.com/body.html"), "GET", | 379 ServiceWorkerFetchRequest(GURL("http://example.com/body.html"), "GET", |
| 380 headers, Referrer(), false); | 380 headers, Referrer(), false); |
| 381 body_request_with_query_ = ServiceWorkerFetchRequest( | 381 body_request_with_query_ = ServiceWorkerFetchRequest( |
| 382 GURL("http://example.com/body.html?query=test"), "GET", headers, | 382 GURL("http://example.com/body.html?query=test"), "GET", headers, |
| 383 Referrer(), false); | 383 Referrer(), false); |
| 384 no_body_request_ = | 384 no_body_request_ = |
| 385 ServiceWorkerFetchRequest(GURL("http://example.com/no_body.html"), | 385 ServiceWorkerFetchRequest(GURL("http://example.com/no_body.html"), |
| 386 "GET", headers, Referrer(), false); | 386 "GET", headers, Referrer(), false); |
| 387 body_head_request_ = | |
| 388 ServiceWorkerFetchRequest(GURL("http://example.com/body.html"), "HEAD", | |
| 389 headers, Referrer(), false); | |
| 387 | 390 |
| 388 std::string expected_response; | 391 std::string expected_response; |
| 389 for (int i = 0; i < 100; ++i) | 392 for (int i = 0; i < 100; ++i) |
| 390 expected_blob_data_ += kTestData; | 393 expected_blob_data_ += kTestData; |
| 391 | 394 |
| 392 std::unique_ptr<storage::BlobDataBuilder> blob_data( | 395 std::unique_ptr<storage::BlobDataBuilder> blob_data( |
| 393 new storage::BlobDataBuilder("blob-id:myblob")); | 396 new storage::BlobDataBuilder("blob-id:myblob")); |
| 394 blob_data->AppendData(expected_blob_data_); | 397 blob_data->AppendData(expected_blob_data_); |
| 395 | 398 |
| 396 blob_handle_ = | 399 blob_handle_ = |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 685 storage::BlobStorageContext* blob_storage_context_; | 688 storage::BlobStorageContext* blob_storage_context_; |
| 686 | 689 |
| 687 std::unique_ptr<TestCacheStorageCache> cache_; | 690 std::unique_ptr<TestCacheStorageCache> cache_; |
| 688 | 691 |
| 689 ServiceWorkerFetchRequest body_request_; | 692 ServiceWorkerFetchRequest body_request_; |
| 690 ServiceWorkerResponse body_response_; | 693 ServiceWorkerResponse body_response_; |
| 691 ServiceWorkerFetchRequest body_request_with_query_; | 694 ServiceWorkerFetchRequest body_request_with_query_; |
| 692 ServiceWorkerResponse body_response_with_query_; | 695 ServiceWorkerResponse body_response_with_query_; |
| 693 ServiceWorkerFetchRequest no_body_request_; | 696 ServiceWorkerFetchRequest no_body_request_; |
| 694 ServiceWorkerResponse no_body_response_; | 697 ServiceWorkerResponse no_body_response_; |
| 698 ServiceWorkerFetchRequest body_head_request_; | |
| 695 std::unique_ptr<storage::BlobDataHandle> blob_handle_; | 699 std::unique_ptr<storage::BlobDataHandle> blob_handle_; |
| 696 std::string expected_blob_data_; | 700 std::string expected_blob_data_; |
| 697 | 701 |
| 698 CacheStorageError callback_error_ = CACHE_STORAGE_OK; | 702 CacheStorageError callback_error_ = CACHE_STORAGE_OK; |
| 699 std::unique_ptr<ServiceWorkerResponse> callback_response_; | 703 std::unique_ptr<ServiceWorkerResponse> callback_response_; |
| 700 std::unique_ptr<storage::BlobDataHandle> callback_response_data_; | 704 std::unique_ptr<storage::BlobDataHandle> callback_response_data_; |
| 701 std::vector<std::string> callback_strings_; | 705 std::vector<std::string> callback_strings_; |
| 702 bool callback_closed_ = false; | 706 bool callback_closed_ = false; |
| 703 int64_t callback_size_ = 0; | 707 int64_t callback_size_ = 0; |
| 704 }; | 708 }; |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 798 | 802 |
| 799 EXPECT_TRUE(Put(body_request_, body_response_)); | 803 EXPECT_TRUE(Put(body_request_, body_response_)); |
| 800 EXPECT_TRUE(Match(body_request_)); | 804 EXPECT_TRUE(Match(body_request_)); |
| 801 EXPECT_TRUE(callback_response_data_); | 805 EXPECT_TRUE(callback_response_data_); |
| 802 | 806 |
| 803 EXPECT_TRUE(Put(body_request_, no_body_response_)); | 807 EXPECT_TRUE(Put(body_request_, no_body_response_)); |
| 804 EXPECT_TRUE(Match(body_request_)); | 808 EXPECT_TRUE(Match(body_request_)); |
| 805 EXPECT_FALSE(callback_response_data_); | 809 EXPECT_FALSE(callback_response_data_); |
| 806 } | 810 } |
| 807 | 811 |
| 808 TEST_P(CacheStorageCacheTestP, PutReplcaceInBatch) { | 812 TEST_P(CacheStorageCacheTestP, PutReplaceInBatch) { |
| 809 CacheStorageBatchOperation operation1; | 813 CacheStorageBatchOperation operation1; |
| 810 operation1.operation_type = CACHE_STORAGE_CACHE_OPERATION_TYPE_PUT; | 814 operation1.operation_type = CACHE_STORAGE_CACHE_OPERATION_TYPE_PUT; |
| 811 operation1.request = body_request_; | 815 operation1.request = body_request_; |
| 812 operation1.response = no_body_response_; | 816 operation1.response = no_body_response_; |
| 813 | 817 |
| 814 CacheStorageBatchOperation operation2; | 818 CacheStorageBatchOperation operation2; |
| 815 operation2.operation_type = CACHE_STORAGE_CACHE_OPERATION_TYPE_PUT; | 819 operation2.operation_type = CACHE_STORAGE_CACHE_OPERATION_TYPE_PUT; |
| 816 operation2.request = body_request_; | 820 operation2.request = body_request_; |
| 817 operation2.response = body_response_; | 821 operation2.response = body_response_; |
| 818 | 822 |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 837 | 841 |
| 838 TEST_P(CacheStorageCacheTestP, MatchBody) { | 842 TEST_P(CacheStorageCacheTestP, MatchBody) { |
| 839 EXPECT_TRUE(Put(body_request_, body_response_)); | 843 EXPECT_TRUE(Put(body_request_, body_response_)); |
| 840 EXPECT_TRUE(Match(body_request_)); | 844 EXPECT_TRUE(Match(body_request_)); |
| 841 EXPECT_TRUE( | 845 EXPECT_TRUE( |
| 842 ResponseMetadataEqual(SetCacheName(body_response_), *callback_response_)); | 846 ResponseMetadataEqual(SetCacheName(body_response_), *callback_response_)); |
| 843 EXPECT_TRUE( | 847 EXPECT_TRUE( |
| 844 ResponseBodiesEqual(expected_blob_data_, *callback_response_data_)); | 848 ResponseBodiesEqual(expected_blob_data_, *callback_response_data_)); |
| 845 } | 849 } |
| 846 | 850 |
| 851 TEST_P(CacheStorageCacheTestP, MatchBodyHead) { | |
| 852 EXPECT_TRUE(Put(body_request_, body_response_)); | |
| 853 EXPECT_FALSE(Match(body_head_request_)); | |
| 854 } | |
| 855 | |
| 847 TEST_P(CacheStorageCacheTestP, MatchAll_Empty) { | 856 TEST_P(CacheStorageCacheTestP, MatchAll_Empty) { |
| 848 std::unique_ptr<CacheStorageCache::Responses> responses; | 857 std::unique_ptr<CacheStorageCache::Responses> responses; |
| 849 std::unique_ptr<CacheStorageCache::BlobDataHandles> body_handles; | 858 std::unique_ptr<CacheStorageCache::BlobDataHandles> body_handles; |
| 850 EXPECT_TRUE(MatchAll(&responses, &body_handles)); | 859 EXPECT_TRUE(MatchAll(&responses, &body_handles)); |
| 851 EXPECT_TRUE(responses->empty()); | 860 EXPECT_TRUE(responses->empty()); |
| 852 EXPECT_TRUE(body_handles->empty()); | 861 EXPECT_TRUE(body_handles->empty()); |
| 853 } | 862 } |
| 854 | 863 |
| 855 TEST_P(CacheStorageCacheTestP, MatchAll_NoBody) { | 864 TEST_P(CacheStorageCacheTestP, MatchAll_NoBody) { |
| 856 EXPECT_TRUE(Put(no_body_request_, no_body_response_)); | 865 EXPECT_TRUE(Put(no_body_request_, no_body_response_)); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 941 matched_set.insert(response.url.spec()); | 950 matched_set.insert(response.url.spec()); |
| 942 } else if (response.url.spec() == "http://example.com/body.html") { | 951 } else if (response.url.spec() == "http://example.com/body.html") { |
| 943 EXPECT_TRUE( | 952 EXPECT_TRUE( |
| 944 ResponseMetadataEqual(SetCacheName(body_response_), response)); | 953 ResponseMetadataEqual(SetCacheName(body_response_), response)); |
| 945 matched_set.insert(response.url.spec()); | 954 matched_set.insert(response.url.spec()); |
| 946 } | 955 } |
| 947 } | 956 } |
| 948 EXPECT_EQ(2u, matched_set.size()); | 957 EXPECT_EQ(2u, matched_set.size()); |
| 949 } | 958 } |
| 950 | 959 |
| 960 TEST_P(CacheStorageCacheTestP, MatchAll_HEAD) { | |
|
jkarlin
2016/08/10 17:30:04
For consistency, can you change to MatchAll_Head
jsbell
2016/08/10 20:10:48
Done.
| |
| 961 EXPECT_TRUE(Put(body_request_, body_response_)); | |
| 962 | |
| 963 std::unique_ptr<CacheStorageCache::Responses> responses; | |
| 964 std::unique_ptr<CacheStorageCache::BlobDataHandles> body_handles; | |
| 965 CacheStorageCacheQueryParams match_params; | |
| 966 match_params.ignore_search = true; | |
| 967 EXPECT_TRUE( | |
| 968 MatchAll(body_head_request_, match_params, &responses, &body_handles)); | |
| 969 EXPECT_TRUE(responses->empty()); | |
| 970 EXPECT_TRUE(body_handles->empty()); | |
| 971 | |
| 972 match_params.ignore_method = true; | |
| 973 EXPECT_TRUE( | |
| 974 MatchAll(body_head_request_, match_params, &responses, &body_handles)); | |
| 975 ASSERT_EQ(1u, responses->size()); | |
| 976 ASSERT_EQ(1u, body_handles->size()); | |
| 977 EXPECT_TRUE( | |
| 978 ResponseMetadataEqual(SetCacheName(body_response_), responses->at(0))); | |
| 979 EXPECT_TRUE(ResponseBodiesEqual(expected_blob_data_, body_handles->at(0))); | |
| 980 } | |
| 981 | |
| 951 TEST_P(CacheStorageCacheTestP, Vary) { | 982 TEST_P(CacheStorageCacheTestP, Vary) { |
| 952 body_request_.headers["vary_foo"] = "foo"; | 983 body_request_.headers["vary_foo"] = "foo"; |
| 953 body_response_.headers["vary"] = "vary_foo"; | 984 body_response_.headers["vary"] = "vary_foo"; |
| 954 EXPECT_TRUE(Put(body_request_, body_response_)); | 985 EXPECT_TRUE(Put(body_request_, body_response_)); |
| 955 EXPECT_TRUE(Match(body_request_)); | 986 EXPECT_TRUE(Match(body_request_)); |
| 956 | 987 |
| 957 body_request_.headers["vary_foo"] = "bar"; | 988 body_request_.headers["vary_foo"] = "bar"; |
| 958 EXPECT_FALSE(Match(body_request_)); | 989 EXPECT_FALSE(Match(body_request_)); |
| 959 | 990 |
| 960 body_request_.headers.erase("vary_foo"); | 991 body_request_.headers.erase("vary_foo"); |
| (...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1412 EXPECT_EQ(1, sequence_out); | 1443 EXPECT_EQ(1, sequence_out); |
| 1413 close_loop2->Run(); | 1444 close_loop2->Run(); |
| 1414 EXPECT_EQ(2, sequence_out); | 1445 EXPECT_EQ(2, sequence_out); |
| 1415 } | 1446 } |
| 1416 | 1447 |
| 1417 INSTANTIATE_TEST_CASE_P(CacheStorageCacheTest, | 1448 INSTANTIATE_TEST_CASE_P(CacheStorageCacheTest, |
| 1418 CacheStorageCacheTestP, | 1449 CacheStorageCacheTestP, |
| 1419 ::testing::Values(false, true)); | 1450 ::testing::Values(false, true)); |
| 1420 | 1451 |
| 1421 } // namespace content | 1452 } // namespace content |
| OLD | NEW |