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

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

Issue 2721933002: HttpCache::Transaction layer allowing parallel validation (Closed)
Patch Set: Rebased + test-only changes for fixing the new Push Cache Lookup failing unit tests Created 3 years, 8 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
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
150 class DeleteCacheCompletionCallback : public TestCompletionCallbackBase { 154 class DeleteCacheCompletionCallback : public TestCompletionCallbackBase {
151 public: 155 public:
152 explicit DeleteCacheCompletionCallback(MockHttpCache* cache) 156 explicit DeleteCacheCompletionCallback(MockHttpCache* cache)
153 : cache_(cache), 157 : cache_(cache),
154 callback_(base::Bind(&DeleteCacheCompletionCallback::OnComplete, 158 callback_(base::Bind(&DeleteCacheCompletionCallback::OnComplete,
155 base::Unretained(this))) { 159 base::Unretained(this))) {
156 } 160 }
157 161
158 const CompletionCallback& callback() const { return callback_; } 162 const CompletionCallback& callback() const { return callback_; }
159 163
(...skipping 1208 matching lines...) Expand 10 before | Expand all | Expand 10 after
1368 // All requests are waiting for the active entry. 1372 // All requests are waiting for the active entry.
1369 for (int i = 0; i < kNumTransactions; ++i) { 1373 for (int i = 0; i < kNumTransactions; ++i) {
1370 Context* c = context_list[i]; 1374 Context* c = context_list[i];
1371 EXPECT_EQ(LOAD_STATE_WAITING_FOR_CACHE, c->trans->GetLoadState()); 1375 EXPECT_EQ(LOAD_STATE_WAITING_FOR_CACHE, c->trans->GetLoadState());
1372 } 1376 }
1373 1377
1374 // Allow all requests to move from the Create queue to the active entry. 1378 // Allow all requests to move from the Create queue to the active entry.
1375 base::RunLoop().RunUntilIdle(); 1379 base::RunLoop().RunUntilIdle();
1376 1380
1377 // The first request should be a writer at this point, and the subsequent 1381 // The first request should be a writer at this point, and the subsequent
1378 // requests should be pending. 1382 // requests should have passed the validation phase and waiting for the
1383 // response to be written to the cache before they can read.
1384 EXPECT_TRUE(cache.IsWriterPresent(kSimpleGET_Transaction.url));
1385 EXPECT_EQ(4, cache.GetCountDoneHeadersQueue(kSimpleGET_Transaction.url));
1379 1386
1380 EXPECT_EQ(1, cache.network_layer()->transaction_count()); 1387 EXPECT_EQ(1, cache.network_layer()->transaction_count());
1381 EXPECT_EQ(0, cache.disk_cache()->open_count()); 1388 EXPECT_EQ(0, cache.disk_cache()->open_count());
1382 EXPECT_EQ(1, cache.disk_cache()->create_count()); 1389 EXPECT_EQ(1, cache.disk_cache()->create_count());
1383 1390
1384 // All requests depend on the writer, and the writer is between Start and 1391 // All requests depend on the writer, and the writer is between Start and
1385 // Read, i.e. idle. 1392 // Read, i.e. idle.
1386 for (int i = 0; i < kNumTransactions; ++i) { 1393 for (int i = 0; i < kNumTransactions; ++i) {
1387 Context* c = context_list[i]; 1394 Context* c = context_list[i];
1388 EXPECT_EQ(LOAD_STATE_IDLE, c->trans->GetLoadState()); 1395 EXPECT_EQ(LOAD_STATE_IDLE, c->trans->GetLoadState());
1389 } 1396 }
1390 1397
1391 for (int i = 0; i < kNumTransactions; ++i) { 1398 for (int i = 0; i < kNumTransactions; ++i) {
1392 Context* c = context_list[i]; 1399 Context* c = context_list[i];
1393 if (c->result == ERR_IO_PENDING) 1400 if (c->result == ERR_IO_PENDING)
1394 c->result = c->callback.WaitForResult(); 1401 c->result = c->callback.WaitForResult();
1402
1403 if (i == 1) {
1404 EXPECT_FALSE(cache.IsWriterPresent(kSimpleGET_Transaction.url));
1405 EXPECT_EQ(4, cache.GetCountReaders(kSimpleGET_Transaction.url));
jkarlin 2017/04/20 15:05:32 Perhaps: if (i > 0) { EXPECT_FALSE(cache.IsWrite
shivanisha 2017/04/21 23:06:01 done
1406 }
1407
1395 ReadAndVerifyTransaction(c->trans.get(), kSimpleGET_Transaction); 1408 ReadAndVerifyTransaction(c->trans.get(), kSimpleGET_Transaction);
1396 } 1409 }
1397 1410
1398 // We should not have had to re-open the disk entry 1411 // We should not have had to re-open the disk entry
1399 1412
1400 EXPECT_EQ(1, cache.network_layer()->transaction_count()); 1413 EXPECT_EQ(1, cache.network_layer()->transaction_count());
1401 EXPECT_EQ(0, cache.disk_cache()->open_count()); 1414 EXPECT_EQ(0, cache.disk_cache()->open_count());
1402 EXPECT_EQ(1, cache.disk_cache()->create_count()); 1415 EXPECT_EQ(1, cache.disk_cache()->create_count());
1403 1416
1404 for (int i = 0; i < kNumTransactions; ++i) { 1417 for (int i = 0; i < kNumTransactions; ++i) {
1405 Context* c = context_list[i]; 1418 Context* c = context_list[i];
1406 delete c; 1419 delete c;
1407 } 1420 }
1408 } 1421 }
1409 1422
1423 // Parallel validation results in 200.
1424 TEST(HttpCache, SimpleGET_ParallelValidationNoMatch) {
jkarlin 2017/04/20 15:05:38 Please make the changes in this test in all of the
shivanisha 2017/04/21 23:06:01 Done
1425 MockHttpCache cache;
1426
1427 MockHttpRequest request(kSimpleGET_Transaction);
1428 request.load_flags |= LOAD_VALIDATE_CACHE;
1429
1430 std::vector<Context*> context_list;
jkarlin 2017/04/20 15:05:40 std::vector<std::unique_ptr<Context>> context_list
shivanisha 2017/04/21 23:06:01 done
1431 const int kNumTransactions = 5;
1432
1433 for (int i = 0; i < kNumTransactions; ++i) {
1434 context_list.push_back(new Context());
jkarlin 2017/04/20 15:05:33 push_back(base::MakeUnique<Context>());
shivanisha 2017/04/21 23:06:01 done
1435 Context* c = context_list[i];
1436
1437 c->result = cache.CreateTransaction(&c->trans);
1438 ASSERT_THAT(c->result, IsOk());
1439 EXPECT_EQ(LOAD_STATE_IDLE, c->trans->GetLoadState());
1440
1441 c->result =
1442 c->trans->Start(&request, c->callback.callback(), NetLogWithSource());
1443 }
1444
1445 // All requests are waiting for the active entry.
1446 for (int i = 0; i < kNumTransactions; ++i) {
jkarlin 2017/04/20 15:05:32 for(auto context : context_list) { EXPECT_EQ(LOA
shivanisha 2017/04/21 23:06:01 It seems auto context doesn't work with unique_ptr
jkarlin 2017/04/24 15:57:26 Sorry, that was supposed to be auto& context. You
shivanisha 2017/04/24 18:29:02 Done
1447 Context* c = context_list[i];
1448 EXPECT_EQ(LOAD_STATE_WAITING_FOR_CACHE, c->trans->GetLoadState());
1449 }
1450
1451 // Allow all requests to move from the Create queue to the active entry.
1452 base::RunLoop().RunUntilIdle();
1453
1454 // The first request should be a writer at this point, and the subsequent
1455 // requests should have passed the validation phase and created their own
1456 // entries since none of them matched the headers of the earlier one.
1457 EXPECT_TRUE(cache.IsWriterPresent(kSimpleGET_Transaction.url));
1458
1459 EXPECT_EQ(5, cache.network_layer()->transaction_count());
1460 EXPECT_EQ(0, cache.disk_cache()->open_count());
1461 EXPECT_EQ(3, cache.disk_cache()->create_count());
jkarlin 2017/04/20 15:05:36 The comment above makes me think that we'd expect
shivanisha 2017/04/21 23:06:01 done
1462
1463 // All requests depend on the writer, and the writer is between Start and
1464 // Read, i.e. idle.
1465 for (int i = 0; i < kNumTransactions; ++i) {
jkarlin 2017/04/20 15:05:32 for each loop as above
shivanisha 2017/04/21 23:06:01 done
1466 Context* c = context_list[i];
1467 EXPECT_EQ(LOAD_STATE_IDLE, c->trans->GetLoadState());
1468 }
1469
1470 for (int i = 0; i < kNumTransactions; ++i) {
jkarlin 2017/04/20 15:05:35 for each loop
shivanisha 2017/04/21 23:06:01 done
1471 Context* c = context_list[i];
1472 if (c->result == ERR_IO_PENDING)
1473 c->result = c->callback.WaitForResult();
1474 ReadAndVerifyTransaction(c->trans.get(), kSimpleGET_Transaction);
1475 }
1476
1477 EXPECT_EQ(5, cache.network_layer()->transaction_count());
1478 EXPECT_EQ(0, cache.disk_cache()->open_count());
1479 EXPECT_EQ(3, cache.disk_cache()->create_count());
1480
1481 for (int i = 0; i < kNumTransactions; ++i) {
jkarlin 2017/04/20 15:05:38 For loop no longer needed with unique pointers abo
shivanisha 2017/04/21 23:06:01 removed
1482 Context* c = context_list[i];
1483 delete c;
1484 }
1485 }
1486
1487 // Tests that a GET followed by a DELETE results in DELETE immediately starting
1488 // the headers phase and the entry is doomed.
1489 TEST(HttpCache, SimpleGET_ParallelValidationDelete) {
1490 MockHttpCache cache;
1491
1492 MockHttpRequest request(kSimpleGET_Transaction);
1493 request.load_flags |= LOAD_VALIDATE_CACHE;
1494
1495 MockHttpRequest delete_request(kSimpleGET_Transaction);
1496 delete_request.method = "DELETE";
1497
1498 std::vector<Context*> context_list;
1499 const int kNumTransactions = 2;
1500
1501 for (int i = 0; i < kNumTransactions; ++i) {
1502 context_list.push_back(new Context());
1503 Context* c = context_list[i];
1504
1505 MockHttpRequest* this_request = &request;
1506 if (i == 1)
1507 this_request = &delete_request;
1508
1509 c->result = cache.CreateTransaction(&c->trans);
1510 ASSERT_THAT(c->result, IsOk());
1511 EXPECT_EQ(LOAD_STATE_IDLE, c->trans->GetLoadState());
1512
1513 c->result = c->trans->Start(this_request, c->callback.callback(),
1514 NetLogWithSource());
1515 }
1516
1517 // All requests are waiting for the active entry.
1518 for (int i = 0; i < kNumTransactions; ++i) {
1519 Context* c = context_list[i];
1520 EXPECT_EQ(LOAD_STATE_WAITING_FOR_CACHE, c->trans->GetLoadState());
1521 }
1522
1523 // Allow all requests to move from the Create queue to the active entry.
1524 base::RunLoop().RunUntilIdle();
1525
1526 // The first request should be a writer at this point, and the subsequent
1527 // request should have passed the validation phase and doomed the existing
1528 // entry.
1529 EXPECT_TRUE(
1530 cache.disk_cache()->IsDiskEntryDoomed(kSimpleGET_Transaction.url));
1531
1532 EXPECT_EQ(2, cache.network_layer()->transaction_count());
1533 EXPECT_EQ(0, cache.disk_cache()->open_count());
1534 EXPECT_EQ(1, cache.disk_cache()->create_count());
1535
1536 // All requests depend on the writer, and the writer is between Start and
1537 // Read, i.e. idle.
1538 for (int i = 0; i < kNumTransactions; ++i) {
1539 Context* c = context_list[i];
1540 EXPECT_EQ(LOAD_STATE_IDLE, c->trans->GetLoadState());
1541 }
1542
1543 for (int i = 0; i < kNumTransactions; ++i) {
1544 Context* c = context_list[i];
1545 if (c->result == ERR_IO_PENDING)
1546 c->result = c->callback.WaitForResult();
1547 ReadAndVerifyTransaction(c->trans.get(), kSimpleGET_Transaction);
1548 }
1549
1550 EXPECT_EQ(2, cache.network_layer()->transaction_count());
1551 EXPECT_EQ(0, cache.disk_cache()->open_count());
1552 EXPECT_EQ(1, cache.disk_cache()->create_count());
1553
1554 for (int i = 0; i < kNumTransactions; ++i) {
1555 Context* c = context_list[i];
1556 delete c;
1557 }
1558 }
1559
1560 // Tests that a transaction which is in validated queue can be destroyed without
1561 // any impact to other transactions.
1562 TEST(HttpCache, SimpleGET_ParallelValidationCancelValidated) {
1563 MockHttpCache cache;
1564
1565 MockHttpRequest request(kSimpleGET_Transaction);
1566
1567 std::vector<Context*> context_list;
1568 const int kNumTransactions = 2;
1569
1570 for (int i = 0; i < kNumTransactions; ++i) {
1571 context_list.push_back(new Context());
1572 Context* c = context_list[i];
1573
1574 c->result = cache.CreateTransaction(&c->trans);
1575 ASSERT_THAT(c->result, IsOk());
1576
1577 c->result =
1578 c->trans->Start(&request, c->callback.callback(), NetLogWithSource());
1579 }
1580
1581 // Allow all requests to move from the Create queue to the active entry.
1582 base::RunLoop().RunUntilIdle();
1583
1584 // The first request should be a writer at this point, and the subsequent
1585 // requests should have completed validation.
1586
1587 EXPECT_EQ(1, cache.network_layer()->transaction_count());
1588 EXPECT_EQ(0, cache.disk_cache()->open_count());
1589 EXPECT_EQ(1, cache.disk_cache()->create_count());
1590
1591 EXPECT_TRUE(cache.IsWriterPresent(kSimpleGET_Transaction.url));
1592 EXPECT_EQ(1, cache.GetCountDoneHeadersQueue(kSimpleGET_Transaction.url));
1593
1594 Context* c = context_list[1];
1595 delete c;
1596 context_list[1] = nullptr;
1597
1598 EXPECT_EQ(0, cache.GetCountDoneHeadersQueue(kSimpleGET_Transaction.url));
1599
1600 // Complete the rest of the transactions.
1601 for (int i = 0; i < kNumTransactions; ++i) {
1602 if (i == 1)
1603 continue;
1604 Context* c = context_list[i];
1605 ReadAndVerifyTransaction(c->trans.get(), kSimpleGET_Transaction);
1606 }
1607
1608 EXPECT_EQ(1, cache.network_layer()->transaction_count());
1609 EXPECT_EQ(0, cache.disk_cache()->open_count());
1610 EXPECT_EQ(1, cache.disk_cache()->create_count());
1611
1612 for (int i = 0; i < kNumTransactions; ++i) {
1613 if (i == 1)
1614 continue;
1615 Context* c = context_list[i];
1616 delete c;
1617 }
1618 }
1619
1620 // Tests that a transaction which is in readers can be destroyed without
1621 // any impact to other transactions.
1622 TEST(HttpCache, SimpleGET_ParallelValidationCancelReader) {
1623 MockHttpCache cache;
1624
1625 MockHttpRequest request(kSimpleGET_Transaction);
1626
1627 MockTransaction transaction(kSimpleGET_Transaction);
1628 transaction.load_flags |= LOAD_VALIDATE_CACHE;
1629 MockHttpRequest validate_request(transaction);
1630
1631 std::vector<Context*> context_list;
1632 int kNumTransactions = 4;
1633
1634 for (int i = 0; i < kNumTransactions; ++i) {
1635 context_list.push_back(new Context());
1636 Context* c = context_list[i];
1637
1638 c->result = cache.CreateTransaction(&c->trans);
1639 ASSERT_THAT(c->result, IsOk());
1640
1641 MockHttpRequest* this_request = &request;
1642 if (i == 3) {
1643 this_request = &validate_request;
1644 c->trans->SetBeforeNetworkStartCallback(base::Bind(&DeferNetworkStart));
1645 }
1646
1647 c->result = c->trans->Start(this_request, c->callback.callback(),
1648 NetLogWithSource());
1649 }
1650
1651 // Allow all requests to move from the Create queue to the active entry.
1652 base::RunLoop().RunUntilIdle();
1653
1654 EXPECT_EQ(2, cache.network_layer()->transaction_count());
1655 EXPECT_EQ(0, cache.disk_cache()->open_count());
1656 EXPECT_EQ(1, cache.disk_cache()->create_count());
1657
1658 EXPECT_TRUE(cache.IsWriterPresent(kSimpleGET_Transaction.url));
1659 EXPECT_EQ(2, cache.GetCountDoneHeadersQueue(kSimpleGET_Transaction.url));
1660 EXPECT_TRUE(cache.IsHeadersTransactionPresent(kSimpleGET_Transaction.url));
1661
1662 // Complete the response body.
1663 Context* c = context_list[0];
1664 ReadAndVerifyTransaction(c->trans.get(), kSimpleGET_Transaction);
1665
1666 // Rest of the transactions should move to readers.
1667 EXPECT_FALSE(cache.IsWriterPresent(kSimpleGET_Transaction.url));
1668 EXPECT_EQ(2, cache.GetCountReaders(kSimpleGET_Transaction.url));
1669 EXPECT_EQ(0, cache.GetCountDoneHeadersQueue(kSimpleGET_Transaction.url));
1670 EXPECT_TRUE(cache.IsHeadersTransactionPresent(kSimpleGET_Transaction.url));
1671
1672 // Add 2 new transactions.
1673 kNumTransactions = 6;
1674
1675 for (int i = 4; i < kNumTransactions; ++i) {
1676 context_list.push_back(new Context());
1677 Context* c = context_list[i];
1678
1679 c->result = cache.CreateTransaction(&c->trans);
1680 ASSERT_THAT(c->result, IsOk());
1681
1682 c->result =
1683 c->trans->Start(&request, c->callback.callback(), NetLogWithSource());
1684 }
1685
1686 EXPECT_EQ(2, cache.GetCountAddToEntryQueue(kSimpleGET_Transaction.url));
1687
1688 // Delete a reader.
1689 c = context_list[1];
1690 delete c;
1691 context_list[1] = nullptr;
1692
1693 // Deleting the reader did not impact any other transaction.
1694 EXPECT_EQ(1, cache.GetCountReaders(kSimpleGET_Transaction.url));
1695 EXPECT_EQ(2, cache.GetCountAddToEntryQueue(kSimpleGET_Transaction.url));
1696 EXPECT_TRUE(cache.IsHeadersTransactionPresent(kSimpleGET_Transaction.url));
1697
1698 // Resume network start for headers_transaction. It will doom the entry as it
1699 // will be a 200 and will go to network for the response body.
1700 c = context_list[3];
1701 c->trans->ResumeNetworkStart();
1702
1703 // The pending transactions will be added to a new entry.
1704 base::RunLoop().RunUntilIdle();
1705
1706 EXPECT_EQ(1, cache.GetCountDoneHeadersQueue(kSimpleGET_Transaction.url));
1707 EXPECT_TRUE(cache.IsWriterPresent(kSimpleGET_Transaction.url));
1708
1709 // Complete the rest of the transactions.
1710 for (int i = 2; i < kNumTransactions; ++i) {
1711 Context* c = context_list[i];
1712 ReadAndVerifyTransaction(c->trans.get(), kSimpleGET_Transaction);
1713 }
1714
1715 EXPECT_EQ(3, cache.network_layer()->transaction_count());
1716 EXPECT_EQ(0, cache.disk_cache()->open_count());
1717 EXPECT_EQ(2, cache.disk_cache()->create_count());
1718
1719 for (int i = 0; i < kNumTransactions; ++i) {
1720 if (i == 1)
1721 continue;
1722 Context* c = context_list[i];
1723 delete c;
1724 }
1725 }
1726
1727 // Tests that a transaction is in validated queue and writer is destroyed
1728 // leading to restarting the validated transaction.
1729 TEST(HttpCache, SimpleGET_ParallelValidationCancelWriter) {
1730 MockHttpCache cache;
1731
1732 MockHttpRequest request(kSimpleGET_Transaction);
1733
1734 MockTransaction transaction(kSimpleGET_Transaction);
1735 transaction.load_flags |= LOAD_VALIDATE_CACHE;
1736 MockHttpRequest validate_request(transaction);
1737
1738 std::vector<Context*> context_list;
1739 const int kNumTransactions = 3;
1740
1741 for (int i = 0; i < kNumTransactions; ++i) {
1742 context_list.push_back(new Context());
1743 Context* c = context_list[i];
1744
1745 c->result = cache.CreateTransaction(&c->trans);
1746 ASSERT_THAT(c->result, IsOk());
1747
1748 MockHttpRequest* this_request = &request;
1749 if (i == 2) {
1750 this_request = &validate_request;
1751 c->trans->SetBeforeNetworkStartCallback(base::Bind(&DeferNetworkStart));
1752 }
1753
1754 c->result = c->trans->Start(this_request, c->callback.callback(),
1755 NetLogWithSource());
1756 }
1757
1758 // Allow all requests to move from the Create queue to the active entry.
1759 base::RunLoop().RunUntilIdle();
1760
1761 EXPECT_EQ(2, cache.network_layer()->transaction_count());
1762 EXPECT_EQ(0, cache.disk_cache()->open_count());
1763 EXPECT_EQ(1, cache.disk_cache()->create_count());
1764
1765 EXPECT_TRUE(cache.IsWriterPresent(kSimpleGET_Transaction.url));
1766 EXPECT_TRUE(cache.IsHeadersTransactionPresent(kSimpleGET_Transaction.url));
1767 EXPECT_EQ(1, cache.GetCountDoneHeadersQueue(kSimpleGET_Transaction.url));
1768
1769 // Deleting the writer at this point will lead to destroying the entry and
1770 // restarting the remaining transactions which will then create a new entry.
1771 Context* c = context_list[0];
1772 delete c;
1773 context_list[0] = nullptr;
1774
1775 // Resume network start for headers_transaction. It should be restarted due to
1776 // writer cancellation.
1777 c = context_list[2];
1778 c->trans->ResumeNetworkStart();
1779
1780 base::RunLoop().RunUntilIdle();
1781
1782 EXPECT_TRUE(cache.IsWriterPresent(kSimpleGET_Transaction.url));
1783 EXPECT_TRUE(cache.IsHeadersTransactionPresent(kSimpleGET_Transaction.url));
1784
1785 // Resume network start for the transaction the second time.
1786 c->trans->ResumeNetworkStart();
1787 base::RunLoop().RunUntilIdle();
1788
1789 // Headers transaction would have doomed the new entry created.
1790 EXPECT_TRUE(
1791 cache.disk_cache()->IsDiskEntryDoomed(kSimpleGET_Transaction.url));
1792
1793 // Complete the rest of the transactions.
1794 for (int i = 1; i < kNumTransactions; ++i) {
1795 Context* c = context_list[i];
1796 ReadAndVerifyTransaction(c->trans.get(), kSimpleGET_Transaction);
1797 }
1798
1799 EXPECT_EQ(4, cache.network_layer()->transaction_count());
1800 EXPECT_EQ(0, cache.disk_cache()->open_count());
1801 EXPECT_EQ(2, cache.disk_cache()->create_count());
1802
1803 for (int i = 1; i < kNumTransactions; ++i) {
1804 Context* c = context_list[i];
1805 delete c;
1806 }
1807 }
1808
1809 // Tests that a transaction is currently in headers phase and is destroyed
1810 // leading to destroying the entry.
1811 TEST(HttpCache, SimpleGET_ParallelValidationCancelHeaders) {
1812 MockHttpCache cache;
1813
1814 MockHttpRequest request(kSimpleGET_Transaction);
1815
1816 std::vector<Context*> context_list;
1817 const int kNumTransactions = 2;
1818
1819 for (int i = 0; i < kNumTransactions; ++i) {
1820 context_list.push_back(new Context());
1821 Context* c = context_list[i];
1822
1823 c->result = cache.CreateTransaction(&c->trans);
1824 ASSERT_THAT(c->result, IsOk());
1825
1826 if (i == 0)
1827 c->trans->SetBeforeNetworkStartCallback(base::Bind(&DeferNetworkStart));
1828
1829 c->result =
1830 c->trans->Start(&request, c->callback.callback(), NetLogWithSource());
1831 }
1832
1833 base::RunLoop().RunUntilIdle();
1834
1835 EXPECT_TRUE(cache.IsHeadersTransactionPresent(kSimpleGET_Transaction.url));
1836 EXPECT_EQ(1, cache.GetCountAddToEntryQueue(kSimpleGET_Transaction.url));
1837
1838 EXPECT_EQ(1, cache.network_layer()->transaction_count());
1839 EXPECT_EQ(0, cache.disk_cache()->open_count());
1840 EXPECT_EQ(1, cache.disk_cache()->create_count());
1841
1842 // Delete the headers transaction.
1843 Context* c = context_list[0];
1844 delete c;
1845 context_list[0] = nullptr;
1846
1847 base::RunLoop().RunUntilIdle();
1848
1849 // Complete the rest of the transactions.
1850 for (int i = 0; i < kNumTransactions; ++i) {
1851 if (i == 0)
1852 continue;
1853 Context* c = context_list[i];
1854 ReadAndVerifyTransaction(c->trans.get(), kSimpleGET_Transaction);
1855 }
1856
1857 EXPECT_EQ(2, cache.network_layer()->transaction_count());
1858 EXPECT_EQ(0, cache.disk_cache()->open_count());
1859 EXPECT_EQ(2, cache.disk_cache()->create_count());
1860
1861 for (int i = 1; i < kNumTransactions; ++i) {
1862 Context* c = context_list[i];
1863 delete c;
1864 }
1865 }
1866
jkarlin 2017/04/20 15:05:36 Can you also add a test case where the writer is d
shivanisha 2017/04/21 23:06:01 That's tested in SimpleGET_ParallelValidationCance
1867 // Similar to the above test, except here cache write fails and the
1868 // validated transactions should be restarted.
1869 TEST(HttpCache, SimpleGET_ParallelValidationFailWrite) {
1870 MockHttpCache cache;
1871
1872 MockHttpRequest request(kSimpleGET_Transaction);
1873
1874 std::vector<Context*> context_list;
1875 const int kNumTransactions = 5;
1876
1877 for (int i = 0; i < kNumTransactions; ++i) {
1878 context_list.push_back(new Context());
1879 Context* c = context_list[i];
1880
1881 c->result = cache.CreateTransaction(&c->trans);
1882 ASSERT_THAT(c->result, IsOk());
1883 EXPECT_EQ(LOAD_STATE_IDLE, c->trans->GetLoadState());
1884
1885 c->result =
1886 c->trans->Start(&request, c->callback.callback(), NetLogWithSource());
1887 }
1888
1889 // All requests are waiting for the active entry.
1890 for (int i = 0; i < kNumTransactions; ++i) {
1891 Context* c = context_list[i];
1892 EXPECT_EQ(LOAD_STATE_WAITING_FOR_CACHE, c->trans->GetLoadState());
1893 }
1894
1895 // Allow all requests to move from the Create queue to the active entry.
1896 base::RunLoop().RunUntilIdle();
1897
1898 // The first request should be a writer at this point, and the subsequent
1899 // requests should have passed the validation phase and waiting for the
1900 // response to be written to the cache before they can read.
1901 EXPECT_TRUE(cache.IsWriterPresent(kSimpleGET_Transaction.url));
1902 EXPECT_EQ(4, cache.GetCountDoneHeadersQueue(kSimpleGET_Transaction.url));
1903
1904 // All requests depend on the writer, and the writer is between Start and
1905 // Read, i.e. idle.
1906 for (int i = 0; i < kNumTransactions; ++i) {
1907 Context* c = context_list[i];
1908 EXPECT_EQ(LOAD_STATE_IDLE, c->trans->GetLoadState());
1909 }
1910
1911 // The first request should be a writer at this point, and the subsequent
1912 // requests should have passed the validation phase and waiting for the
1913 // response to be written to the cache before they can read.
1914
1915 EXPECT_EQ(1, cache.network_layer()->transaction_count());
1916 EXPECT_EQ(0, cache.disk_cache()->open_count());
1917 EXPECT_EQ(1, cache.disk_cache()->create_count());
1918
1919 // Fail the request.
1920 cache.disk_cache()->set_soft_failures(true);
1921 // We have to open the entry again to propagate the failure flag.
1922 disk_cache::Entry* en;
1923 cache.OpenBackendEntry(kSimpleGET_Transaction.url, &en);
1924 en->Close();
1925
1926 for (int i = 0; i < kNumTransactions; ++i) {
1927 Context* c = context_list[i];
1928 if (c->result == ERR_IO_PENDING)
1929 c->result = c->callback.WaitForResult();
1930 if (i == 1) {
1931 // The earlier entry must be destroyed and its disk entry doomed.
1932 EXPECT_TRUE(
1933 cache.disk_cache()->IsDiskEntryDoomed(kSimpleGET_Transaction.url));
1934 }
1935 ReadAndVerifyTransaction(c->trans.get(), kSimpleGET_Transaction);
1936 }
1937
1938 // Since validated transactions were restarted and new entry read/write
1939 // operations would also fail, all requests would have gone to the network.
1940 EXPECT_EQ(5, cache.network_layer()->transaction_count());
1941 EXPECT_EQ(1, cache.disk_cache()->open_count());
1942 EXPECT_EQ(5, cache.disk_cache()->create_count());
1943
1944 for (int i = 0; i < kNumTransactions; ++i) {
1945 Context* c = context_list[i];
1946 delete c;
1947 }
1948 }
1949
1410 // This is a test for http://code.google.com/p/chromium/issues/detail?id=4769. 1950 // This is a test for http://code.google.com/p/chromium/issues/detail?id=4769.
1411 // If cancelling a request is racing with another request for the same resource 1951 // If cancelling a request is racing with another request for the same resource
1412 // finishing, we have to make sure that we remove both transactions from the 1952 // finishing, we have to make sure that we remove both transactions from the
1413 // entry. 1953 // entry.
1414 TEST(HttpCache, SimpleGET_RacingReaders) { 1954 TEST(HttpCache, SimpleGET_RacingReaders) {
1415 MockHttpCache cache; 1955 MockHttpCache cache;
1416 1956
1417 MockHttpRequest request(kSimpleGET_Transaction); 1957 MockHttpRequest request(kSimpleGET_Transaction);
1418 MockHttpRequest reader_request(kSimpleGET_Transaction); 1958 MockHttpRequest reader_request(kSimpleGET_Transaction);
1419 reader_request.load_flags = LOAD_ONLY_FROM_CACHE | LOAD_SKIP_CACHE_VALIDATION; 1959 reader_request.load_flags = LOAD_ONLY_FROM_CACHE | LOAD_SKIP_CACHE_VALIDATION;
(...skipping 24 matching lines...) Expand all
1444 1984
1445 EXPECT_EQ(1, cache.network_layer()->transaction_count()); 1985 EXPECT_EQ(1, cache.network_layer()->transaction_count());
1446 EXPECT_EQ(0, cache.disk_cache()->open_count()); 1986 EXPECT_EQ(0, cache.disk_cache()->open_count());
1447 EXPECT_EQ(1, cache.disk_cache()->create_count()); 1987 EXPECT_EQ(1, cache.disk_cache()->create_count());
1448 1988
1449 Context* c = context_list[0]; 1989 Context* c = context_list[0];
1450 ASSERT_THAT(c->result, IsError(ERR_IO_PENDING)); 1990 ASSERT_THAT(c->result, IsError(ERR_IO_PENDING));
1451 c->result = c->callback.WaitForResult(); 1991 c->result = c->callback.WaitForResult();
1452 ReadAndVerifyTransaction(c->trans.get(), kSimpleGET_Transaction); 1992 ReadAndVerifyTransaction(c->trans.get(), kSimpleGET_Transaction);
1453 1993
1454 // Now we have 2 active readers and two queued transactions. 1994 // Now all transactions should be waiting for read to be invoked. Two readers
1455 1995 // are because of the load flags and remaining two transactions were converted
1996 // to readers after skipping validation. Note that the remaining two went on
1997 // to process the headers in parallel with readers presnt on the entry.
jkarlin 2017/04/20 15:05:38 s/presnt/present/
shivanisha 2017/04/21 23:06:01 done
1456 EXPECT_EQ(LOAD_STATE_IDLE, context_list[2]->trans->GetLoadState()); 1998 EXPECT_EQ(LOAD_STATE_IDLE, context_list[2]->trans->GetLoadState());
1457 EXPECT_EQ(LOAD_STATE_WAITING_FOR_CACHE, 1999 EXPECT_EQ(LOAD_STATE_IDLE, context_list[3]->trans->GetLoadState());
1458 context_list[3]->trans->GetLoadState());
1459 2000
1460 c = context_list[1]; 2001 c = context_list[1];
1461 ASSERT_THAT(c->result, IsError(ERR_IO_PENDING)); 2002 ASSERT_THAT(c->result, IsError(ERR_IO_PENDING));
1462 c->result = c->callback.WaitForResult(); 2003 c->result = c->callback.WaitForResult();
1463 if (c->result == OK) 2004 if (c->result == OK)
1464 ReadAndVerifyTransaction(c->trans.get(), kSimpleGET_Transaction); 2005 ReadAndVerifyTransaction(c->trans.get(), kSimpleGET_Transaction);
1465 2006
1466 // At this point we have one reader, two pending transactions and a task on 2007 // At this point we have one reader, two pending transactions and a task on
1467 // the queue to move to the next transaction. Now we cancel the request that 2008 // the queue to move to the next transaction. Now we cancel the request that
1468 // is the current reader, and expect the queued task to be able to start the 2009 // 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
1513 ASSERT_THAT(c->result, IsOk()); 2054 ASSERT_THAT(c->result, IsOk());
1514 2055
1515 MockHttpRequest* this_request = &request; 2056 MockHttpRequest* this_request = &request;
1516 if (i == 3) 2057 if (i == 3)
1517 this_request = &writer_request; 2058 this_request = &writer_request;
1518 2059
1519 c->result = c->trans->Start(this_request, c->callback.callback(), 2060 c->result = c->trans->Start(this_request, c->callback.callback(),
1520 NetLogWithSource()); 2061 NetLogWithSource());
1521 } 2062 }
1522 2063
2064 base::RunLoop().RunUntilIdle();
2065
1523 // The first request should be a writer at this point, and the two subsequent 2066 // The first request should be a writer at this point, and the two subsequent
1524 // requests should be pending. The last request doomed the first entry. 2067 // requests should be pending. The last request doomed the first entry.
1525 2068
1526 EXPECT_EQ(2, cache.network_layer()->transaction_count()); 2069 EXPECT_EQ(2, cache.network_layer()->transaction_count());
1527 2070
1528 // Cancel the first queued transaction. 2071 // Cancel the second transaction. Note that this and the 3rd transactions
2072 // would have completed their headers phase and would be waiting in the
2073 // done_headers_queue when the 2nd transaction is cancelled.
1529 context_list[1].reset(); 2074 context_list[1].reset();
1530 2075
1531 for (int i = 0; i < kNumTransactions; ++i) { 2076 for (int i = 0; i < kNumTransactions; ++i) {
1532 if (i == 1) 2077 if (i == 1)
1533 continue; 2078 continue;
1534 Context* c = context_list[i].get(); 2079 Context* c = context_list[i].get();
1535 ASSERT_THAT(c->result, IsError(ERR_IO_PENDING)); 2080 ASSERT_THAT(c->result, IsError(ERR_IO_PENDING));
1536 c->result = c->callback.WaitForResult(); 2081 c->result = c->callback.WaitForResult();
1537 ReadAndVerifyTransaction(c->trans.get(), kSimpleGET_Transaction); 2082 ReadAndVerifyTransaction(c->trans.get(), kSimpleGET_Transaction);
1538 } 2083 }
(...skipping 21 matching lines...) Expand all
1560 ASSERT_THAT(c->result, IsOk()); 2105 ASSERT_THAT(c->result, IsOk());
1561 2106
1562 c->result = 2107 c->result =
1563 c->trans->Start(&request, c->callback.callback(), NetLogWithSource()); 2108 c->trans->Start(&request, c->callback.callback(), NetLogWithSource());
1564 } 2109 }
1565 2110
1566 // Allow all requests to move from the Create queue to the active entry. 2111 // Allow all requests to move from the Create queue to the active entry.
1567 base::RunLoop().RunUntilIdle(); 2112 base::RunLoop().RunUntilIdle();
1568 2113
1569 // The first request should be a writer at this point, and the subsequent 2114 // The first request should be a writer at this point, and the subsequent
1570 // requests should be pending. 2115 // requests should have completed validation. Since the validation does not
2116 // result in a match, a new entry would be created.
1571 2117
1572 EXPECT_EQ(1, cache.network_layer()->transaction_count()); 2118 EXPECT_EQ(3, cache.network_layer()->transaction_count());
1573 EXPECT_EQ(0, cache.disk_cache()->open_count()); 2119 EXPECT_EQ(0, cache.disk_cache()->open_count());
1574 EXPECT_EQ(1, cache.disk_cache()->create_count()); 2120 EXPECT_EQ(2, cache.disk_cache()->create_count());
1575 2121
1576 // Now, make sure that the second request asks for the entry not to be stored. 2122 // Now, make sure that the second request asks for the entry not to be stored.
1577 request_handler.set_no_store(true); 2123 request_handler.set_no_store(true);
1578 2124
1579 for (int i = 0; i < kNumTransactions; ++i) { 2125 for (int i = 0; i < kNumTransactions; ++i) {
1580 Context* c = context_list[i]; 2126 Context* c = context_list[i];
1581 if (c->result == ERR_IO_PENDING) 2127 if (c->result == ERR_IO_PENDING)
1582 c->result = c->callback.WaitForResult(); 2128 c->result = c->callback.WaitForResult();
1583 ReadAndVerifyTransaction(c->trans.get(), kFastNoStoreGET_Transaction); 2129 ReadAndVerifyTransaction(c->trans.get(), kFastNoStoreGET_Transaction);
1584 delete c; 2130 delete c;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1618 2164
1619 EXPECT_EQ(1, cache.network_layer()->transaction_count()); 2165 EXPECT_EQ(1, cache.network_layer()->transaction_count());
1620 EXPECT_EQ(0, cache.disk_cache()->open_count()); 2166 EXPECT_EQ(0, cache.disk_cache()->open_count());
1621 EXPECT_EQ(1, cache.disk_cache()->create_count()); 2167 EXPECT_EQ(1, cache.disk_cache()->create_count());
1622 2168
1623 for (int i = 0; i < kNumTransactions; ++i) { 2169 for (int i = 0; i < kNumTransactions; ++i) {
1624 Context* c = context_list[i]; 2170 Context* c = context_list[i];
1625 if (c->result == ERR_IO_PENDING) 2171 if (c->result == ERR_IO_PENDING)
1626 c->result = c->callback.WaitForResult(); 2172 c->result = c->callback.WaitForResult();
1627 // Destroy only the first transaction. 2173 // Destroy only the first transaction.
2174 // This should lead to all transactions to restart, even those that have
2175 // validated themselves and were waiting for the writer transaction to
2176 // complete writing to the cache.
1628 if (i == 0) { 2177 if (i == 0) {
1629 delete c; 2178 delete c;
1630 context_list[i] = NULL; 2179 context_list[i] = NULL;
1631 } 2180 }
1632 } 2181 }
1633 2182
1634 // Complete the rest of the transactions. 2183 // Complete the rest of the transactions.
1635 for (int i = 1; i < kNumTransactions; ++i) { 2184 for (int i = 1; i < kNumTransactions; ++i) {
1636 Context* c = context_list[i]; 2185 Context* c = context_list[i];
1637 ReadAndVerifyTransaction(c->trans.get(), kSimpleGET_Transaction); 2186 ReadAndVerifyTransaction(c->trans.get(), kSimpleGET_Transaction);
(...skipping 895 matching lines...) Expand 10 before | Expand all | Expand 10 after
2533 } 3082 }
2534 3083
2535 // Helper that does 4 requests using HttpCache: 3084 // Helper that does 4 requests using HttpCache:
2536 // 3085 //
2537 // (1) loads |kUrl| -- expects |net_response_1| to be returned. 3086 // (1) loads |kUrl| -- expects |net_response_1| to be returned.
2538 // (2) loads |kUrl| from cache only -- expects |net_response_1| to be returned. 3087 // (2) loads |kUrl| from cache only -- expects |net_response_1| to be returned.
2539 // (3) loads |kUrl| using |extra_request_headers| -- expects |net_response_2| to 3088 // (3) loads |kUrl| using |extra_request_headers| -- expects |net_response_2| to
2540 // be returned. 3089 // be returned.
2541 // (4) loads |kUrl| from cache only -- expects |cached_response_2| to be 3090 // (4) loads |kUrl| from cache only -- expects |cached_response_2| to be
2542 // returned. 3091 // returned.
3092 // The entry will be created once and will be opened for the 3 subsequent
3093 // requests.
2543 static void ConditionalizedRequestUpdatesCacheHelper( 3094 static void ConditionalizedRequestUpdatesCacheHelper(
2544 const Response& net_response_1, 3095 const Response& net_response_1,
2545 const Response& net_response_2, 3096 const Response& net_response_2,
2546 const Response& cached_response_2, 3097 const Response& cached_response_2,
2547 const char* extra_request_headers) { 3098 const char* extra_request_headers) {
2548 MockHttpCache cache; 3099 MockHttpCache cache;
2549 3100
2550 // The URL we will be requesting. 3101 // The URL we will be requesting.
2551 const char kUrl[] = "http://foobar.com/main.css"; 3102 const char kUrl[] = "http://foobar.com/main.css";
2552 3103
(...skipping 3555 matching lines...) Expand 10 before | Expand all | Expand 10 after
6108 pending->trans->Start(&request, pending->callback.callback(), 6659 pending->trans->Start(&request, pending->callback.callback(),
6109 NetLogWithSource())); 6660 NetLogWithSource()));
6110 EXPECT_THAT(c->callback.GetResult(rv), IsOk()); 6661 EXPECT_THAT(c->callback.GetResult(rv), IsOk());
6111 6662
6112 // Make sure that the entry has some data stored. 6663 // Make sure that the entry has some data stored.
6113 scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(5)); 6664 scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(5));
6114 rv = c->trans->Read(buf.get(), buf->size(), c->callback.callback()); 6665 rv = c->trans->Read(buf.get(), buf->size(), c->callback.callback());
6115 EXPECT_EQ(5, c->callback.GetResult(rv)); 6666 EXPECT_EQ(5, c->callback.GetResult(rv));
6116 6667
6117 // Cancel the requests. 6668 // Cancel the requests.
6669 // Since |pending| is currently vaidating the already written headers
jkarlin 2017/04/20 15:05:37 s/vaidating/validating/
shivanisha 2017/04/21 23:06:01 done
6670 // it will be restarted as well.
6118 delete c; 6671 delete c;
6119 delete pending; 6672 delete pending;
6120 6673
6121 EXPECT_EQ(1, cache.network_layer()->transaction_count()); 6674 EXPECT_EQ(1, cache.network_layer()->transaction_count());
6122 EXPECT_EQ(1, cache.disk_cache()->open_count()); 6675 EXPECT_EQ(1, cache.disk_cache()->open_count());
6123 EXPECT_EQ(2, cache.disk_cache()->create_count()); 6676 EXPECT_EQ(1, cache.disk_cache()->create_count());
6124 6677
6125 base::RunLoop().RunUntilIdle(); 6678 base::RunLoop().RunUntilIdle();
6126 RemoveMockTransaction(&transaction); 6679 RemoveMockTransaction(&transaction);
6127 } 6680 }
6128 6681
6129 // Tests that we delete truncated entries if the server changes its mind midway. 6682 // Tests that we delete truncated entries if the server changes its mind midway.
6130 TEST(HttpCache, GET_IncompleteResource2) { 6683 TEST(HttpCache, GET_IncompleteResource2) {
6131 MockHttpCache cache; 6684 MockHttpCache cache;
6132 AddMockTransaction(&kRangeGET_TransactionOK); 6685 AddMockTransaction(&kRangeGET_TransactionOK);
6133 6686
(...skipping 704 matching lines...) Expand 10 before | Expand all | Expand 10 after
6838 7391
6839 RunTransactionTestWithResponseInfo(cache.http_cache(), kSimpleGET_Transaction, 7392 RunTransactionTestWithResponseInfo(cache.http_cache(), kSimpleGET_Transaction,
6840 &response); 7393 &response);
6841 EXPECT_TRUE(response.metadata.get() == NULL); 7394 EXPECT_TRUE(response.metadata.get() == NULL);
6842 7395
6843 EXPECT_EQ(1, cache.network_layer()->transaction_count()); 7396 EXPECT_EQ(1, cache.network_layer()->transaction_count());
6844 EXPECT_EQ(2, cache.disk_cache()->open_count()); 7397 EXPECT_EQ(2, cache.disk_cache()->open_count());
6845 EXPECT_EQ(1, cache.disk_cache()->create_count()); 7398 EXPECT_EQ(1, cache.disk_cache()->create_count());
6846 } 7399 }
6847 7400
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
6888 // Tests that we ignore VARY checks when writing metadata since the request 7401 // Tests that we ignore VARY checks when writing metadata since the request
6889 // headers for the WriteMetadata transaction are made up. 7402 // headers for the WriteMetadata transaction are made up.
6890 TEST(HttpCache, WriteMetadata_IgnoreVary) { 7403 TEST(HttpCache, WriteMetadata_IgnoreVary) {
6891 MockHttpCache cache; 7404 MockHttpCache cache;
6892 7405
6893 // Write to the cache 7406 // Write to the cache
6894 HttpResponseInfo response; 7407 HttpResponseInfo response;
6895 ScopedMockTransaction transaction(kSimpleGET_Transaction); 7408 ScopedMockTransaction transaction(kSimpleGET_Transaction);
6896 transaction.request_headers = "accept-encoding: gzip\r\n"; 7409 transaction.request_headers = "accept-encoding: gzip\r\n";
6897 transaction.response_headers = 7410 transaction.response_headers =
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
7205 MockHttpRequest request(mock_transaction); 7718 MockHttpRequest request(mock_transaction);
7206 7719
7207 { 7720 {
7208 std::unique_ptr<HttpTransaction> trans; 7721 std::unique_ptr<HttpTransaction> trans;
7209 ASSERT_THAT(cache.CreateTransaction(&trans), IsOk()); 7722 ASSERT_THAT(cache.CreateTransaction(&trans), IsOk());
7210 7723
7211 int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); 7724 int rv = trans->Start(&request, callback.callback(), NetLogWithSource());
7212 EXPECT_THAT(callback.GetResult(rv), IsOk()); 7725 EXPECT_THAT(callback.GetResult(rv), IsOk());
7213 7726
7214 trans->StopCaching(); 7727 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);
7219 } 7728 }
7220 RemoveMockTransaction(&mock_transaction); 7729 RemoveMockTransaction(&mock_transaction);
7221 7730
7222 // Make sure that the ActiveEntry is gone. 7731 // Make sure that the ActiveEntry is gone.
7223 base::RunLoop().RunUntilIdle(); 7732 base::RunLoop().RunUntilIdle();
7224 7733
7225 // Verify that the entry is gone. 7734 // Verify that the entry is gone.
7226 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); 7735 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction);
7227 7736
7228 EXPECT_EQ(2, cache.network_layer()->transaction_count()); 7737 EXPECT_EQ(2, cache.network_layer()->transaction_count());
(...skipping 1031 matching lines...) Expand 10 before | Expand all | Expand 10 after
8260 ASSERT_TRUE(attrs->GetDictionary( 8769 ASSERT_TRUE(attrs->GetDictionary(
8261 base::trace_event::MemoryAllocatorDump::kNameSize, &size_attrs)); 8770 base::trace_event::MemoryAllocatorDump::kNameSize, &size_attrs));
8262 std::string size; 8771 std::string size;
8263 ASSERT_TRUE(size_attrs->GetString("value", &size)); 8772 ASSERT_TRUE(size_attrs->GetString("value", &size));
8264 int actual_size = 0; 8773 int actual_size = 0;
8265 ASSERT_TRUE(base::HexStringToInt(size, &actual_size)); 8774 ASSERT_TRUE(base::HexStringToInt(size, &actual_size));
8266 ASSERT_LT(0, actual_size); 8775 ASSERT_LT(0, actual_size);
8267 } 8776 }
8268 8777
8269 } // namespace net 8778 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698