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 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
681 storage::BlobStorageContext* blob_storage_context_; | 684 storage::BlobStorageContext* blob_storage_context_; |
682 | 685 |
683 std::unique_ptr<TestCacheStorageCache> cache_; | 686 std::unique_ptr<TestCacheStorageCache> cache_; |
684 | 687 |
685 ServiceWorkerFetchRequest body_request_; | 688 ServiceWorkerFetchRequest body_request_; |
686 ServiceWorkerResponse body_response_; | 689 ServiceWorkerResponse body_response_; |
687 ServiceWorkerFetchRequest body_request_with_query_; | 690 ServiceWorkerFetchRequest body_request_with_query_; |
688 ServiceWorkerResponse body_response_with_query_; | 691 ServiceWorkerResponse body_response_with_query_; |
689 ServiceWorkerFetchRequest no_body_request_; | 692 ServiceWorkerFetchRequest no_body_request_; |
690 ServiceWorkerResponse no_body_response_; | 693 ServiceWorkerResponse no_body_response_; |
694 ServiceWorkerFetchRequest body_head_request_; | |
691 std::unique_ptr<storage::BlobDataHandle> blob_handle_; | 695 std::unique_ptr<storage::BlobDataHandle> blob_handle_; |
692 std::string expected_blob_data_; | 696 std::string expected_blob_data_; |
693 | 697 |
694 CacheStorageError callback_error_ = CACHE_STORAGE_OK; | 698 CacheStorageError callback_error_ = CACHE_STORAGE_OK; |
695 std::unique_ptr<ServiceWorkerResponse> callback_response_; | 699 std::unique_ptr<ServiceWorkerResponse> callback_response_; |
696 std::unique_ptr<storage::BlobDataHandle> callback_response_data_; | 700 std::unique_ptr<storage::BlobDataHandle> callback_response_data_; |
697 std::vector<std::string> callback_strings_; | 701 std::vector<std::string> callback_strings_; |
698 bool callback_closed_ = false; | 702 bool callback_closed_ = false; |
699 int64_t callback_size_ = 0; | 703 int64_t callback_size_ = 0; |
700 }; | 704 }; |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
794 | 798 |
795 EXPECT_TRUE(Put(body_request_, body_response_)); | 799 EXPECT_TRUE(Put(body_request_, body_response_)); |
796 EXPECT_TRUE(Match(body_request_)); | 800 EXPECT_TRUE(Match(body_request_)); |
797 EXPECT_TRUE(callback_response_data_); | 801 EXPECT_TRUE(callback_response_data_); |
798 | 802 |
799 EXPECT_TRUE(Put(body_request_, no_body_response_)); | 803 EXPECT_TRUE(Put(body_request_, no_body_response_)); |
800 EXPECT_TRUE(Match(body_request_)); | 804 EXPECT_TRUE(Match(body_request_)); |
801 EXPECT_FALSE(callback_response_data_); | 805 EXPECT_FALSE(callback_response_data_); |
802 } | 806 } |
803 | 807 |
804 TEST_P(CacheStorageCacheTestP, PutReplcaceInBatch) { | 808 TEST_P(CacheStorageCacheTestP, PutReplaceInBatch) { |
805 CacheStorageBatchOperation operation1; | 809 CacheStorageBatchOperation operation1; |
806 operation1.operation_type = CACHE_STORAGE_CACHE_OPERATION_TYPE_PUT; | 810 operation1.operation_type = CACHE_STORAGE_CACHE_OPERATION_TYPE_PUT; |
807 operation1.request = body_request_; | 811 operation1.request = body_request_; |
808 operation1.response = no_body_response_; | 812 operation1.response = no_body_response_; |
809 | 813 |
810 CacheStorageBatchOperation operation2; | 814 CacheStorageBatchOperation operation2; |
811 operation2.operation_type = CACHE_STORAGE_CACHE_OPERATION_TYPE_PUT; | 815 operation2.operation_type = CACHE_STORAGE_CACHE_OPERATION_TYPE_PUT; |
812 operation2.request = body_request_; | 816 operation2.request = body_request_; |
813 operation2.response = body_response_; | 817 operation2.response = body_response_; |
814 | 818 |
(...skipping 18 matching lines...) Expand all Loading... | |
833 | 837 |
834 TEST_P(CacheStorageCacheTestP, MatchBody) { | 838 TEST_P(CacheStorageCacheTestP, MatchBody) { |
835 EXPECT_TRUE(Put(body_request_, body_response_)); | 839 EXPECT_TRUE(Put(body_request_, body_response_)); |
836 EXPECT_TRUE(Match(body_request_)); | 840 EXPECT_TRUE(Match(body_request_)); |
837 EXPECT_TRUE( | 841 EXPECT_TRUE( |
838 ResponseMetadataEqual(SetCacheName(body_response_), *callback_response_)); | 842 ResponseMetadataEqual(SetCacheName(body_response_), *callback_response_)); |
839 EXPECT_TRUE( | 843 EXPECT_TRUE( |
840 ResponseBodiesEqual(expected_blob_data_, *callback_response_data_)); | 844 ResponseBodiesEqual(expected_blob_data_, *callback_response_data_)); |
841 } | 845 } |
842 | 846 |
847 TEST_P(CacheStorageCacheTestP, MatchBodyHead) { | |
848 EXPECT_TRUE(Put(body_request_, body_response_)); | |
849 EXPECT_FALSE(Match(body_head_request_)); | |
850 } | |
851 | |
843 TEST_P(CacheStorageCacheTestP, MatchAll_Empty) { | 852 TEST_P(CacheStorageCacheTestP, MatchAll_Empty) { |
844 std::unique_ptr<CacheStorageCache::Responses> responses; | 853 std::unique_ptr<CacheStorageCache::Responses> responses; |
845 std::unique_ptr<CacheStorageCache::BlobDataHandles> body_handles; | 854 std::unique_ptr<CacheStorageCache::BlobDataHandles> body_handles; |
846 EXPECT_TRUE(MatchAll(&responses, &body_handles)); | 855 EXPECT_TRUE(MatchAll(&responses, &body_handles)); |
847 EXPECT_TRUE(responses->empty()); | 856 EXPECT_TRUE(responses->empty()); |
848 EXPECT_TRUE(body_handles->empty()); | 857 EXPECT_TRUE(body_handles->empty()); |
849 } | 858 } |
850 | 859 |
851 TEST_P(CacheStorageCacheTestP, MatchAll_NoBody) { | 860 TEST_P(CacheStorageCacheTestP, MatchAll_NoBody) { |
852 EXPECT_TRUE(Put(no_body_request_, no_body_response_)); | 861 EXPECT_TRUE(Put(no_body_request_, no_body_response_)); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
937 matched_set.insert(response.url.spec()); | 946 matched_set.insert(response.url.spec()); |
938 } else if (response.url.spec() == "http://example.com/body.html") { | 947 } else if (response.url.spec() == "http://example.com/body.html") { |
939 EXPECT_TRUE( | 948 EXPECT_TRUE( |
940 ResponseMetadataEqual(SetCacheName(body_response_), response)); | 949 ResponseMetadataEqual(SetCacheName(body_response_), response)); |
941 matched_set.insert(response.url.spec()); | 950 matched_set.insert(response.url.spec()); |
942 } | 951 } |
943 } | 952 } |
944 EXPECT_EQ(2u, matched_set.size()); | 953 EXPECT_EQ(2u, matched_set.size()); |
945 } | 954 } |
946 | 955 |
956 TEST_P(CacheStorageCacheTestP, MatchAll_HEAD) { | |
957 EXPECT_TRUE(Put(body_request_, body_response_)); | |
958 | |
959 std::unique_ptr<CacheStorageCache::Responses> responses; | |
960 std::unique_ptr<CacheStorageCache::BlobDataHandles> body_handles; | |
961 CacheStorageCacheQueryParams match_params; | |
962 match_params.ignore_search = true; | |
963 EXPECT_TRUE( | |
964 MatchAll(body_head_request_, match_params, &responses, &body_handles)); | |
965 EXPECT_TRUE(responses->empty()); | |
966 EXPECT_TRUE(body_handles->empty()); | |
967 | |
968 // TODO(jsbell): Test with ignore_method = true when supported. | |
jkarlin
2016/08/10 13:22:45
It looks like it's supported to me, at least on th
jsbell
2016/08/10 17:18:09
Done.
| |
969 // https://crbug.com/426309 | |
970 } | |
971 | |
947 TEST_P(CacheStorageCacheTestP, Vary) { | 972 TEST_P(CacheStorageCacheTestP, Vary) { |
948 body_request_.headers["vary_foo"] = "foo"; | 973 body_request_.headers["vary_foo"] = "foo"; |
949 body_response_.headers["vary"] = "vary_foo"; | 974 body_response_.headers["vary"] = "vary_foo"; |
950 EXPECT_TRUE(Put(body_request_, body_response_)); | 975 EXPECT_TRUE(Put(body_request_, body_response_)); |
951 EXPECT_TRUE(Match(body_request_)); | 976 EXPECT_TRUE(Match(body_request_)); |
952 | 977 |
953 body_request_.headers["vary_foo"] = "bar"; | 978 body_request_.headers["vary_foo"] = "bar"; |
954 EXPECT_FALSE(Match(body_request_)); | 979 EXPECT_FALSE(Match(body_request_)); |
955 | 980 |
956 body_request_.headers.erase("vary_foo"); | 981 body_request_.headers.erase("vary_foo"); |
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1375 EXPECT_EQ(1, sequence_out); | 1400 EXPECT_EQ(1, sequence_out); |
1376 close_loop2->Run(); | 1401 close_loop2->Run(); |
1377 EXPECT_EQ(2, sequence_out); | 1402 EXPECT_EQ(2, sequence_out); |
1378 } | 1403 } |
1379 | 1404 |
1380 INSTANTIATE_TEST_CASE_P(CacheStorageCacheTest, | 1405 INSTANTIATE_TEST_CASE_P(CacheStorageCacheTest, |
1381 CacheStorageCacheTestP, | 1406 CacheStorageCacheTestP, |
1382 ::testing::Values(false, true)); | 1407 ::testing::Values(false, true)); |
1383 | 1408 |
1384 } // namespace content | 1409 } // namespace content |
OLD | NEW |