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

Side by Side Diff: net/http/http_cache_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698