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

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

Issue 2109503009: Refactor net tests to use GMock matchers for checking net::Error results (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Revert changes to contents.txt files Created 4 years, 5 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_auth_sspi_win_unittest.cc ('k') | net/http/http_chunked_decoder_unittest.cc » ('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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 #include "net/http/http_transaction_test_util.h" 43 #include "net/http/http_transaction_test_util.h"
44 #include "net/http/http_util.h" 44 #include "net/http/http_util.h"
45 #include "net/http/mock_http_cache.h" 45 #include "net/http/mock_http_cache.h"
46 #include "net/log/test_net_log.h" 46 #include "net/log/test_net_log.h"
47 #include "net/log/test_net_log_entry.h" 47 #include "net/log/test_net_log_entry.h"
48 #include "net/log/test_net_log_util.h" 48 #include "net/log/test_net_log_util.h"
49 #include "net/socket/client_socket_handle.h" 49 #include "net/socket/client_socket_handle.h"
50 #include "net/ssl/ssl_cert_request_info.h" 50 #include "net/ssl/ssl_cert_request_info.h"
51 #include "net/ssl/ssl_connection_status_flags.h" 51 #include "net/ssl/ssl_connection_status_flags.h"
52 #include "net/test/cert_test_util.h" 52 #include "net/test/cert_test_util.h"
53 #include "net/test/gtest_util.h"
53 #include "net/test/test_data_directory.h" 54 #include "net/test/test_data_directory.h"
54 #include "net/websockets/websocket_handshake_stream_base.h" 55 #include "net/websockets/websocket_handshake_stream_base.h"
56 #include "testing/gmock/include/gmock/gmock.h"
55 #include "testing/gtest/include/gtest/gtest.h" 57 #include "testing/gtest/include/gtest/gtest.h"
56 58
59 using net::test::IsError;
60 using net::test::IsOk;
61
57 using base::Time; 62 using base::Time;
58 63
59 namespace net { 64 namespace net {
60 65
61 namespace { 66 namespace {
62 67
63 // Tests the load timing values of a request that goes through a 68 // Tests the load timing values of a request that goes through a
64 // MockNetworkTransaction. 69 // MockNetworkTransaction.
65 void TestLoadTimingNetworkRequest(const LoadTimingInfo& load_timing_info) { 70 void TestLoadTimingNetworkRequest(const LoadTimingInfo& load_timing_info) {
66 EXPECT_FALSE(load_timing_info.socket_reused); 71 EXPECT_FALSE(load_timing_info.socket_reused);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 }; 131 };
127 132
128 //----------------------------------------------------------------------------- 133 //-----------------------------------------------------------------------------
129 // helpers 134 // helpers
130 135
131 void ReadAndVerifyTransaction(HttpTransaction* trans, 136 void ReadAndVerifyTransaction(HttpTransaction* trans,
132 const MockTransaction& trans_info) { 137 const MockTransaction& trans_info) {
133 std::string content; 138 std::string content;
134 int rv = ReadTransaction(trans, &content); 139 int rv = ReadTransaction(trans, &content);
135 140
136 EXPECT_EQ(OK, rv); 141 EXPECT_THAT(rv, IsOk());
137 std::string expected(trans_info.data); 142 std::string expected(trans_info.data);
138 EXPECT_EQ(expected, content); 143 EXPECT_EQ(expected, content);
139 } 144 }
140 145
141 void RunTransactionTestBase(HttpCache* cache, 146 void RunTransactionTestBase(HttpCache* cache,
142 const MockTransaction& trans_info, 147 const MockTransaction& trans_info,
143 const MockHttpRequest& request, 148 const MockHttpRequest& request,
144 HttpResponseInfo* response_info, 149 HttpResponseInfo* response_info,
145 const BoundNetLog& net_log, 150 const BoundNetLog& net_log,
146 LoadTimingInfo* load_timing_info, 151 LoadTimingInfo* load_timing_info,
147 int64_t* sent_bytes, 152 int64_t* sent_bytes,
148 int64_t* received_bytes, 153 int64_t* received_bytes,
149 IPEndPoint* remote_endpoint) { 154 IPEndPoint* remote_endpoint) {
150 TestCompletionCallback callback; 155 TestCompletionCallback callback;
151 156
152 // write to the cache 157 // write to the cache
153 158
154 std::unique_ptr<HttpTransaction> trans; 159 std::unique_ptr<HttpTransaction> trans;
155 int rv = cache->CreateTransaction(DEFAULT_PRIORITY, &trans); 160 int rv = cache->CreateTransaction(DEFAULT_PRIORITY, &trans);
156 EXPECT_EQ(OK, rv); 161 EXPECT_THAT(rv, IsOk());
157 ASSERT_TRUE(trans.get()); 162 ASSERT_TRUE(trans.get());
158 163
159 rv = trans->Start(&request, callback.callback(), net_log); 164 rv = trans->Start(&request, callback.callback(), net_log);
160 if (rv == ERR_IO_PENDING) 165 if (rv == ERR_IO_PENDING)
161 rv = callback.WaitForResult(); 166 rv = callback.WaitForResult();
162 ASSERT_EQ(trans_info.return_code, rv); 167 ASSERT_EQ(trans_info.return_code, rv);
163 168
164 if (OK != rv) 169 if (OK != rv)
165 return; 170 return;
166 171
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 } // namespace 628 } // namespace
624 629
625 630
626 //----------------------------------------------------------------------------- 631 //-----------------------------------------------------------------------------
627 // Tests. 632 // Tests.
628 633
629 TEST(HttpCache, CreateThenDestroy) { 634 TEST(HttpCache, CreateThenDestroy) {
630 MockHttpCache cache; 635 MockHttpCache cache;
631 636
632 std::unique_ptr<HttpTransaction> trans; 637 std::unique_ptr<HttpTransaction> trans;
633 EXPECT_EQ(OK, cache.CreateTransaction(&trans)); 638 EXPECT_THAT(cache.CreateTransaction(&trans), IsOk());
634 ASSERT_TRUE(trans.get()); 639 ASSERT_TRUE(trans.get());
635 } 640 }
636 641
637 TEST(HttpCache, GetBackend) { 642 TEST(HttpCache, GetBackend) {
638 MockHttpCache cache(HttpCache::DefaultBackend::InMemory(0)); 643 MockHttpCache cache(HttpCache::DefaultBackend::InMemory(0));
639 644
640 disk_cache::Backend* backend; 645 disk_cache::Backend* backend;
641 TestCompletionCallback cb; 646 TestCompletionCallback cb;
642 // This will lazily initialize the backend. 647 // This will lazily initialize the backend.
643 int rv = cache.http_cache()->GetBackend(&backend, cb.callback()); 648 int rv = cache.http_cache()->GetBackend(&backend, cb.callback());
644 EXPECT_EQ(OK, cb.GetResult(rv)); 649 EXPECT_THAT(cb.GetResult(rv), IsOk());
645 } 650 }
646 651
647 TEST(HttpCache, SimpleGET) { 652 TEST(HttpCache, SimpleGET) {
648 MockHttpCache cache; 653 MockHttpCache cache;
649 BoundTestNetLog log; 654 BoundTestNetLog log;
650 LoadTimingInfo load_timing_info; 655 LoadTimingInfo load_timing_info;
651 656
652 // Write to the cache. 657 // Write to the cache.
653 RunTransactionTestAndGetTiming(cache.http_cache(), kSimpleGET_Transaction, 658 RunTransactionTestAndGetTiming(cache.http_cache(), kSimpleGET_Transaction,
654 log.bound(), &load_timing_info); 659 log.bound(), &load_timing_info);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
714 719
715 // Tests that IOBuffers are not referenced after IO completes. 720 // Tests that IOBuffers are not referenced after IO completes.
716 TEST(HttpCache, ReleaseBuffer) { 721 TEST(HttpCache, ReleaseBuffer) {
717 MockHttpCache cache; 722 MockHttpCache cache;
718 723
719 // Write to the cache. 724 // Write to the cache.
720 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); 725 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction);
721 726
722 MockHttpRequest request(kSimpleGET_Transaction); 727 MockHttpRequest request(kSimpleGET_Transaction);
723 std::unique_ptr<HttpTransaction> trans; 728 std::unique_ptr<HttpTransaction> trans;
724 ASSERT_EQ(OK, cache.CreateTransaction(&trans)); 729 ASSERT_THAT(cache.CreateTransaction(&trans), IsOk());
725 730
726 const int kBufferSize = 10; 731 const int kBufferSize = 10;
727 scoped_refptr<IOBuffer> buffer(new IOBuffer(kBufferSize)); 732 scoped_refptr<IOBuffer> buffer(new IOBuffer(kBufferSize));
728 ReleaseBufferCompletionCallback cb(buffer.get()); 733 ReleaseBufferCompletionCallback cb(buffer.get());
729 734
730 int rv = trans->Start(&request, cb.callback(), BoundNetLog()); 735 int rv = trans->Start(&request, cb.callback(), BoundNetLog());
731 EXPECT_EQ(OK, cb.GetResult(rv)); 736 EXPECT_THAT(cb.GetResult(rv), IsOk());
732 737
733 rv = trans->Read(buffer.get(), kBufferSize, cb.callback()); 738 rv = trans->Read(buffer.get(), kBufferSize, cb.callback());
734 EXPECT_EQ(kBufferSize, cb.GetResult(rv)); 739 EXPECT_EQ(kBufferSize, cb.GetResult(rv));
735 } 740 }
736 741
737 TEST(HttpCache, SimpleGETWithDiskFailures) { 742 TEST(HttpCache, SimpleGETWithDiskFailures) {
738 MockHttpCache cache; 743 MockHttpCache cache;
739 744
740 cache.disk_cache()->set_soft_failures(true); 745 cache.disk_cache()->set_soft_failures(true);
741 746
(...skipping 14 matching lines...) Expand all
756 761
757 // Tests that disk failures after the transaction has started don't cause the 762 // Tests that disk failures after the transaction has started don't cause the
758 // request to fail. 763 // request to fail.
759 TEST(HttpCache, SimpleGETWithDiskFailures2) { 764 TEST(HttpCache, SimpleGETWithDiskFailures2) {
760 MockHttpCache cache; 765 MockHttpCache cache;
761 766
762 MockHttpRequest request(kSimpleGET_Transaction); 767 MockHttpRequest request(kSimpleGET_Transaction);
763 768
764 std::unique_ptr<Context> c(new Context()); 769 std::unique_ptr<Context> c(new Context());
765 int rv = cache.CreateTransaction(&c->trans); 770 int rv = cache.CreateTransaction(&c->trans);
766 ASSERT_EQ(OK, rv); 771 ASSERT_THAT(rv, IsOk());
767 772
768 rv = c->trans->Start(&request, c->callback.callback(), BoundNetLog()); 773 rv = c->trans->Start(&request, c->callback.callback(), BoundNetLog());
769 EXPECT_EQ(ERR_IO_PENDING, rv); 774 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
770 rv = c->callback.WaitForResult(); 775 rv = c->callback.WaitForResult();
771 776
772 // Start failing request now. 777 // Start failing request now.
773 cache.disk_cache()->set_soft_failures(true); 778 cache.disk_cache()->set_soft_failures(true);
774 779
775 // We have to open the entry again to propagate the failure flag. 780 // We have to open the entry again to propagate the failure flag.
776 disk_cache::Entry* en; 781 disk_cache::Entry* en;
777 ASSERT_TRUE(cache.OpenBackendEntry(kSimpleGET_Transaction.url, &en)); 782 ASSERT_TRUE(cache.OpenBackendEntry(kSimpleGET_Transaction.url, &en));
778 en->Close(); 783 en->Close();
779 784
(...skipping 21 matching lines...) Expand all
801 806
802 EXPECT_EQ(1, cache.network_layer()->transaction_count()); 807 EXPECT_EQ(1, cache.network_layer()->transaction_count());
803 EXPECT_EQ(0, cache.disk_cache()->open_count()); 808 EXPECT_EQ(0, cache.disk_cache()->open_count());
804 EXPECT_EQ(1, cache.disk_cache()->create_count()); 809 EXPECT_EQ(1, cache.disk_cache()->create_count());
805 810
806 cache.disk_cache()->set_soft_failures(true); 811 cache.disk_cache()->set_soft_failures(true);
807 812
808 // Now fail to read from the cache. 813 // Now fail to read from the cache.
809 std::unique_ptr<Context> c(new Context()); 814 std::unique_ptr<Context> c(new Context());
810 int rv = cache.CreateTransaction(&c->trans); 815 int rv = cache.CreateTransaction(&c->trans);
811 ASSERT_EQ(OK, rv); 816 ASSERT_THAT(rv, IsOk());
812 817
813 MockHttpRequest request(kSimpleGET_Transaction); 818 MockHttpRequest request(kSimpleGET_Transaction);
814 rv = c->trans->Start(&request, c->callback.callback(), BoundNetLog()); 819 rv = c->trans->Start(&request, c->callback.callback(), BoundNetLog());
815 EXPECT_EQ(OK, c->callback.GetResult(rv)); 820 EXPECT_THAT(c->callback.GetResult(rv), IsOk());
816 821
817 // Now verify that the entry was removed from the cache. 822 // Now verify that the entry was removed from the cache.
818 cache.disk_cache()->set_soft_failures(false); 823 cache.disk_cache()->set_soft_failures(false);
819 824
820 EXPECT_EQ(2, cache.network_layer()->transaction_count()); 825 EXPECT_EQ(2, cache.network_layer()->transaction_count());
821 EXPECT_EQ(1, cache.disk_cache()->open_count()); 826 EXPECT_EQ(1, cache.disk_cache()->open_count());
822 EXPECT_EQ(2, cache.disk_cache()->create_count()); 827 EXPECT_EQ(2, cache.disk_cache()->create_count());
823 828
824 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); 829 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction);
825 830
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
904 MockHttpCache cache; 909 MockHttpCache cache;
905 910
906 // force this transaction to read from the cache 911 // force this transaction to read from the cache
907 MockTransaction transaction(kSimpleGET_Transaction); 912 MockTransaction transaction(kSimpleGET_Transaction);
908 transaction.load_flags |= LOAD_ONLY_FROM_CACHE; 913 transaction.load_flags |= LOAD_ONLY_FROM_CACHE;
909 914
910 MockHttpRequest request(transaction); 915 MockHttpRequest request(transaction);
911 TestCompletionCallback callback; 916 TestCompletionCallback callback;
912 917
913 std::unique_ptr<HttpTransaction> trans; 918 std::unique_ptr<HttpTransaction> trans;
914 ASSERT_EQ(OK, cache.CreateTransaction(&trans)); 919 ASSERT_THAT(cache.CreateTransaction(&trans), IsOk());
915 920
916 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); 921 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
917 if (rv == ERR_IO_PENDING) 922 if (rv == ERR_IO_PENDING)
918 rv = callback.WaitForResult(); 923 rv = callback.WaitForResult();
919 ASSERT_EQ(ERR_CACHE_MISS, rv); 924 ASSERT_THAT(rv, IsError(ERR_CACHE_MISS));
920 925
921 trans.reset(); 926 trans.reset();
922 927
923 EXPECT_EQ(0, cache.network_layer()->transaction_count()); 928 EXPECT_EQ(0, cache.network_layer()->transaction_count());
924 EXPECT_EQ(0, cache.disk_cache()->open_count()); 929 EXPECT_EQ(0, cache.disk_cache()->open_count());
925 EXPECT_EQ(0, cache.disk_cache()->create_count()); 930 EXPECT_EQ(0, cache.disk_cache()->create_count());
926 } 931 }
927 932
928 TEST(HttpCache, SimpleGET_LoadPreferringCache_Hit) { 933 TEST(HttpCache, SimpleGET_LoadPreferringCache_Hit) {
929 MockHttpCache cache; 934 MockHttpCache cache;
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
1022 RemoveMockTransaction(&transaction); 1027 RemoveMockTransaction(&transaction);
1023 1028
1024 // Network failure with error; should fail but have was_cached set. 1029 // Network failure with error; should fail but have was_cached set.
1025 transaction.return_code = ERR_FAILED; 1030 transaction.return_code = ERR_FAILED;
1026 AddMockTransaction(&transaction); 1031 AddMockTransaction(&transaction);
1027 1032
1028 MockHttpRequest request(transaction); 1033 MockHttpRequest request(transaction);
1029 TestCompletionCallback callback; 1034 TestCompletionCallback callback;
1030 std::unique_ptr<HttpTransaction> trans; 1035 std::unique_ptr<HttpTransaction> trans;
1031 int rv = cache.http_cache()->CreateTransaction(DEFAULT_PRIORITY, &trans); 1036 int rv = cache.http_cache()->CreateTransaction(DEFAULT_PRIORITY, &trans);
1032 EXPECT_EQ(OK, rv); 1037 EXPECT_THAT(rv, IsOk());
1033 ASSERT_TRUE(trans.get()); 1038 ASSERT_TRUE(trans.get());
1034 rv = trans->Start(&request, callback.callback(), BoundNetLog()); 1039 rv = trans->Start(&request, callback.callback(), BoundNetLog());
1035 EXPECT_EQ(ERR_FAILED, callback.GetResult(rv)); 1040 EXPECT_THAT(callback.GetResult(rv), IsError(ERR_FAILED));
1036 1041
1037 const HttpResponseInfo* response_info = trans->GetResponseInfo(); 1042 const HttpResponseInfo* response_info = trans->GetResponseInfo();
1038 ASSERT_TRUE(response_info); 1043 ASSERT_TRUE(response_info);
1039 EXPECT_TRUE(response_info->was_cached); 1044 EXPECT_TRUE(response_info->was_cached);
1040 EXPECT_EQ(2, cache.network_layer()->transaction_count()); 1045 EXPECT_EQ(2, cache.network_layer()->transaction_count());
1041 1046
1042 RemoveMockTransaction(&transaction); 1047 RemoveMockTransaction(&transaction);
1043 } 1048 }
1044 1049
1045 // Confirm if we have an empty cache, a read is marked as network verified. 1050 // Confirm if we have an empty cache, a read is marked as network verified.
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
1260 MockHttpRequest request(kSimpleGET_Transaction); 1265 MockHttpRequest request(kSimpleGET_Transaction);
1261 1266
1262 std::vector<Context*> context_list; 1267 std::vector<Context*> context_list;
1263 const int kNumTransactions = 5; 1268 const int kNumTransactions = 5;
1264 1269
1265 for (int i = 0; i < kNumTransactions; ++i) { 1270 for (int i = 0; i < kNumTransactions; ++i) {
1266 context_list.push_back(new Context()); 1271 context_list.push_back(new Context());
1267 Context* c = context_list[i]; 1272 Context* c = context_list[i];
1268 1273
1269 c->result = cache.CreateTransaction(&c->trans); 1274 c->result = cache.CreateTransaction(&c->trans);
1270 ASSERT_EQ(OK, c->result); 1275 ASSERT_THAT(c->result, IsOk());
1271 EXPECT_EQ(LOAD_STATE_IDLE, c->trans->GetLoadState()); 1276 EXPECT_EQ(LOAD_STATE_IDLE, c->trans->GetLoadState());
1272 1277
1273 c->result = 1278 c->result =
1274 c->trans->Start(&request, c->callback.callback(), BoundNetLog()); 1279 c->trans->Start(&request, c->callback.callback(), BoundNetLog());
1275 } 1280 }
1276 1281
1277 // All requests are waiting for the active entry. 1282 // All requests are waiting for the active entry.
1278 for (int i = 0; i < kNumTransactions; ++i) { 1283 for (int i = 0; i < kNumTransactions; ++i) {
1279 Context* c = context_list[i]; 1284 Context* c = context_list[i];
1280 EXPECT_EQ(LOAD_STATE_WAITING_FOR_CACHE, c->trans->GetLoadState()); 1285 EXPECT_EQ(LOAD_STATE_WAITING_FOR_CACHE, c->trans->GetLoadState());
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1328 reader_request.load_flags = LOAD_ONLY_FROM_CACHE; 1333 reader_request.load_flags = LOAD_ONLY_FROM_CACHE;
1329 1334
1330 std::vector<Context*> context_list; 1335 std::vector<Context*> context_list;
1331 const int kNumTransactions = 5; 1336 const int kNumTransactions = 5;
1332 1337
1333 for (int i = 0; i < kNumTransactions; ++i) { 1338 for (int i = 0; i < kNumTransactions; ++i) {
1334 context_list.push_back(new Context()); 1339 context_list.push_back(new Context());
1335 Context* c = context_list[i]; 1340 Context* c = context_list[i];
1336 1341
1337 c->result = cache.CreateTransaction(&c->trans); 1342 c->result = cache.CreateTransaction(&c->trans);
1338 ASSERT_EQ(OK, c->result); 1343 ASSERT_THAT(c->result, IsOk());
1339 1344
1340 MockHttpRequest* this_request = &request; 1345 MockHttpRequest* this_request = &request;
1341 if (i == 1 || i == 2) 1346 if (i == 1 || i == 2)
1342 this_request = &reader_request; 1347 this_request = &reader_request;
1343 1348
1344 c->result = 1349 c->result =
1345 c->trans->Start(this_request, c->callback.callback(), BoundNetLog()); 1350 c->trans->Start(this_request, c->callback.callback(), BoundNetLog());
1346 } 1351 }
1347 1352
1348 // Allow all requests to move from the Create queue to the active entry. 1353 // Allow all requests to move from the Create queue to the active entry.
1349 base::RunLoop().RunUntilIdle(); 1354 base::RunLoop().RunUntilIdle();
1350 1355
1351 // The first request should be a writer at this point, and the subsequent 1356 // The first request should be a writer at this point, and the subsequent
1352 // requests should be pending. 1357 // requests should be pending.
1353 1358
1354 EXPECT_EQ(1, cache.network_layer()->transaction_count()); 1359 EXPECT_EQ(1, cache.network_layer()->transaction_count());
1355 EXPECT_EQ(0, cache.disk_cache()->open_count()); 1360 EXPECT_EQ(0, cache.disk_cache()->open_count());
1356 EXPECT_EQ(1, cache.disk_cache()->create_count()); 1361 EXPECT_EQ(1, cache.disk_cache()->create_count());
1357 1362
1358 Context* c = context_list[0]; 1363 Context* c = context_list[0];
1359 ASSERT_EQ(ERR_IO_PENDING, c->result); 1364 ASSERT_THAT(c->result, IsError(ERR_IO_PENDING));
1360 c->result = c->callback.WaitForResult(); 1365 c->result = c->callback.WaitForResult();
1361 ReadAndVerifyTransaction(c->trans.get(), kSimpleGET_Transaction); 1366 ReadAndVerifyTransaction(c->trans.get(), kSimpleGET_Transaction);
1362 1367
1363 // Now we have 2 active readers and two queued transactions. 1368 // Now we have 2 active readers and two queued transactions.
1364 1369
1365 EXPECT_EQ(LOAD_STATE_IDLE, context_list[2]->trans->GetLoadState()); 1370 EXPECT_EQ(LOAD_STATE_IDLE, context_list[2]->trans->GetLoadState());
1366 EXPECT_EQ(LOAD_STATE_WAITING_FOR_CACHE, 1371 EXPECT_EQ(LOAD_STATE_WAITING_FOR_CACHE,
1367 context_list[3]->trans->GetLoadState()); 1372 context_list[3]->trans->GetLoadState());
1368 1373
1369 c = context_list[1]; 1374 c = context_list[1];
1370 ASSERT_EQ(ERR_IO_PENDING, c->result); 1375 ASSERT_THAT(c->result, IsError(ERR_IO_PENDING));
1371 c->result = c->callback.WaitForResult(); 1376 c->result = c->callback.WaitForResult();
1372 if (c->result == OK) 1377 if (c->result == OK)
1373 ReadAndVerifyTransaction(c->trans.get(), kSimpleGET_Transaction); 1378 ReadAndVerifyTransaction(c->trans.get(), kSimpleGET_Transaction);
1374 1379
1375 // At this point we have one reader, two pending transactions and a task on 1380 // At this point we have one reader, two pending transactions and a task on
1376 // the queue to move to the next transaction. Now we cancel the request that 1381 // the queue to move to the next transaction. Now we cancel the request that
1377 // is the current reader, and expect the queued task to be able to start the 1382 // is the current reader, and expect the queued task to be able to start the
1378 // next request. 1383 // next request.
1379 1384
1380 c = context_list[2]; 1385 c = context_list[2];
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1412 writer_request.load_flags = LOAD_BYPASS_CACHE; 1417 writer_request.load_flags = LOAD_BYPASS_CACHE;
1413 1418
1414 std::vector<std::unique_ptr<Context>> context_list; 1419 std::vector<std::unique_ptr<Context>> context_list;
1415 const int kNumTransactions = 4; 1420 const int kNumTransactions = 4;
1416 1421
1417 for (int i = 0; i < kNumTransactions; ++i) { 1422 for (int i = 0; i < kNumTransactions; ++i) {
1418 context_list.push_back(base::WrapUnique(new Context())); 1423 context_list.push_back(base::WrapUnique(new Context()));
1419 Context* c = context_list[i].get(); 1424 Context* c = context_list[i].get();
1420 1425
1421 c->result = cache.CreateTransaction(&c->trans); 1426 c->result = cache.CreateTransaction(&c->trans);
1422 ASSERT_EQ(OK, c->result); 1427 ASSERT_THAT(c->result, IsOk());
1423 1428
1424 MockHttpRequest* this_request = &request; 1429 MockHttpRequest* this_request = &request;
1425 if (i == 3) 1430 if (i == 3)
1426 this_request = &writer_request; 1431 this_request = &writer_request;
1427 1432
1428 c->result = 1433 c->result =
1429 c->trans->Start(this_request, c->callback.callback(), BoundNetLog()); 1434 c->trans->Start(this_request, c->callback.callback(), BoundNetLog());
1430 } 1435 }
1431 1436
1432 // The first request should be a writer at this point, and the two subsequent 1437 // The first request should be a writer at this point, and the two subsequent
1433 // requests should be pending. The last request doomed the first entry. 1438 // requests should be pending. The last request doomed the first entry.
1434 1439
1435 EXPECT_EQ(2, cache.network_layer()->transaction_count()); 1440 EXPECT_EQ(2, cache.network_layer()->transaction_count());
1436 1441
1437 // Cancel the first queued transaction. 1442 // Cancel the first queued transaction.
1438 context_list[1].reset(); 1443 context_list[1].reset();
1439 1444
1440 for (int i = 0; i < kNumTransactions; ++i) { 1445 for (int i = 0; i < kNumTransactions; ++i) {
1441 if (i == 1) 1446 if (i == 1)
1442 continue; 1447 continue;
1443 Context* c = context_list[i].get(); 1448 Context* c = context_list[i].get();
1444 ASSERT_EQ(ERR_IO_PENDING, c->result); 1449 ASSERT_THAT(c->result, IsError(ERR_IO_PENDING));
1445 c->result = c->callback.WaitForResult(); 1450 c->result = c->callback.WaitForResult();
1446 ReadAndVerifyTransaction(c->trans.get(), kSimpleGET_Transaction); 1451 ReadAndVerifyTransaction(c->trans.get(), kSimpleGET_Transaction);
1447 } 1452 }
1448 } 1453 }
1449 1454
1450 // This is a test for http://code.google.com/p/chromium/issues/detail?id=4731. 1455 // This is a test for http://code.google.com/p/chromium/issues/detail?id=4731.
1451 // We may attempt to delete an entry synchronously with the act of adding a new 1456 // We may attempt to delete an entry synchronously with the act of adding a new
1452 // transaction to said entry. 1457 // transaction to said entry.
1453 TEST(HttpCache, FastNoStoreGET_DoneWithPending) { 1458 TEST(HttpCache, FastNoStoreGET_DoneWithPending) {
1454 MockHttpCache cache; 1459 MockHttpCache cache;
1455 1460
1456 // The headers will be served right from the call to Start() the request. 1461 // The headers will be served right from the call to Start() the request.
1457 MockHttpRequest request(kFastNoStoreGET_Transaction); 1462 MockHttpRequest request(kFastNoStoreGET_Transaction);
1458 FastTransactionServer request_handler; 1463 FastTransactionServer request_handler;
1459 AddMockTransaction(&kFastNoStoreGET_Transaction); 1464 AddMockTransaction(&kFastNoStoreGET_Transaction);
1460 1465
1461 std::vector<Context*> context_list; 1466 std::vector<Context*> context_list;
1462 const int kNumTransactions = 3; 1467 const int kNumTransactions = 3;
1463 1468
1464 for (int i = 0; i < kNumTransactions; ++i) { 1469 for (int i = 0; i < kNumTransactions; ++i) {
1465 context_list.push_back(new Context()); 1470 context_list.push_back(new Context());
1466 Context* c = context_list[i]; 1471 Context* c = context_list[i];
1467 1472
1468 c->result = cache.CreateTransaction(&c->trans); 1473 c->result = cache.CreateTransaction(&c->trans);
1469 ASSERT_EQ(OK, c->result); 1474 ASSERT_THAT(c->result, IsOk());
1470 1475
1471 c->result = 1476 c->result =
1472 c->trans->Start(&request, c->callback.callback(), BoundNetLog()); 1477 c->trans->Start(&request, c->callback.callback(), BoundNetLog());
1473 } 1478 }
1474 1479
1475 // Allow all requests to move from the Create queue to the active entry. 1480 // Allow all requests to move from the Create queue to the active entry.
1476 base::RunLoop().RunUntilIdle(); 1481 base::RunLoop().RunUntilIdle();
1477 1482
1478 // The first request should be a writer at this point, and the subsequent 1483 // The first request should be a writer at this point, and the subsequent
1479 // requests should be pending. 1484 // requests should be pending.
(...skipping 26 matching lines...) Expand all
1506 MockHttpRequest request(kSimpleGET_Transaction); 1511 MockHttpRequest request(kSimpleGET_Transaction);
1507 1512
1508 std::vector<Context*> context_list; 1513 std::vector<Context*> context_list;
1509 const int kNumTransactions = 2; 1514 const int kNumTransactions = 2;
1510 1515
1511 for (int i = 0; i < kNumTransactions; ++i) { 1516 for (int i = 0; i < kNumTransactions; ++i) {
1512 context_list.push_back(new Context()); 1517 context_list.push_back(new Context());
1513 Context* c = context_list[i]; 1518 Context* c = context_list[i];
1514 1519
1515 c->result = cache.CreateTransaction(&c->trans); 1520 c->result = cache.CreateTransaction(&c->trans);
1516 ASSERT_EQ(OK, c->result); 1521 ASSERT_THAT(c->result, IsOk());
1517 1522
1518 c->result = 1523 c->result =
1519 c->trans->Start(&request, c->callback.callback(), BoundNetLog()); 1524 c->trans->Start(&request, c->callback.callback(), BoundNetLog());
1520 } 1525 }
1521 1526
1522 // Allow all requests to move from the Create queue to the active entry. 1527 // Allow all requests to move from the Create queue to the active entry.
1523 base::RunLoop().RunUntilIdle(); 1528 base::RunLoop().RunUntilIdle();
1524 1529
1525 // The first request should be a writer at this point, and the subsequent 1530 // The first request should be a writer at this point, and the subsequent
1526 // requests should be pending. 1531 // requests should be pending.
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1566 MockHttpRequest request(kSimpleGET_Transaction); 1571 MockHttpRequest request(kSimpleGET_Transaction);
1567 1572
1568 std::vector<Context*> context_list; 1573 std::vector<Context*> context_list;
1569 const int kNumTransactions = 5; 1574 const int kNumTransactions = 5;
1570 1575
1571 for (int i = 0; i < kNumTransactions; i++) { 1576 for (int i = 0; i < kNumTransactions; i++) {
1572 context_list.push_back(new Context()); 1577 context_list.push_back(new Context());
1573 Context* c = context_list[i]; 1578 Context* c = context_list[i];
1574 1579
1575 c->result = cache.CreateTransaction(&c->trans); 1580 c->result = cache.CreateTransaction(&c->trans);
1576 ASSERT_EQ(OK, c->result); 1581 ASSERT_THAT(c->result, IsOk());
1577 1582
1578 c->result = 1583 c->result =
1579 c->trans->Start(&request, c->callback.callback(), BoundNetLog()); 1584 c->trans->Start(&request, c->callback.callback(), BoundNetLog());
1580 } 1585 }
1581 1586
1582 // The first request should be creating the disk cache entry and the others 1587 // The first request should be creating the disk cache entry and the others
1583 // should be pending. 1588 // should be pending.
1584 1589
1585 EXPECT_EQ(0, cache.network_layer()->transaction_count()); 1590 EXPECT_EQ(0, cache.network_layer()->transaction_count());
1586 EXPECT_EQ(0, cache.disk_cache()->open_count()); 1591 EXPECT_EQ(0, cache.disk_cache()->open_count());
(...skipping 30 matching lines...) Expand all
1617 1622
1618 // Tests that we can cancel a single request to open a disk cache entry. 1623 // Tests that we can cancel a single request to open a disk cache entry.
1619 TEST(HttpCache, SimpleGET_CancelCreate) { 1624 TEST(HttpCache, SimpleGET_CancelCreate) {
1620 MockHttpCache cache; 1625 MockHttpCache cache;
1621 1626
1622 MockHttpRequest request(kSimpleGET_Transaction); 1627 MockHttpRequest request(kSimpleGET_Transaction);
1623 1628
1624 Context* c = new Context(); 1629 Context* c = new Context();
1625 1630
1626 c->result = cache.CreateTransaction(&c->trans); 1631 c->result = cache.CreateTransaction(&c->trans);
1627 ASSERT_EQ(OK, c->result); 1632 ASSERT_THAT(c->result, IsOk());
1628 1633
1629 c->result = c->trans->Start(&request, c->callback.callback(), BoundNetLog()); 1634 c->result = c->trans->Start(&request, c->callback.callback(), BoundNetLog());
1630 EXPECT_EQ(ERR_IO_PENDING, c->result); 1635 EXPECT_THAT(c->result, IsError(ERR_IO_PENDING));
1631 1636
1632 // Release the reference that the mock disk cache keeps for this entry, so 1637 // Release the reference that the mock disk cache keeps for this entry, so
1633 // that we test that the http cache handles the cancellation correctly. 1638 // that we test that the http cache handles the cancellation correctly.
1634 cache.disk_cache()->ReleaseAll(); 1639 cache.disk_cache()->ReleaseAll();
1635 delete c; 1640 delete c;
1636 1641
1637 base::RunLoop().RunUntilIdle(); 1642 base::RunLoop().RunUntilIdle();
1638 EXPECT_EQ(1, cache.disk_cache()->create_count()); 1643 EXPECT_EQ(1, cache.disk_cache()->create_count());
1639 } 1644 }
1640 1645
1641 // Tests that we delete/create entries even if multiple requests are queued. 1646 // Tests that we delete/create entries even if multiple requests are queued.
1642 TEST(HttpCache, SimpleGET_ManyWriters_BypassCache) { 1647 TEST(HttpCache, SimpleGET_ManyWriters_BypassCache) {
1643 MockHttpCache cache; 1648 MockHttpCache cache;
1644 1649
1645 MockHttpRequest request(kSimpleGET_Transaction); 1650 MockHttpRequest request(kSimpleGET_Transaction);
1646 request.load_flags = LOAD_BYPASS_CACHE; 1651 request.load_flags = LOAD_BYPASS_CACHE;
1647 1652
1648 std::vector<Context*> context_list; 1653 std::vector<Context*> context_list;
1649 const int kNumTransactions = 5; 1654 const int kNumTransactions = 5;
1650 1655
1651 for (int i = 0; i < kNumTransactions; i++) { 1656 for (int i = 0; i < kNumTransactions; i++) {
1652 context_list.push_back(new Context()); 1657 context_list.push_back(new Context());
1653 Context* c = context_list[i]; 1658 Context* c = context_list[i];
1654 1659
1655 c->result = cache.CreateTransaction(&c->trans); 1660 c->result = cache.CreateTransaction(&c->trans);
1656 ASSERT_EQ(OK, c->result); 1661 ASSERT_THAT(c->result, IsOk());
1657 1662
1658 c->result = 1663 c->result =
1659 c->trans->Start(&request, c->callback.callback(), BoundNetLog()); 1664 c->trans->Start(&request, c->callback.callback(), BoundNetLog());
1660 } 1665 }
1661 1666
1662 // The first request should be deleting the disk cache entry and the others 1667 // The first request should be deleting the disk cache entry and the others
1663 // should be pending. 1668 // should be pending.
1664 1669
1665 EXPECT_EQ(0, cache.network_layer()->transaction_count()); 1670 EXPECT_EQ(0, cache.network_layer()->transaction_count());
1666 EXPECT_EQ(0, cache.disk_cache()->open_count()); 1671 EXPECT_EQ(0, cache.disk_cache()->open_count());
(...skipping 18 matching lines...) Expand all
1685 } 1690 }
1686 1691
1687 // Tests that a (simulated) timeout allows transactions waiting on the cache 1692 // Tests that a (simulated) timeout allows transactions waiting on the cache
1688 // lock to continue. 1693 // lock to continue.
1689 TEST(HttpCache, SimpleGET_WriterTimeout) { 1694 TEST(HttpCache, SimpleGET_WriterTimeout) {
1690 MockHttpCache cache; 1695 MockHttpCache cache;
1691 cache.BypassCacheLock(); 1696 cache.BypassCacheLock();
1692 1697
1693 MockHttpRequest request(kSimpleGET_Transaction); 1698 MockHttpRequest request(kSimpleGET_Transaction);
1694 Context c1, c2; 1699 Context c1, c2;
1695 ASSERT_EQ(OK, cache.CreateTransaction(&c1.trans)); 1700 ASSERT_THAT(cache.CreateTransaction(&c1.trans), IsOk());
1696 ASSERT_EQ(ERR_IO_PENDING, 1701 ASSERT_EQ(ERR_IO_PENDING,
1697 c1.trans->Start(&request, c1.callback.callback(), BoundNetLog())); 1702 c1.trans->Start(&request, c1.callback.callback(), BoundNetLog()));
1698 ASSERT_EQ(OK, cache.CreateTransaction(&c2.trans)); 1703 ASSERT_THAT(cache.CreateTransaction(&c2.trans), IsOk());
1699 ASSERT_EQ(ERR_IO_PENDING, 1704 ASSERT_EQ(ERR_IO_PENDING,
1700 c2.trans->Start(&request, c2.callback.callback(), BoundNetLog())); 1705 c2.trans->Start(&request, c2.callback.callback(), BoundNetLog()));
1701 1706
1702 // The second request is queued after the first one. 1707 // The second request is queued after the first one.
1703 1708
1704 c2.callback.WaitForResult(); 1709 c2.callback.WaitForResult();
1705 ReadAndVerifyTransaction(c2.trans.get(), kSimpleGET_Transaction); 1710 ReadAndVerifyTransaction(c2.trans.get(), kSimpleGET_Transaction);
1706 1711
1707 // Complete the first transaction. 1712 // Complete the first transaction.
1708 c1.callback.WaitForResult(); 1713 c1.callback.WaitForResult();
1709 ReadAndVerifyTransaction(c1.trans.get(), kSimpleGET_Transaction); 1714 ReadAndVerifyTransaction(c1.trans.get(), kSimpleGET_Transaction);
1710 } 1715 }
1711 1716
1712 TEST(HttpCache, SimpleGET_AbandonedCacheRead) { 1717 TEST(HttpCache, SimpleGET_AbandonedCacheRead) {
1713 MockHttpCache cache; 1718 MockHttpCache cache;
1714 1719
1715 // write to the cache 1720 // write to the cache
1716 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); 1721 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction);
1717 1722
1718 MockHttpRequest request(kSimpleGET_Transaction); 1723 MockHttpRequest request(kSimpleGET_Transaction);
1719 TestCompletionCallback callback; 1724 TestCompletionCallback callback;
1720 1725
1721 std::unique_ptr<HttpTransaction> trans; 1726 std::unique_ptr<HttpTransaction> trans;
1722 ASSERT_EQ(OK, cache.CreateTransaction(&trans)); 1727 ASSERT_THAT(cache.CreateTransaction(&trans), IsOk());
1723 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); 1728 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
1724 if (rv == ERR_IO_PENDING) 1729 if (rv == ERR_IO_PENDING)
1725 rv = callback.WaitForResult(); 1730 rv = callback.WaitForResult();
1726 ASSERT_EQ(OK, rv); 1731 ASSERT_THAT(rv, IsOk());
1727 1732
1728 scoped_refptr<IOBuffer> buf(new IOBuffer(256)); 1733 scoped_refptr<IOBuffer> buf(new IOBuffer(256));
1729 rv = trans->Read(buf.get(), 256, callback.callback()); 1734 rv = trans->Read(buf.get(), 256, callback.callback());
1730 EXPECT_EQ(ERR_IO_PENDING, rv); 1735 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
1731 1736
1732 // Test that destroying the transaction while it is reading from the cache 1737 // Test that destroying the transaction while it is reading from the cache
1733 // works properly. 1738 // works properly.
1734 trans.reset(); 1739 trans.reset();
1735 1740
1736 // Make sure we pump any pending events, which should include a call to 1741 // Make sure we pump any pending events, which should include a call to
1737 // HttpCache::Transaction::OnCacheReadCompleted. 1742 // HttpCache::Transaction::OnCacheReadCompleted.
1738 base::RunLoop().RunUntilIdle(); 1743 base::RunLoop().RunUntilIdle();
1739 } 1744 }
1740 1745
1741 // Tests that we can delete the HttpCache and deal with queued transactions 1746 // Tests that we can delete the HttpCache and deal with queued transactions
1742 // ("waiting for the backend" as opposed to Active or Doomed entries). 1747 // ("waiting for the backend" as opposed to Active or Doomed entries).
1743 TEST(HttpCache, SimpleGET_ManyWriters_DeleteCache) { 1748 TEST(HttpCache, SimpleGET_ManyWriters_DeleteCache) {
1744 std::unique_ptr<MockHttpCache> cache( 1749 std::unique_ptr<MockHttpCache> cache(
1745 new MockHttpCache(base::WrapUnique(new MockBackendNoCbFactory()))); 1750 new MockHttpCache(base::WrapUnique(new MockBackendNoCbFactory())));
1746 1751
1747 MockHttpRequest request(kSimpleGET_Transaction); 1752 MockHttpRequest request(kSimpleGET_Transaction);
1748 1753
1749 std::vector<Context*> context_list; 1754 std::vector<Context*> context_list;
1750 const int kNumTransactions = 5; 1755 const int kNumTransactions = 5;
1751 1756
1752 for (int i = 0; i < kNumTransactions; i++) { 1757 for (int i = 0; i < kNumTransactions; i++) {
1753 context_list.push_back(new Context()); 1758 context_list.push_back(new Context());
1754 Context* c = context_list[i]; 1759 Context* c = context_list[i];
1755 1760
1756 c->result = cache->CreateTransaction(&c->trans); 1761 c->result = cache->CreateTransaction(&c->trans);
1757 ASSERT_EQ(OK, c->result); 1762 ASSERT_THAT(c->result, IsOk());
1758 1763
1759 c->result = 1764 c->result =
1760 c->trans->Start(&request, c->callback.callback(), BoundNetLog()); 1765 c->trans->Start(&request, c->callback.callback(), BoundNetLog());
1761 } 1766 }
1762 1767
1763 // The first request should be creating the disk cache entry and the others 1768 // The first request should be creating the disk cache entry and the others
1764 // should be pending. 1769 // should be pending.
1765 1770
1766 EXPECT_EQ(0, cache->network_layer()->transaction_count()); 1771 EXPECT_EQ(0, cache->network_layer()->transaction_count());
1767 EXPECT_EQ(0, cache->disk_cache()->open_count()); 1772 EXPECT_EQ(0, cache->disk_cache()->open_count());
(...skipping 18 matching lines...) Expand all
1786 MockHttpRequest request2(kETagGET_Transaction); 1791 MockHttpRequest request2(kETagGET_Transaction);
1787 1792
1788 std::vector<Context*> context_list; 1793 std::vector<Context*> context_list;
1789 const int kNumTransactions = 3; 1794 const int kNumTransactions = 3;
1790 1795
1791 for (int i = 0; i < kNumTransactions; i++) { 1796 for (int i = 0; i < kNumTransactions; i++) {
1792 context_list.push_back(new Context()); 1797 context_list.push_back(new Context());
1793 Context* c = context_list[i]; 1798 Context* c = context_list[i];
1794 1799
1795 c->result = cache.CreateTransaction(&c->trans); 1800 c->result = cache.CreateTransaction(&c->trans);
1796 ASSERT_EQ(OK, c->result); 1801 ASSERT_THAT(c->result, IsOk());
1797 } 1802 }
1798 1803
1799 context_list[0]->result = context_list[0]->trans->Start( 1804 context_list[0]->result = context_list[0]->trans->Start(
1800 &request0, context_list[0]->callback.callback(), BoundNetLog()); 1805 &request0, context_list[0]->callback.callback(), BoundNetLog());
1801 context_list[1]->result = context_list[1]->trans->Start( 1806 context_list[1]->result = context_list[1]->trans->Start(
1802 &request1, context_list[1]->callback.callback(), BoundNetLog()); 1807 &request1, context_list[1]->callback.callback(), BoundNetLog());
1803 context_list[2]->result = context_list[2]->trans->Start( 1808 context_list[2]->result = context_list[2]->trans->Start(
1804 &request2, context_list[2]->callback.callback(), BoundNetLog()); 1809 &request2, context_list[2]->callback.callback(), BoundNetLog());
1805 1810
1806 // Just to make sure that everything is still pending. 1811 // Just to make sure that everything is still pending.
(...skipping 25 matching lines...) Expand all
1832 MockHttpRequest request2(kETagGET_Transaction); 1837 MockHttpRequest request2(kETagGET_Transaction);
1833 1838
1834 std::vector<Context*> context_list; 1839 std::vector<Context*> context_list;
1835 const int kNumTransactions = 3; 1840 const int kNumTransactions = 3;
1836 1841
1837 for (int i = 0; i < kNumTransactions; i++) { 1842 for (int i = 0; i < kNumTransactions; i++) {
1838 context_list.push_back(new Context()); 1843 context_list.push_back(new Context());
1839 Context* c = context_list[i]; 1844 Context* c = context_list[i];
1840 1845
1841 c->result = cache.CreateTransaction(&c->trans); 1846 c->result = cache.CreateTransaction(&c->trans);
1842 ASSERT_EQ(OK, c->result); 1847 ASSERT_THAT(c->result, IsOk());
1843 } 1848 }
1844 1849
1845 context_list[0]->result = context_list[0]->trans->Start( 1850 context_list[0]->result = context_list[0]->trans->Start(
1846 &request0, context_list[0]->callback.callback(), BoundNetLog()); 1851 &request0, context_list[0]->callback.callback(), BoundNetLog());
1847 context_list[1]->result = context_list[1]->trans->Start( 1852 context_list[1]->result = context_list[1]->trans->Start(
1848 &request1, context_list[1]->callback.callback(), BoundNetLog()); 1853 &request1, context_list[1]->callback.callback(), BoundNetLog());
1849 context_list[2]->result = context_list[2]->trans->Start( 1854 context_list[2]->result = context_list[2]->trans->Start(
1850 &request2, context_list[2]->callback.callback(), BoundNetLog()); 1855 &request2, context_list[2]->callback.callback(), BoundNetLog());
1851 1856
1852 // Just to make sure that everything is still pending. 1857 // Just to make sure that everything is still pending.
(...skipping 26 matching lines...) Expand all
1879 // Tests that we can delete the cache while creating the backend. 1884 // Tests that we can delete the cache while creating the backend.
1880 TEST(HttpCache, DeleteCacheWaitingForBackend) { 1885 TEST(HttpCache, DeleteCacheWaitingForBackend) {
1881 MockBlockingBackendFactory* factory = new MockBlockingBackendFactory(); 1886 MockBlockingBackendFactory* factory = new MockBlockingBackendFactory();
1882 std::unique_ptr<MockHttpCache> cache( 1887 std::unique_ptr<MockHttpCache> cache(
1883 new MockHttpCache(base::WrapUnique(factory))); 1888 new MockHttpCache(base::WrapUnique(factory)));
1884 1889
1885 MockHttpRequest request(kSimpleGET_Transaction); 1890 MockHttpRequest request(kSimpleGET_Transaction);
1886 1891
1887 std::unique_ptr<Context> c(new Context()); 1892 std::unique_ptr<Context> c(new Context());
1888 c->result = cache->CreateTransaction(&c->trans); 1893 c->result = cache->CreateTransaction(&c->trans);
1889 ASSERT_EQ(OK, c->result); 1894 ASSERT_THAT(c->result, IsOk());
1890 1895
1891 c->trans->Start(&request, c->callback.callback(), BoundNetLog()); 1896 c->trans->Start(&request, c->callback.callback(), BoundNetLog());
1892 1897
1893 // Just to make sure that everything is still pending. 1898 // Just to make sure that everything is still pending.
1894 base::RunLoop().RunUntilIdle(); 1899 base::RunLoop().RunUntilIdle();
1895 1900
1896 // The request should be creating the disk cache. 1901 // The request should be creating the disk cache.
1897 EXPECT_FALSE(c->callback.have_result()); 1902 EXPECT_FALSE(c->callback.have_result());
1898 1903
1899 // We cannot call FinishCreation because the factory itself will go away with 1904 // We cannot call FinishCreation because the factory itself will go away with
(...skipping 10 matching lines...) Expand all
1910 1915
1911 // Tests that we can delete the cache while creating the backend, from within 1916 // Tests that we can delete the cache while creating the backend, from within
1912 // one of the callbacks. 1917 // one of the callbacks.
1913 TEST(HttpCache, DeleteCacheWaitingForBackend2) { 1918 TEST(HttpCache, DeleteCacheWaitingForBackend2) {
1914 MockBlockingBackendFactory* factory = new MockBlockingBackendFactory(); 1919 MockBlockingBackendFactory* factory = new MockBlockingBackendFactory();
1915 MockHttpCache* cache = new MockHttpCache(base::WrapUnique(factory)); 1920 MockHttpCache* cache = new MockHttpCache(base::WrapUnique(factory));
1916 1921
1917 DeleteCacheCompletionCallback cb(cache); 1922 DeleteCacheCompletionCallback cb(cache);
1918 disk_cache::Backend* backend; 1923 disk_cache::Backend* backend;
1919 int rv = cache->http_cache()->GetBackend(&backend, cb.callback()); 1924 int rv = cache->http_cache()->GetBackend(&backend, cb.callback());
1920 EXPECT_EQ(ERR_IO_PENDING, rv); 1925 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
1921 1926
1922 // Now let's queue a regular transaction 1927 // Now let's queue a regular transaction
1923 MockHttpRequest request(kSimpleGET_Transaction); 1928 MockHttpRequest request(kSimpleGET_Transaction);
1924 1929
1925 std::unique_ptr<Context> c(new Context()); 1930 std::unique_ptr<Context> c(new Context());
1926 c->result = cache->CreateTransaction(&c->trans); 1931 c->result = cache->CreateTransaction(&c->trans);
1927 ASSERT_EQ(OK, c->result); 1932 ASSERT_THAT(c->result, IsOk());
1928 1933
1929 c->trans->Start(&request, c->callback.callback(), BoundNetLog()); 1934 c->trans->Start(&request, c->callback.callback(), BoundNetLog());
1930 1935
1931 // And another direct backend request. 1936 // And another direct backend request.
1932 TestCompletionCallback cb2; 1937 TestCompletionCallback cb2;
1933 rv = cache->http_cache()->GetBackend(&backend, cb2.callback()); 1938 rv = cache->http_cache()->GetBackend(&backend, cb2.callback());
1934 EXPECT_EQ(ERR_IO_PENDING, rv); 1939 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
1935 1940
1936 // Just to make sure that everything is still pending. 1941 // Just to make sure that everything is still pending.
1937 base::RunLoop().RunUntilIdle(); 1942 base::RunLoop().RunUntilIdle();
1938 1943
1939 // The request should be queued. 1944 // The request should be queued.
1940 EXPECT_FALSE(c->callback.have_result()); 1945 EXPECT_FALSE(c->callback.have_result());
1941 1946
1942 // Generate the callback. 1947 // Generate the callback.
1943 factory->FinishCreation(); 1948 factory->FinishCreation();
1944 rv = cb.WaitForResult(); 1949 rv = cb.WaitForResult();
1945 1950
1946 // The cache should be gone by now. 1951 // The cache should be gone by now.
1947 base::RunLoop().RunUntilIdle(); 1952 base::RunLoop().RunUntilIdle();
1948 EXPECT_EQ(OK, c->callback.GetResult(c->result)); 1953 EXPECT_THAT(c->callback.GetResult(c->result), IsOk());
1949 EXPECT_FALSE(cb2.have_result()); 1954 EXPECT_FALSE(cb2.have_result());
1950 } 1955 }
1951 1956
1952 // Fails only on bots. crbug.com/533640 1957 // Fails only on bots. crbug.com/533640
1953 #if defined(OS_ANDROID) 1958 #if defined(OS_ANDROID)
1954 #define MAYBE_TypicalGET_ConditionalRequest \ 1959 #define MAYBE_TypicalGET_ConditionalRequest \
1955 DISABLED_TypicalGET_ConditionalRequest 1960 DISABLED_TypicalGET_ConditionalRequest
1956 #else 1961 #else
1957 #define MAYBE_TypicalGET_ConditionalRequest TypicalGET_ConditionalRequest 1962 #define MAYBE_TypicalGET_ConditionalRequest TypicalGET_ConditionalRequest
1958 #endif 1963 #endif
(...skipping 935 matching lines...) Expand 10 before | Expand all | Expand 10 after
2894 TEST(HttpCache, SimplePOST_LoadOnlyFromCache_Miss) { 2899 TEST(HttpCache, SimplePOST_LoadOnlyFromCache_Miss) {
2895 MockHttpCache cache; 2900 MockHttpCache cache;
2896 2901
2897 MockTransaction transaction(kSimplePOST_Transaction); 2902 MockTransaction transaction(kSimplePOST_Transaction);
2898 transaction.load_flags |= LOAD_ONLY_FROM_CACHE; 2903 transaction.load_flags |= LOAD_ONLY_FROM_CACHE;
2899 2904
2900 MockHttpRequest request(transaction); 2905 MockHttpRequest request(transaction);
2901 TestCompletionCallback callback; 2906 TestCompletionCallback callback;
2902 2907
2903 std::unique_ptr<HttpTransaction> trans; 2908 std::unique_ptr<HttpTransaction> trans;
2904 ASSERT_EQ(OK, cache.CreateTransaction(&trans)); 2909 ASSERT_THAT(cache.CreateTransaction(&trans), IsOk());
2905 ASSERT_TRUE(trans.get()); 2910 ASSERT_TRUE(trans.get());
2906 2911
2907 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); 2912 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
2908 ASSERT_EQ(ERR_CACHE_MISS, callback.GetResult(rv)); 2913 ASSERT_THAT(callback.GetResult(rv), IsError(ERR_CACHE_MISS));
2909 2914
2910 trans.reset(); 2915 trans.reset();
2911 2916
2912 EXPECT_EQ(0, cache.network_layer()->transaction_count()); 2917 EXPECT_EQ(0, cache.network_layer()->transaction_count());
2913 EXPECT_EQ(0, cache.disk_cache()->open_count()); 2918 EXPECT_EQ(0, cache.disk_cache()->open_count());
2914 EXPECT_EQ(0, cache.disk_cache()->create_count()); 2919 EXPECT_EQ(0, cache.disk_cache()->create_count());
2915 } 2920 }
2916 2921
2917 TEST(HttpCache, SimplePOST_LoadOnlyFromCache_Hit) { 2922 TEST(HttpCache, SimplePOST_LoadOnlyFromCache_Hit) {
2918 MockHttpCache cache; 2923 MockHttpCache cache;
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
3149 MockHttpCache cache; 3154 MockHttpCache cache;
3150 MockTransaction transaction(kSimplePOST_Transaction); 3155 MockTransaction transaction(kSimplePOST_Transaction);
3151 AddMockTransaction(&transaction); 3156 AddMockTransaction(&transaction);
3152 transaction.load_flags |= LOAD_ONLY_FROM_CACHE; 3157 transaction.load_flags |= LOAD_ONLY_FROM_CACHE;
3153 transaction.method = "HEAD"; 3158 transaction.method = "HEAD";
3154 3159
3155 MockHttpRequest request(transaction); 3160 MockHttpRequest request(transaction);
3156 TestCompletionCallback callback; 3161 TestCompletionCallback callback;
3157 3162
3158 std::unique_ptr<HttpTransaction> trans; 3163 std::unique_ptr<HttpTransaction> trans;
3159 ASSERT_EQ(OK, cache.CreateTransaction(&trans)); 3164 ASSERT_THAT(cache.CreateTransaction(&trans), IsOk());
3160 ASSERT_TRUE(trans.get()); 3165 ASSERT_TRUE(trans.get());
3161 3166
3162 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); 3167 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
3163 ASSERT_EQ(ERR_CACHE_MISS, callback.GetResult(rv)); 3168 ASSERT_THAT(callback.GetResult(rv), IsError(ERR_CACHE_MISS));
3164 3169
3165 trans.reset(); 3170 trans.reset();
3166 3171
3167 EXPECT_EQ(0, cache.network_layer()->transaction_count()); 3172 EXPECT_EQ(0, cache.network_layer()->transaction_count());
3168 EXPECT_EQ(0, cache.disk_cache()->open_count()); 3173 EXPECT_EQ(0, cache.disk_cache()->open_count());
3169 EXPECT_EQ(0, cache.disk_cache()->create_count()); 3174 EXPECT_EQ(0, cache.disk_cache()->create_count());
3170 RemoveMockTransaction(&transaction); 3175 RemoveMockTransaction(&transaction);
3171 } 3176 }
3172 3177
3173 // Tests that a HEAD request is served from a cached GET. 3178 // Tests that a HEAD request is served from a cached GET.
(...skipping 1979 matching lines...) Expand 10 before | Expand all | Expand 10 after
5153 #endif 5158 #endif
5154 // Tests that we don't delete a sparse entry when we cancel a request. 5159 // Tests that we don't delete a sparse entry when we cancel a request.
5155 TEST(HttpCache, MAYBE_RangeGET_Cancel) { 5160 TEST(HttpCache, MAYBE_RangeGET_Cancel) {
5156 MockHttpCache cache; 5161 MockHttpCache cache;
5157 AddMockTransaction(&kRangeGET_TransactionOK); 5162 AddMockTransaction(&kRangeGET_TransactionOK);
5158 5163
5159 MockHttpRequest request(kRangeGET_TransactionOK); 5164 MockHttpRequest request(kRangeGET_TransactionOK);
5160 5165
5161 Context* c = new Context(); 5166 Context* c = new Context();
5162 int rv = cache.CreateTransaction(&c->trans); 5167 int rv = cache.CreateTransaction(&c->trans);
5163 ASSERT_EQ(OK, rv); 5168 ASSERT_THAT(rv, IsOk());
5164 5169
5165 rv = c->trans->Start(&request, c->callback.callback(), BoundNetLog()); 5170 rv = c->trans->Start(&request, c->callback.callback(), BoundNetLog());
5166 if (rv == ERR_IO_PENDING) 5171 if (rv == ERR_IO_PENDING)
5167 rv = c->callback.WaitForResult(); 5172 rv = c->callback.WaitForResult();
5168 5173
5169 EXPECT_EQ(1, cache.network_layer()->transaction_count()); 5174 EXPECT_EQ(1, cache.network_layer()->transaction_count());
5170 EXPECT_EQ(0, cache.disk_cache()->open_count()); 5175 EXPECT_EQ(0, cache.disk_cache()->open_count());
5171 EXPECT_EQ(1, cache.disk_cache()->create_count()); 5176 EXPECT_EQ(1, cache.disk_cache()->create_count());
5172 5177
5173 // Make sure that the entry has some data stored. 5178 // Make sure that the entry has some data stored.
(...skipping 24 matching lines...) Expand all
5198 TEST(HttpCache, MAYBE_RangeGET_Cancel2) { 5203 TEST(HttpCache, MAYBE_RangeGET_Cancel2) {
5199 MockHttpCache cache; 5204 MockHttpCache cache;
5200 AddMockTransaction(&kRangeGET_TransactionOK); 5205 AddMockTransaction(&kRangeGET_TransactionOK);
5201 5206
5202 RunTransactionTest(cache.http_cache(), kRangeGET_TransactionOK); 5207 RunTransactionTest(cache.http_cache(), kRangeGET_TransactionOK);
5203 MockHttpRequest request(kRangeGET_TransactionOK); 5208 MockHttpRequest request(kRangeGET_TransactionOK);
5204 request.load_flags |= LOAD_VALIDATE_CACHE; 5209 request.load_flags |= LOAD_VALIDATE_CACHE;
5205 5210
5206 Context* c = new Context(); 5211 Context* c = new Context();
5207 int rv = cache.CreateTransaction(&c->trans); 5212 int rv = cache.CreateTransaction(&c->trans);
5208 ASSERT_EQ(OK, rv); 5213 ASSERT_THAT(rv, IsOk());
5209 5214
5210 rv = c->trans->Start(&request, c->callback.callback(), BoundNetLog()); 5215 rv = c->trans->Start(&request, c->callback.callback(), BoundNetLog());
5211 if (rv == ERR_IO_PENDING) 5216 if (rv == ERR_IO_PENDING)
5212 rv = c->callback.WaitForResult(); 5217 rv = c->callback.WaitForResult();
5213 5218
5214 EXPECT_EQ(2, cache.network_layer()->transaction_count()); 5219 EXPECT_EQ(2, cache.network_layer()->transaction_count());
5215 EXPECT_EQ(1, cache.disk_cache()->open_count()); 5220 EXPECT_EQ(1, cache.disk_cache()->open_count());
5216 EXPECT_EQ(1, cache.disk_cache()->create_count()); 5221 EXPECT_EQ(1, cache.disk_cache()->create_count());
5217 5222
5218 // Make sure that we revalidate the entry and read from the cache (a single 5223 // Make sure that we revalidate the entry and read from the cache (a single
5219 // read will return while waiting for the network). 5224 // read will return while waiting for the network).
5220 scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(5)); 5225 scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(5));
5221 rv = c->trans->Read(buf.get(), buf->size(), c->callback.callback()); 5226 rv = c->trans->Read(buf.get(), buf->size(), c->callback.callback());
5222 EXPECT_EQ(5, c->callback.GetResult(rv)); 5227 EXPECT_EQ(5, c->callback.GetResult(rv));
5223 rv = c->trans->Read(buf.get(), buf->size(), c->callback.callback()); 5228 rv = c->trans->Read(buf.get(), buf->size(), c->callback.callback());
5224 EXPECT_EQ(ERR_IO_PENDING, rv); 5229 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
5225 5230
5226 // Destroy the transaction before completing the read. 5231 // Destroy the transaction before completing the read.
5227 delete c; 5232 delete c;
5228 5233
5229 // We have the read and the delete (OnProcessPendingQueue) waiting on the 5234 // We have the read and the delete (OnProcessPendingQueue) waiting on the
5230 // message loop. This means that a new transaction will just reuse the same 5235 // message loop. This means that a new transaction will just reuse the same
5231 // active entry (no open or create). 5236 // active entry (no open or create).
5232 5237
5233 RunTransactionTest(cache.http_cache(), kRangeGET_TransactionOK); 5238 RunTransactionTest(cache.http_cache(), kRangeGET_TransactionOK);
5234 5239
5235 EXPECT_EQ(2, cache.network_layer()->transaction_count()); 5240 EXPECT_EQ(2, cache.network_layer()->transaction_count());
5236 EXPECT_EQ(1, cache.disk_cache()->open_count()); 5241 EXPECT_EQ(1, cache.disk_cache()->open_count());
5237 EXPECT_EQ(1, cache.disk_cache()->create_count()); 5242 EXPECT_EQ(1, cache.disk_cache()->create_count());
5238 RemoveMockTransaction(&kRangeGET_TransactionOK); 5243 RemoveMockTransaction(&kRangeGET_TransactionOK);
5239 } 5244 }
5240 5245
5241 // A slight variation of the previous test, this time we cancel two requests in 5246 // A slight variation of the previous test, this time we cancel two requests in
5242 // a row, making sure that the second is waiting for the entry to be ready. 5247 // a row, making sure that the second is waiting for the entry to be ready.
5243 TEST(HttpCache, RangeGET_Cancel3) { 5248 TEST(HttpCache, RangeGET_Cancel3) {
5244 MockHttpCache cache; 5249 MockHttpCache cache;
5245 AddMockTransaction(&kRangeGET_TransactionOK); 5250 AddMockTransaction(&kRangeGET_TransactionOK);
5246 5251
5247 RunTransactionTest(cache.http_cache(), kRangeGET_TransactionOK); 5252 RunTransactionTest(cache.http_cache(), kRangeGET_TransactionOK);
5248 MockHttpRequest request(kRangeGET_TransactionOK); 5253 MockHttpRequest request(kRangeGET_TransactionOK);
5249 request.load_flags |= LOAD_VALIDATE_CACHE; 5254 request.load_flags |= LOAD_VALIDATE_CACHE;
5250 5255
5251 Context* c = new Context(); 5256 Context* c = new Context();
5252 int rv = cache.CreateTransaction(&c->trans); 5257 int rv = cache.CreateTransaction(&c->trans);
5253 ASSERT_EQ(OK, rv); 5258 ASSERT_THAT(rv, IsOk());
5254 5259
5255 rv = c->trans->Start(&request, c->callback.callback(), BoundNetLog()); 5260 rv = c->trans->Start(&request, c->callback.callback(), BoundNetLog());
5256 EXPECT_EQ(ERR_IO_PENDING, rv); 5261 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
5257 rv = c->callback.WaitForResult(); 5262 rv = c->callback.WaitForResult();
5258 5263
5259 EXPECT_EQ(2, cache.network_layer()->transaction_count()); 5264 EXPECT_EQ(2, cache.network_layer()->transaction_count());
5260 EXPECT_EQ(1, cache.disk_cache()->open_count()); 5265 EXPECT_EQ(1, cache.disk_cache()->open_count());
5261 EXPECT_EQ(1, cache.disk_cache()->create_count()); 5266 EXPECT_EQ(1, cache.disk_cache()->create_count());
5262 5267
5263 // Make sure that we revalidate the entry and read from the cache (a single 5268 // Make sure that we revalidate the entry and read from the cache (a single
5264 // read will return while waiting for the network). 5269 // read will return while waiting for the network).
5265 scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(5)); 5270 scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(5));
5266 rv = c->trans->Read(buf.get(), buf->size(), c->callback.callback()); 5271 rv = c->trans->Read(buf.get(), buf->size(), c->callback.callback());
5267 EXPECT_EQ(5, c->callback.GetResult(rv)); 5272 EXPECT_EQ(5, c->callback.GetResult(rv));
5268 rv = c->trans->Read(buf.get(), buf->size(), c->callback.callback()); 5273 rv = c->trans->Read(buf.get(), buf->size(), c->callback.callback());
5269 EXPECT_EQ(ERR_IO_PENDING, rv); 5274 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
5270 5275
5271 // Destroy the transaction before completing the read. 5276 // Destroy the transaction before completing the read.
5272 delete c; 5277 delete c;
5273 5278
5274 // We have the read and the delete (OnProcessPendingQueue) waiting on the 5279 // We have the read and the delete (OnProcessPendingQueue) waiting on the
5275 // message loop. This means that a new transaction will just reuse the same 5280 // message loop. This means that a new transaction will just reuse the same
5276 // active entry (no open or create). 5281 // active entry (no open or create).
5277 5282
5278 c = new Context(); 5283 c = new Context();
5279 rv = cache.CreateTransaction(&c->trans); 5284 rv = cache.CreateTransaction(&c->trans);
5280 ASSERT_EQ(OK, rv); 5285 ASSERT_THAT(rv, IsOk());
5281 5286
5282 rv = c->trans->Start(&request, c->callback.callback(), BoundNetLog()); 5287 rv = c->trans->Start(&request, c->callback.callback(), BoundNetLog());
5283 EXPECT_EQ(ERR_IO_PENDING, rv); 5288 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
5284 5289
5285 MockDiskEntry::IgnoreCallbacks(true); 5290 MockDiskEntry::IgnoreCallbacks(true);
5286 base::RunLoop().RunUntilIdle(); 5291 base::RunLoop().RunUntilIdle();
5287 MockDiskEntry::IgnoreCallbacks(false); 5292 MockDiskEntry::IgnoreCallbacks(false);
5288 5293
5289 // The new transaction is waiting for the query range callback. 5294 // The new transaction is waiting for the query range callback.
5290 delete c; 5295 delete c;
5291 5296
5292 // And we should not crash when the callback is delivered. 5297 // And we should not crash when the callback is delivered.
5293 base::RunLoop().RunUntilIdle(); 5298 base::RunLoop().RunUntilIdle();
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
5545 5550
5546 // Force this transaction to read from the cache. 5551 // Force this transaction to read from the cache.
5547 MockTransaction transaction(kRangeGET_TransactionOK); 5552 MockTransaction transaction(kRangeGET_TransactionOK);
5548 transaction.load_flags |= LOAD_ONLY_FROM_CACHE; 5553 transaction.load_flags |= LOAD_ONLY_FROM_CACHE;
5549 5554
5550 MockHttpRequest request(transaction); 5555 MockHttpRequest request(transaction);
5551 TestCompletionCallback callback; 5556 TestCompletionCallback callback;
5552 5557
5553 std::unique_ptr<HttpTransaction> trans; 5558 std::unique_ptr<HttpTransaction> trans;
5554 int rv = cache.http_cache()->CreateTransaction(DEFAULT_PRIORITY, &trans); 5559 int rv = cache.http_cache()->CreateTransaction(DEFAULT_PRIORITY, &trans);
5555 EXPECT_EQ(OK, rv); 5560 EXPECT_THAT(rv, IsOk());
5556 ASSERT_TRUE(trans.get()); 5561 ASSERT_TRUE(trans.get());
5557 5562
5558 rv = trans->Start(&request, callback.callback(), BoundNetLog()); 5563 rv = trans->Start(&request, callback.callback(), BoundNetLog());
5559 if (rv == ERR_IO_PENDING) 5564 if (rv == ERR_IO_PENDING)
5560 rv = callback.WaitForResult(); 5565 rv = callback.WaitForResult();
5561 ASSERT_EQ(ERR_CACHE_MISS, rv); 5566 ASSERT_THAT(rv, IsError(ERR_CACHE_MISS));
5562 5567
5563 trans.reset(); 5568 trans.reset();
5564 5569
5565 EXPECT_EQ(1, cache.network_layer()->transaction_count()); 5570 EXPECT_EQ(1, cache.network_layer()->transaction_count());
5566 EXPECT_EQ(1, cache.disk_cache()->open_count()); 5571 EXPECT_EQ(1, cache.disk_cache()->open_count());
5567 EXPECT_EQ(1, cache.disk_cache()->create_count()); 5572 EXPECT_EQ(1, cache.disk_cache()->create_count());
5568 5573
5569 RemoveMockTransaction(&kRangeGET_TransactionOK); 5574 RemoveMockTransaction(&kRangeGET_TransactionOK);
5570 } 5575 }
5571 #endif 5576 #endif
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
5623 5628
5624 // Tests that we delete an entry when the request is cancelled before starting 5629 // Tests that we delete an entry when the request is cancelled before starting
5625 // to read from the network. 5630 // to read from the network.
5626 TEST(HttpCache, DoomOnDestruction) { 5631 TEST(HttpCache, DoomOnDestruction) {
5627 MockHttpCache cache; 5632 MockHttpCache cache;
5628 5633
5629 MockHttpRequest request(kSimpleGET_Transaction); 5634 MockHttpRequest request(kSimpleGET_Transaction);
5630 5635
5631 Context* c = new Context(); 5636 Context* c = new Context();
5632 int rv = cache.CreateTransaction(&c->trans); 5637 int rv = cache.CreateTransaction(&c->trans);
5633 ASSERT_EQ(OK, rv); 5638 ASSERT_THAT(rv, IsOk());
5634 5639
5635 rv = c->trans->Start(&request, c->callback.callback(), BoundNetLog()); 5640 rv = c->trans->Start(&request, c->callback.callback(), BoundNetLog());
5636 if (rv == ERR_IO_PENDING) 5641 if (rv == ERR_IO_PENDING)
5637 c->result = c->callback.WaitForResult(); 5642 c->result = c->callback.WaitForResult();
5638 5643
5639 EXPECT_EQ(1, cache.network_layer()->transaction_count()); 5644 EXPECT_EQ(1, cache.network_layer()->transaction_count());
5640 EXPECT_EQ(0, cache.disk_cache()->open_count()); 5645 EXPECT_EQ(0, cache.disk_cache()->open_count());
5641 EXPECT_EQ(1, cache.disk_cache()->create_count()); 5646 EXPECT_EQ(1, cache.disk_cache()->create_count());
5642 5647
5643 // Destroy the transaction. We only have the headers so we should delete this 5648 // Destroy the transaction. We only have the headers so we should delete this
5644 // entry. 5649 // entry.
5645 delete c; 5650 delete c;
5646 5651
5647 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); 5652 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction);
5648 5653
5649 EXPECT_EQ(2, cache.network_layer()->transaction_count()); 5654 EXPECT_EQ(2, cache.network_layer()->transaction_count());
5650 EXPECT_EQ(0, cache.disk_cache()->open_count()); 5655 EXPECT_EQ(0, cache.disk_cache()->open_count());
5651 EXPECT_EQ(2, cache.disk_cache()->create_count()); 5656 EXPECT_EQ(2, cache.disk_cache()->create_count());
5652 } 5657 }
5653 5658
5654 // Tests that we delete an entry when the request is cancelled if the response 5659 // Tests that we delete an entry when the request is cancelled if the response
5655 // does not have content-length and strong validators. 5660 // does not have content-length and strong validators.
5656 TEST(HttpCache, DoomOnDestruction2) { 5661 TEST(HttpCache, DoomOnDestruction2) {
5657 MockHttpCache cache; 5662 MockHttpCache cache;
5658 5663
5659 MockHttpRequest request(kSimpleGET_Transaction); 5664 MockHttpRequest request(kSimpleGET_Transaction);
5660 5665
5661 Context* c = new Context(); 5666 Context* c = new Context();
5662 int rv = cache.CreateTransaction(&c->trans); 5667 int rv = cache.CreateTransaction(&c->trans);
5663 ASSERT_EQ(OK, rv); 5668 ASSERT_THAT(rv, IsOk());
5664 5669
5665 rv = c->trans->Start(&request, c->callback.callback(), BoundNetLog()); 5670 rv = c->trans->Start(&request, c->callback.callback(), BoundNetLog());
5666 if (rv == ERR_IO_PENDING) 5671 if (rv == ERR_IO_PENDING)
5667 rv = c->callback.WaitForResult(); 5672 rv = c->callback.WaitForResult();
5668 5673
5669 EXPECT_EQ(1, cache.network_layer()->transaction_count()); 5674 EXPECT_EQ(1, cache.network_layer()->transaction_count());
5670 EXPECT_EQ(0, cache.disk_cache()->open_count()); 5675 EXPECT_EQ(0, cache.disk_cache()->open_count());
5671 EXPECT_EQ(1, cache.disk_cache()->create_count()); 5676 EXPECT_EQ(1, cache.disk_cache()->create_count());
5672 5677
5673 // Make sure that the entry has some data stored. 5678 // Make sure that the entry has some data stored.
(...skipping 22 matching lines...) Expand all
5696 transaction.response_headers = 5701 transaction.response_headers =
5697 "Last-Modified: Wed, 28 Nov 2007 00:40:09 GMT\n" 5702 "Last-Modified: Wed, 28 Nov 2007 00:40:09 GMT\n"
5698 "Content-Length: 22\n" 5703 "Content-Length: 22\n"
5699 "Accept-Ranges: none\n" 5704 "Accept-Ranges: none\n"
5700 "Etag: \"foopy\"\n"; 5705 "Etag: \"foopy\"\n";
5701 AddMockTransaction(&transaction); 5706 AddMockTransaction(&transaction);
5702 MockHttpRequest request(transaction); 5707 MockHttpRequest request(transaction);
5703 5708
5704 Context* c = new Context(); 5709 Context* c = new Context();
5705 int rv = cache.CreateTransaction(&c->trans); 5710 int rv = cache.CreateTransaction(&c->trans);
5706 ASSERT_EQ(OK, rv); 5711 ASSERT_THAT(rv, IsOk());
5707 5712
5708 rv = c->trans->Start(&request, c->callback.callback(), BoundNetLog()); 5713 rv = c->trans->Start(&request, c->callback.callback(), BoundNetLog());
5709 if (rv == ERR_IO_PENDING) 5714 if (rv == ERR_IO_PENDING)
5710 rv = c->callback.WaitForResult(); 5715 rv = c->callback.WaitForResult();
5711 5716
5712 EXPECT_EQ(1, cache.network_layer()->transaction_count()); 5717 EXPECT_EQ(1, cache.network_layer()->transaction_count());
5713 EXPECT_EQ(0, cache.disk_cache()->open_count()); 5718 EXPECT_EQ(0, cache.disk_cache()->open_count());
5714 EXPECT_EQ(1, cache.disk_cache()->create_count()); 5719 EXPECT_EQ(1, cache.disk_cache()->create_count());
5715 5720
5716 // Make sure that the entry has some data stored. 5721 // Make sure that the entry has some data stored.
(...skipping 22 matching lines...) Expand all
5739 ScopedMockTransaction transaction(kSimpleGET_Transaction); 5744 ScopedMockTransaction transaction(kSimpleGET_Transaction);
5740 transaction.response_headers = 5745 transaction.response_headers =
5741 "Last-Modified: Wed, 28 Nov 2007 00:40:09 GMT\n" 5746 "Last-Modified: Wed, 28 Nov 2007 00:40:09 GMT\n"
5742 "Content-Length: 22\n" 5747 "Content-Length: 22\n"
5743 "Etag: \"foopy\"\n"; 5748 "Etag: \"foopy\"\n";
5744 MockHttpRequest request(transaction); 5749 MockHttpRequest request(transaction);
5745 5750
5746 std::unique_ptr<Context> c(new Context()); 5751 std::unique_ptr<Context> c(new Context());
5747 5752
5748 int rv = cache.CreateTransaction(&c->trans); 5753 int rv = cache.CreateTransaction(&c->trans);
5749 ASSERT_EQ(OK, rv); 5754 ASSERT_THAT(rv, IsOk());
5750 5755
5751 rv = c->trans->Start(&request, c->callback.callback(), BoundNetLog()); 5756 rv = c->trans->Start(&request, c->callback.callback(), BoundNetLog());
5752 if (rv == ERR_IO_PENDING) 5757 if (rv == ERR_IO_PENDING)
5753 rv = c->callback.WaitForResult(); 5758 rv = c->callback.WaitForResult();
5754 5759
5755 EXPECT_EQ(1, cache.network_layer()->transaction_count()); 5760 EXPECT_EQ(1, cache.network_layer()->transaction_count());
5756 EXPECT_EQ(0, cache.disk_cache()->open_count()); 5761 EXPECT_EQ(0, cache.disk_cache()->open_count());
5757 EXPECT_EQ(1, cache.disk_cache()->create_count()); 5762 EXPECT_EQ(1, cache.disk_cache()->create_count());
5758 5763
5759 // Make sure that the entry has some data stored. 5764 // Make sure that the entry has some data stored.
5760 scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(10)); 5765 scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(10));
5761 rv = c->trans->Read(buf.get(), buf->size(), c->callback.callback()); 5766 rv = c->trans->Read(buf.get(), buf->size(), c->callback.callback());
5762 if (rv == ERR_IO_PENDING) 5767 if (rv == ERR_IO_PENDING)
5763 rv = c->callback.WaitForResult(); 5768 rv = c->callback.WaitForResult();
5764 EXPECT_EQ(buf->size(), rv); 5769 EXPECT_EQ(buf->size(), rv);
5765 5770
5766 // We want to cancel the request when the transaction is busy. 5771 // We want to cancel the request when the transaction is busy.
5767 rv = c->trans->Read(buf.get(), buf->size(), c->callback.callback()); 5772 rv = c->trans->Read(buf.get(), buf->size(), c->callback.callback());
5768 EXPECT_EQ(ERR_IO_PENDING, rv); 5773 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
5769 EXPECT_FALSE(c->callback.have_result()); 5774 EXPECT_FALSE(c->callback.have_result());
5770 5775
5771 MockHttpCache::SetTestMode(TEST_MODE_SYNC_ALL); 5776 MockHttpCache::SetTestMode(TEST_MODE_SYNC_ALL);
5772 5777
5773 // Destroy the transaction. 5778 // Destroy the transaction.
5774 c->trans.reset(); 5779 c->trans.reset();
5775 MockHttpCache::SetTestMode(0); 5780 MockHttpCache::SetTestMode(0);
5776 5781
5777 5782
5778 // Make sure that we don't invoke the callback. We may have an issue if the 5783 // Make sure that we don't invoke the callback. We may have an issue if the
(...skipping 12 matching lines...) Expand all
5791 5796
5792 ScopedMockTransaction transaction(kSimpleGET_Transaction); 5797 ScopedMockTransaction transaction(kSimpleGET_Transaction);
5793 transaction.response_headers = 5798 transaction.response_headers =
5794 "Last-Modified: Wed, 28 Nov 2007 00:40:09 GMT\n" 5799 "Last-Modified: Wed, 28 Nov 2007 00:40:09 GMT\n"
5795 "Content-Length: 22\n" 5800 "Content-Length: 22\n"
5796 "Etag: \"foopy\"\n"; 5801 "Etag: \"foopy\"\n";
5797 MockHttpRequest request(transaction); 5802 MockHttpRequest request(transaction);
5798 5803
5799 std::unique_ptr<Context> c(new Context()); 5804 std::unique_ptr<Context> c(new Context());
5800 int rv = cache.CreateTransaction(&c->trans); 5805 int rv = cache.CreateTransaction(&c->trans);
5801 ASSERT_EQ(OK, rv); 5806 ASSERT_THAT(rv, IsOk());
5802 5807
5803 rv = c->trans->Start(&request, c->callback.callback(), BoundNetLog()); 5808 rv = c->trans->Start(&request, c->callback.callback(), BoundNetLog());
5804 EXPECT_EQ(OK, c->callback.GetResult(rv)); 5809 EXPECT_THAT(c->callback.GetResult(rv), IsOk());
5805 5810
5806 // Read everything. 5811 // Read everything.
5807 scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(22)); 5812 scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(22));
5808 rv = c->trans->Read(buf.get(), buf->size(), c->callback.callback()); 5813 rv = c->trans->Read(buf.get(), buf->size(), c->callback.callback());
5809 EXPECT_EQ(buf->size(), c->callback.GetResult(rv)); 5814 EXPECT_EQ(buf->size(), c->callback.GetResult(rv));
5810 5815
5811 // Destroy the transaction. 5816 // Destroy the transaction.
5812 c->trans.reset(); 5817 c->trans.reset();
5813 5818
5814 // Verify that the entry is not marked as truncated. 5819 // Verify that the entry is not marked as truncated.
5815 VerifyTruncatedFlag(&cache, kSimpleGET_Transaction.url, false, 0); 5820 VerifyTruncatedFlag(&cache, kSimpleGET_Transaction.url, false, 0);
5816 } 5821 }
5817 5822
5818 // Tests that sparse entries don't set the truncate flag. 5823 // Tests that sparse entries don't set the truncate flag.
5819 TEST(HttpCache, RangeGET_DontTruncate) { 5824 TEST(HttpCache, RangeGET_DontTruncate) {
5820 MockHttpCache cache; 5825 MockHttpCache cache;
5821 5826
5822 ScopedMockTransaction transaction(kRangeGET_TransactionOK); 5827 ScopedMockTransaction transaction(kRangeGET_TransactionOK);
5823 transaction.request_headers = "Range: bytes = 0-19\r\n" EXTRA_HEADER; 5828 transaction.request_headers = "Range: bytes = 0-19\r\n" EXTRA_HEADER;
5824 5829
5825 std::unique_ptr<MockHttpRequest> request(new MockHttpRequest(transaction)); 5830 std::unique_ptr<MockHttpRequest> request(new MockHttpRequest(transaction));
5826 std::unique_ptr<HttpTransaction> trans; 5831 std::unique_ptr<HttpTransaction> trans;
5827 5832
5828 int rv = cache.http_cache()->CreateTransaction(DEFAULT_PRIORITY, &trans); 5833 int rv = cache.http_cache()->CreateTransaction(DEFAULT_PRIORITY, &trans);
5829 EXPECT_EQ(OK, rv); 5834 EXPECT_THAT(rv, IsOk());
5830 5835
5831 TestCompletionCallback cb; 5836 TestCompletionCallback cb;
5832 rv = trans->Start(request.get(), cb.callback(), BoundNetLog()); 5837 rv = trans->Start(request.get(), cb.callback(), BoundNetLog());
5833 EXPECT_EQ(0, cb.GetResult(rv)); 5838 EXPECT_EQ(0, cb.GetResult(rv));
5834 5839
5835 scoped_refptr<IOBuffer> buf(new IOBuffer(10)); 5840 scoped_refptr<IOBuffer> buf(new IOBuffer(10));
5836 rv = trans->Read(buf.get(), 10, cb.callback()); 5841 rv = trans->Read(buf.get(), 10, cb.callback());
5837 EXPECT_EQ(10, cb.GetResult(rv)); 5842 EXPECT_EQ(10, cb.GetResult(rv));
5838 5843
5839 // Should not trigger any DCHECK. 5844 // Should not trigger any DCHECK.
5840 trans.reset(); 5845 trans.reset();
5841 VerifyTruncatedFlag(&cache, kRangeGET_TransactionOK.url, false, 0); 5846 VerifyTruncatedFlag(&cache, kRangeGET_TransactionOK.url, false, 0);
5842 } 5847 }
5843 5848
5844 // Tests that sparse entries don't set the truncate flag (when the byte range 5849 // Tests that sparse entries don't set the truncate flag (when the byte range
5845 // starts after 0). 5850 // starts after 0).
5846 TEST(HttpCache, RangeGET_DontTruncate2) { 5851 TEST(HttpCache, RangeGET_DontTruncate2) {
5847 MockHttpCache cache; 5852 MockHttpCache cache;
5848 5853
5849 ScopedMockTransaction transaction(kRangeGET_TransactionOK); 5854 ScopedMockTransaction transaction(kRangeGET_TransactionOK);
5850 transaction.request_headers = "Range: bytes = 30-49\r\n" EXTRA_HEADER; 5855 transaction.request_headers = "Range: bytes = 30-49\r\n" EXTRA_HEADER;
5851 5856
5852 std::unique_ptr<MockHttpRequest> request(new MockHttpRequest(transaction)); 5857 std::unique_ptr<MockHttpRequest> request(new MockHttpRequest(transaction));
5853 std::unique_ptr<HttpTransaction> trans; 5858 std::unique_ptr<HttpTransaction> trans;
5854 5859
5855 int rv = cache.http_cache()->CreateTransaction(DEFAULT_PRIORITY, &trans); 5860 int rv = cache.http_cache()->CreateTransaction(DEFAULT_PRIORITY, &trans);
5856 EXPECT_EQ(OK, rv); 5861 EXPECT_THAT(rv, IsOk());
5857 5862
5858 TestCompletionCallback cb; 5863 TestCompletionCallback cb;
5859 rv = trans->Start(request.get(), cb.callback(), BoundNetLog()); 5864 rv = trans->Start(request.get(), cb.callback(), BoundNetLog());
5860 EXPECT_EQ(0, cb.GetResult(rv)); 5865 EXPECT_EQ(0, cb.GetResult(rv));
5861 5866
5862 scoped_refptr<IOBuffer> buf(new IOBuffer(10)); 5867 scoped_refptr<IOBuffer> buf(new IOBuffer(10));
5863 rv = trans->Read(buf.get(), 10, cb.callback()); 5868 rv = trans->Read(buf.get(), 10, cb.callback());
5864 EXPECT_EQ(10, cb.GetResult(rv)); 5869 EXPECT_EQ(10, cb.GetResult(rv));
5865 5870
5866 // Should not trigger any DCHECK. 5871 // Should not trigger any DCHECK.
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
5967 std::string response_headers(transaction.response_headers); 5972 std::string response_headers(transaction.response_headers);
5968 response_headers += ("Cache-Control: no-store\n"); 5973 response_headers += ("Cache-Control: no-store\n");
5969 transaction.response_headers = response_headers.c_str(); 5974 transaction.response_headers = response_headers.c_str();
5970 transaction.data = kFullRangeData; 5975 transaction.data = kFullRangeData;
5971 AddMockTransaction(&transaction); 5976 AddMockTransaction(&transaction);
5972 5977
5973 MockHttpRequest request(transaction); 5978 MockHttpRequest request(transaction);
5974 Context* c = new Context(); 5979 Context* c = new Context();
5975 5980
5976 int rv = cache.CreateTransaction(&c->trans); 5981 int rv = cache.CreateTransaction(&c->trans);
5977 ASSERT_EQ(OK, rv); 5982 ASSERT_THAT(rv, IsOk());
5978 5983
5979 // Queue another request to this transaction. We have to start this request 5984 // Queue another request to this transaction. We have to start this request
5980 // before the first one gets the response from the server and dooms the entry, 5985 // before the first one gets the response from the server and dooms the entry,
5981 // otherwise it will just create a new entry without being queued to the first 5986 // otherwise it will just create a new entry without being queued to the first
5982 // request. 5987 // request.
5983 Context* pending = new Context(); 5988 Context* pending = new Context();
5984 ASSERT_EQ(OK, cache.CreateTransaction(&pending->trans)); 5989 ASSERT_THAT(cache.CreateTransaction(&pending->trans), IsOk());
5985 5990
5986 rv = c->trans->Start(&request, c->callback.callback(), BoundNetLog()); 5991 rv = c->trans->Start(&request, c->callback.callback(), BoundNetLog());
5987 EXPECT_EQ(ERR_IO_PENDING, 5992 EXPECT_EQ(ERR_IO_PENDING,
5988 pending->trans->Start(&request, pending->callback.callback(), 5993 pending->trans->Start(&request, pending->callback.callback(),
5989 BoundNetLog())); 5994 BoundNetLog()));
5990 EXPECT_EQ(OK, c->callback.GetResult(rv)); 5995 EXPECT_THAT(c->callback.GetResult(rv), IsOk());
5991 5996
5992 // Make sure that the entry has some data stored. 5997 // Make sure that the entry has some data stored.
5993 scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(5)); 5998 scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(5));
5994 rv = c->trans->Read(buf.get(), buf->size(), c->callback.callback()); 5999 rv = c->trans->Read(buf.get(), buf->size(), c->callback.callback());
5995 EXPECT_EQ(5, c->callback.GetResult(rv)); 6000 EXPECT_EQ(5, c->callback.GetResult(rv));
5996 6001
5997 // Cancel the requests. 6002 // Cancel the requests.
5998 delete c; 6003 delete c;
5999 delete pending; 6004 delete pending;
6000 6005
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
6058 CreateTruncatedEntry(raw_headers, &cache); 6063 CreateTruncatedEntry(raw_headers, &cache);
6059 6064
6060 // Now make a regular request. 6065 // Now make a regular request.
6061 std::string headers; 6066 std::string headers;
6062 MockTransaction transaction(kRangeGET_TransactionOK); 6067 MockTransaction transaction(kRangeGET_TransactionOK);
6063 transaction.request_headers = EXTRA_HEADER; 6068 transaction.request_headers = EXTRA_HEADER;
6064 transaction.data = kFullRangeData; 6069 transaction.data = kFullRangeData;
6065 6070
6066 std::unique_ptr<Context> c(new Context); 6071 std::unique_ptr<Context> c(new Context);
6067 int rv = cache.CreateTransaction(&c->trans); 6072 int rv = cache.CreateTransaction(&c->trans);
6068 ASSERT_EQ(OK, rv); 6073 ASSERT_THAT(rv, IsOk());
6069 6074
6070 MockHttpRequest request(transaction); 6075 MockHttpRequest request(transaction);
6071 rv = c->trans->Start(&request, c->callback.callback(), BoundNetLog()); 6076 rv = c->trans->Start(&request, c->callback.callback(), BoundNetLog());
6072 EXPECT_EQ(OK, c->callback.GetResult(rv)); 6077 EXPECT_THAT(c->callback.GetResult(rv), IsOk());
6073 6078
6074 // We should have checked with the server before finishing Start(). 6079 // We should have checked with the server before finishing Start().
6075 EXPECT_EQ(1, cache.network_layer()->transaction_count()); 6080 EXPECT_EQ(1, cache.network_layer()->transaction_count());
6076 EXPECT_EQ(1, cache.disk_cache()->open_count()); 6081 EXPECT_EQ(1, cache.disk_cache()->open_count());
6077 EXPECT_EQ(1, cache.disk_cache()->create_count()); 6082 EXPECT_EQ(1, cache.disk_cache()->create_count());
6078 6083
6079 RemoveMockTransaction(&kRangeGET_TransactionOK); 6084 RemoveMockTransaction(&kRangeGET_TransactionOK);
6080 } 6085 }
6081 6086
6082 // Tests that we handle 401s for truncated resources. 6087 // Tests that we handle 401s for truncated resources.
(...skipping 10 matching lines...) Expand all
6093 6098
6094 // Now make a regular request. 6099 // Now make a regular request.
6095 MockTransaction transaction(kRangeGET_TransactionOK); 6100 MockTransaction transaction(kRangeGET_TransactionOK);
6096 transaction.request_headers = "X-Require-Mock-Auth: dummy\r\n" 6101 transaction.request_headers = "X-Require-Mock-Auth: dummy\r\n"
6097 EXTRA_HEADER; 6102 EXTRA_HEADER;
6098 transaction.data = kFullRangeData; 6103 transaction.data = kFullRangeData;
6099 RangeTransactionServer handler; 6104 RangeTransactionServer handler;
6100 6105
6101 std::unique_ptr<Context> c(new Context); 6106 std::unique_ptr<Context> c(new Context);
6102 int rv = cache.CreateTransaction(&c->trans); 6107 int rv = cache.CreateTransaction(&c->trans);
6103 ASSERT_EQ(OK, rv); 6108 ASSERT_THAT(rv, IsOk());
6104 6109
6105 MockHttpRequest request(transaction); 6110 MockHttpRequest request(transaction);
6106 rv = c->trans->Start(&request, c->callback.callback(), BoundNetLog()); 6111 rv = c->trans->Start(&request, c->callback.callback(), BoundNetLog());
6107 EXPECT_EQ(OK, c->callback.GetResult(rv)); 6112 EXPECT_THAT(c->callback.GetResult(rv), IsOk());
6108 6113
6109 const HttpResponseInfo* response = c->trans->GetResponseInfo(); 6114 const HttpResponseInfo* response = c->trans->GetResponseInfo();
6110 ASSERT_TRUE(response); 6115 ASSERT_TRUE(response);
6111 ASSERT_EQ(401, response->headers->response_code()); 6116 ASSERT_EQ(401, response->headers->response_code());
6112 rv = c->trans->RestartWithAuth(AuthCredentials(), c->callback.callback()); 6117 rv = c->trans->RestartWithAuth(AuthCredentials(), c->callback.callback());
6113 EXPECT_EQ(OK, c->callback.GetResult(rv)); 6118 EXPECT_THAT(c->callback.GetResult(rv), IsOk());
6114 response = c->trans->GetResponseInfo(); 6119 response = c->trans->GetResponseInfo();
6115 ASSERT_TRUE(response); 6120 ASSERT_TRUE(response);
6116 ASSERT_EQ(200, response->headers->response_code()); 6121 ASSERT_EQ(200, response->headers->response_code());
6117 6122
6118 ReadAndVerifyTransaction(c->trans.get(), transaction); 6123 ReadAndVerifyTransaction(c->trans.get(), transaction);
6119 c.reset(); // The destructor could delete the entry. 6124 c.reset(); // The destructor could delete the entry.
6120 EXPECT_EQ(2, cache.network_layer()->transaction_count()); 6125 EXPECT_EQ(2, cache.network_layer()->transaction_count());
6121 6126
6122 // Verify that the entry was not deleted. 6127 // Verify that the entry was not deleted.
6123 disk_cache::Entry* entry; 6128 disk_cache::Entry* entry;
(...skipping 20 matching lines...) Expand all
6144 // And now read from the cache and the network. 10-19 will get a 6149 // And now read from the cache and the network. 10-19 will get a
6145 // 401, but will have already returned 0-9. 6150 // 401, but will have already returned 0-9.
6146 // We do not set X-Require-Mock-Auth because that causes the mock 6151 // We do not set X-Require-Mock-Auth because that causes the mock
6147 // network transaction to become IsReadyToRestartForAuth(). 6152 // network transaction to become IsReadyToRestartForAuth().
6148 transaction.request_headers = 6153 transaction.request_headers =
6149 "Range: bytes = 0-79\r\n" 6154 "Range: bytes = 0-79\r\n"
6150 "X-Require-Mock-Auth-Alt: dummy\r\n" EXTRA_HEADER; 6155 "X-Require-Mock-Auth-Alt: dummy\r\n" EXTRA_HEADER;
6151 6156
6152 std::unique_ptr<Context> c(new Context); 6157 std::unique_ptr<Context> c(new Context);
6153 int rv = cache.CreateTransaction(&c->trans); 6158 int rv = cache.CreateTransaction(&c->trans);
6154 ASSERT_EQ(OK, rv); 6159 ASSERT_THAT(rv, IsOk());
6155 6160
6156 MockHttpRequest request(transaction); 6161 MockHttpRequest request(transaction);
6157 6162
6158 rv = c->trans->Start(&request, c->callback.callback(), BoundNetLog()); 6163 rv = c->trans->Start(&request, c->callback.callback(), BoundNetLog());
6159 if (rv == ERR_IO_PENDING) 6164 if (rv == ERR_IO_PENDING)
6160 rv = c->callback.WaitForResult(); 6165 rv = c->callback.WaitForResult();
6161 std::string content; 6166 std::string content;
6162 rv = ReadTransaction(c->trans.get(), &content); 6167 rv = ReadTransaction(c->trans.get(), &content);
6163 EXPECT_EQ(ERR_CACHE_AUTH_FAILURE_AFTER_READ, rv); 6168 EXPECT_THAT(rv, IsError(ERR_CACHE_AUTH_FAILURE_AFTER_READ));
6164 } 6169 }
6165 6170
6166 // Tests that we cache a 200 response to the validation request. 6171 // Tests that we cache a 200 response to the validation request.
6167 TEST(HttpCache, GET_IncompleteResource4) { 6172 TEST(HttpCache, GET_IncompleteResource4) {
6168 MockHttpCache cache; 6173 MockHttpCache cache;
6169 ScopedMockTransaction transaction(kRangeGET_TransactionOK); 6174 ScopedMockTransaction transaction(kRangeGET_TransactionOK);
6170 6175
6171 std::string raw_headers("HTTP/1.1 200 OK\n" 6176 std::string raw_headers("HTTP/1.1 200 OK\n"
6172 "Last-Modified: Sat, 18 Apr 2009 01:10:43 GMT\n" 6177 "Last-Modified: Sat, 18 Apr 2009 01:10:43 GMT\n"
6173 "ETag: \"foo\"\n" 6178 "ETag: \"foo\"\n"
(...skipping 29 matching lines...) Expand all
6203 "Accept-Ranges: bytes\n" 6208 "Accept-Ranges: bytes\n"
6204 "Content-Length: 80\n"); 6209 "Content-Length: 80\n");
6205 CreateTruncatedEntry(raw_headers, &cache); 6210 CreateTruncatedEntry(raw_headers, &cache);
6206 6211
6207 // Now make a regular request. 6212 // Now make a regular request.
6208 transaction.request_headers = EXTRA_HEADER; 6213 transaction.request_headers = EXTRA_HEADER;
6209 6214
6210 MockHttpRequest request(transaction); 6215 MockHttpRequest request(transaction);
6211 Context* c = new Context(); 6216 Context* c = new Context();
6212 int rv = cache.CreateTransaction(&c->trans); 6217 int rv = cache.CreateTransaction(&c->trans);
6213 ASSERT_EQ(OK, rv); 6218 ASSERT_THAT(rv, IsOk());
6214 6219
6215 rv = c->trans->Start(&request, c->callback.callback(), BoundNetLog()); 6220 rv = c->trans->Start(&request, c->callback.callback(), BoundNetLog());
6216 EXPECT_EQ(OK, c->callback.GetResult(rv)); 6221 EXPECT_THAT(c->callback.GetResult(rv), IsOk());
6217 6222
6218 // Read 20 bytes from the cache, and 10 from the net. 6223 // Read 20 bytes from the cache, and 10 from the net.
6219 scoped_refptr<IOBuffer> buf(new IOBuffer(100)); 6224 scoped_refptr<IOBuffer> buf(new IOBuffer(100));
6220 rv = c->trans->Read(buf.get(), 20, c->callback.callback()); 6225 rv = c->trans->Read(buf.get(), 20, c->callback.callback());
6221 EXPECT_EQ(20, c->callback.GetResult(rv)); 6226 EXPECT_EQ(20, c->callback.GetResult(rv));
6222 rv = c->trans->Read(buf.get(), 10, c->callback.callback()); 6227 rv = c->trans->Read(buf.get(), 10, c->callback.callback());
6223 EXPECT_EQ(10, c->callback.GetResult(rv)); 6228 EXPECT_EQ(10, c->callback.GetResult(rv));
6224 6229
6225 // At this point, we are already reading so canceling the request should leave 6230 // At this point, we are already reading so canceling the request should leave
6226 // a truncated one. 6231 // a truncated one.
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
6286 6291
6287 r3.load_flags |= LOAD_ONLY_FROM_CACHE; 6292 r3.load_flags |= LOAD_ONLY_FROM_CACHE;
6288 c3.Start(&r3, BoundNetLog()); 6293 c3.Start(&r3, BoundNetLog());
6289 6294
6290 base::RunLoop().Run(); 6295 base::RunLoop().Run();
6291 6296
6292 EXPECT_TRUE(c1.is_done()); 6297 EXPECT_TRUE(c1.is_done());
6293 EXPECT_TRUE(c2.is_done()); 6298 EXPECT_TRUE(c2.is_done());
6294 EXPECT_TRUE(c3.is_done()); 6299 EXPECT_TRUE(c3.is_done());
6295 6300
6296 EXPECT_EQ(OK, c1.error()); 6301 EXPECT_THAT(c1.error(), IsOk());
6297 EXPECT_EQ(OK, c2.error()); 6302 EXPECT_THAT(c2.error(), IsOk());
6298 EXPECT_EQ(OK, c3.error()); 6303 EXPECT_THAT(c3.error(), IsOk());
6299 } 6304 }
6300 6305
6301 TEST(HttpCache, ValidationResultsIn200) { 6306 TEST(HttpCache, ValidationResultsIn200) {
6302 MockHttpCache cache; 6307 MockHttpCache cache;
6303 6308
6304 // This test ensures that a conditional request, which results in a 200 6309 // This test ensures that a conditional request, which results in a 200
6305 // instead of a 304, properly truncates the existing response data. 6310 // instead of a 304, properly truncates the existing response data.
6306 6311
6307 // write to the cache 6312 // write to the cache
6308 RunTransactionTest(cache.http_cache(), kETagGET_Transaction); 6313 RunTransactionTest(cache.http_cache(), kETagGET_Transaction);
(...skipping 13 matching lines...) Expand all
6322 ScopedMockTransaction kTestTransaction(kSimpleGET_Transaction); 6327 ScopedMockTransaction kTestTransaction(kSimpleGET_Transaction);
6323 kTestTransaction.status = "HTTP/1.1 301 Moved Permanently"; 6328 kTestTransaction.status = "HTTP/1.1 301 Moved Permanently";
6324 kTestTransaction.response_headers = "Location: http://www.bar.com/\n"; 6329 kTestTransaction.response_headers = "Location: http://www.bar.com/\n";
6325 6330
6326 MockHttpRequest request(kTestTransaction); 6331 MockHttpRequest request(kTestTransaction);
6327 TestCompletionCallback callback; 6332 TestCompletionCallback callback;
6328 6333
6329 // Write to the cache. 6334 // Write to the cache.
6330 { 6335 {
6331 std::unique_ptr<HttpTransaction> trans; 6336 std::unique_ptr<HttpTransaction> trans;
6332 ASSERT_EQ(OK, cache.CreateTransaction(&trans)); 6337 ASSERT_THAT(cache.CreateTransaction(&trans), IsOk());
6333 6338
6334 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); 6339 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
6335 if (rv == ERR_IO_PENDING) 6340 if (rv == ERR_IO_PENDING)
6336 rv = callback.WaitForResult(); 6341 rv = callback.WaitForResult();
6337 ASSERT_EQ(OK, rv); 6342 ASSERT_THAT(rv, IsOk());
6338 6343
6339 const HttpResponseInfo* info = trans->GetResponseInfo(); 6344 const HttpResponseInfo* info = trans->GetResponseInfo();
6340 ASSERT_TRUE(info); 6345 ASSERT_TRUE(info);
6341 6346
6342 EXPECT_EQ(info->headers->response_code(), 301); 6347 EXPECT_EQ(info->headers->response_code(), 301);
6343 6348
6344 std::string location; 6349 std::string location;
6345 info->headers->EnumerateHeader(NULL, "Location", &location); 6350 info->headers->EnumerateHeader(NULL, "Location", &location);
6346 EXPECT_EQ(location, "http://www.bar.com/"); 6351 EXPECT_EQ(location, "http://www.bar.com/");
6347 6352
6348 // Mark the transaction as completed so it is cached. 6353 // Mark the transaction as completed so it is cached.
6349 trans->DoneReading(); 6354 trans->DoneReading();
6350 6355
6351 // Destroy transaction when going out of scope. We have not actually 6356 // Destroy transaction when going out of scope. We have not actually
6352 // read the response body -- want to test that it is still getting cached. 6357 // read the response body -- want to test that it is still getting cached.
6353 } 6358 }
6354 EXPECT_EQ(1, cache.network_layer()->transaction_count()); 6359 EXPECT_EQ(1, cache.network_layer()->transaction_count());
6355 EXPECT_EQ(0, cache.disk_cache()->open_count()); 6360 EXPECT_EQ(0, cache.disk_cache()->open_count());
6356 EXPECT_EQ(1, cache.disk_cache()->create_count()); 6361 EXPECT_EQ(1, cache.disk_cache()->create_count());
6357 6362
6358 // Active entries in the cache are not retired synchronously. Make 6363 // Active entries in the cache are not retired synchronously. Make
6359 // sure the next run hits the MockHttpCache and open_count is 6364 // sure the next run hits the MockHttpCache and open_count is
6360 // correct. 6365 // correct.
6361 base::RunLoop().RunUntilIdle(); 6366 base::RunLoop().RunUntilIdle();
6362 6367
6363 // Read from the cache. 6368 // Read from the cache.
6364 { 6369 {
6365 std::unique_ptr<HttpTransaction> trans; 6370 std::unique_ptr<HttpTransaction> trans;
6366 ASSERT_EQ(OK, cache.CreateTransaction(&trans)); 6371 ASSERT_THAT(cache.CreateTransaction(&trans), IsOk());
6367 6372
6368 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); 6373 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
6369 if (rv == ERR_IO_PENDING) 6374 if (rv == ERR_IO_PENDING)
6370 rv = callback.WaitForResult(); 6375 rv = callback.WaitForResult();
6371 ASSERT_EQ(OK, rv); 6376 ASSERT_THAT(rv, IsOk());
6372 6377
6373 const HttpResponseInfo* info = trans->GetResponseInfo(); 6378 const HttpResponseInfo* info = trans->GetResponseInfo();
6374 ASSERT_TRUE(info); 6379 ASSERT_TRUE(info);
6375 6380
6376 EXPECT_EQ(info->headers->response_code(), 301); 6381 EXPECT_EQ(info->headers->response_code(), 301);
6377 6382
6378 std::string location; 6383 std::string location;
6379 info->headers->EnumerateHeader(NULL, "Location", &location); 6384 info->headers->EnumerateHeader(NULL, "Location", &location);
6380 EXPECT_EQ(location, "http://www.bar.com/"); 6385 EXPECT_EQ(location, "http://www.bar.com/");
6381 6386
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
6537 // write to the cache 6542 // write to the cache
6538 RunTransactionTest(cache.http_cache(), transaction); 6543 RunTransactionTest(cache.http_cache(), transaction);
6539 6544
6540 // Test that it was not cached. 6545 // Test that it was not cached.
6541 transaction.load_flags |= LOAD_ONLY_FROM_CACHE; 6546 transaction.load_flags |= LOAD_ONLY_FROM_CACHE;
6542 6547
6543 MockHttpRequest request(transaction); 6548 MockHttpRequest request(transaction);
6544 TestCompletionCallback callback; 6549 TestCompletionCallback callback;
6545 6550
6546 std::unique_ptr<HttpTransaction> trans; 6551 std::unique_ptr<HttpTransaction> trans;
6547 ASSERT_EQ(OK, cache.CreateTransaction(&trans)); 6552 ASSERT_THAT(cache.CreateTransaction(&trans), IsOk());
6548 6553
6549 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); 6554 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
6550 if (rv == ERR_IO_PENDING) 6555 if (rv == ERR_IO_PENDING)
6551 rv = callback.WaitForResult(); 6556 rv = callback.WaitForResult();
6552 ASSERT_EQ(ERR_CACHE_MISS, rv); 6557 ASSERT_THAT(rv, IsError(ERR_CACHE_MISS));
6553 } 6558 }
6554 6559
6555 // Ensure that we don't crash by if left-behind transactions. 6560 // Ensure that we don't crash by if left-behind transactions.
6556 TEST(HttpCache, OutlivedTransactions) { 6561 TEST(HttpCache, OutlivedTransactions) {
6557 MockHttpCache* cache = new MockHttpCache; 6562 MockHttpCache* cache = new MockHttpCache;
6558 6563
6559 std::unique_ptr<HttpTransaction> trans; 6564 std::unique_ptr<HttpTransaction> trans;
6560 EXPECT_EQ(OK, cache->CreateTransaction(&trans)); 6565 EXPECT_THAT(cache->CreateTransaction(&trans), IsOk());
6561 6566
6562 delete cache; 6567 delete cache;
6563 trans.reset(); 6568 trans.reset();
6564 } 6569 }
6565 6570
6566 // Test that the disabled mode works. 6571 // Test that the disabled mode works.
6567 TEST(HttpCache, CacheDisabledMode) { 6572 TEST(HttpCache, CacheDisabledMode) {
6568 MockHttpCache cache; 6573 MockHttpCache cache;
6569 6574
6570 // write to the cache 6575 // write to the cache
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
6791 } 6796 }
6792 6797
6793 // Tests that we don't mark entries as truncated when a filter detects the end 6798 // Tests that we don't mark entries as truncated when a filter detects the end
6794 // of the stream. 6799 // of the stream.
6795 TEST(HttpCache, FilterCompletion) { 6800 TEST(HttpCache, FilterCompletion) {
6796 MockHttpCache cache; 6801 MockHttpCache cache;
6797 TestCompletionCallback callback; 6802 TestCompletionCallback callback;
6798 6803
6799 { 6804 {
6800 std::unique_ptr<HttpTransaction> trans; 6805 std::unique_ptr<HttpTransaction> trans;
6801 ASSERT_EQ(OK, cache.CreateTransaction(&trans)); 6806 ASSERT_THAT(cache.CreateTransaction(&trans), IsOk());
6802 6807
6803 MockHttpRequest request(kSimpleGET_Transaction); 6808 MockHttpRequest request(kSimpleGET_Transaction);
6804 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); 6809 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
6805 EXPECT_EQ(OK, callback.GetResult(rv)); 6810 EXPECT_THAT(callback.GetResult(rv), IsOk());
6806 6811
6807 scoped_refptr<IOBuffer> buf(new IOBuffer(256)); 6812 scoped_refptr<IOBuffer> buf(new IOBuffer(256));
6808 rv = trans->Read(buf.get(), 256, callback.callback()); 6813 rv = trans->Read(buf.get(), 256, callback.callback());
6809 EXPECT_GT(callback.GetResult(rv), 0); 6814 EXPECT_GT(callback.GetResult(rv), 0);
6810 6815
6811 // Now make sure that the entry is preserved. 6816 // Now make sure that the entry is preserved.
6812 trans->DoneReading(); 6817 trans->DoneReading();
6813 } 6818 }
6814 6819
6815 // Make sure that the ActiveEntry is gone. 6820 // Make sure that the ActiveEntry is gone.
(...skipping 11 matching lines...) Expand all
6827 // entry when DoneReading() is called before any Read() calls, such as 6832 // entry when DoneReading() is called before any Read() calls, such as
6828 // for a redirect. 6833 // for a redirect.
6829 TEST(HttpCache, DoneReading) { 6834 TEST(HttpCache, DoneReading) {
6830 MockHttpCache cache; 6835 MockHttpCache cache;
6831 TestCompletionCallback callback; 6836 TestCompletionCallback callback;
6832 6837
6833 ScopedMockTransaction transaction(kSimpleGET_Transaction); 6838 ScopedMockTransaction transaction(kSimpleGET_Transaction);
6834 transaction.data = ""; 6839 transaction.data = "";
6835 6840
6836 std::unique_ptr<HttpTransaction> trans; 6841 std::unique_ptr<HttpTransaction> trans;
6837 ASSERT_EQ(OK, cache.CreateTransaction(&trans)); 6842 ASSERT_THAT(cache.CreateTransaction(&trans), IsOk());
6838 6843
6839 MockHttpRequest request(transaction); 6844 MockHttpRequest request(transaction);
6840 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); 6845 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
6841 EXPECT_EQ(OK, callback.GetResult(rv)); 6846 EXPECT_THAT(callback.GetResult(rv), IsOk());
6842 6847
6843 trans->DoneReading(); 6848 trans->DoneReading();
6844 // Leave the transaction around. 6849 // Leave the transaction around.
6845 6850
6846 // Make sure that the ActiveEntry is gone. 6851 // Make sure that the ActiveEntry is gone.
6847 base::RunLoop().RunUntilIdle(); 6852 base::RunLoop().RunUntilIdle();
6848 6853
6849 // Read from the cache. This should not deadlock. 6854 // Read from the cache. This should not deadlock.
6850 RunTransactionTest(cache.http_cache(), transaction); 6855 RunTransactionTest(cache.http_cache(), transaction);
6851 6856
6852 EXPECT_EQ(1, cache.network_layer()->transaction_count()); 6857 EXPECT_EQ(1, cache.network_layer()->transaction_count());
6853 EXPECT_EQ(1, cache.disk_cache()->open_count()); 6858 EXPECT_EQ(1, cache.disk_cache()->open_count());
6854 EXPECT_EQ(1, cache.disk_cache()->create_count()); 6859 EXPECT_EQ(1, cache.disk_cache()->create_count());
6855 } 6860 }
6856 6861
6857 // Tests that we stop caching when told. 6862 // Tests that we stop caching when told.
6858 TEST(HttpCache, StopCachingDeletesEntry) { 6863 TEST(HttpCache, StopCachingDeletesEntry) {
6859 MockHttpCache cache; 6864 MockHttpCache cache;
6860 TestCompletionCallback callback; 6865 TestCompletionCallback callback;
6861 MockHttpRequest request(kSimpleGET_Transaction); 6866 MockHttpRequest request(kSimpleGET_Transaction);
6862 6867
6863 { 6868 {
6864 std::unique_ptr<HttpTransaction> trans; 6869 std::unique_ptr<HttpTransaction> trans;
6865 ASSERT_EQ(OK, cache.CreateTransaction(&trans)); 6870 ASSERT_THAT(cache.CreateTransaction(&trans), IsOk());
6866 6871
6867 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); 6872 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
6868 EXPECT_EQ(OK, callback.GetResult(rv)); 6873 EXPECT_THAT(callback.GetResult(rv), IsOk());
6869 6874
6870 scoped_refptr<IOBuffer> buf(new IOBuffer(256)); 6875 scoped_refptr<IOBuffer> buf(new IOBuffer(256));
6871 rv = trans->Read(buf.get(), 10, callback.callback()); 6876 rv = trans->Read(buf.get(), 10, callback.callback());
6872 EXPECT_EQ(10, callback.GetResult(rv)); 6877 EXPECT_EQ(10, callback.GetResult(rv));
6873 6878
6874 trans->StopCaching(); 6879 trans->StopCaching();
6875 6880
6876 // We should be able to keep reading. 6881 // We should be able to keep reading.
6877 rv = trans->Read(buf.get(), 256, callback.callback()); 6882 rv = trans->Read(buf.get(), 256, callback.callback());
6878 EXPECT_GT(callback.GetResult(rv), 0); 6883 EXPECT_GT(callback.GetResult(rv), 0);
(...skipping 14 matching lines...) Expand all
6893 6898
6894 // Tests that we stop caching when told, even if DoneReading is called 6899 // Tests that we stop caching when told, even if DoneReading is called
6895 // after StopCaching. 6900 // after StopCaching.
6896 TEST(HttpCache, StopCachingThenDoneReadingDeletesEntry) { 6901 TEST(HttpCache, StopCachingThenDoneReadingDeletesEntry) {
6897 MockHttpCache cache; 6902 MockHttpCache cache;
6898 TestCompletionCallback callback; 6903 TestCompletionCallback callback;
6899 MockHttpRequest request(kSimpleGET_Transaction); 6904 MockHttpRequest request(kSimpleGET_Transaction);
6900 6905
6901 { 6906 {
6902 std::unique_ptr<HttpTransaction> trans; 6907 std::unique_ptr<HttpTransaction> trans;
6903 ASSERT_EQ(OK, cache.CreateTransaction(&trans)); 6908 ASSERT_THAT(cache.CreateTransaction(&trans), IsOk());
6904 6909
6905 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); 6910 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
6906 EXPECT_EQ(OK, callback.GetResult(rv)); 6911 EXPECT_THAT(callback.GetResult(rv), IsOk());
6907 6912
6908 scoped_refptr<IOBuffer> buf(new IOBuffer(256)); 6913 scoped_refptr<IOBuffer> buf(new IOBuffer(256));
6909 rv = trans->Read(buf.get(), 10, callback.callback()); 6914 rv = trans->Read(buf.get(), 10, callback.callback());
6910 EXPECT_EQ(10, callback.GetResult(rv)); 6915 EXPECT_EQ(10, callback.GetResult(rv));
6911 6916
6912 trans->StopCaching(); 6917 trans->StopCaching();
6913 6918
6914 // We should be able to keep reading. 6919 // We should be able to keep reading.
6915 rv = trans->Read(buf.get(), 256, callback.callback()); 6920 rv = trans->Read(buf.get(), 256, callback.callback());
6916 EXPECT_GT(callback.GetResult(rv), 0); 6921 EXPECT_GT(callback.GetResult(rv), 0);
(...skipping 19 matching lines...) Expand all
6936 TEST(HttpCache, StopCachingWithAuthDeletesEntry) { 6941 TEST(HttpCache, StopCachingWithAuthDeletesEntry) {
6937 MockHttpCache cache; 6942 MockHttpCache cache;
6938 TestCompletionCallback callback; 6943 TestCompletionCallback callback;
6939 MockTransaction mock_transaction(kSimpleGET_Transaction); 6944 MockTransaction mock_transaction(kSimpleGET_Transaction);
6940 mock_transaction.status = "HTTP/1.1 401 Unauthorized"; 6945 mock_transaction.status = "HTTP/1.1 401 Unauthorized";
6941 AddMockTransaction(&mock_transaction); 6946 AddMockTransaction(&mock_transaction);
6942 MockHttpRequest request(mock_transaction); 6947 MockHttpRequest request(mock_transaction);
6943 6948
6944 { 6949 {
6945 std::unique_ptr<HttpTransaction> trans; 6950 std::unique_ptr<HttpTransaction> trans;
6946 ASSERT_EQ(OK, cache.CreateTransaction(&trans)); 6951 ASSERT_THAT(cache.CreateTransaction(&trans), IsOk());
6947 6952
6948 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); 6953 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
6949 EXPECT_EQ(OK, callback.GetResult(rv)); 6954 EXPECT_THAT(callback.GetResult(rv), IsOk());
6950 6955
6951 trans->StopCaching(); 6956 trans->StopCaching();
6952 6957
6953 scoped_refptr<IOBuffer> buf(new IOBuffer(256)); 6958 scoped_refptr<IOBuffer> buf(new IOBuffer(256));
6954 rv = trans->Read(buf.get(), 10, callback.callback()); 6959 rv = trans->Read(buf.get(), 10, callback.callback());
6955 EXPECT_EQ(callback.GetResult(rv), 10); 6960 EXPECT_EQ(callback.GetResult(rv), 10);
6956 } 6961 }
6957 RemoveMockTransaction(&mock_transaction); 6962 RemoveMockTransaction(&mock_transaction);
6958 6963
6959 // Make sure that the ActiveEntry is gone. 6964 // Make sure that the ActiveEntry is gone.
6960 base::RunLoop().RunUntilIdle(); 6965 base::RunLoop().RunUntilIdle();
6961 6966
6962 // Verify that the entry is gone. 6967 // Verify that the entry is gone.
6963 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); 6968 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction);
6964 6969
6965 EXPECT_EQ(2, cache.network_layer()->transaction_count()); 6970 EXPECT_EQ(2, cache.network_layer()->transaction_count());
6966 EXPECT_EQ(0, cache.disk_cache()->open_count()); 6971 EXPECT_EQ(0, cache.disk_cache()->open_count());
6967 EXPECT_EQ(2, cache.disk_cache()->create_count()); 6972 EXPECT_EQ(2, cache.disk_cache()->create_count());
6968 } 6973 }
6969 6974
6970 // Tests that when we are told to stop caching we don't throw away valid data. 6975 // Tests that when we are told to stop caching we don't throw away valid data.
6971 TEST(HttpCache, StopCachingSavesEntry) { 6976 TEST(HttpCache, StopCachingSavesEntry) {
6972 MockHttpCache cache; 6977 MockHttpCache cache;
6973 TestCompletionCallback callback; 6978 TestCompletionCallback callback;
6974 MockHttpRequest request(kSimpleGET_Transaction); 6979 MockHttpRequest request(kSimpleGET_Transaction);
6975 6980
6976 { 6981 {
6977 std::unique_ptr<HttpTransaction> trans; 6982 std::unique_ptr<HttpTransaction> trans;
6978 ASSERT_EQ(OK, cache.CreateTransaction(&trans)); 6983 ASSERT_THAT(cache.CreateTransaction(&trans), IsOk());
6979 6984
6980 // Force a response that can be resumed. 6985 // Force a response that can be resumed.
6981 ScopedMockTransaction mock_transaction(kSimpleGET_Transaction); 6986 ScopedMockTransaction mock_transaction(kSimpleGET_Transaction);
6982 AddMockTransaction(&mock_transaction); 6987 AddMockTransaction(&mock_transaction);
6983 mock_transaction.response_headers = "Cache-Control: max-age=10000\n" 6988 mock_transaction.response_headers = "Cache-Control: max-age=10000\n"
6984 "Content-Length: 42\n" 6989 "Content-Length: 42\n"
6985 "Etag: \"foo\"\n"; 6990 "Etag: \"foo\"\n";
6986 6991
6987 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); 6992 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
6988 EXPECT_EQ(OK, callback.GetResult(rv)); 6993 EXPECT_THAT(callback.GetResult(rv), IsOk());
6989 6994
6990 scoped_refptr<IOBuffer> buf(new IOBuffer(256)); 6995 scoped_refptr<IOBuffer> buf(new IOBuffer(256));
6991 rv = trans->Read(buf.get(), 10, callback.callback()); 6996 rv = trans->Read(buf.get(), 10, callback.callback());
6992 EXPECT_EQ(callback.GetResult(rv), 10); 6997 EXPECT_EQ(callback.GetResult(rv), 10);
6993 6998
6994 trans->StopCaching(); 6999 trans->StopCaching();
6995 7000
6996 // We should be able to keep reading. 7001 // We should be able to keep reading.
6997 rv = trans->Read(buf.get(), 256, callback.callback()); 7002 rv = trans->Read(buf.get(), 256, callback.callback());
6998 EXPECT_GT(callback.GetResult(rv), 0); 7003 EXPECT_GT(callback.GetResult(rv), 0);
(...skipping 17 matching lines...) Expand all
7016 std::string raw_headers("HTTP/1.1 200 OK\n" 7021 std::string raw_headers("HTTP/1.1 200 OK\n"
7017 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" 7022 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n"
7018 "ETag: \"foo\"\n" 7023 "ETag: \"foo\"\n"
7019 "Accept-Ranges: bytes\n" 7024 "Accept-Ranges: bytes\n"
7020 "Content-Length: 80\n"); 7025 "Content-Length: 80\n");
7021 CreateTruncatedEntry(raw_headers, &cache); 7026 CreateTruncatedEntry(raw_headers, &cache);
7022 7027
7023 { 7028 {
7024 // Now make a regular request. 7029 // Now make a regular request.
7025 std::unique_ptr<HttpTransaction> trans; 7030 std::unique_ptr<HttpTransaction> trans;
7026 ASSERT_EQ(OK, cache.CreateTransaction(&trans)); 7031 ASSERT_THAT(cache.CreateTransaction(&trans), IsOk());
7027 7032
7028 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); 7033 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
7029 EXPECT_EQ(OK, callback.GetResult(rv)); 7034 EXPECT_THAT(callback.GetResult(rv), IsOk());
7030 7035
7031 scoped_refptr<IOBuffer> buf(new IOBuffer(256)); 7036 scoped_refptr<IOBuffer> buf(new IOBuffer(256));
7032 rv = trans->Read(buf.get(), 10, callback.callback()); 7037 rv = trans->Read(buf.get(), 10, callback.callback());
7033 EXPECT_EQ(callback.GetResult(rv), 10); 7038 EXPECT_EQ(callback.GetResult(rv), 10);
7034 7039
7035 // This is actually going to do nothing. 7040 // This is actually going to do nothing.
7036 trans->StopCaching(); 7041 trans->StopCaching();
7037 7042
7038 // We should be able to keep reading. 7043 // We should be able to keep reading.
7039 rv = trans->Read(buf.get(), 256, callback.callback()); 7044 rv = trans->Read(buf.get(), 256, callback.callback());
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
7358 // Verify that the entry is marked as incomplete. 7363 // Verify that the entry is marked as incomplete.
7359 VerifyTruncatedFlag(&cache, kSimpleGET_Transaction.url, true, 0); 7364 VerifyTruncatedFlag(&cache, kSimpleGET_Transaction.url, true, 0);
7360 } 7365 }
7361 7366
7362 // Make sure that calling SetPriority on a cache transaction passes on 7367 // Make sure that calling SetPriority on a cache transaction passes on
7363 // its priority updates to its underlying network transaction. 7368 // its priority updates to its underlying network transaction.
7364 TEST(HttpCache, SetPriority) { 7369 TEST(HttpCache, SetPriority) {
7365 MockHttpCache cache; 7370 MockHttpCache cache;
7366 7371
7367 std::unique_ptr<HttpTransaction> trans; 7372 std::unique_ptr<HttpTransaction> trans;
7368 ASSERT_EQ(OK, cache.http_cache()->CreateTransaction(IDLE, &trans)); 7373 ASSERT_THAT(cache.http_cache()->CreateTransaction(IDLE, &trans), IsOk());
7369 7374
7370 // Shouldn't crash, but doesn't do anything either. 7375 // Shouldn't crash, but doesn't do anything either.
7371 trans->SetPriority(LOW); 7376 trans->SetPriority(LOW);
7372 7377
7373 EXPECT_FALSE(cache.network_layer()->last_transaction()); 7378 EXPECT_FALSE(cache.network_layer()->last_transaction());
7374 EXPECT_EQ(DEFAULT_PRIORITY, 7379 EXPECT_EQ(DEFAULT_PRIORITY,
7375 cache.network_layer()->last_create_transaction_priority()); 7380 cache.network_layer()->last_create_transaction_priority());
7376 7381
7377 HttpRequestInfo info; 7382 HttpRequestInfo info;
7378 info.url = GURL(kSimpleGET_Transaction.url); 7383 info.url = GURL(kSimpleGET_Transaction.url);
7379 TestCompletionCallback callback; 7384 TestCompletionCallback callback;
7380 EXPECT_EQ(ERR_IO_PENDING, 7385 EXPECT_EQ(ERR_IO_PENDING,
7381 trans->Start(&info, callback.callback(), BoundNetLog())); 7386 trans->Start(&info, callback.callback(), BoundNetLog()));
7382 7387
7383 EXPECT_TRUE(cache.network_layer()->last_transaction()); 7388 EXPECT_TRUE(cache.network_layer()->last_transaction());
7384 if (cache.network_layer()->last_transaction()) { 7389 if (cache.network_layer()->last_transaction()) {
7385 EXPECT_EQ(LOW, cache.network_layer()->last_create_transaction_priority()); 7390 EXPECT_EQ(LOW, cache.network_layer()->last_create_transaction_priority());
7386 EXPECT_EQ(LOW, cache.network_layer()->last_transaction()->priority()); 7391 EXPECT_EQ(LOW, cache.network_layer()->last_transaction()->priority());
7387 } 7392 }
7388 7393
7389 trans->SetPriority(HIGHEST); 7394 trans->SetPriority(HIGHEST);
7390 7395
7391 if (cache.network_layer()->last_transaction()) { 7396 if (cache.network_layer()->last_transaction()) {
7392 EXPECT_EQ(LOW, cache.network_layer()->last_create_transaction_priority()); 7397 EXPECT_EQ(LOW, cache.network_layer()->last_create_transaction_priority());
7393 EXPECT_EQ(HIGHEST, cache.network_layer()->last_transaction()->priority()); 7398 EXPECT_EQ(HIGHEST, cache.network_layer()->last_transaction()->priority());
7394 } 7399 }
7395 7400
7396 EXPECT_EQ(OK, callback.WaitForResult()); 7401 EXPECT_THAT(callback.WaitForResult(), IsOk());
7397 } 7402 }
7398 7403
7399 // Make sure that calling SetWebSocketHandshakeStreamCreateHelper on a cache 7404 // Make sure that calling SetWebSocketHandshakeStreamCreateHelper on a cache
7400 // transaction passes on its argument to the underlying network transaction. 7405 // transaction passes on its argument to the underlying network transaction.
7401 TEST(HttpCache, SetWebSocketHandshakeStreamCreateHelper) { 7406 TEST(HttpCache, SetWebSocketHandshakeStreamCreateHelper) {
7402 MockHttpCache cache; 7407 MockHttpCache cache;
7403 7408
7404 FakeWebSocketHandshakeStreamCreateHelper create_helper; 7409 FakeWebSocketHandshakeStreamCreateHelper create_helper;
7405 std::unique_ptr<HttpTransaction> trans; 7410 std::unique_ptr<HttpTransaction> trans;
7406 ASSERT_EQ(OK, cache.http_cache()->CreateTransaction(IDLE, &trans)); 7411 ASSERT_THAT(cache.http_cache()->CreateTransaction(IDLE, &trans), IsOk());
7407 7412
7408 EXPECT_FALSE(cache.network_layer()->last_transaction()); 7413 EXPECT_FALSE(cache.network_layer()->last_transaction());
7409 7414
7410 HttpRequestInfo info; 7415 HttpRequestInfo info;
7411 info.url = GURL(kSimpleGET_Transaction.url); 7416 info.url = GURL(kSimpleGET_Transaction.url);
7412 TestCompletionCallback callback; 7417 TestCompletionCallback callback;
7413 EXPECT_EQ(ERR_IO_PENDING, 7418 EXPECT_EQ(ERR_IO_PENDING,
7414 trans->Start(&info, callback.callback(), BoundNetLog())); 7419 trans->Start(&info, callback.callback(), BoundNetLog()));
7415 7420
7416 ASSERT_TRUE(cache.network_layer()->last_transaction()); 7421 ASSERT_TRUE(cache.network_layer()->last_transaction());
7417 EXPECT_FALSE(cache.network_layer()->last_transaction()-> 7422 EXPECT_FALSE(cache.network_layer()->last_transaction()->
7418 websocket_handshake_stream_create_helper()); 7423 websocket_handshake_stream_create_helper());
7419 trans->SetWebSocketHandshakeStreamCreateHelper(&create_helper); 7424 trans->SetWebSocketHandshakeStreamCreateHelper(&create_helper);
7420 EXPECT_EQ(&create_helper, 7425 EXPECT_EQ(&create_helper,
7421 cache.network_layer()->last_transaction()-> 7426 cache.network_layer()->last_transaction()->
7422 websocket_handshake_stream_create_helper()); 7427 websocket_handshake_stream_create_helper());
7423 EXPECT_EQ(OK, callback.WaitForResult()); 7428 EXPECT_THAT(callback.WaitForResult(), IsOk());
7424 } 7429 }
7425 7430
7426 // Make sure that a cache transaction passes on its priority to 7431 // Make sure that a cache transaction passes on its priority to
7427 // newly-created network transactions. 7432 // newly-created network transactions.
7428 TEST(HttpCache, SetPriorityNewTransaction) { 7433 TEST(HttpCache, SetPriorityNewTransaction) {
7429 MockHttpCache cache; 7434 MockHttpCache cache;
7430 AddMockTransaction(&kRangeGET_TransactionOK); 7435 AddMockTransaction(&kRangeGET_TransactionOK);
7431 7436
7432 std::string raw_headers("HTTP/1.1 200 OK\n" 7437 std::string raw_headers("HTTP/1.1 200 OK\n"
7433 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" 7438 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n"
7434 "ETag: \"foo\"\n" 7439 "ETag: \"foo\"\n"
7435 "Accept-Ranges: bytes\n" 7440 "Accept-Ranges: bytes\n"
7436 "Content-Length: 80\n"); 7441 "Content-Length: 80\n");
7437 CreateTruncatedEntry(raw_headers, &cache); 7442 CreateTruncatedEntry(raw_headers, &cache);
7438 7443
7439 // Now make a regular request. 7444 // Now make a regular request.
7440 std::string headers; 7445 std::string headers;
7441 MockTransaction transaction(kRangeGET_TransactionOK); 7446 MockTransaction transaction(kRangeGET_TransactionOK);
7442 transaction.request_headers = EXTRA_HEADER; 7447 transaction.request_headers = EXTRA_HEADER;
7443 transaction.data = kFullRangeData; 7448 transaction.data = kFullRangeData;
7444 7449
7445 std::unique_ptr<HttpTransaction> trans; 7450 std::unique_ptr<HttpTransaction> trans;
7446 ASSERT_EQ(OK, cache.http_cache()->CreateTransaction(MEDIUM, &trans)); 7451 ASSERT_THAT(cache.http_cache()->CreateTransaction(MEDIUM, &trans), IsOk());
7447 EXPECT_EQ(DEFAULT_PRIORITY, 7452 EXPECT_EQ(DEFAULT_PRIORITY,
7448 cache.network_layer()->last_create_transaction_priority()); 7453 cache.network_layer()->last_create_transaction_priority());
7449 7454
7450 MockHttpRequest info(transaction); 7455 MockHttpRequest info(transaction);
7451 TestCompletionCallback callback; 7456 TestCompletionCallback callback;
7452 EXPECT_EQ(ERR_IO_PENDING, 7457 EXPECT_EQ(ERR_IO_PENDING,
7453 trans->Start(&info, callback.callback(), BoundNetLog())); 7458 trans->Start(&info, callback.callback(), BoundNetLog()));
7454 EXPECT_EQ(OK, callback.WaitForResult()); 7459 EXPECT_THAT(callback.WaitForResult(), IsOk());
7455 7460
7456 EXPECT_EQ(MEDIUM, cache.network_layer()->last_create_transaction_priority()); 7461 EXPECT_EQ(MEDIUM, cache.network_layer()->last_create_transaction_priority());
7457 7462
7458 trans->SetPriority(HIGHEST); 7463 trans->SetPriority(HIGHEST);
7459 // Should trigger a new network transaction and pick up the new 7464 // Should trigger a new network transaction and pick up the new
7460 // priority. 7465 // priority.
7461 ReadAndVerifyTransaction(trans.get(), transaction); 7466 ReadAndVerifyTransaction(trans.get(), transaction);
7462 7467
7463 EXPECT_EQ(HIGHEST, cache.network_layer()->last_create_transaction_priority()); 7468 EXPECT_EQ(HIGHEST, cache.network_layer()->last_create_transaction_priority());
7464 7469
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
7830 // Create a transaction for bytes 0-9. 7835 // Create a transaction for bytes 0-9.
7831 MockHttpRequest request(kRangeGET_TransactionOK); 7836 MockHttpRequest request(kRangeGET_TransactionOK);
7832 MockTransaction transaction(kRangeGET_TransactionOK); 7837 MockTransaction transaction(kRangeGET_TransactionOK);
7833 transaction.request_headers = "Range: bytes = 0-9\r\n" EXTRA_HEADER; 7838 transaction.request_headers = "Range: bytes = 0-9\r\n" EXTRA_HEADER;
7834 transaction.data = "rg: 00-09 "; 7839 transaction.data = "rg: 00-09 ";
7835 AddMockTransaction(&transaction); 7840 AddMockTransaction(&transaction);
7836 7841
7837 TestCompletionCallback callback; 7842 TestCompletionCallback callback;
7838 std::unique_ptr<HttpTransaction> trans; 7843 std::unique_ptr<HttpTransaction> trans;
7839 int rv = cache.http_cache()->CreateTransaction(DEFAULT_PRIORITY, &trans); 7844 int rv = cache.http_cache()->CreateTransaction(DEFAULT_PRIORITY, &trans);
7840 EXPECT_EQ(OK, rv); 7845 EXPECT_THAT(rv, IsOk());
7841 ASSERT_TRUE(trans.get()); 7846 ASSERT_TRUE(trans.get());
7842 7847
7843 // Start our transaction. 7848 // Start our transaction.
7844 trans->Start(&request, callback.callback(), BoundNetLog()); 7849 trans->Start(&request, callback.callback(), BoundNetLog());
7845 7850
7846 // A second transaction on a different part of the file (the default 7851 // A second transaction on a different part of the file (the default
7847 // kRangeGET_TransactionOK requests 40-49) should not be blocked by 7852 // kRangeGET_TransactionOK requests 40-49) should not be blocked by
7848 // the already pending transaction. 7853 // the already pending transaction.
7849 RunTransactionTest(cache.http_cache(), kRangeGET_TransactionOK); 7854 RunTransactionTest(cache.http_cache(), kRangeGET_TransactionOK);
7850 7855
7851 // Let the first transaction complete. 7856 // Let the first transaction complete.
7852 callback.WaitForResult(); 7857 callback.WaitForResult();
7853 7858
7854 RemoveMockTransaction(&transaction); 7859 RemoveMockTransaction(&transaction);
7855 } 7860 }
7856 7861
7857 // Makes sure that a request stops using the cache when the response headers 7862 // Makes sure that a request stops using the cache when the response headers
7858 // with "Cache-Control: no-store" arrives. That means that another request for 7863 // with "Cache-Control: no-store" arrives. That means that another request for
7859 // the same URL can be processed before the response body of the original 7864 // the same URL can be processed before the response body of the original
7860 // request arrives. 7865 // request arrives.
7861 TEST(HttpCache, NoStoreResponseShouldNotBlockFollowingRequests) { 7866 TEST(HttpCache, NoStoreResponseShouldNotBlockFollowingRequests) {
7862 MockHttpCache cache; 7867 MockHttpCache cache;
7863 ScopedMockTransaction mock_transaction(kSimpleGET_Transaction); 7868 ScopedMockTransaction mock_transaction(kSimpleGET_Transaction);
7864 mock_transaction.response_headers = "Cache-Control: no-store\n"; 7869 mock_transaction.response_headers = "Cache-Control: no-store\n";
7865 MockHttpRequest request(mock_transaction); 7870 MockHttpRequest request(mock_transaction);
7866 7871
7867 std::unique_ptr<Context> first(new Context); 7872 std::unique_ptr<Context> first(new Context);
7868 first->result = cache.CreateTransaction(&first->trans); 7873 first->result = cache.CreateTransaction(&first->trans);
7869 ASSERT_EQ(OK, first->result); 7874 ASSERT_THAT(first->result, IsOk());
7870 EXPECT_EQ(LOAD_STATE_IDLE, first->trans->GetLoadState()); 7875 EXPECT_EQ(LOAD_STATE_IDLE, first->trans->GetLoadState());
7871 first->result = 7876 first->result =
7872 first->trans->Start(&request, first->callback.callback(), BoundNetLog()); 7877 first->trans->Start(&request, first->callback.callback(), BoundNetLog());
7873 EXPECT_EQ(LOAD_STATE_WAITING_FOR_CACHE, first->trans->GetLoadState()); 7878 EXPECT_EQ(LOAD_STATE_WAITING_FOR_CACHE, first->trans->GetLoadState());
7874 7879
7875 base::RunLoop().RunUntilIdle(); 7880 base::RunLoop().RunUntilIdle();
7876 EXPECT_EQ(LOAD_STATE_IDLE, first->trans->GetLoadState()); 7881 EXPECT_EQ(LOAD_STATE_IDLE, first->trans->GetLoadState());
7877 ASSERT_TRUE(first->trans->GetResponseInfo()); 7882 ASSERT_TRUE(first->trans->GetResponseInfo());
7878 EXPECT_TRUE(first->trans->GetResponseInfo()->headers->HasHeaderValue( 7883 EXPECT_TRUE(first->trans->GetResponseInfo()->headers->HasHeaderValue(
7879 "Cache-Control", "no-store")); 7884 "Cache-Control", "no-store"));
7880 // Here we have read the response header but not read the response body yet. 7885 // Here we have read the response header but not read the response body yet.
7881 7886
7882 // Let us create the second (read) transaction. 7887 // Let us create the second (read) transaction.
7883 std::unique_ptr<Context> second(new Context); 7888 std::unique_ptr<Context> second(new Context);
7884 second->result = cache.CreateTransaction(&second->trans); 7889 second->result = cache.CreateTransaction(&second->trans);
7885 ASSERT_EQ(OK, second->result); 7890 ASSERT_THAT(second->result, IsOk());
7886 EXPECT_EQ(LOAD_STATE_IDLE, second->trans->GetLoadState()); 7891 EXPECT_EQ(LOAD_STATE_IDLE, second->trans->GetLoadState());
7887 second->result = second->trans->Start(&request, second->callback.callback(), 7892 second->result = second->trans->Start(&request, second->callback.callback(),
7888 BoundNetLog()); 7893 BoundNetLog());
7889 7894
7890 // Here the second transaction proceeds without reading the first body. 7895 // Here the second transaction proceeds without reading the first body.
7891 EXPECT_EQ(LOAD_STATE_WAITING_FOR_CACHE, second->trans->GetLoadState()); 7896 EXPECT_EQ(LOAD_STATE_WAITING_FOR_CACHE, second->trans->GetLoadState());
7892 base::RunLoop().RunUntilIdle(); 7897 base::RunLoop().RunUntilIdle();
7893 EXPECT_EQ(LOAD_STATE_IDLE, second->trans->GetLoadState()); 7898 EXPECT_EQ(LOAD_STATE_IDLE, second->trans->GetLoadState());
7894 ASSERT_TRUE(second->trans->GetResponseInfo()); 7899 ASSERT_TRUE(second->trans->GetResponseInfo());
7895 EXPECT_TRUE(second->trans->GetResponseInfo()->headers->HasHeaderValue( 7900 EXPECT_TRUE(second->trans->GetResponseInfo()->headers->HasHeaderValue(
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
7999 EXPECT_EQ(1, cache.disk_cache()->open_count()); 8004 EXPECT_EQ(1, cache.disk_cache()->open_count());
8000 EXPECT_EQ(1, cache.disk_cache()->create_count()); 8005 EXPECT_EQ(1, cache.disk_cache()->create_count());
8001 EXPECT_TRUE(response_info.was_cached); 8006 EXPECT_TRUE(response_info.was_cached);
8002 8007
8003 // The new SSL state is reported. 8008 // The new SSL state is reported.
8004 EXPECT_EQ(status2, response_info.ssl_info.connection_status); 8009 EXPECT_EQ(status2, response_info.ssl_info.connection_status);
8005 EXPECT_TRUE(cert2->Equals(response_info.ssl_info.cert.get())); 8010 EXPECT_TRUE(cert2->Equals(response_info.ssl_info.cert.get()));
8006 } 8011 }
8007 8012
8008 } // namespace net 8013 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_auth_sspi_win_unittest.cc ('k') | net/http/http_chunked_decoder_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698