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

Side by Side Diff: content/browser/appcache/appcache_storage_impl_unittest.cc

Issue 344493002: Move all remaining appcache-related code to content namespace (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <stack> 5 #include <stack>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
11 #include "base/files/scoped_temp_dir.h" 11 #include "base/files/scoped_temp_dir.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/message_loop/message_loop.h" 13 #include "base/message_loop/message_loop.h"
14 #include "base/synchronization/waitable_event.h" 14 #include "base/synchronization/waitable_event.h"
15 #include "base/threading/thread.h" 15 #include "base/threading/thread.h"
16 #include "content/browser/appcache/appcache.h"
17 #include "content/browser/appcache/appcache_backend_impl.h"
18 #include "content/browser/appcache/appcache_database.h"
19 #include "content/browser/appcache/appcache_entry.h"
20 #include "content/browser/appcache/appcache_group.h"
21 #include "content/browser/appcache/appcache_host.h"
16 #include "content/browser/appcache/appcache_interceptor.h" 22 #include "content/browser/appcache/appcache_interceptor.h"
23 #include "content/browser/appcache/appcache_request_handler.h"
24 #include "content/browser/appcache/appcache_service_impl.h"
25 #include "content/browser/appcache/appcache_storage_impl.h"
17 #include "net/base/net_errors.h" 26 #include "net/base/net_errors.h"
18 #include "net/base/request_priority.h" 27 #include "net/base/request_priority.h"
19 #include "net/http/http_response_headers.h" 28 #include "net/http/http_response_headers.h"
20 #include "net/url_request/url_request_error_job.h" 29 #include "net/url_request/url_request_error_job.h"
21 #include "net/url_request/url_request_job_factory_impl.h" 30 #include "net/url_request/url_request_job_factory_impl.h"
22 #include "net/url_request/url_request_test_job.h" 31 #include "net/url_request/url_request_test_job.h"
23 #include "net/url_request/url_request_test_util.h" 32 #include "net/url_request/url_request_test_util.h"
24 #include "sql/test/test_helpers.h" 33 #include "sql/test/test_helpers.h"
25 #include "testing/gtest/include/gtest/gtest.h" 34 #include "testing/gtest/include/gtest/gtest.h"
26 #include "webkit/browser/appcache/appcache.h"
27 #include "webkit/browser/appcache/appcache_backend_impl.h"
28 #include "webkit/browser/appcache/appcache_database.h"
29 #include "webkit/browser/appcache/appcache_entry.h"
30 #include "webkit/browser/appcache/appcache_group.h"
31 #include "webkit/browser/appcache/appcache_host.h"
32 #include "webkit/browser/appcache/appcache_request_handler.h"
33 #include "webkit/browser/appcache/appcache_service_impl.h"
34 #include "webkit/browser/appcache/appcache_storage_impl.h"
35 #include "webkit/browser/quota/quota_manager.h" 35 #include "webkit/browser/quota/quota_manager.h"
36 36
37 using appcache::APPCACHE_FALLBACK_NAMESPACE;
38 using appcache::APPCACHE_NETWORK_NAMESPACE;
39 using appcache::AppCacheBackendImpl;
40 using appcache::AppCacheDatabase;
41 using appcache::AppCacheEntry;
42 using appcache::AppCacheFrontend;
43 using appcache::AppCacheHost;
44 using appcache::AppCacheInfo;
45 using appcache::AppCacheGroup;
46 using appcache::AppCacheServiceImpl;
47 using appcache::AppCacheStorage;
48 using appcache::AppCacheStorageImpl;
49 using appcache::AppCacheStorageReference;
50 using appcache::AppCache;
51 using appcache::AppCacheErrorDetails;
52 using appcache::AppCacheEventID;
53 using appcache::kAppCacheNoCacheId;
54 using appcache::kAppCacheNoResponseId;
55 using appcache::APPCACHE_INTERCEPT_NAMESPACE;
56 using appcache::AppCacheLogLevel;
57 using appcache::Namespace;
58 using appcache::AppCacheStatus;
59
60 namespace content { 37 namespace content {
61 38
62 namespace { 39 namespace {
63 40
64 const base::Time kZeroTime; 41 const base::Time kZeroTime;
65 const GURL kManifestUrl("http://blah/manifest"); 42 const GURL kManifestUrl("http://blah/manifest");
66 const GURL kManifestUrl2("http://blah/manifest2"); 43 const GURL kManifestUrl2("http://blah/manifest2");
67 const GURL kManifestUrl3("http://blah/manifest3"); 44 const GURL kManifestUrl3("http://blah/manifest3");
68 const GURL kEntryUrl("http://blah/entry"); 45 const GURL kEntryUrl("http://blah/entry");
69 const GURL kEntryUrl2("http://blah/entry2"); 46 const GURL kEntryUrl2("http://blah/entry2");
(...skipping 977 matching lines...) Expand 10 before | Expand all | Expand 10 after
1047 PushNextTask(base::Bind( 1024 PushNextTask(base::Bind(
1048 &AppCacheStorageImplTest::Verify_BasicFindMainFallbackResponse, 1025 &AppCacheStorageImplTest::Verify_BasicFindMainFallbackResponse,
1049 base::Unretained(this))); 1026 base::Unretained(this)));
1050 1027
1051 // Setup some preconditions. Create a complete cache with a 1028 // Setup some preconditions. Create a complete cache with a
1052 // fallback namespace and entry. 1029 // fallback namespace and entry.
1053 MakeCacheAndGroup(kManifestUrl, 2, 1, true); 1030 MakeCacheAndGroup(kManifestUrl, 2, 1, true);
1054 cache_->AddEntry(kEntryUrl, AppCacheEntry(AppCacheEntry::FALLBACK, 1)); 1031 cache_->AddEntry(kEntryUrl, AppCacheEntry(AppCacheEntry::FALLBACK, 1));
1055 cache_->AddEntry(kEntryUrl2, AppCacheEntry(AppCacheEntry::FALLBACK, 2)); 1032 cache_->AddEntry(kEntryUrl2, AppCacheEntry(AppCacheEntry::FALLBACK, 2));
1056 cache_->fallback_namespaces_.push_back( 1033 cache_->fallback_namespaces_.push_back(
1057 Namespace(APPCACHE_FALLBACK_NAMESPACE, 1034 AppCacheNamespace(APPCACHE_FALLBACK_NAMESPACE,
1058 kFallbackNamespace2, 1035 kFallbackNamespace2,
1059 kEntryUrl2, 1036 kEntryUrl2,
1060 false)); 1037 false));
1061 cache_->fallback_namespaces_.push_back( 1038 cache_->fallback_namespaces_.push_back(
1062 Namespace(APPCACHE_FALLBACK_NAMESPACE, 1039 AppCacheNamespace(APPCACHE_FALLBACK_NAMESPACE,
1063 kFallbackNamespace, 1040 kFallbackNamespace,
1064 kEntryUrl, 1041 kEntryUrl,
1065 false)); 1042 false));
1066 AppCacheDatabase::CacheRecord cache_record; 1043 AppCacheDatabase::CacheRecord cache_record;
1067 std::vector<AppCacheDatabase::EntryRecord> entries; 1044 std::vector<AppCacheDatabase::EntryRecord> entries;
1068 std::vector<AppCacheDatabase::NamespaceRecord> intercepts; 1045 std::vector<AppCacheDatabase::NamespaceRecord> intercepts;
1069 std::vector<AppCacheDatabase::NamespaceRecord> fallbacks; 1046 std::vector<AppCacheDatabase::NamespaceRecord> fallbacks;
1070 std::vector<AppCacheDatabase::OnlineWhiteListRecord> whitelists; 1047 std::vector<AppCacheDatabase::OnlineWhiteListRecord> whitelists;
1071 cache_->ToDatabaseRecords(group_.get(), 1048 cache_->ToDatabaseRecords(group_.get(),
1072 &cache_record, 1049 &cache_record,
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1125 PushNextTask(base::Bind( 1102 PushNextTask(base::Bind(
1126 &AppCacheStorageImplTest::Verify_BasicFindMainInterceptResponse, 1103 &AppCacheStorageImplTest::Verify_BasicFindMainInterceptResponse,
1127 base::Unretained(this))); 1104 base::Unretained(this)));
1128 1105
1129 // Setup some preconditions. Create a complete cache with an 1106 // Setup some preconditions. Create a complete cache with an
1130 // intercept namespace and entry. 1107 // intercept namespace and entry.
1131 MakeCacheAndGroup(kManifestUrl, 2, 1, true); 1108 MakeCacheAndGroup(kManifestUrl, 2, 1, true);
1132 cache_->AddEntry(kEntryUrl, AppCacheEntry(AppCacheEntry::INTERCEPT, 1)); 1109 cache_->AddEntry(kEntryUrl, AppCacheEntry(AppCacheEntry::INTERCEPT, 1));
1133 cache_->AddEntry(kEntryUrl2, AppCacheEntry(AppCacheEntry::INTERCEPT, 2)); 1110 cache_->AddEntry(kEntryUrl2, AppCacheEntry(AppCacheEntry::INTERCEPT, 2));
1134 cache_->intercept_namespaces_.push_back( 1111 cache_->intercept_namespaces_.push_back(
1135 Namespace(APPCACHE_INTERCEPT_NAMESPACE, kInterceptNamespace2, 1112 AppCacheNamespace(APPCACHE_INTERCEPT_NAMESPACE, kInterceptNamespace2,
1136 kEntryUrl2, false)); 1113 kEntryUrl2, false));
1137 cache_->intercept_namespaces_.push_back( 1114 cache_->intercept_namespaces_.push_back(
1138 Namespace(APPCACHE_INTERCEPT_NAMESPACE, kInterceptNamespace, 1115 AppCacheNamespace(APPCACHE_INTERCEPT_NAMESPACE, kInterceptNamespace,
1139 kEntryUrl, false)); 1116 kEntryUrl, false));
1140 AppCacheDatabase::CacheRecord cache_record; 1117 AppCacheDatabase::CacheRecord cache_record;
1141 std::vector<AppCacheDatabase::EntryRecord> entries; 1118 std::vector<AppCacheDatabase::EntryRecord> entries;
1142 std::vector<AppCacheDatabase::NamespaceRecord> intercepts; 1119 std::vector<AppCacheDatabase::NamespaceRecord> intercepts;
1143 std::vector<AppCacheDatabase::NamespaceRecord> fallbacks; 1120 std::vector<AppCacheDatabase::NamespaceRecord> fallbacks;
1144 std::vector<AppCacheDatabase::OnlineWhiteListRecord> whitelists; 1121 std::vector<AppCacheDatabase::OnlineWhiteListRecord> whitelists;
1145 cache_->ToDatabaseRecords(group_.get(), 1122 cache_->ToDatabaseRecords(group_.get(),
1146 &cache_record, 1123 &cache_record,
1147 &entries, 1124 &entries,
1148 &intercepts, 1125 &intercepts,
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1195 void FindInterceptPatternMatchInWorkingSet() { 1172 void FindInterceptPatternMatchInWorkingSet() {
1196 FindInterceptPatternMatch(false); 1173 FindInterceptPatternMatch(false);
1197 } 1174 }
1198 1175
1199 void FindInterceptPatternMatch(bool drop_from_working_set) { 1176 void FindInterceptPatternMatch(bool drop_from_working_set) {
1200 // Setup some preconditions. Create a complete cache with an 1177 // Setup some preconditions. Create a complete cache with an
1201 // pattern matching intercept namespace and entry. 1178 // pattern matching intercept namespace and entry.
1202 MakeCacheAndGroup(kManifestUrl, 2, 1, true); 1179 MakeCacheAndGroup(kManifestUrl, 2, 1, true);
1203 cache_->AddEntry(kEntryUrl, AppCacheEntry(AppCacheEntry::INTERCEPT, 1)); 1180 cache_->AddEntry(kEntryUrl, AppCacheEntry(AppCacheEntry::INTERCEPT, 1));
1204 cache_->intercept_namespaces_.push_back( 1181 cache_->intercept_namespaces_.push_back(
1205 Namespace(APPCACHE_INTERCEPT_NAMESPACE, kInterceptPatternNamespace, 1182 AppCacheNamespace(APPCACHE_INTERCEPT_NAMESPACE,
1206 kEntryUrl, true)); 1183 kInterceptPatternNamespace, kEntryUrl, true));
1207 AppCacheDatabase::CacheRecord cache_record; 1184 AppCacheDatabase::CacheRecord cache_record;
1208 std::vector<AppCacheDatabase::EntryRecord> entries; 1185 std::vector<AppCacheDatabase::EntryRecord> entries;
1209 std::vector<AppCacheDatabase::NamespaceRecord> intercepts; 1186 std::vector<AppCacheDatabase::NamespaceRecord> intercepts;
1210 std::vector<AppCacheDatabase::NamespaceRecord> fallbacks; 1187 std::vector<AppCacheDatabase::NamespaceRecord> fallbacks;
1211 std::vector<AppCacheDatabase::OnlineWhiteListRecord> whitelists; 1188 std::vector<AppCacheDatabase::OnlineWhiteListRecord> whitelists;
1212 cache_->ToDatabaseRecords(group_.get(), 1189 cache_->ToDatabaseRecords(group_.get(),
1213 &cache_record, 1190 &cache_record,
1214 &entries, 1191 &entries,
1215 &intercepts, 1192 &intercepts,
1216 &fallbacks, 1193 &fallbacks,
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
1282 void FindFallbackPatternMatchInWorkingSet() { 1259 void FindFallbackPatternMatchInWorkingSet() {
1283 FindFallbackPatternMatch(false); 1260 FindFallbackPatternMatch(false);
1284 } 1261 }
1285 1262
1286 void FindFallbackPatternMatch(bool drop_from_working_set) { 1263 void FindFallbackPatternMatch(bool drop_from_working_set) {
1287 // Setup some preconditions. Create a complete cache with a 1264 // Setup some preconditions. Create a complete cache with a
1288 // pattern matching fallback namespace and entry. 1265 // pattern matching fallback namespace and entry.
1289 MakeCacheAndGroup(kManifestUrl, 2, 1, true); 1266 MakeCacheAndGroup(kManifestUrl, 2, 1, true);
1290 cache_->AddEntry(kEntryUrl, AppCacheEntry(AppCacheEntry::FALLBACK, 1)); 1267 cache_->AddEntry(kEntryUrl, AppCacheEntry(AppCacheEntry::FALLBACK, 1));
1291 cache_->fallback_namespaces_.push_back( 1268 cache_->fallback_namespaces_.push_back(
1292 Namespace(APPCACHE_FALLBACK_NAMESPACE, kFallbackPatternNamespace, 1269 AppCacheNamespace(APPCACHE_FALLBACK_NAMESPACE,
1293 kEntryUrl, true)); 1270 kFallbackPatternNamespace, kEntryUrl, true));
1294 AppCacheDatabase::CacheRecord cache_record; 1271 AppCacheDatabase::CacheRecord cache_record;
1295 std::vector<AppCacheDatabase::EntryRecord> entries; 1272 std::vector<AppCacheDatabase::EntryRecord> entries;
1296 std::vector<AppCacheDatabase::NamespaceRecord> intercepts; 1273 std::vector<AppCacheDatabase::NamespaceRecord> intercepts;
1297 std::vector<AppCacheDatabase::NamespaceRecord> fallbacks; 1274 std::vector<AppCacheDatabase::NamespaceRecord> fallbacks;
1298 std::vector<AppCacheDatabase::OnlineWhiteListRecord> whitelists; 1275 std::vector<AppCacheDatabase::OnlineWhiteListRecord> whitelists;
1299 cache_->ToDatabaseRecords(group_.get(), 1276 cache_->ToDatabaseRecords(group_.get(),
1300 &cache_record, 1277 &cache_record,
1301 &entries, 1278 &entries,
1302 &intercepts, 1279 &intercepts,
1303 &fallbacks, 1280 &fallbacks,
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
1413 cache_->AddEntry( 1390 cache_->AddEntry(
1414 entry_record.url, 1391 entry_record.url,
1415 AppCacheEntry(entry_record.flags, entry_record.response_id)); 1392 AppCacheEntry(entry_record.flags, entry_record.response_id));
1416 AppCacheDatabase::NamespaceRecord fallback_namespace_record; 1393 AppCacheDatabase::NamespaceRecord fallback_namespace_record;
1417 fallback_namespace_record.cache_id = id; 1394 fallback_namespace_record.cache_id = id;
1418 fallback_namespace_record.namespace_.target_url = entry_record.url; 1395 fallback_namespace_record.namespace_.target_url = entry_record.url;
1419 fallback_namespace_record.namespace_.namespace_url = kFallbackNamespace; 1396 fallback_namespace_record.namespace_.namespace_url = kFallbackNamespace;
1420 fallback_namespace_record.origin = manifest_url.GetOrigin(); 1397 fallback_namespace_record.origin = manifest_url.GetOrigin();
1421 EXPECT_TRUE(database()->InsertNamespace(&fallback_namespace_record)); 1398 EXPECT_TRUE(database()->InsertNamespace(&fallback_namespace_record));
1422 cache_->fallback_namespaces_.push_back( 1399 cache_->fallback_namespaces_.push_back(
1423 Namespace(APPCACHE_FALLBACK_NAMESPACE, 1400 AppCacheNamespace(APPCACHE_FALLBACK_NAMESPACE,
1424 kFallbackNamespace, 1401 kFallbackNamespace,
1425 kEntryUrl2, 1402 kEntryUrl2,
1426 false)); 1403 false));
1427 } 1404 }
1428 1405
1429 void Verify_FindMainResponseWithMultipleHits() { 1406 void Verify_FindMainResponseWithMultipleHits() {
1430 EXPECT_EQ(kEntryUrl, delegate()->found_url_); 1407 EXPECT_EQ(kEntryUrl, delegate()->found_url_);
1431 EXPECT_EQ(kManifestUrl3, delegate()->found_manifest_url_); 1408 EXPECT_EQ(kManifestUrl3, delegate()->found_manifest_url_);
1432 EXPECT_EQ(3, delegate()->found_cache_id_); 1409 EXPECT_EQ(3, delegate()->found_cache_id_);
1433 EXPECT_EQ(3, delegate()->found_group_id_); 1410 EXPECT_EQ(3, delegate()->found_group_id_);
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
1528 1505
1529 void FindMainResponseExclusions(bool drop_from_working_set) { 1506 void FindMainResponseExclusions(bool drop_from_working_set) {
1530 // Setup some preconditions. Create a complete cache with a 1507 // Setup some preconditions. Create a complete cache with a
1531 // foreign entry, an online namespace, and a second online 1508 // foreign entry, an online namespace, and a second online
1532 // namespace nested within a fallback namespace. 1509 // namespace nested within a fallback namespace.
1533 MakeCacheAndGroup(kManifestUrl, 1, 1, true); 1510 MakeCacheAndGroup(kManifestUrl, 1, 1, true);
1534 cache_->AddEntry(kEntryUrl, 1511 cache_->AddEntry(kEntryUrl,
1535 AppCacheEntry(AppCacheEntry::EXPLICIT | AppCacheEntry::FOREIGN, 1)); 1512 AppCacheEntry(AppCacheEntry::EXPLICIT | AppCacheEntry::FOREIGN, 1));
1536 cache_->AddEntry(kEntryUrl2, AppCacheEntry(AppCacheEntry::FALLBACK, 2)); 1513 cache_->AddEntry(kEntryUrl2, AppCacheEntry(AppCacheEntry::FALLBACK, 2));
1537 cache_->fallback_namespaces_.push_back( 1514 cache_->fallback_namespaces_.push_back(
1538 Namespace(APPCACHE_FALLBACK_NAMESPACE, 1515 AppCacheNamespace(APPCACHE_FALLBACK_NAMESPACE,
1539 kFallbackNamespace, 1516 kFallbackNamespace,
1540 kEntryUrl2, 1517 kEntryUrl2,
1541 false)); 1518 false));
1542 cache_->online_whitelist_namespaces_.push_back( 1519 cache_->online_whitelist_namespaces_.push_back(
1543 Namespace(APPCACHE_NETWORK_NAMESPACE, kOnlineNamespace, 1520 AppCacheNamespace(APPCACHE_NETWORK_NAMESPACE, kOnlineNamespace,
1544 GURL(), false)); 1521 GURL(), false));
1545 cache_->online_whitelist_namespaces_.push_back( 1522 cache_->online_whitelist_namespaces_.push_back(
1546 Namespace(APPCACHE_NETWORK_NAMESPACE, kOnlineNamespaceWithinFallback, 1523 AppCacheNamespace(APPCACHE_NETWORK_NAMESPACE,
1547 GURL(), false)); 1524 kOnlineNamespaceWithinFallback, GURL(), false));
1548 1525
1549 AppCacheDatabase::EntryRecord entry_record; 1526 AppCacheDatabase::EntryRecord entry_record;
1550 entry_record.cache_id = 1; 1527 entry_record.cache_id = 1;
1551 entry_record.url = kEntryUrl; 1528 entry_record.url = kEntryUrl;
1552 entry_record.flags = AppCacheEntry::EXPLICIT | AppCacheEntry::FOREIGN; 1529 entry_record.flags = AppCacheEntry::EXPLICIT | AppCacheEntry::FOREIGN;
1553 entry_record.response_id = 1; 1530 entry_record.response_id = 1;
1554 EXPECT_TRUE(database()->InsertEntry(&entry_record)); 1531 EXPECT_TRUE(database()->InsertEntry(&entry_record));
1555 AppCacheDatabase::OnlineWhiteListRecord whitelist_record; 1532 AppCacheDatabase::OnlineWhiteListRecord whitelist_record;
1556 whitelist_record.cache_id = 1; 1533 whitelist_record.cache_id = 1;
1557 whitelist_record.namespace_url = kOnlineNamespace; 1534 whitelist_record.namespace_url = kOnlineNamespace;
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after
2041 RunTestOnIOThread(&AppCacheStorageImplTest::Reinitialize2); 2018 RunTestOnIOThread(&AppCacheStorageImplTest::Reinitialize2);
2042 } 2019 }
2043 2020
2044 TEST_F(AppCacheStorageImplTest, Reinitialize3) { 2021 TEST_F(AppCacheStorageImplTest, Reinitialize3) {
2045 RunTestOnIOThread(&AppCacheStorageImplTest::Reinitialize3); 2022 RunTestOnIOThread(&AppCacheStorageImplTest::Reinitialize3);
2046 } 2023 }
2047 2024
2048 // That's all folks! 2025 // That's all folks!
2049 2026
2050 } // namespace content 2027 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698