OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "net/http/http_cache.h" | 5 #include "net/http/http_cache.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <vector> |
10 | 11 |
11 #include "base/bind.h" | 12 #include "base/bind.h" |
12 #include "base/bind_helpers.h" | 13 #include "base/bind_helpers.h" |
13 #include "base/memory/scoped_vector.h" | 14 #include "base/memory/scoped_ptr.h" |
14 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
15 #include "base/run_loop.h" | 16 #include "base/run_loop.h" |
16 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
17 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
18 #include "base/test/simple_test_clock.h" | 19 #include "base/test/simple_test_clock.h" |
19 #include "net/base/cache_type.h" | 20 #include "net/base/cache_type.h" |
20 #include "net/base/elements_upload_data_stream.h" | 21 #include "net/base/elements_upload_data_stream.h" |
21 #include "net/base/host_port_pair.h" | 22 #include "net/base/host_port_pair.h" |
22 #include "net/base/ip_endpoint.h" | 23 #include "net/base/ip_endpoint.h" |
23 #include "net/base/load_flags.h" | 24 #include "net/base/load_flags.h" |
(...skipping 1383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1407 // the pending transactions before the first one completes. | 1408 // the pending transactions before the first one completes. |
1408 // See http://code.google.com/p/chromium/issues/detail?id=25588 | 1409 // See http://code.google.com/p/chromium/issues/detail?id=25588 |
1409 TEST(HttpCache, SimpleGET_DoomWithPending) { | 1410 TEST(HttpCache, SimpleGET_DoomWithPending) { |
1410 // We need simultaneous doomed / not_doomed entries so let's use a real cache. | 1411 // We need simultaneous doomed / not_doomed entries so let's use a real cache. |
1411 MockHttpCache cache(HttpCache::DefaultBackend::InMemory(1024 * 1024)); | 1412 MockHttpCache cache(HttpCache::DefaultBackend::InMemory(1024 * 1024)); |
1412 | 1413 |
1413 MockHttpRequest request(kSimpleGET_Transaction); | 1414 MockHttpRequest request(kSimpleGET_Transaction); |
1414 MockHttpRequest writer_request(kSimpleGET_Transaction); | 1415 MockHttpRequest writer_request(kSimpleGET_Transaction); |
1415 writer_request.load_flags = LOAD_BYPASS_CACHE; | 1416 writer_request.load_flags = LOAD_BYPASS_CACHE; |
1416 | 1417 |
1417 ScopedVector<Context> context_list; | 1418 std::vector<scoped_ptr<Context>> context_list; |
1418 const int kNumTransactions = 4; | 1419 const int kNumTransactions = 4; |
1419 | 1420 |
1420 for (int i = 0; i < kNumTransactions; ++i) { | 1421 for (int i = 0; i < kNumTransactions; ++i) { |
1421 context_list.push_back(new Context()); | 1422 context_list.push_back(make_scoped_ptr(new Context())); |
1422 Context* c = context_list[i]; | 1423 Context* c = context_list[i].get(); |
1423 | 1424 |
1424 c->result = cache.CreateTransaction(&c->trans); | 1425 c->result = cache.CreateTransaction(&c->trans); |
1425 ASSERT_EQ(OK, c->result); | 1426 ASSERT_EQ(OK, c->result); |
1426 | 1427 |
1427 MockHttpRequest* this_request = &request; | 1428 MockHttpRequest* this_request = &request; |
1428 if (i == 3) | 1429 if (i == 3) |
1429 this_request = &writer_request; | 1430 this_request = &writer_request; |
1430 | 1431 |
1431 c->result = | 1432 c->result = |
1432 c->trans->Start(this_request, c->callback.callback(), BoundNetLog()); | 1433 c->trans->Start(this_request, c->callback.callback(), BoundNetLog()); |
1433 } | 1434 } |
1434 | 1435 |
1435 // The first request should be a writer at this point, and the two subsequent | 1436 // The first request should be a writer at this point, and the two subsequent |
1436 // requests should be pending. The last request doomed the first entry. | 1437 // requests should be pending. The last request doomed the first entry. |
1437 | 1438 |
1438 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 1439 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
1439 | 1440 |
1440 // Cancel the first queued transaction. | 1441 // Cancel the first queued transaction. |
1441 delete context_list[1]; | 1442 context_list[1].reset(); |
1442 context_list.get()[1] = NULL; | |
1443 | 1443 |
1444 for (int i = 0; i < kNumTransactions; ++i) { | 1444 for (int i = 0; i < kNumTransactions; ++i) { |
1445 if (i == 1) | 1445 if (i == 1) |
1446 continue; | 1446 continue; |
1447 Context* c = context_list[i]; | 1447 Context* c = context_list[i].get(); |
1448 ASSERT_EQ(ERR_IO_PENDING, c->result); | 1448 ASSERT_EQ(ERR_IO_PENDING, c->result); |
1449 c->result = c->callback.WaitForResult(); | 1449 c->result = c->callback.WaitForResult(); |
1450 ReadAndVerifyTransaction(c->trans.get(), kSimpleGET_Transaction); | 1450 ReadAndVerifyTransaction(c->trans.get(), kSimpleGET_Transaction); |
1451 } | 1451 } |
1452 } | 1452 } |
1453 | 1453 |
1454 // This is a test for http://code.google.com/p/chromium/issues/detail?id=4731. | 1454 // This is a test for http://code.google.com/p/chromium/issues/detail?id=4731. |
1455 // We may attempt to delete an entry synchronously with the act of adding a new | 1455 // We may attempt to delete an entry synchronously with the act of adding a new |
1456 // transaction to said entry. | 1456 // transaction to said entry. |
1457 TEST(HttpCache, FastNoStoreGET_DoneWithPending) { | 1457 TEST(HttpCache, FastNoStoreGET_DoneWithPending) { |
(...skipping 1461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2919 | 2919 |
2920 TEST(HttpCache, SimplePOST_LoadOnlyFromCache_Hit) { | 2920 TEST(HttpCache, SimplePOST_LoadOnlyFromCache_Hit) { |
2921 MockHttpCache cache; | 2921 MockHttpCache cache; |
2922 | 2922 |
2923 // Test that we hit the cache for POST requests. | 2923 // Test that we hit the cache for POST requests. |
2924 | 2924 |
2925 MockTransaction transaction(kSimplePOST_Transaction); | 2925 MockTransaction transaction(kSimplePOST_Transaction); |
2926 | 2926 |
2927 const int64 kUploadId = 1; // Just a dummy value. | 2927 const int64 kUploadId = 1; // Just a dummy value. |
2928 | 2928 |
2929 ScopedVector<UploadElementReader> element_readers; | 2929 std::vector<scoped_ptr<UploadElementReader>> element_readers; |
2930 element_readers.push_back(new UploadBytesElementReader("hello", 5)); | 2930 element_readers.push_back( |
2931 ElementsUploadDataStream upload_data_stream(element_readers.Pass(), | 2931 make_scoped_ptr(new UploadBytesElementReader("hello", 5))); |
| 2932 ElementsUploadDataStream upload_data_stream(std::move(element_readers), |
2932 kUploadId); | 2933 kUploadId); |
2933 MockHttpRequest request(transaction); | 2934 MockHttpRequest request(transaction); |
2934 request.upload_data_stream = &upload_data_stream; | 2935 request.upload_data_stream = &upload_data_stream; |
2935 | 2936 |
2936 // Populate the cache. | 2937 // Populate the cache. |
2937 RunTransactionTestWithRequest(cache.http_cache(), transaction, request, NULL); | 2938 RunTransactionTestWithRequest(cache.http_cache(), transaction, request, NULL); |
2938 | 2939 |
2939 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 2940 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
2940 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 2941 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
2941 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 2942 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
2942 | 2943 |
2943 // Load from cache. | 2944 // Load from cache. |
2944 request.load_flags |= LOAD_ONLY_FROM_CACHE; | 2945 request.load_flags |= LOAD_ONLY_FROM_CACHE; |
2945 RunTransactionTestWithRequest(cache.http_cache(), transaction, request, NULL); | 2946 RunTransactionTestWithRequest(cache.http_cache(), transaction, request, NULL); |
2946 | 2947 |
2947 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 2948 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
2948 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 2949 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
2949 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 2950 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
2950 } | 2951 } |
2951 | 2952 |
2952 // Test that we don't hit the cache for POST requests if there is a byte range. | 2953 // Test that we don't hit the cache for POST requests if there is a byte range. |
2953 TEST(HttpCache, SimplePOST_WithRanges) { | 2954 TEST(HttpCache, SimplePOST_WithRanges) { |
2954 MockHttpCache cache; | 2955 MockHttpCache cache; |
2955 | 2956 |
2956 MockTransaction transaction(kSimplePOST_Transaction); | 2957 MockTransaction transaction(kSimplePOST_Transaction); |
2957 transaction.request_headers = "Range: bytes = 0-4\r\n"; | 2958 transaction.request_headers = "Range: bytes = 0-4\r\n"; |
2958 | 2959 |
2959 const int64 kUploadId = 1; // Just a dummy value. | 2960 const int64 kUploadId = 1; // Just a dummy value. |
2960 | 2961 |
2961 ScopedVector<UploadElementReader> element_readers; | 2962 std::vector<scoped_ptr<UploadElementReader>> element_readers; |
2962 element_readers.push_back(new UploadBytesElementReader("hello", 5)); | 2963 element_readers.push_back( |
2963 ElementsUploadDataStream upload_data_stream(element_readers.Pass(), | 2964 make_scoped_ptr(new UploadBytesElementReader("hello", 5))); |
| 2965 ElementsUploadDataStream upload_data_stream(std::move(element_readers), |
2964 kUploadId); | 2966 kUploadId); |
2965 | 2967 |
2966 MockHttpRequest request(transaction); | 2968 MockHttpRequest request(transaction); |
2967 request.upload_data_stream = &upload_data_stream; | 2969 request.upload_data_stream = &upload_data_stream; |
2968 | 2970 |
2969 // Attempt to populate the cache. | 2971 // Attempt to populate the cache. |
2970 RunTransactionTestWithRequest(cache.http_cache(), transaction, request, NULL); | 2972 RunTransactionTestWithRequest(cache.http_cache(), transaction, request, NULL); |
2971 | 2973 |
2972 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 2974 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
2973 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 2975 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
2974 EXPECT_EQ(0, cache.disk_cache()->create_count()); | 2976 EXPECT_EQ(0, cache.disk_cache()->create_count()); |
2975 } | 2977 } |
2976 | 2978 |
2977 // Tests that a POST is cached separately from a previously cached GET. | 2979 // Tests that a POST is cached separately from a previously cached GET. |
2978 TEST(HttpCache, SimplePOST_SeparateCache) { | 2980 TEST(HttpCache, SimplePOST_SeparateCache) { |
2979 MockHttpCache cache; | 2981 MockHttpCache cache; |
2980 | 2982 |
2981 ScopedVector<UploadElementReader> element_readers; | 2983 std::vector<scoped_ptr<UploadElementReader>> element_readers; |
2982 element_readers.push_back(new UploadBytesElementReader("hello", 5)); | 2984 element_readers.push_back( |
2983 ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 1); | 2985 make_scoped_ptr(new UploadBytesElementReader("hello", 5))); |
| 2986 ElementsUploadDataStream upload_data_stream(std::move(element_readers), 1); |
2984 | 2987 |
2985 MockTransaction transaction(kSimplePOST_Transaction); | 2988 MockTransaction transaction(kSimplePOST_Transaction); |
2986 MockHttpRequest req1(transaction); | 2989 MockHttpRequest req1(transaction); |
2987 req1.upload_data_stream = &upload_data_stream; | 2990 req1.upload_data_stream = &upload_data_stream; |
2988 | 2991 |
2989 RunTransactionTestWithRequest(cache.http_cache(), transaction, req1, NULL); | 2992 RunTransactionTestWithRequest(cache.http_cache(), transaction, req1, NULL); |
2990 | 2993 |
2991 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 2994 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
2992 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 2995 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
2993 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 2996 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
(...skipping 16 matching lines...) Expand all Loading... |
3010 AddMockTransaction(&transaction); | 3013 AddMockTransaction(&transaction); |
3011 MockHttpRequest req1(transaction); | 3014 MockHttpRequest req1(transaction); |
3012 | 3015 |
3013 // Attempt to populate the cache. | 3016 // Attempt to populate the cache. |
3014 RunTransactionTestWithRequest(cache.http_cache(), transaction, req1, NULL); | 3017 RunTransactionTestWithRequest(cache.http_cache(), transaction, req1, NULL); |
3015 | 3018 |
3016 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 3019 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
3017 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 3020 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
3018 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 3021 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
3019 | 3022 |
3020 ScopedVector<UploadElementReader> element_readers; | 3023 std::vector<scoped_ptr<UploadElementReader>> element_readers; |
3021 element_readers.push_back(new UploadBytesElementReader("hello", 5)); | 3024 element_readers.push_back( |
3022 ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 1); | 3025 make_scoped_ptr(new UploadBytesElementReader("hello", 5))); |
| 3026 ElementsUploadDataStream upload_data_stream(std::move(element_readers), 1); |
3023 | 3027 |
3024 transaction.method = "POST"; | 3028 transaction.method = "POST"; |
3025 transaction.status = "HTTP/1.1 205 No Content"; | 3029 transaction.status = "HTTP/1.1 205 No Content"; |
3026 MockHttpRequest req2(transaction); | 3030 MockHttpRequest req2(transaction); |
3027 req2.upload_data_stream = &upload_data_stream; | 3031 req2.upload_data_stream = &upload_data_stream; |
3028 | 3032 |
3029 RunTransactionTestWithRequest(cache.http_cache(), transaction, req2, NULL); | 3033 RunTransactionTestWithRequest(cache.http_cache(), transaction, req2, NULL); |
3030 | 3034 |
3031 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 3035 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
3032 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 3036 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
(...skipping 16 matching lines...) Expand all Loading... |
3049 AddMockTransaction(&transaction); | 3053 AddMockTransaction(&transaction); |
3050 MockHttpRequest req1(transaction); | 3054 MockHttpRequest req1(transaction); |
3051 | 3055 |
3052 // Attempt to populate the cache. | 3056 // Attempt to populate the cache. |
3053 RunTransactionTestWithRequest(cache.http_cache(), transaction, req1, NULL); | 3057 RunTransactionTestWithRequest(cache.http_cache(), transaction, req1, NULL); |
3054 | 3058 |
3055 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 3059 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
3056 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 3060 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
3057 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 3061 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
3058 | 3062 |
3059 ScopedVector<UploadElementReader> element_readers; | 3063 std::vector<scoped_ptr<UploadElementReader>> element_readers; |
3060 element_readers.push_back(new UploadBytesElementReader("hello", 5)); | 3064 element_readers.push_back( |
3061 ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); | 3065 make_scoped_ptr(new UploadBytesElementReader("hello", 5))); |
| 3066 ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
3062 | 3067 |
3063 transaction.method = "POST"; | 3068 transaction.method = "POST"; |
3064 transaction.status = "HTTP/1.1 205 No Content"; | 3069 transaction.status = "HTTP/1.1 205 No Content"; |
3065 MockHttpRequest req2(transaction); | 3070 MockHttpRequest req2(transaction); |
3066 req2.upload_data_stream = &upload_data_stream; | 3071 req2.upload_data_stream = &upload_data_stream; |
3067 | 3072 |
3068 RunTransactionTestWithRequest(cache.http_cache(), transaction, req2, NULL); | 3073 RunTransactionTestWithRequest(cache.http_cache(), transaction, req2, NULL); |
3069 | 3074 |
3070 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 3075 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
3071 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 3076 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
3072 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 3077 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
3073 | 3078 |
3074 RunTransactionTestWithRequest(cache.http_cache(), transaction, req1, NULL); | 3079 RunTransactionTestWithRequest(cache.http_cache(), transaction, req1, NULL); |
3075 | 3080 |
3076 EXPECT_EQ(3, cache.network_layer()->transaction_count()); | 3081 EXPECT_EQ(3, cache.network_layer()->transaction_count()); |
3077 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 3082 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
3078 EXPECT_EQ(2, cache.disk_cache()->create_count()); | 3083 EXPECT_EQ(2, cache.disk_cache()->create_count()); |
3079 RemoveMockTransaction(&transaction); | 3084 RemoveMockTransaction(&transaction); |
3080 } | 3085 } |
3081 | 3086 |
3082 // Tests that processing a POST before creating the backend doesn't crash. | 3087 // Tests that processing a POST before creating the backend doesn't crash. |
3083 TEST(HttpCache, SimplePOST_NoUploadId_NoBackend) { | 3088 TEST(HttpCache, SimplePOST_NoUploadId_NoBackend) { |
3084 // This will initialize a cache object with NULL backend. | 3089 // This will initialize a cache object with NULL backend. |
3085 scoped_ptr<MockBlockingBackendFactory> factory( | 3090 scoped_ptr<MockBlockingBackendFactory> factory( |
3086 new MockBlockingBackendFactory()); | 3091 new MockBlockingBackendFactory()); |
3087 factory->set_fail(true); | 3092 factory->set_fail(true); |
3088 factory->FinishCreation(); | 3093 factory->FinishCreation(); |
3089 MockHttpCache cache(factory.Pass()); | 3094 MockHttpCache cache(factory.Pass()); |
3090 | 3095 |
3091 ScopedVector<UploadElementReader> element_readers; | 3096 std::vector<scoped_ptr<UploadElementReader>> element_readers; |
3092 element_readers.push_back(new UploadBytesElementReader("hello", 5)); | 3097 element_readers.push_back( |
3093 ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); | 3098 make_scoped_ptr(new UploadBytesElementReader("hello", 5))); |
| 3099 ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
3094 | 3100 |
3095 MockTransaction transaction(kSimplePOST_Transaction); | 3101 MockTransaction transaction(kSimplePOST_Transaction); |
3096 AddMockTransaction(&transaction); | 3102 AddMockTransaction(&transaction); |
3097 MockHttpRequest req(transaction); | 3103 MockHttpRequest req(transaction); |
3098 req.upload_data_stream = &upload_data_stream; | 3104 req.upload_data_stream = &upload_data_stream; |
3099 | 3105 |
3100 RunTransactionTestWithRequest(cache.http_cache(), transaction, req, NULL); | 3106 RunTransactionTestWithRequest(cache.http_cache(), transaction, req, NULL); |
3101 | 3107 |
3102 RemoveMockTransaction(&transaction); | 3108 RemoveMockTransaction(&transaction); |
3103 } | 3109 } |
3104 | 3110 |
3105 // Tests that we don't invalidate entries as a result of a failed POST. | 3111 // Tests that we don't invalidate entries as a result of a failed POST. |
3106 TEST(HttpCache, SimplePOST_DontInvalidate_100) { | 3112 TEST(HttpCache, SimplePOST_DontInvalidate_100) { |
3107 MockHttpCache cache; | 3113 MockHttpCache cache; |
3108 | 3114 |
3109 MockTransaction transaction(kSimpleGET_Transaction); | 3115 MockTransaction transaction(kSimpleGET_Transaction); |
3110 AddMockTransaction(&transaction); | 3116 AddMockTransaction(&transaction); |
3111 MockHttpRequest req1(transaction); | 3117 MockHttpRequest req1(transaction); |
3112 | 3118 |
3113 // Attempt to populate the cache. | 3119 // Attempt to populate the cache. |
3114 RunTransactionTestWithRequest(cache.http_cache(), transaction, req1, NULL); | 3120 RunTransactionTestWithRequest(cache.http_cache(), transaction, req1, NULL); |
3115 | 3121 |
3116 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 3122 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
3117 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 3123 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
3118 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 3124 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
3119 | 3125 |
3120 ScopedVector<UploadElementReader> element_readers; | 3126 std::vector<scoped_ptr<UploadElementReader>> element_readers; |
3121 element_readers.push_back(new UploadBytesElementReader("hello", 5)); | 3127 element_readers.push_back( |
3122 ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 1); | 3128 make_scoped_ptr(new UploadBytesElementReader("hello", 5))); |
| 3129 ElementsUploadDataStream upload_data_stream(std::move(element_readers), 1); |
3123 | 3130 |
3124 transaction.method = "POST"; | 3131 transaction.method = "POST"; |
3125 transaction.status = "HTTP/1.1 100 Continue"; | 3132 transaction.status = "HTTP/1.1 100 Continue"; |
3126 MockHttpRequest req2(transaction); | 3133 MockHttpRequest req2(transaction); |
3127 req2.upload_data_stream = &upload_data_stream; | 3134 req2.upload_data_stream = &upload_data_stream; |
3128 | 3135 |
3129 RunTransactionTestWithRequest(cache.http_cache(), transaction, req2, NULL); | 3136 RunTransactionTestWithRequest(cache.http_cache(), transaction, req2, NULL); |
3130 | 3137 |
3131 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 3138 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
3132 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 3139 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3421 RemoveMockTransaction(&transaction); | 3428 RemoveMockTransaction(&transaction); |
3422 } | 3429 } |
3423 | 3430 |
3424 // Tests that we do not cache the response of a PUT. | 3431 // Tests that we do not cache the response of a PUT. |
3425 TEST(HttpCache, SimplePUT_Miss) { | 3432 TEST(HttpCache, SimplePUT_Miss) { |
3426 MockHttpCache cache; | 3433 MockHttpCache cache; |
3427 | 3434 |
3428 MockTransaction transaction(kSimplePOST_Transaction); | 3435 MockTransaction transaction(kSimplePOST_Transaction); |
3429 transaction.method = "PUT"; | 3436 transaction.method = "PUT"; |
3430 | 3437 |
3431 ScopedVector<UploadElementReader> element_readers; | 3438 std::vector<scoped_ptr<UploadElementReader>> element_readers; |
3432 element_readers.push_back(new UploadBytesElementReader("hello", 5)); | 3439 element_readers.push_back( |
3433 ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); | 3440 make_scoped_ptr(new UploadBytesElementReader("hello", 5))); |
| 3441 ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
3434 | 3442 |
3435 MockHttpRequest request(transaction); | 3443 MockHttpRequest request(transaction); |
3436 request.upload_data_stream = &upload_data_stream; | 3444 request.upload_data_stream = &upload_data_stream; |
3437 | 3445 |
3438 // Attempt to populate the cache. | 3446 // Attempt to populate the cache. |
3439 RunTransactionTestWithRequest(cache.http_cache(), transaction, request, NULL); | 3447 RunTransactionTestWithRequest(cache.http_cache(), transaction, request, NULL); |
3440 | 3448 |
3441 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 3449 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
3442 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 3450 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
3443 EXPECT_EQ(0, cache.disk_cache()->create_count()); | 3451 EXPECT_EQ(0, cache.disk_cache()->create_count()); |
3444 } | 3452 } |
3445 | 3453 |
3446 // Tests that we invalidate entries as a result of a PUT. | 3454 // Tests that we invalidate entries as a result of a PUT. |
3447 TEST(HttpCache, SimplePUT_Invalidate) { | 3455 TEST(HttpCache, SimplePUT_Invalidate) { |
3448 MockHttpCache cache; | 3456 MockHttpCache cache; |
3449 | 3457 |
3450 MockTransaction transaction(kSimpleGET_Transaction); | 3458 MockTransaction transaction(kSimpleGET_Transaction); |
3451 MockHttpRequest req1(transaction); | 3459 MockHttpRequest req1(transaction); |
3452 | 3460 |
3453 // Attempt to populate the cache. | 3461 // Attempt to populate the cache. |
3454 RunTransactionTestWithRequest(cache.http_cache(), transaction, req1, NULL); | 3462 RunTransactionTestWithRequest(cache.http_cache(), transaction, req1, NULL); |
3455 | 3463 |
3456 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 3464 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
3457 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 3465 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
3458 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 3466 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
3459 | 3467 |
3460 ScopedVector<UploadElementReader> element_readers; | 3468 std::vector<scoped_ptr<UploadElementReader>> element_readers; |
3461 element_readers.push_back(new UploadBytesElementReader("hello", 5)); | 3469 element_readers.push_back( |
3462 ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); | 3470 make_scoped_ptr(new UploadBytesElementReader("hello", 5))); |
| 3471 ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
3463 | 3472 |
3464 transaction.method = "PUT"; | 3473 transaction.method = "PUT"; |
3465 MockHttpRequest req2(transaction); | 3474 MockHttpRequest req2(transaction); |
3466 req2.upload_data_stream = &upload_data_stream; | 3475 req2.upload_data_stream = &upload_data_stream; |
3467 | 3476 |
3468 RunTransactionTestWithRequest(cache.http_cache(), transaction, req2, NULL); | 3477 RunTransactionTestWithRequest(cache.http_cache(), transaction, req2, NULL); |
3469 | 3478 |
3470 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 3479 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
3471 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 3480 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
3472 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 3481 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
(...skipping 13 matching lines...) Expand all Loading... |
3486 AddMockTransaction(&transaction); | 3495 AddMockTransaction(&transaction); |
3487 MockHttpRequest req1(transaction); | 3496 MockHttpRequest req1(transaction); |
3488 | 3497 |
3489 // Attempt to populate the cache. | 3498 // Attempt to populate the cache. |
3490 RunTransactionTestWithRequest(cache.http_cache(), transaction, req1, NULL); | 3499 RunTransactionTestWithRequest(cache.http_cache(), transaction, req1, NULL); |
3491 | 3500 |
3492 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 3501 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
3493 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 3502 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
3494 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 3503 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
3495 | 3504 |
3496 ScopedVector<UploadElementReader> element_readers; | 3505 std::vector<scoped_ptr<UploadElementReader>> element_readers; |
3497 element_readers.push_back(new UploadBytesElementReader("hello", 5)); | 3506 element_readers.push_back( |
3498 ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); | 3507 make_scoped_ptr(new UploadBytesElementReader("hello", 5))); |
| 3508 ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
3499 | 3509 |
3500 transaction.method = "PUT"; | 3510 transaction.method = "PUT"; |
3501 transaction.status = "HTTP/1.1 305 Use Proxy"; | 3511 transaction.status = "HTTP/1.1 305 Use Proxy"; |
3502 MockHttpRequest req2(transaction); | 3512 MockHttpRequest req2(transaction); |
3503 req2.upload_data_stream = &upload_data_stream; | 3513 req2.upload_data_stream = &upload_data_stream; |
3504 | 3514 |
3505 RunTransactionTestWithRequest(cache.http_cache(), transaction, req2, NULL); | 3515 RunTransactionTestWithRequest(cache.http_cache(), transaction, req2, NULL); |
3506 | 3516 |
3507 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 3517 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
3508 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 3518 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
(...skipping 15 matching lines...) Expand all Loading... |
3524 AddMockTransaction(&transaction); | 3534 AddMockTransaction(&transaction); |
3525 MockHttpRequest req1(transaction); | 3535 MockHttpRequest req1(transaction); |
3526 | 3536 |
3527 // Attempt to populate the cache. | 3537 // Attempt to populate the cache. |
3528 RunTransactionTestWithRequest(cache.http_cache(), transaction, req1, NULL); | 3538 RunTransactionTestWithRequest(cache.http_cache(), transaction, req1, NULL); |
3529 | 3539 |
3530 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 3540 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
3531 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 3541 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
3532 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 3542 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
3533 | 3543 |
3534 ScopedVector<UploadElementReader> element_readers; | 3544 std::vector<scoped_ptr<UploadElementReader>> element_readers; |
3535 element_readers.push_back(new UploadBytesElementReader("hello", 5)); | 3545 element_readers.push_back( |
3536 ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); | 3546 make_scoped_ptr(new UploadBytesElementReader("hello", 5))); |
| 3547 ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
3537 | 3548 |
3538 transaction.method = "PUT"; | 3549 transaction.method = "PUT"; |
3539 transaction.status = "HTTP/1.1 404 Not Found"; | 3550 transaction.status = "HTTP/1.1 404 Not Found"; |
3540 MockHttpRequest req2(transaction); | 3551 MockHttpRequest req2(transaction); |
3541 req2.upload_data_stream = &upload_data_stream; | 3552 req2.upload_data_stream = &upload_data_stream; |
3542 | 3553 |
3543 RunTransactionTestWithRequest(cache.http_cache(), transaction, req2, NULL); | 3554 RunTransactionTestWithRequest(cache.http_cache(), transaction, req2, NULL); |
3544 | 3555 |
3545 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 3556 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
3546 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 3557 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
3547 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 3558 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
3548 | 3559 |
3549 RunTransactionTestWithRequest(cache.http_cache(), transaction, req1, NULL); | 3560 RunTransactionTestWithRequest(cache.http_cache(), transaction, req1, NULL); |
3550 | 3561 |
3551 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 3562 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
3552 EXPECT_EQ(2, cache.disk_cache()->open_count()); | 3563 EXPECT_EQ(2, cache.disk_cache()->open_count()); |
3553 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 3564 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
3554 RemoveMockTransaction(&transaction); | 3565 RemoveMockTransaction(&transaction); |
3555 } | 3566 } |
3556 | 3567 |
3557 // Tests that we do not cache the response of a DELETE. | 3568 // Tests that we do not cache the response of a DELETE. |
3558 TEST(HttpCache, SimpleDELETE_Miss) { | 3569 TEST(HttpCache, SimpleDELETE_Miss) { |
3559 MockHttpCache cache; | 3570 MockHttpCache cache; |
3560 | 3571 |
3561 MockTransaction transaction(kSimplePOST_Transaction); | 3572 MockTransaction transaction(kSimplePOST_Transaction); |
3562 transaction.method = "DELETE"; | 3573 transaction.method = "DELETE"; |
3563 | 3574 |
3564 ScopedVector<UploadElementReader> element_readers; | 3575 std::vector<scoped_ptr<UploadElementReader>> element_readers; |
3565 element_readers.push_back(new UploadBytesElementReader("hello", 5)); | 3576 element_readers.push_back( |
3566 ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); | 3577 make_scoped_ptr(new UploadBytesElementReader("hello", 5))); |
| 3578 ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
3567 | 3579 |
3568 MockHttpRequest request(transaction); | 3580 MockHttpRequest request(transaction); |
3569 request.upload_data_stream = &upload_data_stream; | 3581 request.upload_data_stream = &upload_data_stream; |
3570 | 3582 |
3571 // Attempt to populate the cache. | 3583 // Attempt to populate the cache. |
3572 RunTransactionTestWithRequest(cache.http_cache(), transaction, request, NULL); | 3584 RunTransactionTestWithRequest(cache.http_cache(), transaction, request, NULL); |
3573 | 3585 |
3574 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 3586 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
3575 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 3587 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
3576 EXPECT_EQ(0, cache.disk_cache()->create_count()); | 3588 EXPECT_EQ(0, cache.disk_cache()->create_count()); |
3577 } | 3589 } |
3578 | 3590 |
3579 // Tests that we invalidate entries as a result of a DELETE. | 3591 // Tests that we invalidate entries as a result of a DELETE. |
3580 TEST(HttpCache, SimpleDELETE_Invalidate) { | 3592 TEST(HttpCache, SimpleDELETE_Invalidate) { |
3581 MockHttpCache cache; | 3593 MockHttpCache cache; |
3582 | 3594 |
3583 MockTransaction transaction(kSimpleGET_Transaction); | 3595 MockTransaction transaction(kSimpleGET_Transaction); |
3584 MockHttpRequest req1(transaction); | 3596 MockHttpRequest req1(transaction); |
3585 | 3597 |
3586 // Attempt to populate the cache. | 3598 // Attempt to populate the cache. |
3587 RunTransactionTestWithRequest(cache.http_cache(), transaction, req1, NULL); | 3599 RunTransactionTestWithRequest(cache.http_cache(), transaction, req1, NULL); |
3588 | 3600 |
3589 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 3601 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
3590 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 3602 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
3591 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 3603 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
3592 | 3604 |
3593 ScopedVector<UploadElementReader> element_readers; | 3605 std::vector<scoped_ptr<UploadElementReader>> element_readers; |
3594 element_readers.push_back(new UploadBytesElementReader("hello", 5)); | 3606 element_readers.push_back( |
3595 ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); | 3607 make_scoped_ptr(new UploadBytesElementReader("hello", 5))); |
| 3608 ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
3596 | 3609 |
3597 transaction.method = "DELETE"; | 3610 transaction.method = "DELETE"; |
3598 MockHttpRequest req2(transaction); | 3611 MockHttpRequest req2(transaction); |
3599 req2.upload_data_stream = &upload_data_stream; | 3612 req2.upload_data_stream = &upload_data_stream; |
3600 | 3613 |
3601 RunTransactionTestWithRequest(cache.http_cache(), transaction, req2, NULL); | 3614 RunTransactionTestWithRequest(cache.http_cache(), transaction, req2, NULL); |
3602 | 3615 |
3603 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 3616 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
3604 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 3617 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
3605 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 3618 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
(...skipping 4112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7718 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 7731 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
7719 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 7732 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
7720 EXPECT_TRUE(response_info.was_cached); | 7733 EXPECT_TRUE(response_info.was_cached); |
7721 | 7734 |
7722 // The new SSL state is reported. | 7735 // The new SSL state is reported. |
7723 EXPECT_EQ(status2, response_info.ssl_info.connection_status); | 7736 EXPECT_EQ(status2, response_info.ssl_info.connection_status); |
7724 EXPECT_TRUE(cert2->Equals(response_info.ssl_info.cert.get())); | 7737 EXPECT_TRUE(cert2->Equals(response_info.ssl_info.cert.get())); |
7725 } | 7738 } |
7726 | 7739 |
7727 } // namespace net | 7740 } // namespace net |
OLD | NEW |