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

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

Issue 335015: Http cache: Make sure that we remove pending transactions... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/http/http_cache.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2009 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 "base/hash_tables.h" 7 #include "base/hash_tables.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/scoped_vector.h"
9 #include "base/string_util.h" 10 #include "base/string_util.h"
10 #include "net/base/net_errors.h" 11 #include "net/base/net_errors.h"
11 #include "net/base/load_flags.h" 12 #include "net/base/load_flags.h"
12 #include "net/base/load_log_unittest.h" 13 #include "net/base/load_log_unittest.h"
13 #include "net/base/ssl_cert_request_info.h" 14 #include "net/base/ssl_cert_request_info.h"
14 #include "net/disk_cache/disk_cache.h" 15 #include "net/disk_cache/disk_cache.h"
15 #include "net/http/http_byte_range.h" 16 #include "net/http/http_byte_range.h"
16 #include "net/http/http_request_info.h" 17 #include "net/http/http_request_info.h"
17 #include "net/http/http_response_headers.h" 18 #include "net/http/http_response_headers.h"
18 #include "net/http/http_response_info.h" 19 #include "net/http/http_response_info.h"
(...skipping 1114 matching lines...) Expand 10 before | Expand all | Expand 10 after
1133 EXPECT_EQ(1, cache.network_layer()->transaction_count()); 1134 EXPECT_EQ(1, cache.network_layer()->transaction_count());
1134 EXPECT_EQ(0, cache.disk_cache()->open_count()); 1135 EXPECT_EQ(0, cache.disk_cache()->open_count());
1135 EXPECT_EQ(1, cache.disk_cache()->create_count()); 1136 EXPECT_EQ(1, cache.disk_cache()->create_count());
1136 1137
1137 for (int i = 0; i < kNumTransactions; ++i) { 1138 for (int i = 0; i < kNumTransactions; ++i) {
1138 Context* c = context_list[i]; 1139 Context* c = context_list[i];
1139 delete c; 1140 delete c;
1140 } 1141 }
1141 } 1142 }
1142 1143
1144 // Tests that we can doom an entry with pending transactions and delete one of
1145 // the pending transactions before the first one completes.
1146 // See http://code.google.com/p/chromium/issues/detail?id=25588
1147 TEST(HttpCache, SimpleGET_DoomWithPending) {
1148 // We need simultaneous doomed / not_doomed entries so let's use a real cache.
1149 disk_cache::Backend* disk_cache =
1150 disk_cache::CreateInMemoryCacheBackend(1024 * 1024);
1151 MockHttpCache cache(disk_cache);
1152
1153 MockHttpRequest request(kSimpleGET_Transaction);
1154 MockHttpRequest writer_request(kSimpleGET_Transaction);
1155 writer_request.load_flags = net::LOAD_BYPASS_CACHE;
1156
1157 ScopedVector<Context> context_list;
1158 const int kNumTransactions = 4;
1159
1160 for (int i = 0; i < kNumTransactions; ++i) {
1161 context_list.push_back(new Context());
1162 Context* c = context_list[i];
1163
1164 c->result = cache.http_cache()->CreateTransaction(&c->trans);
1165 EXPECT_EQ(net::OK, c->result);
1166
1167 MockHttpRequest* this_request = &request;
1168 if (i == 3)
1169 this_request = &writer_request;
1170
1171 c->result = c->trans->Start(this_request, &c->callback, NULL);
1172 }
1173
1174 // The first request should be a writer at this point, and the two subsequent
1175 // requests should be pending. The last request doomed the first entry.
1176
1177 EXPECT_EQ(2, cache.network_layer()->transaction_count());
1178
1179 // Cancel the first queued transaction.
1180 delete context_list[1];
1181 context_list.get()[1] = NULL;
1182
1183 for (int i = 0; i < kNumTransactions; ++i) {
1184 if (i == 1)
1185 continue;
1186 Context* c = context_list[i];
1187 ASSERT_EQ(net::ERR_IO_PENDING, c->result);
1188 c->result = c->callback.WaitForResult();
1189 ReadAndVerifyTransaction(c->trans.get(), kSimpleGET_Transaction);
1190 }
1191 }
1192
1143 // This is a test for http://code.google.com/p/chromium/issues/detail?id=4731. 1193 // This is a test for http://code.google.com/p/chromium/issues/detail?id=4731.
1144 // We may attempt to delete an entry synchronously with the act of adding a new 1194 // We may attempt to delete an entry synchronously with the act of adding a new
1145 // transaction to said entry. 1195 // transaction to said entry.
1146 TEST(HttpCache, FastNoStoreGET_DoneWithPending) { 1196 TEST(HttpCache, FastNoStoreGET_DoneWithPending) {
1147 MockHttpCache cache; 1197 MockHttpCache cache;
1148 1198
1149 // The headers will be served right from the call to Start() the request. 1199 // The headers will be served right from the call to Start() the request.
1150 MockHttpRequest request(kFastNoStoreGET_Transaction); 1200 MockHttpRequest request(kFastNoStoreGET_Transaction);
1151 FastTransactionServer request_handler; 1201 FastTransactionServer request_handler;
1152 AddMockTransaction(&kFastNoStoreGET_Transaction); 1202 AddMockTransaction(&kFastNoStoreGET_Transaction);
(...skipping 2042 matching lines...) Expand 10 before | Expand all | Expand 10 after
3195 std::string headers; 3245 std::string headers;
3196 response.headers->GetNormalizedHeaders(&headers); 3246 response.headers->GetNormalizedHeaders(&headers);
3197 3247
3198 EXPECT_EQ("HTTP/1.1 200 OK\n" 3248 EXPECT_EQ("HTTP/1.1 200 OK\n"
3199 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" 3249 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n"
3200 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", 3250 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n",
3201 headers); 3251 headers);
3202 3252
3203 RemoveMockTransaction(&mock_network_response); 3253 RemoveMockTransaction(&mock_network_response);
3204 } 3254 }
OLDNEW
« no previous file with comments | « net/http/http_cache.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698