Chromium Code Reviews| 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 <memory> | 10 #include <memory> |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 140 // same value. | 140 // same value. |
| 141 EXPECT_FALSE(load_timing_info.send_start.is_null()); | 141 EXPECT_FALSE(load_timing_info.send_start.is_null()); |
| 142 EXPECT_EQ(load_timing_info.send_start, load_timing_info.send_end); | 142 EXPECT_EQ(load_timing_info.send_start, load_timing_info.send_end); |
| 143 | 143 |
| 144 // Set by URLRequest / URLRequestHttpJob, at a higher level. | 144 // Set by URLRequest / URLRequestHttpJob, at a higher level. |
| 145 EXPECT_TRUE(load_timing_info.request_start_time.is_null()); | 145 EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 146 EXPECT_TRUE(load_timing_info.request_start.is_null()); | 146 EXPECT_TRUE(load_timing_info.request_start.is_null()); |
| 147 EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); | 147 EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
| 148 } | 148 } |
| 149 | 149 |
| 150 void DeferNetworkStart(bool* defer) { | 150 void DeferCallback(bool* defer) { |
| 151 *defer = true; | 151 *defer = true; |
| 152 } | 152 } |
| 153 | 153 |
| 154 class DeleteCacheCompletionCallback : public TestCompletionCallbackBase { | 154 class DeleteCacheCompletionCallback : public TestCompletionCallbackBase { |
| 155 public: | 155 public: |
| 156 explicit DeleteCacheCompletionCallback(MockHttpCache* cache) | 156 explicit DeleteCacheCompletionCallback(MockHttpCache* cache) |
| 157 : cache_(cache), | 157 : cache_(cache), |
| 158 callback_(base::Bind(&DeleteCacheCompletionCallback::OnComplete, | 158 callback_(base::Bind(&DeleteCacheCompletionCallback::OnComplete, |
| 159 base::Unretained(this))) { | 159 base::Unretained(this))) { |
| 160 } | 160 } |
| (...skipping 1310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1471 c->result = c->callback.WaitForResult(); | 1471 c->result = c->callback.WaitForResult(); |
| 1472 | 1472 |
| 1473 ReadAndVerifyTransaction(c->trans.get(), kRangeGET_TransactionOK); | 1473 ReadAndVerifyTransaction(c->trans.get(), kRangeGET_TransactionOK); |
| 1474 } | 1474 } |
| 1475 | 1475 |
| 1476 EXPECT_EQ(5, cache.network_layer()->transaction_count()); | 1476 EXPECT_EQ(5, cache.network_layer()->transaction_count()); |
| 1477 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 1477 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| 1478 EXPECT_EQ(5, cache.disk_cache()->create_count()); | 1478 EXPECT_EQ(5, cache.disk_cache()->create_count()); |
| 1479 } | 1479 } |
| 1480 | 1480 |
| 1481 // Tests that if a transaction is dooming the entry and the entry was doomed by | |
| 1482 // another transaction that was not part of the entry, there should not be a | |
| 1483 // assertion hit. (crbug.com/736993) | |
|
jkarlin
2017/07/07 20:03:15
After F2F we discussed that this test doesn't actu
shivanisha
2017/07/10 18:51:27
Added 2 tests. Without the fix, the first dooms th
| |
| 1484 TEST(HttpCache, RangeGET_ParallelValidationNoMatchDoomEntry) { | |
| 1485 MockHttpCache cache; | |
| 1486 | |
| 1487 ScopedMockTransaction transaction(kRangeGET_TransactionOK); | |
| 1488 MockHttpRequest request(transaction); | |
| 1489 | |
| 1490 MockTransaction dooming_transaction(kRangeGET_TransactionOK); | |
| 1491 dooming_transaction.load_flags |= LOAD_BYPASS_CACHE; | |
| 1492 MockHttpRequest dooming_request(dooming_transaction); | |
| 1493 | |
| 1494 std::vector<std::unique_ptr<Context>> context_list; | |
| 1495 const int kNumTransactions = 3; | |
| 1496 | |
| 1497 for (int i = 0; i < kNumTransactions; ++i) { | |
| 1498 context_list.push_back(base::MakeUnique<Context>()); | |
| 1499 auto& c = context_list[i]; | |
| 1500 | |
| 1501 c->result = cache.CreateTransaction(&c->trans); | |
| 1502 ASSERT_THAT(c->result, IsOk()); | |
| 1503 EXPECT_EQ(LOAD_STATE_IDLE, c->trans->GetLoadState()); | |
| 1504 | |
| 1505 MockHttpRequest* this_request = &request; | |
| 1506 | |
| 1507 if (i == 2) | |
| 1508 this_request = &dooming_request; | |
| 1509 | |
| 1510 if (i == 1) { | |
| 1511 cache.disk_cache()->SetBeforeCacheOperationCallback( | |
| 1512 kRangeGET_TransactionOK.url, base::Bind(&DeferCallback)); | |
| 1513 } | |
| 1514 | |
| 1515 c->result = c->trans->Start(this_request, c->callback.callback(), | |
| 1516 NetLogWithSource()); | |
| 1517 | |
| 1518 // Continue the transactions. 2nd will pause at the cache reading state and | |
| 1519 // 3rd transaction will doom the entry. | |
| 1520 base::RunLoop().RunUntilIdle(); | |
| 1521 } | |
| 1522 | |
| 1523 EXPECT_TRUE( | |
| 1524 cache.disk_cache()->IsDiskEntryDoomed(kRangeGET_TransactionOK.url)); | |
| 1525 | |
| 1526 // Resume cache read by 1st transaction which will lead to dooming the entry | |
| 1527 // as well since the entry cannot be validated. This double dooming should not | |
| 1528 // lead to an assertion. | |
| 1529 cache.disk_cache()->ResumeDoomedEntryCacheOperation( | |
| 1530 kRangeGET_TransactionOK.url); | |
| 1531 base::RunLoop().RunUntilIdle(); | |
| 1532 | |
| 1533 EXPECT_EQ(3, cache.network_layer()->transaction_count()); | |
| 1534 EXPECT_EQ(0, cache.disk_cache()->open_count()); | |
| 1535 EXPECT_EQ(3, cache.disk_cache()->create_count()); | |
| 1536 | |
| 1537 for (auto& context : context_list) { | |
| 1538 EXPECT_EQ(LOAD_STATE_IDLE, context->trans->GetLoadState()); | |
| 1539 } | |
| 1540 | |
| 1541 for (auto& c : context_list) { | |
| 1542 ReadAndVerifyTransaction(c->trans.get(), kRangeGET_TransactionOK); | |
| 1543 } | |
| 1544 | |
| 1545 EXPECT_EQ(3, cache.network_layer()->transaction_count()); | |
| 1546 EXPECT_EQ(0, cache.disk_cache()->open_count()); | |
| 1547 EXPECT_EQ(3, cache.disk_cache()->create_count()); | |
| 1548 } | |
| 1549 | |
| 1481 // Tests parallel validation on range requests with non-overlapping ranges. | 1550 // Tests parallel validation on range requests with non-overlapping ranges. |
| 1482 TEST(HttpCache, RangeGET_ParallelValidationDifferentRanges) { | 1551 TEST(HttpCache, RangeGET_ParallelValidationDifferentRanges) { |
| 1483 MockHttpCache cache; | 1552 MockHttpCache cache; |
| 1484 | 1553 |
| 1485 ScopedMockTransaction transaction(kRangeGET_TransactionOK); | 1554 ScopedMockTransaction transaction(kRangeGET_TransactionOK); |
| 1486 | 1555 |
| 1487 std::vector<std::unique_ptr<Context>> context_list; | 1556 std::vector<std::unique_ptr<Context>> context_list; |
| 1488 const int kNumTransactions = 2; | 1557 const int kNumTransactions = 2; |
| 1489 | 1558 |
| 1490 for (int i = 0; i < kNumTransactions; ++i) { | 1559 for (int i = 0; i < kNumTransactions; ++i) { |
| (...skipping 598 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2089 for (int i = 0; i < kNumTransactions; ++i) { | 2158 for (int i = 0; i < kNumTransactions; ++i) { |
| 2090 context_list.push_back(base::MakeUnique<Context>()); | 2159 context_list.push_back(base::MakeUnique<Context>()); |
| 2091 auto& c = context_list[i]; | 2160 auto& c = context_list[i]; |
| 2092 | 2161 |
| 2093 c->result = cache.CreateTransaction(&c->trans); | 2162 c->result = cache.CreateTransaction(&c->trans); |
| 2094 ASSERT_THAT(c->result, IsOk()); | 2163 ASSERT_THAT(c->result, IsOk()); |
| 2095 | 2164 |
| 2096 MockHttpRequest* this_request = &request; | 2165 MockHttpRequest* this_request = &request; |
| 2097 if (i == 3) { | 2166 if (i == 3) { |
| 2098 this_request = &validate_request; | 2167 this_request = &validate_request; |
| 2099 c->trans->SetBeforeNetworkStartCallback(base::Bind(&DeferNetworkStart)); | 2168 c->trans->SetBeforeNetworkStartCallback(base::Bind(&DeferCallback)); |
| 2100 } | 2169 } |
| 2101 | 2170 |
| 2102 c->result = c->trans->Start(this_request, c->callback.callback(), | 2171 c->result = c->trans->Start(this_request, c->callback.callback(), |
| 2103 NetLogWithSource()); | 2172 NetLogWithSource()); |
| 2104 } | 2173 } |
| 2105 | 2174 |
| 2106 // Allow all requests to move from the Create queue to the active entry. | 2175 // Allow all requests to move from the Create queue to the active entry. |
| 2107 base::RunLoop().RunUntilIdle(); | 2176 base::RunLoop().RunUntilIdle(); |
| 2108 | 2177 |
| 2109 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 2178 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2187 for (int i = 0; i < kNumTransactions; ++i) { | 2256 for (int i = 0; i < kNumTransactions; ++i) { |
| 2188 context_list.push_back(base::MakeUnique<Context>()); | 2257 context_list.push_back(base::MakeUnique<Context>()); |
| 2189 auto& c = context_list[i]; | 2258 auto& c = context_list[i]; |
| 2190 | 2259 |
| 2191 c->result = cache.CreateTransaction(&c->trans); | 2260 c->result = cache.CreateTransaction(&c->trans); |
| 2192 ASSERT_THAT(c->result, IsOk()); | 2261 ASSERT_THAT(c->result, IsOk()); |
| 2193 | 2262 |
| 2194 MockHttpRequest* this_request = &request; | 2263 MockHttpRequest* this_request = &request; |
| 2195 if (i == 2) { | 2264 if (i == 2) { |
| 2196 this_request = &validate_request; | 2265 this_request = &validate_request; |
| 2197 c->trans->SetBeforeNetworkStartCallback(base::Bind(&DeferNetworkStart)); | 2266 c->trans->SetBeforeNetworkStartCallback(base::Bind(&DeferCallback)); |
| 2198 } | 2267 } |
| 2199 | 2268 |
| 2200 c->result = c->trans->Start(this_request, c->callback.callback(), | 2269 c->result = c->trans->Start(this_request, c->callback.callback(), |
| 2201 NetLogWithSource()); | 2270 NetLogWithSource()); |
| 2202 } | 2271 } |
| 2203 | 2272 |
| 2204 // Allow all requests to move from the Create queue to the active entry. | 2273 // Allow all requests to move from the Create queue to the active entry. |
| 2205 base::RunLoop().RunUntilIdle(); | 2274 base::RunLoop().RunUntilIdle(); |
| 2206 | 2275 |
| 2207 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 2276 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2329 for (int i = 0; i < kNumTransactions; ++i) { | 2398 for (int i = 0; i < kNumTransactions; ++i) { |
| 2330 context_list.push_back(base::MakeUnique<Context>()); | 2399 context_list.push_back(base::MakeUnique<Context>()); |
| 2331 auto& c = context_list[i]; | 2400 auto& c = context_list[i]; |
| 2332 | 2401 |
| 2333 c->result = cache.CreateTransaction(&c->trans); | 2402 c->result = cache.CreateTransaction(&c->trans); |
| 2334 ASSERT_THAT(c->result, IsOk()); | 2403 ASSERT_THAT(c->result, IsOk()); |
| 2335 | 2404 |
| 2336 MockHttpRequest* this_request = &request; | 2405 MockHttpRequest* this_request = &request; |
| 2337 if (i == 2) { | 2406 if (i == 2) { |
| 2338 this_request = &validate_request; | 2407 this_request = &validate_request; |
| 2339 c->trans->SetBeforeNetworkStartCallback(base::Bind(&DeferNetworkStart)); | 2408 c->trans->SetBeforeNetworkStartCallback(base::Bind(&DeferCallback)); |
| 2340 } | 2409 } |
| 2341 | 2410 |
| 2342 c->result = c->trans->Start(this_request, c->callback.callback(), | 2411 c->result = c->trans->Start(this_request, c->callback.callback(), |
| 2343 NetLogWithSource()); | 2412 NetLogWithSource()); |
| 2344 } | 2413 } |
| 2345 | 2414 |
| 2346 // Allow all requests to move from the Create queue to the active entry. | 2415 // Allow all requests to move from the Create queue to the active entry. |
| 2347 base::RunLoop().RunUntilIdle(); | 2416 base::RunLoop().RunUntilIdle(); |
| 2348 | 2417 |
| 2349 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 2418 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2399 std::vector<std::unique_ptr<Context>> context_list; | 2468 std::vector<std::unique_ptr<Context>> context_list; |
| 2400 | 2469 |
| 2401 for (int i = 0; i < kNumTransactions; ++i) { | 2470 for (int i = 0; i < kNumTransactions; ++i) { |
| 2402 context_list.push_back(base::MakeUnique<Context>()); | 2471 context_list.push_back(base::MakeUnique<Context>()); |
| 2403 auto& c = context_list[i]; | 2472 auto& c = context_list[i]; |
| 2404 | 2473 |
| 2405 c->result = cache.CreateTransaction(&c->trans); | 2474 c->result = cache.CreateTransaction(&c->trans); |
| 2406 ASSERT_THAT(c->result, IsOk()); | 2475 ASSERT_THAT(c->result, IsOk()); |
| 2407 | 2476 |
| 2408 if (i == 0) | 2477 if (i == 0) |
| 2409 c->trans->SetBeforeNetworkStartCallback(base::Bind(&DeferNetworkStart)); | 2478 c->trans->SetBeforeNetworkStartCallback(base::Bind(&DeferCallback)); |
| 2410 | 2479 |
| 2411 c->result = | 2480 c->result = |
| 2412 c->trans->Start(&request, c->callback.callback(), NetLogWithSource()); | 2481 c->trans->Start(&request, c->callback.callback(), NetLogWithSource()); |
| 2413 } | 2482 } |
| 2414 | 2483 |
| 2415 base::RunLoop().RunUntilIdle(); | 2484 base::RunLoop().RunUntilIdle(); |
| 2416 | 2485 |
| 2417 EXPECT_TRUE(cache.IsHeadersTransactionPresent(kSimpleGET_Transaction.url)); | 2486 EXPECT_TRUE(cache.IsHeadersTransactionPresent(kSimpleGET_Transaction.url)); |
| 2418 EXPECT_EQ(1, cache.GetCountAddToEntryQueue(kSimpleGET_Transaction.url)); | 2487 EXPECT_EQ(1, cache.GetCountAddToEntryQueue(kSimpleGET_Transaction.url)); |
| 2419 | 2488 |
| (...skipping 6884 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 9304 ASSERT_TRUE(attrs->GetDictionary( | 9373 ASSERT_TRUE(attrs->GetDictionary( |
| 9305 base::trace_event::MemoryAllocatorDump::kNameSize, &size_attrs)); | 9374 base::trace_event::MemoryAllocatorDump::kNameSize, &size_attrs)); |
| 9306 std::string size; | 9375 std::string size; |
| 9307 ASSERT_TRUE(size_attrs->GetString("value", &size)); | 9376 ASSERT_TRUE(size_attrs->GetString("value", &size)); |
| 9308 int actual_size = 0; | 9377 int actual_size = 0; |
| 9309 ASSERT_TRUE(base::HexStringToInt(size, &actual_size)); | 9378 ASSERT_TRUE(base::HexStringToInt(size, &actual_size)); |
| 9310 ASSERT_LT(0, actual_size); | 9379 ASSERT_LT(0, actual_size); |
| 9311 } | 9380 } |
| 9312 | 9381 |
| 9313 } // namespace net | 9382 } // namespace net |
| OLD | NEW |