OLD | NEW |
1 // Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/http/http_cache.h" | 5 #include "net/http/http_cache.h" |
6 | 6 |
7 #include "base/hash_tables.h" | 7 #include "base/hash_tables.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/scoped_vector.h" | 9 #include "base/scoped_vector.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
610 *response_info = *response; | 610 *response_info = *response; |
611 | 611 |
612 ReadAndVerifyTransaction(trans.get(), trans_info); | 612 ReadAndVerifyTransaction(trans.get(), trans_info); |
613 } | 613 } |
614 | 614 |
615 void RunTransactionTestWithRequest(net::HttpCache* cache, | 615 void RunTransactionTestWithRequest(net::HttpCache* cache, |
616 const MockTransaction& trans_info, | 616 const MockTransaction& trans_info, |
617 const MockHttpRequest& request, | 617 const MockHttpRequest& request, |
618 net::HttpResponseInfo* response_info) { | 618 net::HttpResponseInfo* response_info) { |
619 RunTransactionTestWithRequestAndLog(cache, trans_info, request, | 619 RunTransactionTestWithRequestAndLog(cache, trans_info, request, |
620 response_info, NULL); | 620 response_info, net::BoundNetLog()); |
621 } | 621 } |
622 | 622 |
623 void RunTransactionTestWithLog(net::HttpCache* cache, | 623 void RunTransactionTestWithLog(net::HttpCache* cache, |
624 const MockTransaction& trans_info, | 624 const MockTransaction& trans_info, |
625 const net::BoundNetLog& log) { | 625 const net::BoundNetLog& log) { |
626 RunTransactionTestWithRequestAndLog( | 626 RunTransactionTestWithRequestAndLog( |
627 cache, trans_info, MockHttpRequest(trans_info), NULL, log); | 627 cache, trans_info, MockHttpRequest(trans_info), NULL, log); |
628 } | 628 } |
629 | 629 |
630 void RunTransactionTest(net::HttpCache* cache, | 630 void RunTransactionTest(net::HttpCache* cache, |
631 const MockTransaction& trans_info) { | 631 const MockTransaction& trans_info) { |
632 RunTransactionTestWithLog(cache, trans_info, NULL); | 632 RunTransactionTestWithLog(cache, trans_info, net::BoundNetLog()); |
633 } | 633 } |
634 | 634 |
635 void RunTransactionTestWithResponseInfo(net::HttpCache* cache, | 635 void RunTransactionTestWithResponseInfo(net::HttpCache* cache, |
636 const MockTransaction& trans_info, | 636 const MockTransaction& trans_info, |
637 net::HttpResponseInfo* response) { | 637 net::HttpResponseInfo* response) { |
638 RunTransactionTestWithRequest( | 638 RunTransactionTestWithRequest( |
639 cache, trans_info, MockHttpRequest(trans_info), response); | 639 cache, trans_info, MockHttpRequest(trans_info), response); |
640 } | 640 } |
641 | 641 |
642 void RunTransactionTestWithResponse(net::HttpCache* cache, | 642 void RunTransactionTestWithResponse(net::HttpCache* cache, |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
951 // request to fail. | 951 // request to fail. |
952 TEST(HttpCache, SimpleGETWithDiskFailures2) { | 952 TEST(HttpCache, SimpleGETWithDiskFailures2) { |
953 MockHttpCache cache; | 953 MockHttpCache cache; |
954 | 954 |
955 MockHttpRequest request(kSimpleGET_Transaction); | 955 MockHttpRequest request(kSimpleGET_Transaction); |
956 | 956 |
957 scoped_ptr<Context> c(new Context()); | 957 scoped_ptr<Context> c(new Context()); |
958 int rv = cache.http_cache()->CreateTransaction(&c->trans); | 958 int rv = cache.http_cache()->CreateTransaction(&c->trans); |
959 EXPECT_EQ(net::OK, rv); | 959 EXPECT_EQ(net::OK, rv); |
960 | 960 |
961 rv = c->trans->Start(&request, &c->callback, NULL); | 961 rv = c->trans->Start(&request, &c->callback, net::BoundNetLog()); |
962 EXPECT_EQ(net::ERR_IO_PENDING, rv); | 962 EXPECT_EQ(net::ERR_IO_PENDING, rv); |
963 rv = c->callback.WaitForResult(); | 963 rv = c->callback.WaitForResult(); |
964 | 964 |
965 // Start failing request now. | 965 // Start failing request now. |
966 cache.disk_cache()->set_soft_failures(true); | 966 cache.disk_cache()->set_soft_failures(true); |
967 | 967 |
968 // We have to open the entry again to propagate the failure flag. | 968 // We have to open the entry again to propagate the failure flag. |
969 disk_cache::Entry* en; | 969 disk_cache::Entry* en; |
970 ASSERT_EQ(net::OK, cache.disk_cache()->OpenEntry(kSimpleGET_Transaction.url, | 970 ASSERT_EQ(net::OK, cache.disk_cache()->OpenEntry(kSimpleGET_Transaction.url, |
971 &en, NULL)); | 971 &en, NULL)); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1046 transaction.load_flags |= net::LOAD_ONLY_FROM_CACHE; | 1046 transaction.load_flags |= net::LOAD_ONLY_FROM_CACHE; |
1047 | 1047 |
1048 MockHttpRequest request(transaction); | 1048 MockHttpRequest request(transaction); |
1049 TestCompletionCallback callback; | 1049 TestCompletionCallback callback; |
1050 | 1050 |
1051 scoped_ptr<net::HttpTransaction> trans; | 1051 scoped_ptr<net::HttpTransaction> trans; |
1052 int rv = cache.http_cache()->CreateTransaction(&trans); | 1052 int rv = cache.http_cache()->CreateTransaction(&trans); |
1053 EXPECT_EQ(net::OK, rv); | 1053 EXPECT_EQ(net::OK, rv); |
1054 ASSERT_TRUE(trans.get()); | 1054 ASSERT_TRUE(trans.get()); |
1055 | 1055 |
1056 rv = trans->Start(&request, &callback, NULL); | 1056 rv = trans->Start(&request, &callback, net::BoundNetLog()); |
1057 if (rv == net::ERR_IO_PENDING) | 1057 if (rv == net::ERR_IO_PENDING) |
1058 rv = callback.WaitForResult(); | 1058 rv = callback.WaitForResult(); |
1059 ASSERT_EQ(net::ERR_CACHE_MISS, rv); | 1059 ASSERT_EQ(net::ERR_CACHE_MISS, rv); |
1060 | 1060 |
1061 trans.reset(); | 1061 trans.reset(); |
1062 | 1062 |
1063 EXPECT_EQ(0, cache.network_layer()->transaction_count()); | 1063 EXPECT_EQ(0, cache.network_layer()->transaction_count()); |
1064 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 1064 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
1065 EXPECT_EQ(0, cache.disk_cache()->create_count()); | 1065 EXPECT_EQ(0, cache.disk_cache()->create_count()); |
1066 } | 1066 } |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1261 std::vector<Context*> context_list; | 1261 std::vector<Context*> context_list; |
1262 const int kNumTransactions = 5; | 1262 const int kNumTransactions = 5; |
1263 | 1263 |
1264 for (int i = 0; i < kNumTransactions; ++i) { | 1264 for (int i = 0; i < kNumTransactions; ++i) { |
1265 context_list.push_back(new Context()); | 1265 context_list.push_back(new Context()); |
1266 Context* c = context_list[i]; | 1266 Context* c = context_list[i]; |
1267 | 1267 |
1268 c->result = cache.http_cache()->CreateTransaction(&c->trans); | 1268 c->result = cache.http_cache()->CreateTransaction(&c->trans); |
1269 EXPECT_EQ(net::OK, c->result); | 1269 EXPECT_EQ(net::OK, c->result); |
1270 | 1270 |
1271 c->result = c->trans->Start(&request, &c->callback, NULL); | 1271 c->result = c->trans->Start(&request, &c->callback, net::BoundNetLog()); |
1272 } | 1272 } |
1273 | 1273 |
1274 // Allow all requests to move from the Create queue to the active entry. | 1274 // Allow all requests to move from the Create queue to the active entry. |
1275 MessageLoop::current()->RunAllPending(); | 1275 MessageLoop::current()->RunAllPending(); |
1276 | 1276 |
1277 // The first request should be a writer at this point, and the subsequent | 1277 // The first request should be a writer at this point, and the subsequent |
1278 // requests should be pending. | 1278 // requests should be pending. |
1279 | 1279 |
1280 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 1280 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
1281 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 1281 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1318 context_list.push_back(new Context()); | 1318 context_list.push_back(new Context()); |
1319 Context* c = context_list[i]; | 1319 Context* c = context_list[i]; |
1320 | 1320 |
1321 c->result = cache.http_cache()->CreateTransaction(&c->trans); | 1321 c->result = cache.http_cache()->CreateTransaction(&c->trans); |
1322 EXPECT_EQ(net::OK, c->result); | 1322 EXPECT_EQ(net::OK, c->result); |
1323 | 1323 |
1324 MockHttpRequest* this_request = &request; | 1324 MockHttpRequest* this_request = &request; |
1325 if (i == 1 || i == 2) | 1325 if (i == 1 || i == 2) |
1326 this_request = &reader_request; | 1326 this_request = &reader_request; |
1327 | 1327 |
1328 c->result = c->trans->Start(this_request, &c->callback, NULL); | 1328 c->result = c->trans->Start(this_request, &c->callback, net::BoundNetLog()); |
1329 } | 1329 } |
1330 | 1330 |
1331 // Allow all requests to move from the Create queue to the active entry. | 1331 // Allow all requests to move from the Create queue to the active entry. |
1332 MessageLoop::current()->RunAllPending(); | 1332 MessageLoop::current()->RunAllPending(); |
1333 | 1333 |
1334 // The first request should be a writer at this point, and the subsequent | 1334 // The first request should be a writer at this point, and the subsequent |
1335 // requests should be pending. | 1335 // requests should be pending. |
1336 | 1336 |
1337 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 1337 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
1338 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 1338 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1399 context_list.push_back(new Context()); | 1399 context_list.push_back(new Context()); |
1400 Context* c = context_list[i]; | 1400 Context* c = context_list[i]; |
1401 | 1401 |
1402 c->result = cache.http_cache()->CreateTransaction(&c->trans); | 1402 c->result = cache.http_cache()->CreateTransaction(&c->trans); |
1403 EXPECT_EQ(net::OK, c->result); | 1403 EXPECT_EQ(net::OK, c->result); |
1404 | 1404 |
1405 MockHttpRequest* this_request = &request; | 1405 MockHttpRequest* this_request = &request; |
1406 if (i == 3) | 1406 if (i == 3) |
1407 this_request = &writer_request; | 1407 this_request = &writer_request; |
1408 | 1408 |
1409 c->result = c->trans->Start(this_request, &c->callback, NULL); | 1409 c->result = c->trans->Start(this_request, &c->callback, net::BoundNetLog()); |
1410 } | 1410 } |
1411 | 1411 |
1412 // The first request should be a writer at this point, and the two subsequent | 1412 // The first request should be a writer at this point, and the two subsequent |
1413 // requests should be pending. The last request doomed the first entry. | 1413 // requests should be pending. The last request doomed the first entry. |
1414 | 1414 |
1415 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 1415 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
1416 | 1416 |
1417 // Cancel the first queued transaction. | 1417 // Cancel the first queued transaction. |
1418 delete context_list[1]; | 1418 delete context_list[1]; |
1419 context_list.get()[1] = NULL; | 1419 context_list.get()[1] = NULL; |
(...skipping 22 matching lines...) Expand all Loading... |
1442 std::vector<Context*> context_list; | 1442 std::vector<Context*> context_list; |
1443 const int kNumTransactions = 3; | 1443 const int kNumTransactions = 3; |
1444 | 1444 |
1445 for (int i = 0; i < kNumTransactions; ++i) { | 1445 for (int i = 0; i < kNumTransactions; ++i) { |
1446 context_list.push_back(new Context()); | 1446 context_list.push_back(new Context()); |
1447 Context* c = context_list[i]; | 1447 Context* c = context_list[i]; |
1448 | 1448 |
1449 c->result = cache.http_cache()->CreateTransaction(&c->trans); | 1449 c->result = cache.http_cache()->CreateTransaction(&c->trans); |
1450 EXPECT_EQ(net::OK, c->result); | 1450 EXPECT_EQ(net::OK, c->result); |
1451 | 1451 |
1452 c->result = c->trans->Start(&request, &c->callback, NULL); | 1452 c->result = c->trans->Start(&request, &c->callback, net::BoundNetLog()); |
1453 } | 1453 } |
1454 | 1454 |
1455 // Allow all requests to move from the Create queue to the active entry. | 1455 // Allow all requests to move from the Create queue to the active entry. |
1456 MessageLoop::current()->RunAllPending(); | 1456 MessageLoop::current()->RunAllPending(); |
1457 | 1457 |
1458 // The first request should be a writer at this point, and the subsequent | 1458 // The first request should be a writer at this point, and the subsequent |
1459 // requests should be pending. | 1459 // requests should be pending. |
1460 | 1460 |
1461 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 1461 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
1462 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 1462 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
(...skipping 25 matching lines...) Expand all Loading... |
1488 std::vector<Context*> context_list; | 1488 std::vector<Context*> context_list; |
1489 const int kNumTransactions = 2; | 1489 const int kNumTransactions = 2; |
1490 | 1490 |
1491 for (int i = 0; i < kNumTransactions; ++i) { | 1491 for (int i = 0; i < kNumTransactions; ++i) { |
1492 context_list.push_back(new Context()); | 1492 context_list.push_back(new Context()); |
1493 Context* c = context_list[i]; | 1493 Context* c = context_list[i]; |
1494 | 1494 |
1495 c->result = cache.http_cache()->CreateTransaction(&c->trans); | 1495 c->result = cache.http_cache()->CreateTransaction(&c->trans); |
1496 EXPECT_EQ(net::OK, c->result); | 1496 EXPECT_EQ(net::OK, c->result); |
1497 | 1497 |
1498 c->result = c->trans->Start(&request, &c->callback, NULL); | 1498 c->result = c->trans->Start(&request, &c->callback, net::BoundNetLog()); |
1499 } | 1499 } |
1500 | 1500 |
1501 // Allow all requests to move from the Create queue to the active entry. | 1501 // Allow all requests to move from the Create queue to the active entry. |
1502 MessageLoop::current()->RunAllPending(); | 1502 MessageLoop::current()->RunAllPending(); |
1503 | 1503 |
1504 // The first request should be a writer at this point, and the subsequent | 1504 // The first request should be a writer at this point, and the subsequent |
1505 // requests should be pending. | 1505 // requests should be pending. |
1506 | 1506 |
1507 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 1507 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
1508 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 1508 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1547 std::vector<Context*> context_list; | 1547 std::vector<Context*> context_list; |
1548 const int kNumTransactions = 5; | 1548 const int kNumTransactions = 5; |
1549 | 1549 |
1550 for (int i = 0; i < kNumTransactions; i++) { | 1550 for (int i = 0; i < kNumTransactions; i++) { |
1551 context_list.push_back(new Context()); | 1551 context_list.push_back(new Context()); |
1552 Context* c = context_list[i]; | 1552 Context* c = context_list[i]; |
1553 | 1553 |
1554 c->result = cache.http_cache()->CreateTransaction(&c->trans); | 1554 c->result = cache.http_cache()->CreateTransaction(&c->trans); |
1555 EXPECT_EQ(net::OK, c->result); | 1555 EXPECT_EQ(net::OK, c->result); |
1556 | 1556 |
1557 c->result = c->trans->Start(&request, &c->callback, NULL); | 1557 c->result = c->trans->Start(&request, &c->callback, net::BoundNetLog()); |
1558 } | 1558 } |
1559 | 1559 |
1560 // The first request should be creating the disk cache entry and the others | 1560 // The first request should be creating the disk cache entry and the others |
1561 // should be pending. | 1561 // should be pending. |
1562 | 1562 |
1563 EXPECT_EQ(0, cache.network_layer()->transaction_count()); | 1563 EXPECT_EQ(0, cache.network_layer()->transaction_count()); |
1564 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 1564 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
1565 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 1565 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
1566 | 1566 |
1567 // Cancel a request from the pending queue. | 1567 // Cancel a request from the pending queue. |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1603 std::vector<Context*> context_list; | 1603 std::vector<Context*> context_list; |
1604 const int kNumTransactions = 5; | 1604 const int kNumTransactions = 5; |
1605 | 1605 |
1606 for (int i = 0; i < kNumTransactions; i++) { | 1606 for (int i = 0; i < kNumTransactions; i++) { |
1607 context_list.push_back(new Context()); | 1607 context_list.push_back(new Context()); |
1608 Context* c = context_list[i]; | 1608 Context* c = context_list[i]; |
1609 | 1609 |
1610 c->result = cache.http_cache()->CreateTransaction(&c->trans); | 1610 c->result = cache.http_cache()->CreateTransaction(&c->trans); |
1611 EXPECT_EQ(net::OK, c->result); | 1611 EXPECT_EQ(net::OK, c->result); |
1612 | 1612 |
1613 c->result = c->trans->Start(&request, &c->callback, NULL); | 1613 c->result = c->trans->Start(&request, &c->callback, net::BoundNetLog()); |
1614 } | 1614 } |
1615 | 1615 |
1616 // The first request should be deleting the disk cache entry and the others | 1616 // The first request should be deleting the disk cache entry and the others |
1617 // should be pending. | 1617 // should be pending. |
1618 | 1618 |
1619 EXPECT_EQ(0, cache.network_layer()->transaction_count()); | 1619 EXPECT_EQ(0, cache.network_layer()->transaction_count()); |
1620 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 1620 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
1621 EXPECT_EQ(0, cache.disk_cache()->create_count()); | 1621 EXPECT_EQ(0, cache.disk_cache()->create_count()); |
1622 | 1622 |
1623 // Complete the transactions. | 1623 // Complete the transactions. |
(...skipping 19 matching lines...) Expand all Loading... |
1643 | 1643 |
1644 // write to the cache | 1644 // write to the cache |
1645 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); | 1645 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); |
1646 | 1646 |
1647 MockHttpRequest request(kSimpleGET_Transaction); | 1647 MockHttpRequest request(kSimpleGET_Transaction); |
1648 TestCompletionCallback callback; | 1648 TestCompletionCallback callback; |
1649 | 1649 |
1650 scoped_ptr<net::HttpTransaction> trans; | 1650 scoped_ptr<net::HttpTransaction> trans; |
1651 int rv = cache.http_cache()->CreateTransaction(&trans); | 1651 int rv = cache.http_cache()->CreateTransaction(&trans); |
1652 EXPECT_EQ(net::OK, rv); | 1652 EXPECT_EQ(net::OK, rv); |
1653 rv = trans->Start(&request, &callback, NULL); | 1653 rv = trans->Start(&request, &callback, net::BoundNetLog()); |
1654 if (rv == net::ERR_IO_PENDING) | 1654 if (rv == net::ERR_IO_PENDING) |
1655 rv = callback.WaitForResult(); | 1655 rv = callback.WaitForResult(); |
1656 ASSERT_EQ(net::OK, rv); | 1656 ASSERT_EQ(net::OK, rv); |
1657 | 1657 |
1658 scoped_refptr<net::IOBuffer> buf = new net::IOBuffer(256); | 1658 scoped_refptr<net::IOBuffer> buf = new net::IOBuffer(256); |
1659 rv = trans->Read(buf, 256, &callback); | 1659 rv = trans->Read(buf, 256, &callback); |
1660 EXPECT_EQ(net::ERR_IO_PENDING, rv); | 1660 EXPECT_EQ(net::ERR_IO_PENDING, rv); |
1661 | 1661 |
1662 // Test that destroying the transaction while it is reading from the cache | 1662 // Test that destroying the transaction while it is reading from the cache |
1663 // works properly. | 1663 // works properly. |
(...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2274 transaction.load_flags |= net::LOAD_ONLY_FROM_CACHE; | 2274 transaction.load_flags |= net::LOAD_ONLY_FROM_CACHE; |
2275 | 2275 |
2276 MockHttpRequest request(transaction); | 2276 MockHttpRequest request(transaction); |
2277 TestCompletionCallback callback; | 2277 TestCompletionCallback callback; |
2278 | 2278 |
2279 scoped_ptr<net::HttpTransaction> trans; | 2279 scoped_ptr<net::HttpTransaction> trans; |
2280 int rv = cache.http_cache()->CreateTransaction(&trans); | 2280 int rv = cache.http_cache()->CreateTransaction(&trans); |
2281 EXPECT_EQ(net::OK, rv); | 2281 EXPECT_EQ(net::OK, rv); |
2282 ASSERT_TRUE(trans.get()); | 2282 ASSERT_TRUE(trans.get()); |
2283 | 2283 |
2284 rv = trans->Start(&request, &callback, NULL); | 2284 rv = trans->Start(&request, &callback, net::BoundNetLog()); |
2285 if (rv == net::ERR_IO_PENDING) | 2285 if (rv == net::ERR_IO_PENDING) |
2286 rv = callback.WaitForResult(); | 2286 rv = callback.WaitForResult(); |
2287 ASSERT_EQ(net::ERR_CACHE_MISS, rv); | 2287 ASSERT_EQ(net::ERR_CACHE_MISS, rv); |
2288 | 2288 |
2289 trans.reset(); | 2289 trans.reset(); |
2290 | 2290 |
2291 EXPECT_EQ(0, cache.network_layer()->transaction_count()); | 2291 EXPECT_EQ(0, cache.network_layer()->transaction_count()); |
2292 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 2292 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
2293 EXPECT_EQ(0, cache.disk_cache()->create_count()); | 2293 EXPECT_EQ(0, cache.disk_cache()->create_count()); |
2294 } | 2294 } |
(...skipping 723 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3018 MockHttpCache cache; | 3018 MockHttpCache cache; |
3019 cache.http_cache()->set_enable_range_support(true); | 3019 cache.http_cache()->set_enable_range_support(true); |
3020 AddMockTransaction(&kRangeGET_TransactionOK); | 3020 AddMockTransaction(&kRangeGET_TransactionOK); |
3021 | 3021 |
3022 MockHttpRequest request(kRangeGET_TransactionOK); | 3022 MockHttpRequest request(kRangeGET_TransactionOK); |
3023 | 3023 |
3024 Context* c = new Context(); | 3024 Context* c = new Context(); |
3025 int rv = cache.http_cache()->CreateTransaction(&c->trans); | 3025 int rv = cache.http_cache()->CreateTransaction(&c->trans); |
3026 EXPECT_EQ(net::OK, rv); | 3026 EXPECT_EQ(net::OK, rv); |
3027 | 3027 |
3028 rv = c->trans->Start(&request, &c->callback, NULL); | 3028 rv = c->trans->Start(&request, &c->callback, net::BoundNetLog()); |
3029 if (rv == net::ERR_IO_PENDING) | 3029 if (rv == net::ERR_IO_PENDING) |
3030 rv = c->callback.WaitForResult(); | 3030 rv = c->callback.WaitForResult(); |
3031 | 3031 |
3032 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 3032 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
3033 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 3033 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
3034 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 3034 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
3035 | 3035 |
3036 // Make sure that the entry has some data stored. | 3036 // Make sure that the entry has some data stored. |
3037 scoped_refptr<net::IOBufferWithSize> buf = new net::IOBufferWithSize(10); | 3037 scoped_refptr<net::IOBufferWithSize> buf = new net::IOBufferWithSize(10); |
3038 rv = c->trans->Read(buf, buf->size(), &c->callback); | 3038 rv = c->trans->Read(buf, buf->size(), &c->callback); |
(...skipping 19 matching lines...) Expand all Loading... |
3058 cache.http_cache()->set_enable_range_support(true); | 3058 cache.http_cache()->set_enable_range_support(true); |
3059 AddMockTransaction(&kRangeGET_TransactionOK); | 3059 AddMockTransaction(&kRangeGET_TransactionOK); |
3060 | 3060 |
3061 RunTransactionTest(cache.http_cache(), kRangeGET_TransactionOK); | 3061 RunTransactionTest(cache.http_cache(), kRangeGET_TransactionOK); |
3062 MockHttpRequest request(kRangeGET_TransactionOK); | 3062 MockHttpRequest request(kRangeGET_TransactionOK); |
3063 | 3063 |
3064 Context* c = new Context(); | 3064 Context* c = new Context(); |
3065 int rv = cache.http_cache()->CreateTransaction(&c->trans); | 3065 int rv = cache.http_cache()->CreateTransaction(&c->trans); |
3066 EXPECT_EQ(net::OK, rv); | 3066 EXPECT_EQ(net::OK, rv); |
3067 | 3067 |
3068 rv = c->trans->Start(&request, &c->callback, NULL); | 3068 rv = c->trans->Start(&request, &c->callback, net::BoundNetLog()); |
3069 if (rv == net::ERR_IO_PENDING) | 3069 if (rv == net::ERR_IO_PENDING) |
3070 rv = c->callback.WaitForResult(); | 3070 rv = c->callback.WaitForResult(); |
3071 | 3071 |
3072 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 3072 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
3073 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 3073 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
3074 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 3074 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
3075 | 3075 |
3076 // Make sure that we revalidate the entry and read from the cache (a single | 3076 // Make sure that we revalidate the entry and read from the cache (a single |
3077 // read will return while waiting for the network). | 3077 // read will return while waiting for the network). |
3078 scoped_refptr<net::IOBufferWithSize> buf = new net::IOBufferWithSize(5); | 3078 scoped_refptr<net::IOBufferWithSize> buf = new net::IOBufferWithSize(5); |
(...skipping 24 matching lines...) Expand all Loading... |
3103 cache.http_cache()->set_enable_range_support(true); | 3103 cache.http_cache()->set_enable_range_support(true); |
3104 AddMockTransaction(&kRangeGET_TransactionOK); | 3104 AddMockTransaction(&kRangeGET_TransactionOK); |
3105 | 3105 |
3106 RunTransactionTest(cache.http_cache(), kRangeGET_TransactionOK); | 3106 RunTransactionTest(cache.http_cache(), kRangeGET_TransactionOK); |
3107 MockHttpRequest request(kRangeGET_TransactionOK); | 3107 MockHttpRequest request(kRangeGET_TransactionOK); |
3108 | 3108 |
3109 Context* c = new Context(); | 3109 Context* c = new Context(); |
3110 int rv = cache.http_cache()->CreateTransaction(&c->trans); | 3110 int rv = cache.http_cache()->CreateTransaction(&c->trans); |
3111 EXPECT_EQ(net::OK, rv); | 3111 EXPECT_EQ(net::OK, rv); |
3112 | 3112 |
3113 rv = c->trans->Start(&request, &c->callback, NULL); | 3113 rv = c->trans->Start(&request, &c->callback, net::BoundNetLog()); |
3114 EXPECT_EQ(net::ERR_IO_PENDING, rv); | 3114 EXPECT_EQ(net::ERR_IO_PENDING, rv); |
3115 rv = c->callback.WaitForResult(); | 3115 rv = c->callback.WaitForResult(); |
3116 | 3116 |
3117 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 3117 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
3118 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 3118 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
3119 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 3119 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
3120 | 3120 |
3121 // Make sure that we revalidate the entry and read from the cache (a single | 3121 // Make sure that we revalidate the entry and read from the cache (a single |
3122 // read will return while waiting for the network). | 3122 // read will return while waiting for the network). |
3123 scoped_refptr<net::IOBufferWithSize> buf = new net::IOBufferWithSize(5); | 3123 scoped_refptr<net::IOBufferWithSize> buf = new net::IOBufferWithSize(5); |
3124 rv = c->trans->Read(buf, buf->size(), &c->callback); | 3124 rv = c->trans->Read(buf, buf->size(), &c->callback); |
3125 EXPECT_EQ(5, c->callback.GetResult(rv)); | 3125 EXPECT_EQ(5, c->callback.GetResult(rv)); |
3126 rv = c->trans->Read(buf, buf->size(), &c->callback); | 3126 rv = c->trans->Read(buf, buf->size(), &c->callback); |
3127 EXPECT_EQ(net::ERR_IO_PENDING, rv); | 3127 EXPECT_EQ(net::ERR_IO_PENDING, rv); |
3128 | 3128 |
3129 // Destroy the transaction before completing the read. | 3129 // Destroy the transaction before completing the read. |
3130 delete c; | 3130 delete c; |
3131 | 3131 |
3132 // We have the read and the delete (OnProcessPendingQueue) waiting on the | 3132 // We have the read and the delete (OnProcessPendingQueue) waiting on the |
3133 // message loop. This means that a new transaction will just reuse the same | 3133 // message loop. This means that a new transaction will just reuse the same |
3134 // active entry (no open or create). | 3134 // active entry (no open or create). |
3135 | 3135 |
3136 c = new Context(); | 3136 c = new Context(); |
3137 rv = cache.http_cache()->CreateTransaction(&c->trans); | 3137 rv = cache.http_cache()->CreateTransaction(&c->trans); |
3138 EXPECT_EQ(net::OK, rv); | 3138 EXPECT_EQ(net::OK, rv); |
3139 | 3139 |
3140 rv = c->trans->Start(&request, &c->callback, NULL); | 3140 rv = c->trans->Start(&request, &c->callback, net::BoundNetLog()); |
3141 EXPECT_EQ(net::ERR_IO_PENDING, rv); | 3141 EXPECT_EQ(net::ERR_IO_PENDING, rv); |
3142 | 3142 |
3143 MockDiskEntry::IgnoreCallbacks(true); | 3143 MockDiskEntry::IgnoreCallbacks(true); |
3144 MessageLoop::current()->RunAllPending(); | 3144 MessageLoop::current()->RunAllPending(); |
3145 MockDiskEntry::IgnoreCallbacks(false); | 3145 MockDiskEntry::IgnoreCallbacks(false); |
3146 | 3146 |
3147 // The new transaction is waiting for the query range callback. | 3147 // The new transaction is waiting for the query range callback. |
3148 delete c; | 3148 delete c; |
3149 | 3149 |
3150 // And we should not crash when the callback is delivered. | 3150 // And we should not crash when the callback is delivered. |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3469 TEST(HttpCache, DoomOnDestruction) { | 3469 TEST(HttpCache, DoomOnDestruction) { |
3470 MockHttpCache cache; | 3470 MockHttpCache cache; |
3471 cache.http_cache()->set_enable_range_support(true); | 3471 cache.http_cache()->set_enable_range_support(true); |
3472 | 3472 |
3473 MockHttpRequest request(kSimpleGET_Transaction); | 3473 MockHttpRequest request(kSimpleGET_Transaction); |
3474 | 3474 |
3475 Context* c = new Context(); | 3475 Context* c = new Context(); |
3476 int rv = cache.http_cache()->CreateTransaction(&c->trans); | 3476 int rv = cache.http_cache()->CreateTransaction(&c->trans); |
3477 EXPECT_EQ(net::OK, rv); | 3477 EXPECT_EQ(net::OK, rv); |
3478 | 3478 |
3479 rv = c->trans->Start(&request, &c->callback, NULL); | 3479 rv = c->trans->Start(&request, &c->callback, net::BoundNetLog()); |
3480 if (rv == net::ERR_IO_PENDING) | 3480 if (rv == net::ERR_IO_PENDING) |
3481 c->result = c->callback.WaitForResult(); | 3481 c->result = c->callback.WaitForResult(); |
3482 | 3482 |
3483 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 3483 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
3484 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 3484 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
3485 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 3485 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
3486 | 3486 |
3487 // Destroy the transaction. We only have the headers so we should delete this | 3487 // Destroy the transaction. We only have the headers so we should delete this |
3488 // entry. | 3488 // entry. |
3489 delete c; | 3489 delete c; |
(...skipping 10 matching lines...) Expand all Loading... |
3500 TEST(HttpCache, DoomOnDestruction2) { | 3500 TEST(HttpCache, DoomOnDestruction2) { |
3501 MockHttpCache cache; | 3501 MockHttpCache cache; |
3502 cache.http_cache()->set_enable_range_support(true); | 3502 cache.http_cache()->set_enable_range_support(true); |
3503 | 3503 |
3504 MockHttpRequest request(kSimpleGET_Transaction); | 3504 MockHttpRequest request(kSimpleGET_Transaction); |
3505 | 3505 |
3506 Context* c = new Context(); | 3506 Context* c = new Context(); |
3507 int rv = cache.http_cache()->CreateTransaction(&c->trans); | 3507 int rv = cache.http_cache()->CreateTransaction(&c->trans); |
3508 EXPECT_EQ(net::OK, rv); | 3508 EXPECT_EQ(net::OK, rv); |
3509 | 3509 |
3510 rv = c->trans->Start(&request, &c->callback, NULL); | 3510 rv = c->trans->Start(&request, &c->callback, net::BoundNetLog()); |
3511 if (rv == net::ERR_IO_PENDING) | 3511 if (rv == net::ERR_IO_PENDING) |
3512 rv = c->callback.WaitForResult(); | 3512 rv = c->callback.WaitForResult(); |
3513 | 3513 |
3514 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 3514 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
3515 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 3515 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
3516 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 3516 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
3517 | 3517 |
3518 // Make sure that the entry has some data stored. | 3518 // Make sure that the entry has some data stored. |
3519 scoped_refptr<net::IOBufferWithSize> buf = new net::IOBufferWithSize(10); | 3519 scoped_refptr<net::IOBufferWithSize> buf = new net::IOBufferWithSize(10); |
3520 rv = c->trans->Read(buf, buf->size(), &c->callback); | 3520 rv = c->trans->Read(buf, buf->size(), &c->callback); |
(...skipping 23 matching lines...) Expand all Loading... |
3544 "Content-Length: 22\n" | 3544 "Content-Length: 22\n" |
3545 "Accept-Ranges: none\n" | 3545 "Accept-Ranges: none\n" |
3546 "Etag: foopy\n"; | 3546 "Etag: foopy\n"; |
3547 AddMockTransaction(&transaction); | 3547 AddMockTransaction(&transaction); |
3548 MockHttpRequest request(transaction); | 3548 MockHttpRequest request(transaction); |
3549 | 3549 |
3550 Context* c = new Context(); | 3550 Context* c = new Context(); |
3551 int rv = cache.http_cache()->CreateTransaction(&c->trans); | 3551 int rv = cache.http_cache()->CreateTransaction(&c->trans); |
3552 EXPECT_EQ(net::OK, rv); | 3552 EXPECT_EQ(net::OK, rv); |
3553 | 3553 |
3554 rv = c->trans->Start(&request, &c->callback, NULL); | 3554 rv = c->trans->Start(&request, &c->callback, net::BoundNetLog()); |
3555 if (rv == net::ERR_IO_PENDING) | 3555 if (rv == net::ERR_IO_PENDING) |
3556 rv = c->callback.WaitForResult(); | 3556 rv = c->callback.WaitForResult(); |
3557 | 3557 |
3558 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 3558 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
3559 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 3559 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
3560 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 3560 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
3561 | 3561 |
3562 // Make sure that the entry has some data stored. | 3562 // Make sure that the entry has some data stored. |
3563 scoped_refptr<net::IOBufferWithSize> buf = new net::IOBufferWithSize(10); | 3563 scoped_refptr<net::IOBufferWithSize> buf = new net::IOBufferWithSize(10); |
3564 rv = c->trans->Read(buf, buf->size(), &c->callback); | 3564 rv = c->trans->Read(buf, buf->size(), &c->callback); |
(...skipping 23 matching lines...) Expand all Loading... |
3588 "Last-Modified: Wed, 28 Nov 2007 00:40:09 GMT\n" | 3588 "Last-Modified: Wed, 28 Nov 2007 00:40:09 GMT\n" |
3589 "Content-Length: 22\n" | 3589 "Content-Length: 22\n" |
3590 "Etag: foopy\n"; | 3590 "Etag: foopy\n"; |
3591 AddMockTransaction(&transaction); | 3591 AddMockTransaction(&transaction); |
3592 MockHttpRequest request(transaction); | 3592 MockHttpRequest request(transaction); |
3593 | 3593 |
3594 scoped_ptr<Context> c(new Context()); | 3594 scoped_ptr<Context> c(new Context()); |
3595 int rv = cache.http_cache()->CreateTransaction(&c->trans); | 3595 int rv = cache.http_cache()->CreateTransaction(&c->trans); |
3596 EXPECT_EQ(net::OK, rv); | 3596 EXPECT_EQ(net::OK, rv); |
3597 | 3597 |
3598 rv = c->trans->Start(&request, &c->callback, NULL); | 3598 rv = c->trans->Start(&request, &c->callback, net::BoundNetLog()); |
3599 if (rv == net::ERR_IO_PENDING) | 3599 if (rv == net::ERR_IO_PENDING) |
3600 rv = c->callback.WaitForResult(); | 3600 rv = c->callback.WaitForResult(); |
3601 | 3601 |
3602 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 3602 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
3603 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 3603 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
3604 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 3604 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
3605 | 3605 |
3606 // Make sure that the entry has some data stored. | 3606 // Make sure that the entry has some data stored. |
3607 scoped_refptr<net::IOBufferWithSize> buf = new net::IOBufferWithSize(10); | 3607 scoped_refptr<net::IOBufferWithSize> buf = new net::IOBufferWithSize(10); |
3608 rv = c->trans->Read(buf, buf->size(), &c->callback); | 3608 rv = c->trans->Read(buf, buf->size(), &c->callback); |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3794 EXPECT_EQ(len, entry->WriteData(1, 0, buf, len, NULL, true)); | 3794 EXPECT_EQ(len, entry->WriteData(1, 0, buf, len, NULL, true)); |
3795 | 3795 |
3796 // Now make a regular request. | 3796 // Now make a regular request. |
3797 MockTransaction transaction(kRangeGET_TransactionOK); | 3797 MockTransaction transaction(kRangeGET_TransactionOK); |
3798 transaction.request_headers = EXTRA_HEADER; | 3798 transaction.request_headers = EXTRA_HEADER; |
3799 | 3799 |
3800 MockHttpRequest request(transaction); | 3800 MockHttpRequest request(transaction); |
3801 Context* c = new Context(); | 3801 Context* c = new Context(); |
3802 EXPECT_EQ(net::OK, cache.http_cache()->CreateTransaction(&c->trans)); | 3802 EXPECT_EQ(net::OK, cache.http_cache()->CreateTransaction(&c->trans)); |
3803 | 3803 |
3804 int rv = c->trans->Start(&request, &c->callback, NULL); | 3804 int rv = c->trans->Start(&request, &c->callback, net::BoundNetLog()); |
3805 EXPECT_EQ(net::OK, c->callback.GetResult(rv)); | 3805 EXPECT_EQ(net::OK, c->callback.GetResult(rv)); |
3806 | 3806 |
3807 // Read 20 bytes from the cache, and 10 from the net. | 3807 // Read 20 bytes from the cache, and 10 from the net. |
3808 rv = c->trans->Read(buf, len, &c->callback); | 3808 rv = c->trans->Read(buf, len, &c->callback); |
3809 EXPECT_EQ(len, c->callback.GetResult(rv)); | 3809 EXPECT_EQ(len, c->callback.GetResult(rv)); |
3810 rv = c->trans->Read(buf, 10, &c->callback); | 3810 rv = c->trans->Read(buf, 10, &c->callback); |
3811 EXPECT_EQ(10, c->callback.GetResult(rv)); | 3811 EXPECT_EQ(10, c->callback.GetResult(rv)); |
3812 | 3812 |
3813 // At this point, we are already reading so canceling the request should leave | 3813 // At this point, we are already reading so canceling the request should leave |
3814 // a truncated one. | 3814 // a truncated one. |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3885 TEST_MODE_SYNC_CACHE_WRITE); | 3885 TEST_MODE_SYNC_CACHE_WRITE); |
3886 | 3886 |
3887 MockHttpRequest r1(transaction), | 3887 MockHttpRequest r1(transaction), |
3888 r2(transaction), | 3888 r2(transaction), |
3889 r3(transaction); | 3889 r3(transaction); |
3890 | 3890 |
3891 TestTransactionConsumer c1(cache.http_cache()), | 3891 TestTransactionConsumer c1(cache.http_cache()), |
3892 c2(cache.http_cache()), | 3892 c2(cache.http_cache()), |
3893 c3(cache.http_cache()); | 3893 c3(cache.http_cache()); |
3894 | 3894 |
3895 c1.Start(&r1, NULL); | 3895 c1.Start(&r1, net::BoundNetLog()); |
3896 | 3896 |
3897 r2.load_flags |= net::LOAD_ONLY_FROM_CACHE; | 3897 r2.load_flags |= net::LOAD_ONLY_FROM_CACHE; |
3898 c2.Start(&r2, NULL); | 3898 c2.Start(&r2, net::BoundNetLog()); |
3899 | 3899 |
3900 r3.load_flags |= net::LOAD_ONLY_FROM_CACHE; | 3900 r3.load_flags |= net::LOAD_ONLY_FROM_CACHE; |
3901 c3.Start(&r3, NULL); | 3901 c3.Start(&r3, net::BoundNetLog()); |
3902 | 3902 |
3903 MessageLoop::current()->Run(); | 3903 MessageLoop::current()->Run(); |
3904 | 3904 |
3905 EXPECT_TRUE(c1.is_done()); | 3905 EXPECT_TRUE(c1.is_done()); |
3906 EXPECT_TRUE(c2.is_done()); | 3906 EXPECT_TRUE(c2.is_done()); |
3907 EXPECT_TRUE(c3.is_done()); | 3907 EXPECT_TRUE(c3.is_done()); |
3908 | 3908 |
3909 EXPECT_EQ(net::OK, c1.error()); | 3909 EXPECT_EQ(net::OK, c1.error()); |
3910 EXPECT_EQ(net::OK, c2.error()); | 3910 EXPECT_EQ(net::OK, c2.error()); |
3911 EXPECT_EQ(net::OK, c3.error()); | 3911 EXPECT_EQ(net::OK, c3.error()); |
(...skipping 27 matching lines...) Expand all Loading... |
3939 MockHttpRequest request(kTestTransaction); | 3939 MockHttpRequest request(kTestTransaction); |
3940 TestCompletionCallback callback; | 3940 TestCompletionCallback callback; |
3941 | 3941 |
3942 // write to the cache | 3942 // write to the cache |
3943 { | 3943 { |
3944 scoped_ptr<net::HttpTransaction> trans; | 3944 scoped_ptr<net::HttpTransaction> trans; |
3945 int rv = cache.http_cache()->CreateTransaction(&trans); | 3945 int rv = cache.http_cache()->CreateTransaction(&trans); |
3946 EXPECT_EQ(net::OK, rv); | 3946 EXPECT_EQ(net::OK, rv); |
3947 ASSERT_TRUE(trans.get()); | 3947 ASSERT_TRUE(trans.get()); |
3948 | 3948 |
3949 rv = trans->Start(&request, &callback, NULL); | 3949 rv = trans->Start(&request, &callback, net::BoundNetLog()); |
3950 if (rv == net::ERR_IO_PENDING) | 3950 if (rv == net::ERR_IO_PENDING) |
3951 rv = callback.WaitForResult(); | 3951 rv = callback.WaitForResult(); |
3952 ASSERT_EQ(net::OK, rv); | 3952 ASSERT_EQ(net::OK, rv); |
3953 | 3953 |
3954 const net::HttpResponseInfo* info = trans->GetResponseInfo(); | 3954 const net::HttpResponseInfo* info = trans->GetResponseInfo(); |
3955 ASSERT_TRUE(info); | 3955 ASSERT_TRUE(info); |
3956 | 3956 |
3957 EXPECT_EQ(info->headers->response_code(), 301); | 3957 EXPECT_EQ(info->headers->response_code(), 301); |
3958 | 3958 |
3959 std::string location; | 3959 std::string location; |
3960 info->headers->EnumerateHeader(NULL, "Location", &location); | 3960 info->headers->EnumerateHeader(NULL, "Location", &location); |
3961 EXPECT_EQ(location, "http://www.bar.com/"); | 3961 EXPECT_EQ(location, "http://www.bar.com/"); |
3962 | 3962 |
3963 // Destroy transaction when going out of scope. We have not actually | 3963 // Destroy transaction when going out of scope. We have not actually |
3964 // read the response body -- want to test that it is still getting cached. | 3964 // read the response body -- want to test that it is still getting cached. |
3965 } | 3965 } |
3966 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 3966 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
3967 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 3967 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
3968 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 3968 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
3969 | 3969 |
3970 // read from the cache | 3970 // read from the cache |
3971 { | 3971 { |
3972 scoped_ptr<net::HttpTransaction> trans; | 3972 scoped_ptr<net::HttpTransaction> trans; |
3973 int rv = cache.http_cache()->CreateTransaction(&trans); | 3973 int rv = cache.http_cache()->CreateTransaction(&trans); |
3974 EXPECT_EQ(net::OK, rv); | 3974 EXPECT_EQ(net::OK, rv); |
3975 ASSERT_TRUE(trans.get()); | 3975 ASSERT_TRUE(trans.get()); |
3976 | 3976 |
3977 rv = trans->Start(&request, &callback, NULL); | 3977 rv = trans->Start(&request, &callback, net::BoundNetLog()); |
3978 if (rv == net::ERR_IO_PENDING) | 3978 if (rv == net::ERR_IO_PENDING) |
3979 rv = callback.WaitForResult(); | 3979 rv = callback.WaitForResult(); |
3980 ASSERT_EQ(net::OK, rv); | 3980 ASSERT_EQ(net::OK, rv); |
3981 | 3981 |
3982 const net::HttpResponseInfo* info = trans->GetResponseInfo(); | 3982 const net::HttpResponseInfo* info = trans->GetResponseInfo(); |
3983 ASSERT_TRUE(info); | 3983 ASSERT_TRUE(info); |
3984 | 3984 |
3985 EXPECT_EQ(info->headers->response_code(), 301); | 3985 EXPECT_EQ(info->headers->response_code(), 301); |
3986 | 3986 |
3987 std::string location; | 3987 std::string location; |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4095 transaction.load_flags |= net::LOAD_ONLY_FROM_CACHE; | 4095 transaction.load_flags |= net::LOAD_ONLY_FROM_CACHE; |
4096 | 4096 |
4097 MockHttpRequest request(transaction); | 4097 MockHttpRequest request(transaction); |
4098 TestCompletionCallback callback; | 4098 TestCompletionCallback callback; |
4099 | 4099 |
4100 scoped_ptr<net::HttpTransaction> trans; | 4100 scoped_ptr<net::HttpTransaction> trans; |
4101 int rv = cache.http_cache()->CreateTransaction(&trans); | 4101 int rv = cache.http_cache()->CreateTransaction(&trans); |
4102 EXPECT_EQ(net::OK, rv); | 4102 EXPECT_EQ(net::OK, rv); |
4103 ASSERT_TRUE(trans.get()); | 4103 ASSERT_TRUE(trans.get()); |
4104 | 4104 |
4105 rv = trans->Start(&request, &callback, NULL); | 4105 rv = trans->Start(&request, &callback, net::BoundNetLog()); |
4106 if (rv == net::ERR_IO_PENDING) | 4106 if (rv == net::ERR_IO_PENDING) |
4107 rv = callback.WaitForResult(); | 4107 rv = callback.WaitForResult(); |
4108 ASSERT_EQ(net::ERR_CACHE_MISS, rv); | 4108 ASSERT_EQ(net::ERR_CACHE_MISS, rv); |
4109 } | 4109 } |
4110 | 4110 |
4111 // Ensure that we don't crash by if left-behind transactions. | 4111 // Ensure that we don't crash by if left-behind transactions. |
4112 TEST(HttpCache, OutlivedTransactions) { | 4112 TEST(HttpCache, OutlivedTransactions) { |
4113 MockHttpCache* cache = new MockHttpCache; | 4113 MockHttpCache* cache = new MockHttpCache; |
4114 | 4114 |
4115 scoped_ptr<net::HttpTransaction> trans; | 4115 scoped_ptr<net::HttpTransaction> trans; |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4335 // Now return 200 when validating the entry so the metadata will be lost. | 4335 // Now return 200 when validating the entry so the metadata will be lost. |
4336 MockTransaction trans2(kTypicalGET_Transaction); | 4336 MockTransaction trans2(kTypicalGET_Transaction); |
4337 trans2.load_flags = net::LOAD_VALIDATE_CACHE; | 4337 trans2.load_flags = net::LOAD_VALIDATE_CACHE; |
4338 RunTransactionTestWithResponseInfo(cache.http_cache(), trans2, &response); | 4338 RunTransactionTestWithResponseInfo(cache.http_cache(), trans2, &response); |
4339 EXPECT_TRUE(response.metadata.get() == NULL); | 4339 EXPECT_TRUE(response.metadata.get() == NULL); |
4340 | 4340 |
4341 EXPECT_EQ(3, cache.network_layer()->transaction_count()); | 4341 EXPECT_EQ(3, cache.network_layer()->transaction_count()); |
4342 EXPECT_EQ(4, cache.disk_cache()->open_count()); | 4342 EXPECT_EQ(4, cache.disk_cache()->open_count()); |
4343 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 4343 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
4344 } | 4344 } |
OLD | NEW |