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