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

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

Issue 2847653002: Revert of HttpCache::Transaction layer allowing parallel validation (Closed)
Patch Set: Created 3 years, 7 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
« no previous file with comments | « net/http/http_cache_transaction.cc ('k') | net/http/http_transaction_test_util.h » ('j') | 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) 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
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) {
151 *defer = true;
152 }
153
154 class DeleteCacheCompletionCallback : public TestCompletionCallbackBase { 150 class DeleteCacheCompletionCallback : public TestCompletionCallbackBase {
155 public: 151 public:
156 explicit DeleteCacheCompletionCallback(MockHttpCache* cache) 152 explicit DeleteCacheCompletionCallback(MockHttpCache* cache)
157 : cache_(cache), 153 : cache_(cache),
158 callback_(base::Bind(&DeleteCacheCompletionCallback::OnComplete, 154 callback_(base::Bind(&DeleteCacheCompletionCallback::OnComplete,
159 base::Unretained(this))) { 155 base::Unretained(this))) {
160 } 156 }
161 157
162 const CompletionCallback& callback() const { return callback_; } 158 const CompletionCallback& callback() const { return callback_; }
163 159
(...skipping 1183 matching lines...) Expand 10 before | Expand all | Expand 10 after
1347 EXPECT_EQ(1, cache.disk_cache()->open_count()); 1343 EXPECT_EQ(1, cache.disk_cache()->open_count());
1348 EXPECT_EQ(1, cache.disk_cache()->create_count()); 1344 EXPECT_EQ(1, cache.disk_cache()->create_count());
1349 RemoveMockTransaction(&transaction); 1345 RemoveMockTransaction(&transaction);
1350 } 1346 }
1351 1347
1352 TEST(HttpCache, SimpleGET_ManyReaders) { 1348 TEST(HttpCache, SimpleGET_ManyReaders) {
1353 MockHttpCache cache; 1349 MockHttpCache cache;
1354 1350
1355 MockHttpRequest request(kSimpleGET_Transaction); 1351 MockHttpRequest request(kSimpleGET_Transaction);
1356 1352
1357 std::vector<std::unique_ptr<Context>> context_list; 1353 std::vector<Context*> context_list;
1358 const int kNumTransactions = 5; 1354 const int kNumTransactions = 5;
1359 1355
1360 for (int i = 0; i < kNumTransactions; ++i) { 1356 for (int i = 0; i < kNumTransactions; ++i) {
1361 context_list.push_back(base::MakeUnique<Context>()); 1357 context_list.push_back(new Context());
1362 auto& c = context_list[i]; 1358 Context* c = context_list[i];
1363 1359
1364 c->result = cache.CreateTransaction(&c->trans); 1360 c->result = cache.CreateTransaction(&c->trans);
1365 ASSERT_THAT(c->result, IsOk()); 1361 ASSERT_THAT(c->result, IsOk());
1366 EXPECT_EQ(LOAD_STATE_IDLE, c->trans->GetLoadState()); 1362 EXPECT_EQ(LOAD_STATE_IDLE, c->trans->GetLoadState());
1367 1363
1368 c->result = 1364 c->result =
1369 c->trans->Start(&request, c->callback.callback(), NetLogWithSource()); 1365 c->trans->Start(&request, c->callback.callback(), NetLogWithSource());
1370 } 1366 }
1371 1367
1372 // All requests are waiting for the active entry. 1368 // All requests are waiting for the active entry.
1373 for (auto& context : context_list) { 1369 for (int i = 0; i < kNumTransactions; ++i) {
1374 EXPECT_EQ(LOAD_STATE_WAITING_FOR_CACHE, context->trans->GetLoadState()); 1370 Context* c = context_list[i];
1371 EXPECT_EQ(LOAD_STATE_WAITING_FOR_CACHE, c->trans->GetLoadState());
1375 } 1372 }
1376 1373
1377 // Allow all requests to move from the Create queue to the active entry. 1374 // Allow all requests to move from the Create queue to the active entry.
1378 base::RunLoop().RunUntilIdle(); 1375 base::RunLoop().RunUntilIdle();
1379 1376
1380 // The first request should be a writer at this point, and the subsequent 1377 // The first request should be a writer at this point, and the subsequent
1381 // requests should have passed the validation phase and waiting for the 1378 // requests should be pending.
1382 // response to be written to the cache before they can read.
1383 EXPECT_TRUE(cache.IsWriterPresent(kSimpleGET_Transaction.url));
1384 EXPECT_EQ(kNumTransactions - 1,
1385 cache.GetCountDoneHeadersQueue(kSimpleGET_Transaction.url));
1386 1379
1387 EXPECT_EQ(1, cache.network_layer()->transaction_count()); 1380 EXPECT_EQ(1, cache.network_layer()->transaction_count());
1388 EXPECT_EQ(0, cache.disk_cache()->open_count()); 1381 EXPECT_EQ(0, cache.disk_cache()->open_count());
1389 EXPECT_EQ(1, cache.disk_cache()->create_count()); 1382 EXPECT_EQ(1, cache.disk_cache()->create_count());
1390 1383
1391 // All requests depend on the writer, and the writer is between Start and 1384 // All requests depend on the writer, and the writer is between Start and
1392 // Read, i.e. idle. 1385 // Read, i.e. idle.
1393 for (auto& context : context_list) { 1386 for (int i = 0; i < kNumTransactions; ++i) {
1394 EXPECT_EQ(LOAD_STATE_IDLE, context->trans->GetLoadState()); 1387 Context* c = context_list[i];
1388 EXPECT_EQ(LOAD_STATE_IDLE, c->trans->GetLoadState());
1395 } 1389 }
1396 1390
1397 for (int i = 0; i < kNumTransactions; ++i) { 1391 for (int i = 0; i < kNumTransactions; ++i) {
1398 auto& c = context_list[i]; 1392 Context* c = context_list[i];
1399 if (c->result == ERR_IO_PENDING) 1393 if (c->result == ERR_IO_PENDING)
1400 c->result = c->callback.WaitForResult(); 1394 c->result = c->callback.WaitForResult();
1401
1402 if (i > 0) {
1403 EXPECT_FALSE(cache.IsWriterPresent(kSimpleGET_Transaction.url));
1404 EXPECT_EQ(kNumTransactions - i,
1405 cache.GetCountReaders(kSimpleGET_Transaction.url));
1406 }
1407
1408 ReadAndVerifyTransaction(c->trans.get(), kSimpleGET_Transaction); 1395 ReadAndVerifyTransaction(c->trans.get(), kSimpleGET_Transaction);
1409 } 1396 }
1410 1397
1411 // We should not have had to re-open the disk entry 1398 // We should not have had to re-open the disk entry
1412 1399
1413 EXPECT_EQ(1, cache.network_layer()->transaction_count()); 1400 EXPECT_EQ(1, cache.network_layer()->transaction_count());
1414 EXPECT_EQ(0, cache.disk_cache()->open_count()); 1401 EXPECT_EQ(0, cache.disk_cache()->open_count());
1415 EXPECT_EQ(1, cache.disk_cache()->create_count()); 1402 EXPECT_EQ(1, cache.disk_cache()->create_count());
1416 }
1417
1418 // Parallel validation results in 200.
1419 TEST(HttpCache, SimpleGET_ParallelValidationNoMatch) {
1420 MockHttpCache cache;
1421
1422 MockHttpRequest request(kSimpleGET_Transaction);
1423 request.load_flags |= LOAD_VALIDATE_CACHE;
1424
1425 std::vector<std::unique_ptr<Context>> context_list;
1426 const int kNumTransactions = 5;
1427
1428 for (int i = 0; i < kNumTransactions; ++i) {
1429 context_list.push_back(base::MakeUnique<Context>());
1430 auto& c = context_list[i];
1431
1432 c->result = cache.CreateTransaction(&c->trans);
1433 ASSERT_THAT(c->result, IsOk());
1434 EXPECT_EQ(LOAD_STATE_IDLE, c->trans->GetLoadState());
1435
1436 c->result =
1437 c->trans->Start(&request, c->callback.callback(), NetLogWithSource());
1438 }
1439
1440 // All requests are waiting for the active entry.
1441 for (auto& context : context_list) {
1442 EXPECT_EQ(LOAD_STATE_WAITING_FOR_CACHE, context->trans->GetLoadState());
1443 }
1444
1445 // Allow all requests to move from the Create queue to the active entry.
1446 base::RunLoop().RunUntilIdle();
1447
1448 // The first request should be a writer at this point, and the subsequent
1449 // requests should have passed the validation phase and created their own
1450 // entries since none of them matched the headers of the earlier one.
1451 EXPECT_TRUE(cache.IsWriterPresent(kSimpleGET_Transaction.url));
1452
1453 // Note that there are only 3 entries created and not 5 since every other
1454 // transaction would have gone to the network.
1455 EXPECT_EQ(5, cache.network_layer()->transaction_count());
1456 EXPECT_EQ(0, cache.disk_cache()->open_count());
1457 EXPECT_EQ(3, cache.disk_cache()->create_count());
1458
1459 // All requests depend on the writer, and the writer is between Start and
1460 // Read, i.e. idle.
1461 for (auto& context : context_list) {
1462 EXPECT_EQ(LOAD_STATE_IDLE, context->trans->GetLoadState());
1463 }
1464
1465 for (auto& context : context_list) {
1466 if (context->result == ERR_IO_PENDING)
1467 context->result = context->callback.WaitForResult();
1468 ReadAndVerifyTransaction(context->trans.get(), kSimpleGET_Transaction);
1469 }
1470
1471 EXPECT_EQ(5, cache.network_layer()->transaction_count());
1472 EXPECT_EQ(0, cache.disk_cache()->open_count());
1473 EXPECT_EQ(3, cache.disk_cache()->create_count());
1474 }
1475
1476 // Tests that a GET followed by a DELETE results in DELETE immediately starting
1477 // the headers phase and the entry is doomed.
1478 TEST(HttpCache, SimpleGET_ParallelValidationDelete) {
1479 MockHttpCache cache;
1480
1481 MockHttpRequest request(kSimpleGET_Transaction);
1482 request.load_flags |= LOAD_VALIDATE_CACHE;
1483
1484 MockHttpRequest delete_request(kSimpleGET_Transaction);
1485 delete_request.method = "DELETE";
1486
1487 std::vector<std::unique_ptr<Context>> context_list;
1488 const int kNumTransactions = 2;
1489
1490 for (int i = 0; i < kNumTransactions; ++i) {
1491 context_list.push_back(base::MakeUnique<Context>());
1492 auto& c = context_list[i];
1493
1494 MockHttpRequest* this_request = &request;
1495 if (i == 1)
1496 this_request = &delete_request;
1497
1498 c->result = cache.CreateTransaction(&c->trans);
1499 ASSERT_THAT(c->result, IsOk());
1500 EXPECT_EQ(LOAD_STATE_IDLE, c->trans->GetLoadState());
1501
1502 c->result = c->trans->Start(this_request, c->callback.callback(),
1503 NetLogWithSource());
1504 }
1505
1506 // All requests are waiting for the active entry.
1507 for (auto& context : context_list) {
1508 EXPECT_EQ(LOAD_STATE_WAITING_FOR_CACHE, context->trans->GetLoadState());
1509 }
1510
1511 // Allow all requests to move from the Create queue to the active entry.
1512 base::RunLoop().RunUntilIdle();
1513
1514 // The first request should be a writer at this point, and the subsequent
1515 // request should have passed the validation phase and doomed the existing
1516 // entry.
1517 EXPECT_TRUE(
1518 cache.disk_cache()->IsDiskEntryDoomed(kSimpleGET_Transaction.url));
1519
1520 EXPECT_EQ(2, cache.network_layer()->transaction_count());
1521 EXPECT_EQ(0, cache.disk_cache()->open_count());
1522 EXPECT_EQ(1, cache.disk_cache()->create_count());
1523
1524 // All requests depend on the writer, and the writer is between Start and
1525 // Read, i.e. idle.
1526 for (auto& context : context_list) {
1527 EXPECT_EQ(LOAD_STATE_IDLE, context->trans->GetLoadState());
1528 }
1529
1530 for (auto& context : context_list) {
1531 if (context->result == ERR_IO_PENDING)
1532 context->result = context->callback.WaitForResult();
1533 ReadAndVerifyTransaction(context->trans.get(), kSimpleGET_Transaction);
1534 }
1535
1536 EXPECT_EQ(2, cache.network_layer()->transaction_count());
1537 EXPECT_EQ(0, cache.disk_cache()->open_count());
1538 EXPECT_EQ(1, cache.disk_cache()->create_count());
1539 }
1540
1541 // Tests that a transaction which is in validated queue can be destroyed without
1542 // any impact to other transactions.
1543 TEST(HttpCache, SimpleGET_ParallelValidationCancelValidated) {
1544 MockHttpCache cache;
1545
1546 MockHttpRequest request(kSimpleGET_Transaction);
1547
1548 std::vector<std::unique_ptr<Context>> context_list;
1549 const int kNumTransactions = 2;
1550
1551 for (int i = 0; i < kNumTransactions; ++i) {
1552 context_list.push_back(base::MakeUnique<Context>());
1553 auto& c = context_list[i];
1554
1555 c->result = cache.CreateTransaction(&c->trans);
1556 ASSERT_THAT(c->result, IsOk());
1557
1558 c->result =
1559 c->trans->Start(&request, c->callback.callback(), NetLogWithSource());
1560 }
1561
1562 // Allow all requests to move from the Create queue to the active entry.
1563 base::RunLoop().RunUntilIdle();
1564
1565 // The first request should be a writer at this point, and the subsequent
1566 // requests should have completed validation.
1567
1568 EXPECT_EQ(1, cache.network_layer()->transaction_count());
1569 EXPECT_EQ(0, cache.disk_cache()->open_count());
1570 EXPECT_EQ(1, cache.disk_cache()->create_count());
1571 1403
1572 EXPECT_TRUE(cache.IsWriterPresent(kSimpleGET_Transaction.url)); 1404 for (int i = 0; i < kNumTransactions; ++i) {
1573 EXPECT_EQ(1, cache.GetCountDoneHeadersQueue(kSimpleGET_Transaction.url)); 1405 Context* c = context_list[i];
1574 1406 delete c;
1575 context_list[1].reset();
1576
1577 EXPECT_EQ(0, cache.GetCountDoneHeadersQueue(kSimpleGET_Transaction.url));
1578
1579 // Complete the rest of the transactions.
1580 for (auto& context : context_list) {
1581 if (!context)
1582 continue;
1583 ReadAndVerifyTransaction(context->trans.get(), kSimpleGET_Transaction);
1584 } 1407 }
1585
1586 EXPECT_EQ(1, cache.network_layer()->transaction_count());
1587 EXPECT_EQ(0, cache.disk_cache()->open_count());
1588 EXPECT_EQ(1, cache.disk_cache()->create_count());
1589 }
1590
1591 // Tests that a transaction which is in readers can be destroyed without
1592 // any impact to other transactions.
1593 TEST(HttpCache, SimpleGET_ParallelValidationCancelReader) {
1594 MockHttpCache cache;
1595
1596 MockHttpRequest request(kSimpleGET_Transaction);
1597
1598 MockTransaction transaction(kSimpleGET_Transaction);
1599 transaction.load_flags |= LOAD_VALIDATE_CACHE;
1600 MockHttpRequest validate_request(transaction);
1601
1602 int kNumTransactions = 4;
1603 std::vector<std::unique_ptr<Context>> context_list;
1604
1605 for (int i = 0; i < kNumTransactions; ++i) {
1606 context_list.push_back(base::MakeUnique<Context>());
1607 auto& c = context_list[i];
1608
1609 c->result = cache.CreateTransaction(&c->trans);
1610 ASSERT_THAT(c->result, IsOk());
1611
1612 MockHttpRequest* this_request = &request;
1613 if (i == 3) {
1614 this_request = &validate_request;
1615 c->trans->SetBeforeNetworkStartCallback(base::Bind(&DeferNetworkStart));
1616 }
1617
1618 c->result = c->trans->Start(this_request, c->callback.callback(),
1619 NetLogWithSource());
1620 }
1621
1622 // Allow all requests to move from the Create queue to the active entry.
1623 base::RunLoop().RunUntilIdle();
1624
1625 EXPECT_EQ(2, cache.network_layer()->transaction_count());
1626 EXPECT_EQ(0, cache.disk_cache()->open_count());
1627 EXPECT_EQ(1, cache.disk_cache()->create_count());
1628
1629 EXPECT_TRUE(cache.IsWriterPresent(kSimpleGET_Transaction.url));
1630 EXPECT_EQ(2, cache.GetCountDoneHeadersQueue(kSimpleGET_Transaction.url));
1631 EXPECT_TRUE(cache.IsHeadersTransactionPresent(kSimpleGET_Transaction.url));
1632
1633 // Complete the response body.
1634 auto& c = context_list[0];
1635 ReadAndVerifyTransaction(c->trans.get(), kSimpleGET_Transaction);
1636
1637 // Rest of the transactions should move to readers.
1638 EXPECT_FALSE(cache.IsWriterPresent(kSimpleGET_Transaction.url));
1639 EXPECT_EQ(2, cache.GetCountReaders(kSimpleGET_Transaction.url));
1640 EXPECT_EQ(0, cache.GetCountDoneHeadersQueue(kSimpleGET_Transaction.url));
1641 EXPECT_TRUE(cache.IsHeadersTransactionPresent(kSimpleGET_Transaction.url));
1642
1643 // Add 2 new transactions.
1644 kNumTransactions = 6;
1645
1646 for (int i = 4; i < kNumTransactions; ++i) {
1647 context_list.push_back(base::MakeUnique<Context>());
1648 auto& c = context_list[i];
1649
1650 c->result = cache.CreateTransaction(&c->trans);
1651 ASSERT_THAT(c->result, IsOk());
1652
1653 c->result =
1654 c->trans->Start(&request, c->callback.callback(), NetLogWithSource());
1655 }
1656
1657 EXPECT_EQ(2, cache.GetCountAddToEntryQueue(kSimpleGET_Transaction.url));
1658
1659 // Delete a reader.
1660 context_list[1].reset();
1661
1662 // Deleting the reader did not impact any other transaction.
1663 EXPECT_EQ(1, cache.GetCountReaders(kSimpleGET_Transaction.url));
1664 EXPECT_EQ(2, cache.GetCountAddToEntryQueue(kSimpleGET_Transaction.url));
1665 EXPECT_TRUE(cache.IsHeadersTransactionPresent(kSimpleGET_Transaction.url));
1666
1667 // Resume network start for headers_transaction. It will doom the entry as it
1668 // will be a 200 and will go to network for the response body.
1669 auto& context = context_list[3];
1670 context->trans->ResumeNetworkStart();
1671
1672 // The pending transactions will be added to a new entry.
1673 base::RunLoop().RunUntilIdle();
1674
1675 EXPECT_EQ(1, cache.GetCountDoneHeadersQueue(kSimpleGET_Transaction.url));
1676 EXPECT_TRUE(cache.IsWriterPresent(kSimpleGET_Transaction.url));
1677
1678 // Complete the rest of the transactions.
1679 for (int i = 2; i < kNumTransactions; ++i) {
1680 auto& c = context_list[i];
1681 ReadAndVerifyTransaction(c->trans.get(), kSimpleGET_Transaction);
1682 }
1683
1684 EXPECT_EQ(3, cache.network_layer()->transaction_count());
1685 EXPECT_EQ(0, cache.disk_cache()->open_count());
1686 EXPECT_EQ(2, cache.disk_cache()->create_count());
1687 }
1688
1689 // Tests that a transaction is in validated queue and writer is destroyed
1690 // leading to restarting the validated transaction.
1691 TEST(HttpCache, SimpleGET_ParallelValidationCancelWriter) {
1692 MockHttpCache cache;
1693
1694 MockHttpRequest request(kSimpleGET_Transaction);
1695
1696 MockTransaction transaction(kSimpleGET_Transaction);
1697 transaction.load_flags |= LOAD_VALIDATE_CACHE;
1698 MockHttpRequest validate_request(transaction);
1699
1700 const int kNumTransactions = 3;
1701 std::vector<std::unique_ptr<Context>> context_list;
1702
1703 for (int i = 0; i < kNumTransactions; ++i) {
1704 context_list.push_back(base::MakeUnique<Context>());
1705 auto& c = context_list[i];
1706
1707 c->result = cache.CreateTransaction(&c->trans);
1708 ASSERT_THAT(c->result, IsOk());
1709
1710 MockHttpRequest* this_request = &request;
1711 if (i == 2) {
1712 this_request = &validate_request;
1713 c->trans->SetBeforeNetworkStartCallback(base::Bind(&DeferNetworkStart));
1714 }
1715
1716 c->result = c->trans->Start(this_request, c->callback.callback(),
1717 NetLogWithSource());
1718 }
1719
1720 // Allow all requests to move from the Create queue to the active entry.
1721 base::RunLoop().RunUntilIdle();
1722
1723 EXPECT_EQ(2, cache.network_layer()->transaction_count());
1724 EXPECT_EQ(0, cache.disk_cache()->open_count());
1725 EXPECT_EQ(1, cache.disk_cache()->create_count());
1726
1727 EXPECT_TRUE(cache.IsWriterPresent(kSimpleGET_Transaction.url));
1728 EXPECT_TRUE(cache.IsHeadersTransactionPresent(kSimpleGET_Transaction.url));
1729 EXPECT_EQ(1, cache.GetCountDoneHeadersQueue(kSimpleGET_Transaction.url));
1730
1731 // Deleting the writer at this point will lead to destroying the entry and
1732 // restarting the remaining transactions which will then create a new entry.
1733 context_list[0].reset();
1734
1735 // Resume network start for headers_transaction. It should be restarted due to
1736 // writer cancellation.
1737 auto& c = context_list[2];
1738 c->trans->ResumeNetworkStart();
1739
1740 base::RunLoop().RunUntilIdle();
1741
1742 EXPECT_TRUE(cache.IsWriterPresent(kSimpleGET_Transaction.url));
1743 EXPECT_TRUE(cache.IsHeadersTransactionPresent(kSimpleGET_Transaction.url));
1744
1745 // Resume network start for the transaction the second time.
1746 c->trans->ResumeNetworkStart();
1747 base::RunLoop().RunUntilIdle();
1748
1749 // Headers transaction would have doomed the new entry created.
1750 EXPECT_TRUE(
1751 cache.disk_cache()->IsDiskEntryDoomed(kSimpleGET_Transaction.url));
1752
1753 // Complete the rest of the transactions.
1754 for (auto& context : context_list) {
1755 if (!context)
1756 continue;
1757 ReadAndVerifyTransaction(context->trans.get(), kSimpleGET_Transaction);
1758 }
1759
1760 EXPECT_EQ(4, cache.network_layer()->transaction_count());
1761 EXPECT_EQ(0, cache.disk_cache()->open_count());
1762 EXPECT_EQ(2, cache.disk_cache()->create_count());
1763 }
1764
1765 // Tests that a transaction is currently in headers phase and is destroyed
1766 // leading to destroying the entry.
1767 TEST(HttpCache, SimpleGET_ParallelValidationCancelHeaders) {
1768 MockHttpCache cache;
1769
1770 MockHttpRequest request(kSimpleGET_Transaction);
1771
1772 const int kNumTransactions = 2;
1773 std::vector<std::unique_ptr<Context>> context_list;
1774
1775 for (int i = 0; i < kNumTransactions; ++i) {
1776 context_list.push_back(base::MakeUnique<Context>());
1777 auto& c = context_list[i];
1778
1779 c->result = cache.CreateTransaction(&c->trans);
1780 ASSERT_THAT(c->result, IsOk());
1781
1782 if (i == 0)
1783 c->trans->SetBeforeNetworkStartCallback(base::Bind(&DeferNetworkStart));
1784
1785 c->result =
1786 c->trans->Start(&request, c->callback.callback(), NetLogWithSource());
1787 }
1788
1789 base::RunLoop().RunUntilIdle();
1790
1791 EXPECT_TRUE(cache.IsHeadersTransactionPresent(kSimpleGET_Transaction.url));
1792 EXPECT_EQ(1, cache.GetCountAddToEntryQueue(kSimpleGET_Transaction.url));
1793
1794 EXPECT_EQ(1, cache.network_layer()->transaction_count());
1795 EXPECT_EQ(0, cache.disk_cache()->open_count());
1796 EXPECT_EQ(1, cache.disk_cache()->create_count());
1797
1798 // Delete the headers transaction.
1799 context_list[0].reset();
1800
1801 base::RunLoop().RunUntilIdle();
1802
1803 // Complete the rest of the transactions.
1804 for (auto& context : context_list) {
1805 if (!context)
1806 continue;
1807 ReadAndVerifyTransaction(context->trans.get(), kSimpleGET_Transaction);
1808 }
1809
1810 EXPECT_EQ(2, cache.network_layer()->transaction_count());
1811 EXPECT_EQ(0, cache.disk_cache()->open_count());
1812 EXPECT_EQ(2, cache.disk_cache()->create_count());
1813 }
1814
1815 // Similar to the above test, except here cache write fails and the
1816 // validated transactions should be restarted.
1817 TEST(HttpCache, SimpleGET_ParallelValidationFailWrite) {
1818 MockHttpCache cache;
1819
1820 MockHttpRequest request(kSimpleGET_Transaction);
1821
1822 const int kNumTransactions = 5;
1823 std::vector<std::unique_ptr<Context>> context_list;
1824
1825 for (int i = 0; i < kNumTransactions; ++i) {
1826 context_list.push_back(base::MakeUnique<Context>());
1827 auto& c = context_list[i];
1828
1829 c->result = cache.CreateTransaction(&c->trans);
1830 ASSERT_THAT(c->result, IsOk());
1831 EXPECT_EQ(LOAD_STATE_IDLE, c->trans->GetLoadState());
1832
1833 c->result =
1834 c->trans->Start(&request, c->callback.callback(), NetLogWithSource());
1835 }
1836
1837 // All requests are waiting for the active entry.
1838 for (auto& context : context_list) {
1839 EXPECT_EQ(LOAD_STATE_WAITING_FOR_CACHE, context->trans->GetLoadState());
1840 }
1841
1842 // Allow all requests to move from the Create queue to the active entry.
1843 base::RunLoop().RunUntilIdle();
1844
1845 // The first request should be a writer at this point, and the subsequent
1846 // requests should have passed the validation phase and waiting for the
1847 // response to be written to the cache before they can read.
1848 EXPECT_TRUE(cache.IsWriterPresent(kSimpleGET_Transaction.url));
1849 EXPECT_EQ(4, cache.GetCountDoneHeadersQueue(kSimpleGET_Transaction.url));
1850
1851 // All requests depend on the writer, and the writer is between Start and
1852 // Read, i.e. idle.
1853 for (auto& context : context_list) {
1854 EXPECT_EQ(LOAD_STATE_IDLE, context->trans->GetLoadState());
1855 }
1856
1857 // The first request should be a writer at this point, and the subsequent
1858 // requests should have passed the validation phase and waiting for the
1859 // response to be written to the cache before they can read.
1860
1861 EXPECT_EQ(1, cache.network_layer()->transaction_count());
1862 EXPECT_EQ(0, cache.disk_cache()->open_count());
1863 EXPECT_EQ(1, cache.disk_cache()->create_count());
1864
1865 // Fail the request.
1866 cache.disk_cache()->set_soft_failures(true);
1867 // We have to open the entry again to propagate the failure flag.
1868 disk_cache::Entry* en;
1869 cache.OpenBackendEntry(kSimpleGET_Transaction.url, &en);
1870 en->Close();
1871
1872 for (int i = 0; i < kNumTransactions; ++i) {
1873 auto& c = context_list[i];
1874 if (c->result == ERR_IO_PENDING)
1875 c->result = c->callback.WaitForResult();
1876 if (i == 1) {
1877 // The earlier entry must be destroyed and its disk entry doomed.
1878 EXPECT_TRUE(
1879 cache.disk_cache()->IsDiskEntryDoomed(kSimpleGET_Transaction.url));
1880 }
1881 ReadAndVerifyTransaction(c->trans.get(), kSimpleGET_Transaction);
1882 }
1883
1884 // Since validated transactions were restarted and new entry read/write
1885 // operations would also fail, all requests would have gone to the network.
1886 EXPECT_EQ(5, cache.network_layer()->transaction_count());
1887 EXPECT_EQ(1, cache.disk_cache()->open_count());
1888 EXPECT_EQ(5, cache.disk_cache()->create_count());
1889 } 1408 }
1890 1409
1891 // This is a test for http://code.google.com/p/chromium/issues/detail?id=4769. 1410 // This is a test for http://code.google.com/p/chromium/issues/detail?id=4769.
1892 // If cancelling a request is racing with another request for the same resource 1411 // If cancelling a request is racing with another request for the same resource
1893 // finishing, we have to make sure that we remove both transactions from the 1412 // finishing, we have to make sure that we remove both transactions from the
1894 // entry. 1413 // entry.
1895 TEST(HttpCache, SimpleGET_RacingReaders) { 1414 TEST(HttpCache, SimpleGET_RacingReaders) {
1896 MockHttpCache cache; 1415 MockHttpCache cache;
1897 1416
1898 MockHttpRequest request(kSimpleGET_Transaction); 1417 MockHttpRequest request(kSimpleGET_Transaction);
(...skipping 26 matching lines...) Expand all
1925 1444
1926 EXPECT_EQ(1, cache.network_layer()->transaction_count()); 1445 EXPECT_EQ(1, cache.network_layer()->transaction_count());
1927 EXPECT_EQ(0, cache.disk_cache()->open_count()); 1446 EXPECT_EQ(0, cache.disk_cache()->open_count());
1928 EXPECT_EQ(1, cache.disk_cache()->create_count()); 1447 EXPECT_EQ(1, cache.disk_cache()->create_count());
1929 1448
1930 Context* c = context_list[0]; 1449 Context* c = context_list[0];
1931 ASSERT_THAT(c->result, IsError(ERR_IO_PENDING)); 1450 ASSERT_THAT(c->result, IsError(ERR_IO_PENDING));
1932 c->result = c->callback.WaitForResult(); 1451 c->result = c->callback.WaitForResult();
1933 ReadAndVerifyTransaction(c->trans.get(), kSimpleGET_Transaction); 1452 ReadAndVerifyTransaction(c->trans.get(), kSimpleGET_Transaction);
1934 1453
1935 // Now all transactions should be waiting for read to be invoked. Two readers 1454 // Now we have 2 active readers and two queued transactions.
1936 // are because of the load flags and remaining two transactions were converted 1455
1937 // to readers after skipping validation. Note that the remaining two went on
1938 // to process the headers in parallel with readers present on the entry.
1939 EXPECT_EQ(LOAD_STATE_IDLE, context_list[2]->trans->GetLoadState()); 1456 EXPECT_EQ(LOAD_STATE_IDLE, context_list[2]->trans->GetLoadState());
1940 EXPECT_EQ(LOAD_STATE_IDLE, context_list[3]->trans->GetLoadState()); 1457 EXPECT_EQ(LOAD_STATE_WAITING_FOR_CACHE,
1458 context_list[3]->trans->GetLoadState());
1941 1459
1942 c = context_list[1]; 1460 c = context_list[1];
1943 ASSERT_THAT(c->result, IsError(ERR_IO_PENDING)); 1461 ASSERT_THAT(c->result, IsError(ERR_IO_PENDING));
1944 c->result = c->callback.WaitForResult(); 1462 c->result = c->callback.WaitForResult();
1945 if (c->result == OK) 1463 if (c->result == OK)
1946 ReadAndVerifyTransaction(c->trans.get(), kSimpleGET_Transaction); 1464 ReadAndVerifyTransaction(c->trans.get(), kSimpleGET_Transaction);
1947 1465
1948 // At this point we have one reader, two pending transactions and a task on 1466 // At this point we have one reader, two pending transactions and a task on
1949 // the queue to move to the next transaction. Now we cancel the request that 1467 // the queue to move to the next transaction. Now we cancel the request that
1950 // is the current reader, and expect the queued task to be able to start the 1468 // is the current reader, and expect the queued task to be able to start the
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1995 ASSERT_THAT(c->result, IsOk()); 1513 ASSERT_THAT(c->result, IsOk());
1996 1514
1997 MockHttpRequest* this_request = &request; 1515 MockHttpRequest* this_request = &request;
1998 if (i == 3) 1516 if (i == 3)
1999 this_request = &writer_request; 1517 this_request = &writer_request;
2000 1518
2001 c->result = c->trans->Start(this_request, c->callback.callback(), 1519 c->result = c->trans->Start(this_request, c->callback.callback(),
2002 NetLogWithSource()); 1520 NetLogWithSource());
2003 } 1521 }
2004 1522
2005 base::RunLoop().RunUntilIdle();
2006
2007 // The first request should be a writer at this point, and the two subsequent 1523 // The first request should be a writer at this point, and the two subsequent
2008 // requests should be pending. The last request doomed the first entry. 1524 // requests should be pending. The last request doomed the first entry.
2009 1525
2010 EXPECT_EQ(2, cache.network_layer()->transaction_count()); 1526 EXPECT_EQ(2, cache.network_layer()->transaction_count());
2011 1527
2012 // Cancel the second transaction. Note that this and the 3rd transactions 1528 // Cancel the first queued transaction.
2013 // would have completed their headers phase and would be waiting in the
2014 // done_headers_queue when the 2nd transaction is cancelled.
2015 context_list[1].reset(); 1529 context_list[1].reset();
2016 1530
2017 for (int i = 0; i < kNumTransactions; ++i) { 1531 for (int i = 0; i < kNumTransactions; ++i) {
2018 if (i == 1) 1532 if (i == 1)
2019 continue; 1533 continue;
2020 Context* c = context_list[i].get(); 1534 Context* c = context_list[i].get();
2021 ASSERT_THAT(c->result, IsError(ERR_IO_PENDING)); 1535 ASSERT_THAT(c->result, IsError(ERR_IO_PENDING));
2022 c->result = c->callback.WaitForResult(); 1536 c->result = c->callback.WaitForResult();
2023 ReadAndVerifyTransaction(c->trans.get(), kSimpleGET_Transaction); 1537 ReadAndVerifyTransaction(c->trans.get(), kSimpleGET_Transaction);
2024 } 1538 }
(...skipping 21 matching lines...) Expand all
2046 ASSERT_THAT(c->result, IsOk()); 1560 ASSERT_THAT(c->result, IsOk());
2047 1561
2048 c->result = 1562 c->result =
2049 c->trans->Start(&request, c->callback.callback(), NetLogWithSource()); 1563 c->trans->Start(&request, c->callback.callback(), NetLogWithSource());
2050 } 1564 }
2051 1565
2052 // Allow all requests to move from the Create queue to the active entry. 1566 // Allow all requests to move from the Create queue to the active entry.
2053 base::RunLoop().RunUntilIdle(); 1567 base::RunLoop().RunUntilIdle();
2054 1568
2055 // The first request should be a writer at this point, and the subsequent 1569 // The first request should be a writer at this point, and the subsequent
2056 // requests should have completed validation. Since the validation does not 1570 // requests should be pending.
2057 // result in a match, a new entry would be created.
2058 1571
2059 EXPECT_EQ(3, cache.network_layer()->transaction_count()); 1572 EXPECT_EQ(1, cache.network_layer()->transaction_count());
2060 EXPECT_EQ(0, cache.disk_cache()->open_count()); 1573 EXPECT_EQ(0, cache.disk_cache()->open_count());
2061 EXPECT_EQ(2, cache.disk_cache()->create_count()); 1574 EXPECT_EQ(1, cache.disk_cache()->create_count());
2062 1575
2063 // Now, make sure that the second request asks for the entry not to be stored. 1576 // Now, make sure that the second request asks for the entry not to be stored.
2064 request_handler.set_no_store(true); 1577 request_handler.set_no_store(true);
2065 1578
2066 for (int i = 0; i < kNumTransactions; ++i) { 1579 for (int i = 0; i < kNumTransactions; ++i) {
2067 Context* c = context_list[i]; 1580 Context* c = context_list[i];
2068 if (c->result == ERR_IO_PENDING) 1581 if (c->result == ERR_IO_PENDING)
2069 c->result = c->callback.WaitForResult(); 1582 c->result = c->callback.WaitForResult();
2070 ReadAndVerifyTransaction(c->trans.get(), kFastNoStoreGET_Transaction); 1583 ReadAndVerifyTransaction(c->trans.get(), kFastNoStoreGET_Transaction);
2071 delete c; 1584 delete c;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
2105 1618
2106 EXPECT_EQ(1, cache.network_layer()->transaction_count()); 1619 EXPECT_EQ(1, cache.network_layer()->transaction_count());
2107 EXPECT_EQ(0, cache.disk_cache()->open_count()); 1620 EXPECT_EQ(0, cache.disk_cache()->open_count());
2108 EXPECT_EQ(1, cache.disk_cache()->create_count()); 1621 EXPECT_EQ(1, cache.disk_cache()->create_count());
2109 1622
2110 for (int i = 0; i < kNumTransactions; ++i) { 1623 for (int i = 0; i < kNumTransactions; ++i) {
2111 Context* c = context_list[i]; 1624 Context* c = context_list[i];
2112 if (c->result == ERR_IO_PENDING) 1625 if (c->result == ERR_IO_PENDING)
2113 c->result = c->callback.WaitForResult(); 1626 c->result = c->callback.WaitForResult();
2114 // Destroy only the first transaction. 1627 // Destroy only the first transaction.
2115 // This should lead to all transactions to restart, even those that have
2116 // validated themselves and were waiting for the writer transaction to
2117 // complete writing to the cache.
2118 if (i == 0) { 1628 if (i == 0) {
2119 delete c; 1629 delete c;
2120 context_list[i] = NULL; 1630 context_list[i] = NULL;
2121 } 1631 }
2122 } 1632 }
2123 1633
2124 // Complete the rest of the transactions. 1634 // Complete the rest of the transactions.
2125 for (int i = 1; i < kNumTransactions; ++i) { 1635 for (int i = 1; i < kNumTransactions; ++i) {
2126 Context* c = context_list[i]; 1636 Context* c = context_list[i];
2127 ReadAndVerifyTransaction(c->trans.get(), kSimpleGET_Transaction); 1637 ReadAndVerifyTransaction(c->trans.get(), kSimpleGET_Transaction);
(...skipping 895 matching lines...) Expand 10 before | Expand all | Expand 10 after
3023 } 2533 }
3024 2534
3025 // Helper that does 4 requests using HttpCache: 2535 // Helper that does 4 requests using HttpCache:
3026 // 2536 //
3027 // (1) loads |kUrl| -- expects |net_response_1| to be returned. 2537 // (1) loads |kUrl| -- expects |net_response_1| to be returned.
3028 // (2) loads |kUrl| from cache only -- expects |net_response_1| to be returned. 2538 // (2) loads |kUrl| from cache only -- expects |net_response_1| to be returned.
3029 // (3) loads |kUrl| using |extra_request_headers| -- expects |net_response_2| to 2539 // (3) loads |kUrl| using |extra_request_headers| -- expects |net_response_2| to
3030 // be returned. 2540 // be returned.
3031 // (4) loads |kUrl| from cache only -- expects |cached_response_2| to be 2541 // (4) loads |kUrl| from cache only -- expects |cached_response_2| to be
3032 // returned. 2542 // returned.
3033 // The entry will be created once and will be opened for the 3 subsequent
3034 // requests.
3035 static void ConditionalizedRequestUpdatesCacheHelper( 2543 static void ConditionalizedRequestUpdatesCacheHelper(
3036 const Response& net_response_1, 2544 const Response& net_response_1,
3037 const Response& net_response_2, 2545 const Response& net_response_2,
3038 const Response& cached_response_2, 2546 const Response& cached_response_2,
3039 const char* extra_request_headers) { 2547 const char* extra_request_headers) {
3040 MockHttpCache cache; 2548 MockHttpCache cache;
3041 2549
3042 // The URL we will be requesting. 2550 // The URL we will be requesting.
3043 const char kUrl[] = "http://foobar.com/main.css"; 2551 const char kUrl[] = "http://foobar.com/main.css";
3044 2552
(...skipping 3555 matching lines...) Expand 10 before | Expand all | Expand 10 after
6600 pending->trans->Start(&request, pending->callback.callback(), 6108 pending->trans->Start(&request, pending->callback.callback(),
6601 NetLogWithSource())); 6109 NetLogWithSource()));
6602 EXPECT_THAT(c->callback.GetResult(rv), IsOk()); 6110 EXPECT_THAT(c->callback.GetResult(rv), IsOk());
6603 6111
6604 // Make sure that the entry has some data stored. 6112 // Make sure that the entry has some data stored.
6605 scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(5)); 6113 scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(5));
6606 rv = c->trans->Read(buf.get(), buf->size(), c->callback.callback()); 6114 rv = c->trans->Read(buf.get(), buf->size(), c->callback.callback());
6607 EXPECT_EQ(5, c->callback.GetResult(rv)); 6115 EXPECT_EQ(5, c->callback.GetResult(rv));
6608 6116
6609 // Cancel the requests. 6117 // Cancel the requests.
6610 // Since |pending| is currently validating the already written headers
6611 // it will be restarted as well.
6612 delete c; 6118 delete c;
6613 delete pending; 6119 delete pending;
6614 6120
6615 EXPECT_EQ(1, cache.network_layer()->transaction_count()); 6121 EXPECT_EQ(1, cache.network_layer()->transaction_count());
6616 EXPECT_EQ(1, cache.disk_cache()->open_count()); 6122 EXPECT_EQ(1, cache.disk_cache()->open_count());
6617 EXPECT_EQ(1, cache.disk_cache()->create_count()); 6123 EXPECT_EQ(2, cache.disk_cache()->create_count());
6618 6124
6619 base::RunLoop().RunUntilIdle(); 6125 base::RunLoop().RunUntilIdle();
6620 RemoveMockTransaction(&transaction); 6126 RemoveMockTransaction(&transaction);
6621 } 6127 }
6622 6128
6623 // Tests that we delete truncated entries if the server changes its mind midway. 6129 // Tests that we delete truncated entries if the server changes its mind midway.
6624 TEST(HttpCache, GET_IncompleteResource2) { 6130 TEST(HttpCache, GET_IncompleteResource2) {
6625 MockHttpCache cache; 6131 MockHttpCache cache;
6626 AddMockTransaction(&kRangeGET_TransactionOK); 6132 AddMockTransaction(&kRangeGET_TransactionOK);
6627 6133
(...skipping 704 matching lines...) Expand 10 before | Expand all | Expand 10 after
7332 6838
7333 RunTransactionTestWithResponseInfo(cache.http_cache(), kSimpleGET_Transaction, 6839 RunTransactionTestWithResponseInfo(cache.http_cache(), kSimpleGET_Transaction,
7334 &response); 6840 &response);
7335 EXPECT_TRUE(response.metadata.get() == NULL); 6841 EXPECT_TRUE(response.metadata.get() == NULL);
7336 6842
7337 EXPECT_EQ(1, cache.network_layer()->transaction_count()); 6843 EXPECT_EQ(1, cache.network_layer()->transaction_count());
7338 EXPECT_EQ(2, cache.disk_cache()->open_count()); 6844 EXPECT_EQ(2, cache.disk_cache()->open_count());
7339 EXPECT_EQ(1, cache.disk_cache()->create_count()); 6845 EXPECT_EQ(1, cache.disk_cache()->create_count());
7340 } 6846 }
7341 6847
6848 // Tests that if a metadata writer transaction hits cache lock timeout, it will
6849 // error out.
6850 TEST(HttpCache, WriteMetadata_CacheLockTimeout) {
6851 MockHttpCache cache;
6852
6853 // Write to the cache
6854 HttpResponseInfo response;
6855 RunTransactionTestWithResponseInfo(cache.http_cache(), kSimpleGET_Transaction,
6856 &response);
6857 EXPECT_FALSE(response.metadata.get());
6858
6859 MockHttpRequest request(kSimpleGET_Transaction);
6860 Context c1;
6861 ASSERT_THAT(cache.CreateTransaction(&c1.trans), IsOk());
6862 ASSERT_EQ(ERR_IO_PENDING, c1.trans->Start(&request, c1.callback.callback(),
6863 NetLogWithSource()));
6864
6865 cache.SimulateCacheLockTimeout();
6866
6867 // Write meta data to the same entry.
6868 scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(50));
6869 memset(buf->data(), 0, buf->size());
6870 base::strlcpy(buf->data(), "Hi there", buf->size());
6871 cache.http_cache()->WriteMetadata(GURL(kSimpleGET_Transaction.url),
6872 DEFAULT_PRIORITY, response.response_time,
6873 buf.get(), buf->size());
6874
6875 // Release the buffer before the operation takes place.
6876 buf = NULL;
6877
6878 // Makes sure we finish pending operations.
6879 base::RunLoop().RunUntilIdle();
6880
6881 RunTransactionTestWithResponseInfo(cache.http_cache(), kSimpleGET_Transaction,
6882 &response);
6883
6884 // The writer transaction should fail due to cache lock timeout.
6885 ASSERT_FALSE(response.metadata.get());
6886 }
6887
7342 // Tests that we ignore VARY checks when writing metadata since the request 6888 // Tests that we ignore VARY checks when writing metadata since the request
7343 // headers for the WriteMetadata transaction are made up. 6889 // headers for the WriteMetadata transaction are made up.
7344 TEST(HttpCache, WriteMetadata_IgnoreVary) { 6890 TEST(HttpCache, WriteMetadata_IgnoreVary) {
7345 MockHttpCache cache; 6891 MockHttpCache cache;
7346 6892
7347 // Write to the cache 6893 // Write to the cache
7348 HttpResponseInfo response; 6894 HttpResponseInfo response;
7349 ScopedMockTransaction transaction(kSimpleGET_Transaction); 6895 ScopedMockTransaction transaction(kSimpleGET_Transaction);
7350 transaction.request_headers = "accept-encoding: gzip\r\n"; 6896 transaction.request_headers = "accept-encoding: gzip\r\n";
7351 transaction.response_headers = 6897 transaction.response_headers =
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
7659 MockHttpRequest request(mock_transaction); 7205 MockHttpRequest request(mock_transaction);
7660 7206
7661 { 7207 {
7662 std::unique_ptr<HttpTransaction> trans; 7208 std::unique_ptr<HttpTransaction> trans;
7663 ASSERT_THAT(cache.CreateTransaction(&trans), IsOk()); 7209 ASSERT_THAT(cache.CreateTransaction(&trans), IsOk());
7664 7210
7665 int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); 7211 int rv = trans->Start(&request, callback.callback(), NetLogWithSource());
7666 EXPECT_THAT(callback.GetResult(rv), IsOk()); 7212 EXPECT_THAT(callback.GetResult(rv), IsOk());
7667 7213
7668 trans->StopCaching(); 7214 trans->StopCaching();
7215
7216 scoped_refptr<IOBuffer> buf(new IOBuffer(256));
7217 rv = trans->Read(buf.get(), 10, callback.callback());
7218 EXPECT_EQ(callback.GetResult(rv), 10);
7669 } 7219 }
7670 RemoveMockTransaction(&mock_transaction); 7220 RemoveMockTransaction(&mock_transaction);
7671 7221
7672 // Make sure that the ActiveEntry is gone. 7222 // Make sure that the ActiveEntry is gone.
7673 base::RunLoop().RunUntilIdle(); 7223 base::RunLoop().RunUntilIdle();
7674 7224
7675 // Verify that the entry is gone. 7225 // Verify that the entry is gone.
7676 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); 7226 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction);
7677 7227
7678 EXPECT_EQ(2, cache.network_layer()->transaction_count()); 7228 EXPECT_EQ(2, cache.network_layer()->transaction_count());
(...skipping 1031 matching lines...) Expand 10 before | Expand all | Expand 10 after
8710 ASSERT_TRUE(attrs->GetDictionary( 8260 ASSERT_TRUE(attrs->GetDictionary(
8711 base::trace_event::MemoryAllocatorDump::kNameSize, &size_attrs)); 8261 base::trace_event::MemoryAllocatorDump::kNameSize, &size_attrs));
8712 std::string size; 8262 std::string size;
8713 ASSERT_TRUE(size_attrs->GetString("value", &size)); 8263 ASSERT_TRUE(size_attrs->GetString("value", &size));
8714 int actual_size = 0; 8264 int actual_size = 0;
8715 ASSERT_TRUE(base::HexStringToInt(size, &actual_size)); 8265 ASSERT_TRUE(base::HexStringToInt(size, &actual_size));
8716 ASSERT_LT(0, actual_size); 8266 ASSERT_LT(0, actual_size);
8717 } 8267 }
8718 8268
8719 } // namespace net 8269 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_cache_transaction.cc ('k') | net/http/http_transaction_test_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698