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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/memory/scoped_vector.h" | 9 #include "base/memory/scoped_vector.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
148 num_network_delegate_actions)); | 148 num_network_delegate_actions)); |
149 } | 149 } |
150 scoped_ptr<net::HttpTransaction> trans; | 150 scoped_ptr<net::HttpTransaction> trans; |
151 int rv = cache->CreateTransaction(&trans, delegate.get()); | 151 int rv = cache->CreateTransaction(&trans, delegate.get()); |
152 EXPECT_EQ(net::OK, rv); | 152 EXPECT_EQ(net::OK, rv); |
153 ASSERT_TRUE(trans.get()); | 153 ASSERT_TRUE(trans.get()); |
154 | 154 |
155 rv = trans->Start(&request, callback.callback(), net_log); | 155 rv = trans->Start(&request, callback.callback(), net_log); |
156 if (rv == net::ERR_IO_PENDING) | 156 if (rv == net::ERR_IO_PENDING) |
157 rv = callback.WaitForResult(); | 157 rv = callback.WaitForResult(); |
158 ASSERT_EQ(net::OK, rv); | 158 ASSERT_EQ(trans_info.error_return, rv); |
159 | 159 |
160 const net::HttpResponseInfo* response = trans->GetResponseInfo(); | 160 const net::HttpResponseInfo* response = trans->GetResponseInfo(); |
161 ASSERT_TRUE(response); | 161 ASSERT_TRUE(response); |
162 | 162 |
163 if (response_info) | 163 if (response_info) |
164 *response_info = *response; | 164 *response_info = *response; |
165 | 165 |
166 ReadAndVerifyTransaction(trans.get(), trans_info); | 166 ReadAndVerifyTransaction(trans.get(), trans_info); |
167 } | 167 } |
168 | 168 |
rvargas (doing something else)
2013/03/05 02:58:19
This file defines a bunch of transactions... which
Randy Smith (Not in Mondays)
2013/03/05 23:16:14
While I completely don't guarantee that I saw ever
rvargas (doing something else)
2013/03/06 03:11:48
lines 377, 240
Randy Smith (Not in Mondays)
2013/03/06 22:55:55
Ah, got it. Filter failure was looking at codesea
| |
169 void RunTransactionTestWithRequest(net::HttpCache* cache, | 169 void RunTransactionTestWithRequest(net::HttpCache* cache, |
170 const MockTransaction& trans_info, | 170 const MockTransaction& trans_info, |
171 const MockHttpRequest& request, | 171 const MockHttpRequest& request, |
172 net::HttpResponseInfo* response_info) { | 172 net::HttpResponseInfo* response_info) { |
173 RunTransactionTestWithRequestAndLogAndDelegate( | 173 RunTransactionTestWithRequestAndLogAndDelegate( |
174 cache, trans_info, request, response_info, net::BoundNetLog(), | 174 cache, trans_info, request, response_info, net::BoundNetLog(), |
175 kNoDelegateTransactionCheck, kNoDelegateTransactionCheck); | 175 kNoDelegateTransactionCheck, kNoDelegateTransactionCheck); |
176 } | 176 } |
177 | 177 |
178 void RunTransactionTestWithLog(net::HttpCache* cache, | 178 void RunTransactionTestWithLog(net::HttpCache* cache, |
(...skipping 1017 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1196 for (int i = 0; i < kNumTransactions; ++i) { | 1196 for (int i = 0; i < kNumTransactions; ++i) { |
1197 if (i == 1) | 1197 if (i == 1) |
1198 continue; | 1198 continue; |
1199 Context* c = context_list[i]; | 1199 Context* c = context_list[i]; |
1200 ASSERT_EQ(net::ERR_IO_PENDING, c->result); | 1200 ASSERT_EQ(net::ERR_IO_PENDING, c->result); |
1201 c->result = c->callback.WaitForResult(); | 1201 c->result = c->callback.WaitForResult(); |
1202 ReadAndVerifyTransaction(c->trans.get(), kSimpleGET_Transaction); | 1202 ReadAndVerifyTransaction(c->trans.get(), kSimpleGET_Transaction); |
1203 } | 1203 } |
1204 } | 1204 } |
1205 | 1205 |
1206 // Tests that LOAD_CACHE_RETURN_IF_OFFLINE returns proper responses on | |
1207 // network success, offline failure, and non-offline failure. | |
rvargas (doing something else)
2013/03/05 02:58:19
sounds like three different tests.
Randy Smith (Not in Mondays)
2013/03/05 23:16:14
Done.
| |
1208 TEST(HttpCache, SimpleGET_CacheOverride) { | |
rvargas (doing something else)
2013/03/05 02:58:19
could you move this next to a test that goes over
Randy Smith (Not in Mondays)
2013/03/05 23:16:14
Done.
| |
1209 MockHttpCache cache(net::HttpCache::DefaultBackend::InMemory(1024 * 1024)); | |
rvargas (doing something else)
2013/03/05 02:58:19
why a real cache?
Randy Smith (Not in Mondays)
2013/03/05 23:16:14
Naivete': I copy-pasted from the wrong test. Fixe
| |
1210 | |
1211 MockTransaction transaction(kSimpleGET_Transaction); | |
1212 transaction.load_flags |= net::LOAD_CACHE_RETURN_IF_OFFLINE; | |
1213 transaction.response_headers = "Cache-Control: no-cache\n"; | |
1214 | |
1215 // Regular network test; should behave as normal. | |
1216 AddMockTransaction(&transaction); | |
1217 net::HttpResponseInfo response_info; | |
1218 RunTransactionTestWithResponseInfo(cache.http_cache(), transaction, | |
1219 &response_info); | |
1220 | |
1221 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | |
1222 EXPECT_FALSE(response_info.was_cache_override); | |
1223 | |
1224 RemoveMockTransaction(&transaction); | |
1225 | |
1226 // Network failure with offline error; should return cache entry above + | |
1227 // flag signalling stale data. | |
1228 transaction.error_return = net::ERR_NAME_NOT_RESOLVED; | |
1229 AddMockTransaction(&transaction); | |
1230 | |
1231 MockHttpRequest request(transaction); | |
1232 net::TestCompletionCallback callback; | |
1233 scoped_ptr<net::HttpTransaction> trans; | |
1234 int rv = cache.http_cache()->CreateTransaction(&trans, NULL); | |
1235 EXPECT_EQ(net::OK, rv); | |
1236 ASSERT_TRUE(trans.get()); | |
1237 rv = trans->Start(&request, callback.callback(), net::BoundNetLog()); | |
1238 if (rv == net::ERR_IO_PENDING) | |
1239 rv = callback.WaitForResult(); | |
rvargas (doing something else)
2013/03/05 02:58:19
GetResult(rv)
Randy Smith (Not in Mondays)
2013/03/05 23:16:14
Done.
| |
1240 EXPECT_EQ(net::OK, rv); | |
1241 | |
1242 const net::HttpResponseInfo* response_info1 = trans->GetResponseInfo(); | |
1243 ASSERT_TRUE(response_info1); | |
1244 EXPECT_TRUE(response_info1->was_cache_override); | |
1245 ReadAndVerifyTransaction(trans.get(), transaction); | |
1246 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | |
1247 | |
1248 RemoveMockTransaction(&transaction); | |
1249 | |
1250 // Network failure with non-offline error; should fail with that error. | |
1251 transaction.error_return = net::ERR_PROXY_CONNECTION_FAILED; | |
1252 AddMockTransaction(&transaction); | |
1253 | |
1254 net::HttpResponseInfo response_info2; | |
1255 RunTransactionTestWithResponseInfo(cache.http_cache(), transaction, | |
1256 &response_info2); | |
1257 | |
1258 EXPECT_EQ(3, cache.network_layer()->transaction_count()); | |
1259 EXPECT_FALSE(response_info2.was_cache_override); | |
1260 | |
1261 RemoveMockTransaction(&transaction); | |
1262 } | |
1263 | |
1206 // This is a test for http://code.google.com/p/chromium/issues/detail?id=4731. | 1264 // This is a test for http://code.google.com/p/chromium/issues/detail?id=4731. |
1207 // We may attempt to delete an entry synchronously with the act of adding a new | 1265 // We may attempt to delete an entry synchronously with the act of adding a new |
1208 // transaction to said entry. | 1266 // transaction to said entry. |
1209 TEST(HttpCache, FastNoStoreGET_DoneWithPending) { | 1267 TEST(HttpCache, FastNoStoreGET_DoneWithPending) { |
1210 MockHttpCache cache; | 1268 MockHttpCache cache; |
1211 | 1269 |
1212 // The headers will be served right from the call to Start() the request. | 1270 // The headers will be served right from the call to Start() the request. |
1213 MockHttpRequest request(kFastNoStoreGET_Transaction); | 1271 MockHttpRequest request(kFastNoStoreGET_Transaction); |
1214 FastTransactionServer request_handler; | 1272 FastTransactionServer request_handler; |
1215 AddMockTransaction(&kFastNoStoreGET_Transaction); | 1273 AddMockTransaction(&kFastNoStoreGET_Transaction); |
(...skipping 4297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5513 | 5571 |
5514 // Force this transaction to read from the cache. | 5572 // Force this transaction to read from the cache. |
5515 MockTransaction transaction(kSimpleGET_Transaction); | 5573 MockTransaction transaction(kSimpleGET_Transaction); |
5516 transaction.load_flags |= net::LOAD_ONLY_FROM_CACHE; | 5574 transaction.load_flags |= net::LOAD_ONLY_FROM_CACHE; |
5517 | 5575 |
5518 RunTransactionTestWithDelegate(cache.http_cache(), | 5576 RunTransactionTestWithDelegate(cache.http_cache(), |
5519 kSimpleGET_Transaction, | 5577 kSimpleGET_Transaction, |
5520 5, | 5578 5, |
5521 0); | 5579 0); |
5522 } | 5580 } |
OLD | NEW |