OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/http/http_cache.h" | 5 #include "net/http/http_cache.h" |
6 | 6 |
7 #include "base/hash_tables.h" | 7 #include "base/hash_tables.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/scoped_vector.h" | 9 #include "base/scoped_vector.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
529 | 529 |
530 EntryMap entries_; | 530 EntryMap entries_; |
531 int open_count_; | 531 int open_count_; |
532 int create_count_; | 532 int create_count_; |
533 bool fail_requests_; | 533 bool fail_requests_; |
534 bool soft_failures_; | 534 bool soft_failures_; |
535 }; | 535 }; |
536 | 536 |
537 class MockBackendFactory : public net::HttpCache::BackendFactory { | 537 class MockBackendFactory : public net::HttpCache::BackendFactory { |
538 public: | 538 public: |
539 virtual int CreateBackend(net::NetLog* /* net_log */, | 539 virtual int CreateBackend(disk_cache::Backend** backend, |
540 disk_cache::Backend** backend, | |
541 net::CompletionCallback* callback) { | 540 net::CompletionCallback* callback) { |
542 *backend = new MockDiskCache(); | 541 *backend = new MockDiskCache(); |
543 return net::OK; | 542 return net::OK; |
544 } | 543 } |
545 }; | 544 }; |
546 | 545 |
547 class MockHttpCache { | 546 class MockHttpCache { |
548 public: | 547 public: |
549 MockHttpCache() | 548 MockHttpCache() |
550 : http_cache_(new MockNetworkLayer(), NULL, new MockBackendFactory()) { | 549 : http_cache_(new MockNetworkLayer(), new MockBackendFactory()) { |
551 } | 550 } |
552 | 551 |
553 explicit MockHttpCache(net::HttpCache::BackendFactory* disk_cache_factory) | 552 explicit MockHttpCache(net::HttpCache::BackendFactory* disk_cache_factory) |
554 : http_cache_(new MockNetworkLayer(), NULL, disk_cache_factory) { | 553 : http_cache_(new MockNetworkLayer(), disk_cache_factory) { |
555 } | 554 } |
556 | 555 |
557 net::HttpCache* http_cache() { return &http_cache_; } | 556 net::HttpCache* http_cache() { return &http_cache_; } |
558 | 557 |
559 MockNetworkLayer* network_layer() { | 558 MockNetworkLayer* network_layer() { |
560 return static_cast<MockNetworkLayer*>(http_cache_.network_layer()); | 559 return static_cast<MockNetworkLayer*>(http_cache_.network_layer()); |
561 } | 560 } |
562 MockDiskCache* disk_cache() { | 561 MockDiskCache* disk_cache() { |
563 TestCompletionCallback cb; | 562 TestCompletionCallback cb; |
564 disk_cache::Backend* backend; | 563 disk_cache::Backend* backend; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
604 } | 603 } |
605 | 604 |
606 // Helper function to synchronously open a backend entry. | 605 // Helper function to synchronously open a backend entry. |
607 bool OpenBackendEntry(const std::string& key, disk_cache::Entry** entry) { | 606 bool OpenBackendEntry(const std::string& key, disk_cache::Entry** entry) { |
608 TestCompletionCallback cb; | 607 TestCompletionCallback cb; |
609 int rv = disk_cache()->OpenEntry(key, entry, &cb); | 608 int rv = disk_cache()->OpenEntry(key, entry, &cb); |
610 return (cb.GetResult(rv) == net::OK); | 609 return (cb.GetResult(rv) == net::OK); |
611 } | 610 } |
612 | 611 |
613 // Helper function to synchronously create a backend entry. | 612 // Helper function to synchronously create a backend entry. |
614 bool CreateBackendEntry(const std::string& key, disk_cache::Entry** entry, | 613 bool CreateBackendEntry(const std::string& key, disk_cache::Entry** entry) { |
615 net::NetLog* /* net_log */) { | |
616 TestCompletionCallback cb; | 614 TestCompletionCallback cb; |
617 int rv = disk_cache()->CreateEntry(key, entry, &cb); | 615 int rv = disk_cache()->CreateEntry(key, entry, &cb); |
618 return (cb.GetResult(rv) == net::OK); | 616 return (cb.GetResult(rv) == net::OK); |
619 } | 617 } |
620 | 618 |
621 private: | 619 private: |
622 net::HttpCache http_cache_; | 620 net::HttpCache http_cache_; |
623 }; | 621 }; |
624 | 622 |
625 // This version of the disk cache doesn't invoke CreateEntry callbacks. | 623 // This version of the disk cache doesn't invoke CreateEntry callbacks. |
626 class MockDiskCacheNoCB : public MockDiskCache { | 624 class MockDiskCacheNoCB : public MockDiskCache { |
627 virtual int CreateEntry(const std::string& key, disk_cache::Entry** entry, | 625 virtual int CreateEntry(const std::string& key, disk_cache::Entry** entry, |
628 net::CompletionCallback* callback) { | 626 net::CompletionCallback* callback) { |
629 return net::ERR_IO_PENDING; | 627 return net::ERR_IO_PENDING; |
630 } | 628 } |
631 }; | 629 }; |
632 | 630 |
633 class MockBackendNoCbFactory : public net::HttpCache::BackendFactory { | 631 class MockBackendNoCbFactory : public net::HttpCache::BackendFactory { |
634 public: | 632 public: |
635 virtual int CreateBackend(net::NetLog* /* net_log */, | 633 virtual int CreateBackend(disk_cache::Backend** backend, |
636 disk_cache::Backend** backend, | |
637 net::CompletionCallback* callback) { | 634 net::CompletionCallback* callback) { |
638 *backend = new MockDiskCacheNoCB(); | 635 *backend = new MockDiskCacheNoCB(); |
639 return net::OK; | 636 return net::OK; |
640 } | 637 } |
641 }; | 638 }; |
642 | 639 |
643 // This backend factory allows us to control the backend instantiation. | 640 // This backend factory allows us to control the backend instantiation. |
644 class MockBlockingBackendFactory : public net::HttpCache::BackendFactory { | 641 class MockBlockingBackendFactory : public net::HttpCache::BackendFactory { |
645 public: | 642 public: |
646 MockBlockingBackendFactory() | 643 MockBlockingBackendFactory() |
647 : backend_(NULL), callback_(NULL), block_(true), fail_(false) {} | 644 : backend_(NULL), callback_(NULL), block_(true), fail_(false) {} |
648 | 645 |
649 virtual int CreateBackend(net::NetLog* /* net_log */, | 646 virtual int CreateBackend(disk_cache::Backend** backend, |
650 disk_cache::Backend** backend, | |
651 net::CompletionCallback* callback) { | 647 net::CompletionCallback* callback) { |
652 if (!block_) { | 648 if (!block_) { |
653 if (!fail_) | 649 if (!fail_) |
654 *backend = new MockDiskCache(); | 650 *backend = new MockDiskCache(); |
655 return Result(); | 651 return Result(); |
656 } | 652 } |
657 | 653 |
658 backend_ = backend; | 654 backend_ = backend; |
659 callback_ = callback; | 655 callback_ = callback; |
660 return net::ERR_IO_PENDING; | 656 return net::ERR_IO_PENDING; |
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1034 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 1030 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
1035 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 1031 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
1036 } | 1032 } |
1037 | 1033 |
1038 TEST(HttpCache, SimpleGETNoDiskCache) { | 1034 TEST(HttpCache, SimpleGETNoDiskCache) { |
1039 MockHttpCache cache; | 1035 MockHttpCache cache; |
1040 | 1036 |
1041 cache.disk_cache()->set_fail_requests(); | 1037 cache.disk_cache()->set_fail_requests(); |
1042 | 1038 |
1043 net::CapturingBoundNetLog log(net::CapturingNetLog::kUnbounded); | 1039 net::CapturingBoundNetLog log(net::CapturingNetLog::kUnbounded); |
1044 log.SetLogLevel(net::NetLog::LOG_BASIC); | |
1045 | 1040 |
1046 // Read from the network, and don't use the cache. | 1041 // Read from the network, and don't use the cache. |
1047 RunTransactionTestWithLog(cache.http_cache(), kSimpleGET_Transaction, | 1042 RunTransactionTestWithLog(cache.http_cache(), kSimpleGET_Transaction, |
1048 log.bound()); | 1043 log.bound()); |
1049 | 1044 |
1050 // Check that the NetLog was filled as expected. | 1045 // Check that the NetLog was filled as expected. |
1051 // (We attempted to both Open and Create entries, but both failed). | 1046 // (We attempted to both Open and Create entries, but both failed). |
1052 net::CapturingNetLog::EntryList entries; | 1047 net::CapturingNetLog::EntryList entries; |
1053 log.GetEntries(&entries); | 1048 log.GetEntries(&entries); |
1054 | 1049 |
1055 EXPECT_EQ(6u, entries.size()); | 1050 EXPECT_EQ(6u, entries.size()); |
1056 EXPECT_TRUE(net::LogContainsBeginEvent( | 1051 EXPECT_TRUE(net::LogContainsBeginEvent( |
1057 entries, 0, net::NetLog::TYPE_HTTP_CACHE_GET_BACKEND)); | 1052 entries, 0, net::NetLog::TYPE_HTTP_CACHE_WAITING)); |
1058 EXPECT_TRUE(net::LogContainsEndEvent( | 1053 EXPECT_TRUE(net::LogContainsEndEvent( |
1059 entries, 1, net::NetLog::TYPE_HTTP_CACHE_GET_BACKEND)); | 1054 entries, 1, net::NetLog::TYPE_HTTP_CACHE_WAITING)); |
1060 EXPECT_TRUE(net::LogContainsBeginEvent( | 1055 EXPECT_TRUE(net::LogContainsBeginEvent( |
1061 entries, 2, net::NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY)); | 1056 entries, 2, net::NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY)); |
1062 EXPECT_TRUE(net::LogContainsEndEvent( | 1057 EXPECT_TRUE(net::LogContainsEndEvent( |
1063 entries, 3, net::NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY)); | 1058 entries, 3, net::NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY)); |
1064 EXPECT_TRUE(net::LogContainsBeginEvent( | 1059 EXPECT_TRUE(net::LogContainsBeginEvent( |
1065 entries, 4, net::NetLog::TYPE_HTTP_CACHE_CREATE_ENTRY)); | 1060 entries, 4, net::NetLog::TYPE_HTTP_CACHE_CREATE_ENTRY)); |
1066 EXPECT_TRUE(net::LogContainsEndEvent( | 1061 EXPECT_TRUE(net::LogContainsEndEvent( |
1067 entries, 5, net::NetLog::TYPE_HTTP_CACHE_CREATE_ENTRY)); | 1062 entries, 5, net::NetLog::TYPE_HTTP_CACHE_CREATE_ENTRY)); |
1068 | 1063 |
1069 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 1064 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1141 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 1136 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
1142 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 1137 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
1143 EXPECT_EQ(2, cache.disk_cache()->create_count()); | 1138 EXPECT_EQ(2, cache.disk_cache()->create_count()); |
1144 } | 1139 } |
1145 | 1140 |
1146 TEST(HttpCache, SimpleGET_LoadOnlyFromCache_Hit) { | 1141 TEST(HttpCache, SimpleGET_LoadOnlyFromCache_Hit) { |
1147 MockHttpCache cache; | 1142 MockHttpCache cache; |
1148 | 1143 |
1149 net::CapturingBoundNetLog log(net::CapturingNetLog::kUnbounded); | 1144 net::CapturingBoundNetLog log(net::CapturingNetLog::kUnbounded); |
1150 | 1145 |
1151 // This prevents a number of write events from being logged. | |
1152 log.SetLogLevel(net::NetLog::LOG_BASIC); | |
1153 | |
1154 // write to the cache | 1146 // write to the cache |
1155 RunTransactionTestWithLog(cache.http_cache(), kSimpleGET_Transaction, | 1147 RunTransactionTestWithLog(cache.http_cache(), kSimpleGET_Transaction, |
1156 log.bound()); | 1148 log.bound()); |
1157 | 1149 |
1158 // Check that the NetLog was filled as expected. | 1150 // Check that the NetLog was filled as expected. |
1159 net::CapturingNetLog::EntryList entries; | 1151 net::CapturingNetLog::EntryList entries; |
1160 log.GetEntries(&entries); | 1152 log.GetEntries(&entries); |
1161 | 1153 |
1162 EXPECT_EQ(8u, entries.size()); | 1154 EXPECT_EQ(8u, entries.size()); |
1163 EXPECT_TRUE(net::LogContainsBeginEvent( | 1155 EXPECT_TRUE(net::LogContainsBeginEvent( |
1164 entries, 0, net::NetLog::TYPE_HTTP_CACHE_GET_BACKEND)); | 1156 entries, 0, net::NetLog::TYPE_HTTP_CACHE_WAITING)); |
1165 EXPECT_TRUE(net::LogContainsEndEvent( | 1157 EXPECT_TRUE(net::LogContainsEndEvent( |
1166 entries, 1, net::NetLog::TYPE_HTTP_CACHE_GET_BACKEND)); | 1158 entries, 1, net::NetLog::TYPE_HTTP_CACHE_WAITING)); |
1167 EXPECT_TRUE(net::LogContainsBeginEvent( | 1159 EXPECT_TRUE(net::LogContainsBeginEvent( |
1168 entries, 2, net::NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY)); | 1160 entries, 2, net::NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY)); |
1169 EXPECT_TRUE(net::LogContainsEndEvent( | 1161 EXPECT_TRUE(net::LogContainsEndEvent( |
1170 entries, 3, net::NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY)); | 1162 entries, 3, net::NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY)); |
1171 EXPECT_TRUE(net::LogContainsBeginEvent( | 1163 EXPECT_TRUE(net::LogContainsBeginEvent( |
1172 entries, 4, net::NetLog::TYPE_HTTP_CACHE_CREATE_ENTRY)); | 1164 entries, 4, net::NetLog::TYPE_HTTP_CACHE_CREATE_ENTRY)); |
1173 EXPECT_TRUE(net::LogContainsEndEvent( | 1165 EXPECT_TRUE(net::LogContainsEndEvent( |
1174 entries, 5, net::NetLog::TYPE_HTTP_CACHE_CREATE_ENTRY)); | 1166 entries, 5, net::NetLog::TYPE_HTTP_CACHE_CREATE_ENTRY)); |
1175 EXPECT_TRUE(net::LogContainsBeginEvent( | 1167 EXPECT_TRUE(net::LogContainsBeginEvent( |
1176 entries, 6, net::NetLog::TYPE_HTTP_CACHE_ADD_TO_ENTRY)); | 1168 entries, 6, net::NetLog::TYPE_HTTP_CACHE_WAITING)); |
1177 EXPECT_TRUE(net::LogContainsEndEvent( | 1169 EXPECT_TRUE(net::LogContainsEndEvent( |
1178 entries, 7, net::NetLog::TYPE_HTTP_CACHE_ADD_TO_ENTRY)); | 1170 entries, 7, net::NetLog::TYPE_HTTP_CACHE_WAITING)); |
1179 | 1171 |
1180 // force this transaction to read from the cache | 1172 // force this transaction to read from the cache |
1181 MockTransaction transaction(kSimpleGET_Transaction); | 1173 MockTransaction transaction(kSimpleGET_Transaction); |
1182 transaction.load_flags |= net::LOAD_ONLY_FROM_CACHE; | 1174 transaction.load_flags |= net::LOAD_ONLY_FROM_CACHE; |
1183 | 1175 |
1184 log.Clear(); | 1176 log.Clear(); |
1185 | 1177 |
1186 RunTransactionTestWithLog(cache.http_cache(), transaction, log.bound()); | 1178 RunTransactionTestWithLog(cache.http_cache(), transaction, log.bound()); |
1187 | 1179 |
1188 // Check that the NetLog was filled as expected. | 1180 // Check that the NetLog was filled as expected. |
1189 log.GetEntries(&entries); | 1181 log.GetEntries(&entries); |
1190 | 1182 |
1191 EXPECT_EQ(8u, entries.size()); | 1183 EXPECT_EQ(8u, entries.size()); |
1192 EXPECT_TRUE(net::LogContainsBeginEvent( | 1184 EXPECT_TRUE(net::LogContainsBeginEvent( |
1193 entries, 0, net::NetLog::TYPE_HTTP_CACHE_GET_BACKEND)); | 1185 entries, 0, net::NetLog::TYPE_HTTP_CACHE_WAITING)); |
1194 EXPECT_TRUE(net::LogContainsEndEvent( | 1186 EXPECT_TRUE(net::LogContainsEndEvent( |
1195 entries, 1, net::NetLog::TYPE_HTTP_CACHE_GET_BACKEND)); | 1187 entries, 1, net::NetLog::TYPE_HTTP_CACHE_WAITING)); |
1196 EXPECT_TRUE(net::LogContainsBeginEvent( | 1188 EXPECT_TRUE(net::LogContainsBeginEvent( |
1197 entries, 2, net::NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY)); | 1189 entries, 2, net::NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY)); |
1198 EXPECT_TRUE(net::LogContainsEndEvent( | 1190 EXPECT_TRUE(net::LogContainsEndEvent( |
1199 entries, 3, net::NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY)); | 1191 entries, 3, net::NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY)); |
1200 EXPECT_TRUE(net::LogContainsBeginEvent( | 1192 EXPECT_TRUE(net::LogContainsBeginEvent( |
1201 entries, 4, net::NetLog::TYPE_HTTP_CACHE_ADD_TO_ENTRY)); | 1193 entries, 4, net::NetLog::TYPE_HTTP_CACHE_WAITING)); |
1202 EXPECT_TRUE(net::LogContainsEndEvent( | 1194 EXPECT_TRUE(net::LogContainsEndEvent( |
1203 entries, 5, net::NetLog::TYPE_HTTP_CACHE_ADD_TO_ENTRY)); | 1195 entries, 5, net::NetLog::TYPE_HTTP_CACHE_WAITING)); |
1204 EXPECT_TRUE(net::LogContainsBeginEvent( | 1196 EXPECT_TRUE(net::LogContainsBeginEvent( |
1205 entries, 6, net::NetLog::TYPE_HTTP_CACHE_READ_INFO)); | 1197 entries, 6, net::NetLog::TYPE_HTTP_CACHE_READ_INFO)); |
1206 EXPECT_TRUE(net::LogContainsEndEvent( | 1198 EXPECT_TRUE(net::LogContainsEndEvent( |
1207 entries, 7, net::NetLog::TYPE_HTTP_CACHE_READ_INFO)); | 1199 entries, 7, net::NetLog::TYPE_HTTP_CACHE_READ_INFO)); |
1208 | 1200 |
1209 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 1201 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
1210 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 1202 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
1211 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 1203 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
1212 } | 1204 } |
1213 | 1205 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1274 | 1266 |
1275 // Write to the cache. | 1267 // Write to the cache. |
1276 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); | 1268 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); |
1277 | 1269 |
1278 // Force this transaction to write to the cache again. | 1270 // Force this transaction to write to the cache again. |
1279 MockTransaction transaction(kSimpleGET_Transaction); | 1271 MockTransaction transaction(kSimpleGET_Transaction); |
1280 transaction.load_flags |= net::LOAD_BYPASS_CACHE; | 1272 transaction.load_flags |= net::LOAD_BYPASS_CACHE; |
1281 | 1273 |
1282 net::CapturingBoundNetLog log(net::CapturingNetLog::kUnbounded); | 1274 net::CapturingBoundNetLog log(net::CapturingNetLog::kUnbounded); |
1283 | 1275 |
1284 // This prevents a number of write events from being logged. | |
1285 log.SetLogLevel(net::NetLog::LOG_BASIC); | |
1286 | |
1287 RunTransactionTestWithLog(cache.http_cache(), transaction, log.bound()); | 1276 RunTransactionTestWithLog(cache.http_cache(), transaction, log.bound()); |
1288 | 1277 |
1289 // Check that the NetLog was filled as expected. | 1278 // Check that the NetLog was filled as expected. |
1290 net::CapturingNetLog::EntryList entries; | 1279 net::CapturingNetLog::EntryList entries; |
1291 log.GetEntries(&entries); | 1280 log.GetEntries(&entries); |
1292 | 1281 |
1293 EXPECT_EQ(8u, entries.size()); | 1282 EXPECT_EQ(8u, entries.size()); |
1294 EXPECT_TRUE(net::LogContainsBeginEvent( | 1283 EXPECT_TRUE(net::LogContainsBeginEvent( |
1295 entries, 0, net::NetLog::TYPE_HTTP_CACHE_GET_BACKEND)); | 1284 entries, 0, net::NetLog::TYPE_HTTP_CACHE_WAITING)); |
1296 EXPECT_TRUE(net::LogContainsEndEvent( | 1285 EXPECT_TRUE(net::LogContainsEndEvent( |
1297 entries, 1, net::NetLog::TYPE_HTTP_CACHE_GET_BACKEND)); | 1286 entries, 1, net::NetLog::TYPE_HTTP_CACHE_WAITING)); |
1298 EXPECT_TRUE(net::LogContainsBeginEvent( | 1287 EXPECT_TRUE(net::LogContainsBeginEvent( |
1299 entries, 2, net::NetLog::TYPE_HTTP_CACHE_DOOM_ENTRY)); | 1288 entries, 2, net::NetLog::TYPE_HTTP_CACHE_DOOM_ENTRY)); |
1300 EXPECT_TRUE(net::LogContainsEndEvent( | 1289 EXPECT_TRUE(net::LogContainsEndEvent( |
1301 entries, 3, net::NetLog::TYPE_HTTP_CACHE_DOOM_ENTRY)); | 1290 entries, 3, net::NetLog::TYPE_HTTP_CACHE_DOOM_ENTRY)); |
1302 EXPECT_TRUE(net::LogContainsBeginEvent( | 1291 EXPECT_TRUE(net::LogContainsBeginEvent( |
1303 entries, 4, net::NetLog::TYPE_HTTP_CACHE_CREATE_ENTRY)); | 1292 entries, 4, net::NetLog::TYPE_HTTP_CACHE_CREATE_ENTRY)); |
1304 EXPECT_TRUE(net::LogContainsEndEvent( | 1293 EXPECT_TRUE(net::LogContainsEndEvent( |
1305 entries, 5, net::NetLog::TYPE_HTTP_CACHE_CREATE_ENTRY)); | 1294 entries, 5, net::NetLog::TYPE_HTTP_CACHE_CREATE_ENTRY)); |
1306 EXPECT_TRUE(net::LogContainsBeginEvent( | 1295 EXPECT_TRUE(net::LogContainsBeginEvent( |
1307 entries, 6, net::NetLog::TYPE_HTTP_CACHE_ADD_TO_ENTRY)); | 1296 entries, 6, net::NetLog::TYPE_HTTP_CACHE_WAITING)); |
1308 EXPECT_TRUE(net::LogContainsEndEvent( | 1297 EXPECT_TRUE(net::LogContainsEndEvent( |
1309 entries, 7, net::NetLog::TYPE_HTTP_CACHE_ADD_TO_ENTRY)); | 1298 entries, 7, net::NetLog::TYPE_HTTP_CACHE_WAITING)); |
1310 | 1299 |
1311 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 1300 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
1312 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 1301 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
1313 EXPECT_EQ(2, cache.disk_cache()->create_count()); | 1302 EXPECT_EQ(2, cache.disk_cache()->create_count()); |
1314 } | 1303 } |
1315 | 1304 |
1316 TEST(HttpCache, SimpleGET_LoadBypassCache_Implicit) { | 1305 TEST(HttpCache, SimpleGET_LoadBypassCache_Implicit) { |
1317 MockHttpCache cache; | 1306 MockHttpCache cache; |
1318 | 1307 |
1319 // write to the cache | 1308 // write to the cache |
(...skipping 1986 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3306 | 3295 |
3307 RemoveMockTransaction(&transaction); | 3296 RemoveMockTransaction(&transaction); |
3308 } | 3297 } |
3309 | 3298 |
3310 // Tests that we can handle cached 206 responses that are not sparse. | 3299 // Tests that we can handle cached 206 responses that are not sparse. |
3311 TEST(HttpCache, GET_Previous206_NotSparse) { | 3300 TEST(HttpCache, GET_Previous206_NotSparse) { |
3312 MockHttpCache cache; | 3301 MockHttpCache cache; |
3313 | 3302 |
3314 // Create a disk cache entry that stores 206 headers while not being sparse. | 3303 // Create a disk cache entry that stores 206 headers while not being sparse. |
3315 disk_cache::Entry* entry; | 3304 disk_cache::Entry* entry; |
3316 ASSERT_TRUE(cache.CreateBackendEntry(kSimpleGET_Transaction.url, &entry, | 3305 ASSERT_TRUE(cache.CreateBackendEntry(kSimpleGET_Transaction.url, &entry)); |
3317 NULL)); | |
3318 | 3306 |
3319 std::string raw_headers(kRangeGET_TransactionOK.status); | 3307 std::string raw_headers(kRangeGET_TransactionOK.status); |
3320 raw_headers.append("\n"); | 3308 raw_headers.append("\n"); |
3321 raw_headers.append(kRangeGET_TransactionOK.response_headers); | 3309 raw_headers.append(kRangeGET_TransactionOK.response_headers); |
3322 raw_headers = net::HttpUtil::AssembleRawHeaders(raw_headers.data(), | 3310 raw_headers = net::HttpUtil::AssembleRawHeaders(raw_headers.data(), |
3323 raw_headers.size()); | 3311 raw_headers.size()); |
3324 | 3312 |
3325 net::HttpResponseInfo response; | 3313 net::HttpResponseInfo response; |
3326 response.headers = new net::HttpResponseHeaders(raw_headers); | 3314 response.headers = new net::HttpResponseHeaders(raw_headers); |
3327 EXPECT_TRUE(MockHttpCache::WriteResponseInfo(entry, &response, true, false)); | 3315 EXPECT_TRUE(MockHttpCache::WriteResponseInfo(entry, &response, true, false)); |
(...skipping 22 matching lines...) Expand all Loading... |
3350 } | 3338 } |
3351 | 3339 |
3352 // Tests that we can handle cached 206 responses that are not sparse. This time | 3340 // Tests that we can handle cached 206 responses that are not sparse. This time |
3353 // we issue a range request and expect to receive a range. | 3341 // we issue a range request and expect to receive a range. |
3354 TEST(HttpCache, RangeGET_Previous206_NotSparse_2) { | 3342 TEST(HttpCache, RangeGET_Previous206_NotSparse_2) { |
3355 MockHttpCache cache; | 3343 MockHttpCache cache; |
3356 AddMockTransaction(&kRangeGET_TransactionOK); | 3344 AddMockTransaction(&kRangeGET_TransactionOK); |
3357 | 3345 |
3358 // Create a disk cache entry that stores 206 headers while not being sparse. | 3346 // Create a disk cache entry that stores 206 headers while not being sparse. |
3359 disk_cache::Entry* entry; | 3347 disk_cache::Entry* entry; |
3360 ASSERT_TRUE(cache.CreateBackendEntry(kRangeGET_TransactionOK.url, &entry, | 3348 ASSERT_TRUE(cache.CreateBackendEntry(kRangeGET_TransactionOK.url, &entry)); |
3361 NULL)); | |
3362 | 3349 |
3363 std::string raw_headers(kRangeGET_TransactionOK.status); | 3350 std::string raw_headers(kRangeGET_TransactionOK.status); |
3364 raw_headers.append("\n"); | 3351 raw_headers.append("\n"); |
3365 raw_headers.append(kRangeGET_TransactionOK.response_headers); | 3352 raw_headers.append(kRangeGET_TransactionOK.response_headers); |
3366 raw_headers = net::HttpUtil::AssembleRawHeaders(raw_headers.data(), | 3353 raw_headers = net::HttpUtil::AssembleRawHeaders(raw_headers.data(), |
3367 raw_headers.size()); | 3354 raw_headers.size()); |
3368 | 3355 |
3369 net::HttpResponseInfo response; | 3356 net::HttpResponseInfo response; |
3370 response.headers = new net::HttpResponseHeaders(raw_headers); | 3357 response.headers = new net::HttpResponseHeaders(raw_headers); |
3371 EXPECT_TRUE(MockHttpCache::WriteResponseInfo(entry, &response, true, false)); | 3358 EXPECT_TRUE(MockHttpCache::WriteResponseInfo(entry, &response, true, false)); |
(...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3949 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 3936 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
3950 | 3937 |
3951 RemoveMockTransaction(&kRangeGET_TransactionOK); | 3938 RemoveMockTransaction(&kRangeGET_TransactionOK); |
3952 } | 3939 } |
3953 #endif | 3940 #endif |
3954 | 3941 |
3955 // Tests the handling of the "truncation" flag. | 3942 // Tests the handling of the "truncation" flag. |
3956 TEST(HttpCache, WriteResponseInfo_Truncated) { | 3943 TEST(HttpCache, WriteResponseInfo_Truncated) { |
3957 MockHttpCache cache; | 3944 MockHttpCache cache; |
3958 disk_cache::Entry* entry; | 3945 disk_cache::Entry* entry; |
3959 ASSERT_TRUE(cache.CreateBackendEntry("http://www.google.com", &entry, | 3946 ASSERT_TRUE(cache.CreateBackendEntry("http://www.google.com", &entry)); |
3960 NULL)); | |
3961 | 3947 |
3962 std::string headers("HTTP/1.1 200 OK"); | 3948 std::string headers("HTTP/1.1 200 OK"); |
3963 headers = net::HttpUtil::AssembleRawHeaders(headers.data(), headers.size()); | 3949 headers = net::HttpUtil::AssembleRawHeaders(headers.data(), headers.size()); |
3964 net::HttpResponseInfo response; | 3950 net::HttpResponseInfo response; |
3965 response.headers = new net::HttpResponseHeaders(headers); | 3951 response.headers = new net::HttpResponseHeaders(headers); |
3966 | 3952 |
3967 // Set the last argument for this to be an incomplete request. | 3953 // Set the last argument for this to be an incomplete request. |
3968 EXPECT_TRUE(MockHttpCache::WriteResponseInfo(entry, &response, true, true)); | 3954 EXPECT_TRUE(MockHttpCache::WriteResponseInfo(entry, &response, true, true)); |
3969 bool truncated = false; | 3955 bool truncated = false; |
3970 EXPECT_TRUE(MockHttpCache::ReadResponseInfo(entry, &response, &truncated)); | 3956 EXPECT_TRUE(MockHttpCache::ReadResponseInfo(entry, &response, &truncated)); |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4149 RemoveMockTransaction(&transaction); | 4135 RemoveMockTransaction(&transaction); |
4150 } | 4136 } |
4151 | 4137 |
4152 // Tests that we can continue with a request that was interrupted. | 4138 // Tests that we can continue with a request that was interrupted. |
4153 TEST(HttpCache, GET_IncompleteResource) { | 4139 TEST(HttpCache, GET_IncompleteResource) { |
4154 MockHttpCache cache; | 4140 MockHttpCache cache; |
4155 AddMockTransaction(&kRangeGET_TransactionOK); | 4141 AddMockTransaction(&kRangeGET_TransactionOK); |
4156 | 4142 |
4157 // Create a disk cache entry that stores an incomplete resource. | 4143 // Create a disk cache entry that stores an incomplete resource. |
4158 disk_cache::Entry* entry; | 4144 disk_cache::Entry* entry; |
4159 ASSERT_TRUE(cache.CreateBackendEntry(kRangeGET_TransactionOK.url, &entry, | 4145 ASSERT_TRUE(cache.CreateBackendEntry(kRangeGET_TransactionOK.url, &entry)); |
4160 NULL)); | |
4161 | 4146 |
4162 std::string raw_headers("HTTP/1.1 200 OK\n" | 4147 std::string raw_headers("HTTP/1.1 200 OK\n" |
4163 "Last-Modified: Sat, 18 Apr 2009 01:10:43 GMT\n" | 4148 "Last-Modified: Sat, 18 Apr 2009 01:10:43 GMT\n" |
4164 "ETag: \"foo\"\n" | 4149 "ETag: \"foo\"\n" |
4165 "Accept-Ranges: bytes\n" | 4150 "Accept-Ranges: bytes\n" |
4166 "Content-Length: 80\n"); | 4151 "Content-Length: 80\n"); |
4167 raw_headers = net::HttpUtil::AssembleRawHeaders(raw_headers.data(), | 4152 raw_headers = net::HttpUtil::AssembleRawHeaders(raw_headers.data(), |
4168 raw_headers.size()); | 4153 raw_headers.size()); |
4169 | 4154 |
4170 net::HttpResponseInfo response; | 4155 net::HttpResponseInfo response; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4210 entry->Close(); | 4195 entry->Close(); |
4211 } | 4196 } |
4212 | 4197 |
4213 // Tests that we delete truncated entries if the server changes its mind midway. | 4198 // Tests that we delete truncated entries if the server changes its mind midway. |
4214 TEST(HttpCache, GET_IncompleteResource2) { | 4199 TEST(HttpCache, GET_IncompleteResource2) { |
4215 MockHttpCache cache; | 4200 MockHttpCache cache; |
4216 AddMockTransaction(&kRangeGET_TransactionOK); | 4201 AddMockTransaction(&kRangeGET_TransactionOK); |
4217 | 4202 |
4218 // Create a disk cache entry that stores an incomplete resource. | 4203 // Create a disk cache entry that stores an incomplete resource. |
4219 disk_cache::Entry* entry; | 4204 disk_cache::Entry* entry; |
4220 ASSERT_TRUE(cache.CreateBackendEntry(kRangeGET_TransactionOK.url, &entry, | 4205 ASSERT_TRUE(cache.CreateBackendEntry(kRangeGET_TransactionOK.url, &entry)); |
4221 NULL)); | |
4222 | 4206 |
4223 | 4207 |
4224 // Content-length will be intentionally bad. | 4208 // Content-length will be intentionally bad. |
4225 std::string raw_headers("HTTP/1.1 200 OK\n" | 4209 std::string raw_headers("HTTP/1.1 200 OK\n" |
4226 "Last-Modified: Sat, 18 Apr 2009 01:10:43 GMT\n" | 4210 "Last-Modified: Sat, 18 Apr 2009 01:10:43 GMT\n" |
4227 "ETag: \"foo\"\n" | 4211 "ETag: \"foo\"\n" |
4228 "Accept-Ranges: bytes\n" | 4212 "Accept-Ranges: bytes\n" |
4229 "Content-Length: 50\n"); | 4213 "Content-Length: 50\n"); |
4230 raw_headers = net::HttpUtil::AssembleRawHeaders(raw_headers.data(), | 4214 raw_headers = net::HttpUtil::AssembleRawHeaders(raw_headers.data(), |
4231 raw_headers.size()); | 4215 raw_headers.size()); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4270 } | 4254 } |
4271 | 4255 |
4272 // Tests that when we cancel a request that was interrupted, we mark it again | 4256 // Tests that when we cancel a request that was interrupted, we mark it again |
4273 // as truncated. | 4257 // as truncated. |
4274 TEST(HttpCache, GET_CancelIncompleteResource) { | 4258 TEST(HttpCache, GET_CancelIncompleteResource) { |
4275 MockHttpCache cache; | 4259 MockHttpCache cache; |
4276 AddMockTransaction(&kRangeGET_TransactionOK); | 4260 AddMockTransaction(&kRangeGET_TransactionOK); |
4277 | 4261 |
4278 // Create a disk cache entry that stores an incomplete resource. | 4262 // Create a disk cache entry that stores an incomplete resource. |
4279 disk_cache::Entry* entry; | 4263 disk_cache::Entry* entry; |
4280 ASSERT_TRUE(cache.CreateBackendEntry(kRangeGET_TransactionOK.url, &entry, | 4264 ASSERT_TRUE(cache.CreateBackendEntry(kRangeGET_TransactionOK.url, &entry)); |
4281 NULL)); | |
4282 | 4265 |
4283 std::string raw_headers("HTTP/1.1 200 OK\n" | 4266 std::string raw_headers("HTTP/1.1 200 OK\n" |
4284 "Last-Modified: Sat, 18 Apr 2009 01:10:43 GMT\n" | 4267 "Last-Modified: Sat, 18 Apr 2009 01:10:43 GMT\n" |
4285 "ETag: \"foo\"\n" | 4268 "ETag: \"foo\"\n" |
4286 "Accept-Ranges: bytes\n" | 4269 "Accept-Ranges: bytes\n" |
4287 "Content-Length: 80\n"); | 4270 "Content-Length: 80\n"); |
4288 raw_headers = net::HttpUtil::AssembleRawHeaders(raw_headers.data(), | 4271 raw_headers = net::HttpUtil::AssembleRawHeaders(raw_headers.data(), |
4289 raw_headers.size()); | 4272 raw_headers.size()); |
4290 | 4273 |
4291 net::HttpResponseInfo response; | 4274 net::HttpResponseInfo response; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4336 entry->Close(); | 4319 entry->Close(); |
4337 } | 4320 } |
4338 | 4321 |
4339 // Tests that we can handle range requests when we have a truncated entry. | 4322 // Tests that we can handle range requests when we have a truncated entry. |
4340 TEST(HttpCache, RangeGET_IncompleteResource) { | 4323 TEST(HttpCache, RangeGET_IncompleteResource) { |
4341 MockHttpCache cache; | 4324 MockHttpCache cache; |
4342 AddMockTransaction(&kRangeGET_TransactionOK); | 4325 AddMockTransaction(&kRangeGET_TransactionOK); |
4343 | 4326 |
4344 // Create a disk cache entry that stores an incomplete resource. | 4327 // Create a disk cache entry that stores an incomplete resource. |
4345 disk_cache::Entry* entry; | 4328 disk_cache::Entry* entry; |
4346 ASSERT_TRUE(cache.CreateBackendEntry(kRangeGET_TransactionOK.url, &entry, | 4329 ASSERT_TRUE(cache.CreateBackendEntry(kRangeGET_TransactionOK.url, &entry)); |
4347 NULL)); | |
4348 | 4330 |
4349 // Content-length will be intentionally bogus. | 4331 // Content-length will be intentionally bogus. |
4350 std::string raw_headers("HTTP/1.1 200 OK\n" | 4332 std::string raw_headers("HTTP/1.1 200 OK\n" |
4351 "Last-Modified: something\n" | 4333 "Last-Modified: something\n" |
4352 "ETag: \"foo\"\n" | 4334 "ETag: \"foo\"\n" |
4353 "Accept-Ranges: bytes\n" | 4335 "Accept-Ranges: bytes\n" |
4354 "Content-Length: 10\n"); | 4336 "Content-Length: 10\n"); |
4355 raw_headers = net::HttpUtil::AssembleRawHeaders(raw_headers.data(), | 4337 raw_headers = net::HttpUtil::AssembleRawHeaders(raw_headers.data(), |
4356 raw_headers.size()); | 4338 raw_headers.size()); |
4357 | 4339 |
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4840 // Now return 200 when validating the entry so the metadata will be lost. | 4822 // Now return 200 when validating the entry so the metadata will be lost. |
4841 MockTransaction trans2(kTypicalGET_Transaction); | 4823 MockTransaction trans2(kTypicalGET_Transaction); |
4842 trans2.load_flags = net::LOAD_VALIDATE_CACHE; | 4824 trans2.load_flags = net::LOAD_VALIDATE_CACHE; |
4843 RunTransactionTestWithResponseInfo(cache.http_cache(), trans2, &response); | 4825 RunTransactionTestWithResponseInfo(cache.http_cache(), trans2, &response); |
4844 EXPECT_TRUE(response.metadata.get() == NULL); | 4826 EXPECT_TRUE(response.metadata.get() == NULL); |
4845 | 4827 |
4846 EXPECT_EQ(3, cache.network_layer()->transaction_count()); | 4828 EXPECT_EQ(3, cache.network_layer()->transaction_count()); |
4847 EXPECT_EQ(4, cache.disk_cache()->open_count()); | 4829 EXPECT_EQ(4, cache.disk_cache()->open_count()); |
4848 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 4830 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
4849 } | 4831 } |
OLD | NEW |