| OLD | NEW |
| 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 "content/browser/appcache/appcache.h" | 5 #include "content/browser/appcache/appcache.h" |
| 6 #include "content/browser/appcache/appcache_host.h" | 6 #include "content/browser/appcache/appcache_host.h" |
| 7 #include "content/browser/appcache/mock_appcache_service.h" | 7 #include "content/browser/appcache/mock_appcache_service.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 | 9 |
| 10 namespace content { | 10 namespace content { |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 } | 101 } |
| 102 | 102 |
| 103 TEST(AppCacheTest, InitializeWithManifest) { | 103 TEST(AppCacheTest, InitializeWithManifest) { |
| 104 MockAppCacheService service; | 104 MockAppCacheService service; |
| 105 | 105 |
| 106 scoped_refptr<AppCache> cache(new AppCache(service.storage(), 1234)); | 106 scoped_refptr<AppCache> cache(new AppCache(service.storage(), 1234)); |
| 107 EXPECT_TRUE(cache->fallback_namespaces_.empty()); | 107 EXPECT_TRUE(cache->fallback_namespaces_.empty()); |
| 108 EXPECT_TRUE(cache->online_whitelist_namespaces_.empty()); | 108 EXPECT_TRUE(cache->online_whitelist_namespaces_.empty()); |
| 109 EXPECT_FALSE(cache->online_whitelist_all_); | 109 EXPECT_FALSE(cache->online_whitelist_all_); |
| 110 | 110 |
| 111 Manifest manifest; | 111 AppCacheManifest manifest; |
| 112 manifest.explicit_urls.insert("http://one.com"); | 112 manifest.explicit_urls.insert("http://one.com"); |
| 113 manifest.explicit_urls.insert("http://two.com"); | 113 manifest.explicit_urls.insert("http://two.com"); |
| 114 manifest.fallback_namespaces.push_back( | 114 manifest.fallback_namespaces.push_back( |
| 115 AppCacheNamespace(APPCACHE_FALLBACK_NAMESPACE, GURL("http://fb1.com"), | 115 AppCacheNamespace(APPCACHE_FALLBACK_NAMESPACE, GURL("http://fb1.com"), |
| 116 GURL("http://fbone.com"), true)); | 116 GURL("http://fbone.com"), true)); |
| 117 manifest.online_whitelist_namespaces.push_back( | 117 manifest.online_whitelist_namespaces.push_back( |
| 118 AppCacheNamespace(APPCACHE_NETWORK_NAMESPACE, GURL("http://w1.com"), | 118 AppCacheNamespace(APPCACHE_NETWORK_NAMESPACE, GURL("http://w1.com"), |
| 119 GURL(), false)); | 119 GURL(), false)); |
| 120 manifest.online_whitelist_namespaces.push_back( | 120 manifest.online_whitelist_namespaces.push_back( |
| 121 AppCacheNamespace(APPCACHE_NETWORK_NAMESPACE, GURL("http://w2.com"), | 121 AppCacheNamespace(APPCACHE_NETWORK_NAMESPACE, GURL("http://w2.com"), |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 const GURL kOnlineNamespaceWithinOtherNamespaces( | 167 const GURL kOnlineNamespaceWithinOtherNamespaces( |
| 168 "http://blah/fallback_namespace/intercept_namespace/1/online"); | 168 "http://blah/fallback_namespace/intercept_namespace/1/online"); |
| 169 | 169 |
| 170 const int64 kFallbackResponseId1 = 1; | 170 const int64 kFallbackResponseId1 = 1; |
| 171 const int64 kFallbackResponseId2 = 2; | 171 const int64 kFallbackResponseId2 = 2; |
| 172 const int64 kManifestResponseId = 3; | 172 const int64 kManifestResponseId = 3; |
| 173 const int64 kForeignExplicitResponseId = 4; | 173 const int64 kForeignExplicitResponseId = 4; |
| 174 const int64 kExplicitInOnlineNamespaceResponseId = 5; | 174 const int64 kExplicitInOnlineNamespaceResponseId = 5; |
| 175 const int64 kInterceptResponseId = 6; | 175 const int64 kInterceptResponseId = 6; |
| 176 | 176 |
| 177 Manifest manifest; | 177 AppCacheManifest manifest; |
| 178 manifest.online_whitelist_namespaces.push_back( | 178 manifest.online_whitelist_namespaces.push_back( |
| 179 AppCacheNamespace(APPCACHE_NETWORK_NAMESPACE, kOnlineNamespaceUrl, | 179 AppCacheNamespace(APPCACHE_NETWORK_NAMESPACE, kOnlineNamespaceUrl, |
| 180 GURL(), false)); | 180 GURL(), false)); |
| 181 manifest.online_whitelist_namespaces.push_back( | 181 manifest.online_whitelist_namespaces.push_back( |
| 182 AppCacheNamespace(APPCACHE_NETWORK_NAMESPACE, | 182 AppCacheNamespace(APPCACHE_NETWORK_NAMESPACE, |
| 183 kOnlineNamespaceWithinOtherNamespaces, GURL(), false)); | 183 kOnlineNamespaceWithinOtherNamespaces, GURL(), false)); |
| 184 manifest.fallback_namespaces.push_back( | 184 manifest.fallback_namespaces.push_back( |
| 185 AppCacheNamespace(APPCACHE_FALLBACK_NAMESPACE, kFallbackNamespaceUrl1, | 185 AppCacheNamespace(APPCACHE_FALLBACK_NAMESPACE, kFallbackNamespaceUrl1, |
| 186 kFallbackEntryUrl1, false)); | 186 kFallbackEntryUrl1, false)); |
| 187 manifest.fallback_namespaces.push_back( | 187 manifest.fallback_namespaces.push_back( |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 | 358 |
| 359 TEST(AppCacheTest, FindInterceptPatternResponseForRequest) { | 359 TEST(AppCacheTest, FindInterceptPatternResponseForRequest) { |
| 360 MockAppCacheService service; | 360 MockAppCacheService service; |
| 361 | 361 |
| 362 // Setup an appcache with an intercept namespace that uses pattern matching. | 362 // Setup an appcache with an intercept namespace that uses pattern matching. |
| 363 const GURL kInterceptNamespaceBase("http://blah/intercept_namespace/"); | 363 const GURL kInterceptNamespaceBase("http://blah/intercept_namespace/"); |
| 364 const GURL kInterceptPatternNamespace( | 364 const GURL kInterceptPatternNamespace( |
| 365 kInterceptNamespaceBase.Resolve("*.hit*")); | 365 kInterceptNamespaceBase.Resolve("*.hit*")); |
| 366 const GURL kInterceptNamespaceEntry("http://blah/intercept_resource"); | 366 const GURL kInterceptNamespaceEntry("http://blah/intercept_resource"); |
| 367 const int64 kInterceptResponseId = 1; | 367 const int64 kInterceptResponseId = 1; |
| 368 Manifest manifest; | 368 AppCacheManifest manifest; |
| 369 manifest.intercept_namespaces.push_back( | 369 manifest.intercept_namespaces.push_back( |
| 370 AppCacheNamespace(APPCACHE_INTERCEPT_NAMESPACE, | 370 AppCacheNamespace(APPCACHE_INTERCEPT_NAMESPACE, |
| 371 kInterceptPatternNamespace, kInterceptNamespaceEntry, true)); | 371 kInterceptPatternNamespace, kInterceptNamespaceEntry, true)); |
| 372 scoped_refptr<AppCache> cache(new AppCache(service.storage(), 1234)); | 372 scoped_refptr<AppCache> cache(new AppCache(service.storage(), 1234)); |
| 373 cache->InitializeWithManifest(&manifest); | 373 cache->InitializeWithManifest(&manifest); |
| 374 cache->AddEntry( | 374 cache->AddEntry( |
| 375 kInterceptNamespaceEntry, | 375 kInterceptNamespaceEntry, |
| 376 AppCacheEntry(AppCacheEntry::INTERCEPT, kInterceptResponseId)); | 376 AppCacheEntry(AppCacheEntry::INTERCEPT, kInterceptResponseId)); |
| 377 cache->set_complete(true); | 377 cache->set_complete(true); |
| 378 | 378 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 | 429 |
| 430 TEST(AppCacheTest, FindFallbackPatternResponseForRequest) { | 430 TEST(AppCacheTest, FindFallbackPatternResponseForRequest) { |
| 431 MockAppCacheService service; | 431 MockAppCacheService service; |
| 432 | 432 |
| 433 // Setup an appcache with a fallback namespace that uses pattern matching. | 433 // Setup an appcache with a fallback namespace that uses pattern matching. |
| 434 const GURL kFallbackNamespaceBase("http://blah/fallback_namespace/"); | 434 const GURL kFallbackNamespaceBase("http://blah/fallback_namespace/"); |
| 435 const GURL kFallbackPatternNamespace( | 435 const GURL kFallbackPatternNamespace( |
| 436 kFallbackNamespaceBase.Resolve("*.hit*")); | 436 kFallbackNamespaceBase.Resolve("*.hit*")); |
| 437 const GURL kFallbackNamespaceEntry("http://blah/fallback_resource"); | 437 const GURL kFallbackNamespaceEntry("http://blah/fallback_resource"); |
| 438 const int64 kFallbackResponseId = 1; | 438 const int64 kFallbackResponseId = 1; |
| 439 Manifest manifest; | 439 AppCacheManifest manifest; |
| 440 manifest.fallback_namespaces.push_back( | 440 manifest.fallback_namespaces.push_back( |
| 441 AppCacheNamespace(APPCACHE_FALLBACK_NAMESPACE, kFallbackPatternNamespace, | 441 AppCacheNamespace(APPCACHE_FALLBACK_NAMESPACE, kFallbackPatternNamespace, |
| 442 kFallbackNamespaceEntry, true)); | 442 kFallbackNamespaceEntry, true)); |
| 443 scoped_refptr<AppCache> cache(new AppCache(service.storage(), 1234)); | 443 scoped_refptr<AppCache> cache(new AppCache(service.storage(), 1234)); |
| 444 cache->InitializeWithManifest(&manifest); | 444 cache->InitializeWithManifest(&manifest); |
| 445 cache->AddEntry( | 445 cache->AddEntry( |
| 446 kFallbackNamespaceEntry, | 446 kFallbackNamespaceEntry, |
| 447 AppCacheEntry(AppCacheEntry::FALLBACK, kFallbackResponseId)); | 447 AppCacheEntry(AppCacheEntry::FALLBACK, kFallbackResponseId)); |
| 448 cache->set_complete(true); | 448 cache->set_complete(true); |
| 449 | 449 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 499 } | 499 } |
| 500 | 500 |
| 501 | 501 |
| 502 TEST(AppCacheTest, FindNetworkNamespacePatternResponseForRequest) { | 502 TEST(AppCacheTest, FindNetworkNamespacePatternResponseForRequest) { |
| 503 MockAppCacheService service; | 503 MockAppCacheService service; |
| 504 | 504 |
| 505 // Setup an appcache with a network namespace that uses pattern matching. | 505 // Setup an appcache with a network namespace that uses pattern matching. |
| 506 const GURL kNetworkNamespaceBase("http://blah/network_namespace/"); | 506 const GURL kNetworkNamespaceBase("http://blah/network_namespace/"); |
| 507 const GURL kNetworkPatternNamespace( | 507 const GURL kNetworkPatternNamespace( |
| 508 kNetworkNamespaceBase.Resolve("*.hit*")); | 508 kNetworkNamespaceBase.Resolve("*.hit*")); |
| 509 Manifest manifest; | 509 AppCacheManifest manifest; |
| 510 manifest.online_whitelist_namespaces.push_back( | 510 manifest.online_whitelist_namespaces.push_back( |
| 511 AppCacheNamespace(APPCACHE_NETWORK_NAMESPACE, kNetworkPatternNamespace, | 511 AppCacheNamespace(APPCACHE_NETWORK_NAMESPACE, kNetworkPatternNamespace, |
| 512 GURL(), true)); | 512 GURL(), true)); |
| 513 manifest.online_whitelist_all = false; | 513 manifest.online_whitelist_all = false; |
| 514 scoped_refptr<AppCache> cache(new AppCache(service.storage(), 1234)); | 514 scoped_refptr<AppCache> cache(new AppCache(service.storage(), 1234)); |
| 515 cache->InitializeWithManifest(&manifest); | 515 cache->InitializeWithManifest(&manifest); |
| 516 cache->set_complete(true); | 516 cache->set_complete(true); |
| 517 | 517 |
| 518 // See that the pattern match works. | 518 // See that the pattern match works. |
| 519 bool found = false; | 519 bool found = false; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 555 "/intercept return /intercept.html\r" | 555 "/intercept return /intercept.html\r" |
| 556 "FALLBACK:\r" | 556 "FALLBACK:\r" |
| 557 "/ /fallback.html\r" | 557 "/ /fallback.html\r" |
| 558 "NETWORK:\r" | 558 "NETWORK:\r" |
| 559 "/whitelist* isPattern\r" | 559 "/whitelist* isPattern\r" |
| 560 "*\r"); | 560 "*\r"); |
| 561 MockAppCacheService service; | 561 MockAppCacheService service; |
| 562 scoped_refptr<AppCacheGroup> group = | 562 scoped_refptr<AppCacheGroup> group = |
| 563 new AppCacheGroup(service.storage(), kManifestUrl, kGroupId); | 563 new AppCacheGroup(service.storage(), kManifestUrl, kGroupId); |
| 564 scoped_refptr<AppCache> cache(new AppCache(service.storage(), kCacheId)); | 564 scoped_refptr<AppCache> cache(new AppCache(service.storage(), kCacheId)); |
| 565 Manifest manifest; | 565 AppCacheManifest manifest; |
| 566 EXPECT_TRUE(ParseManifest(kManifestUrl, kData.c_str(), kData.length(), | 566 EXPECT_TRUE(ParseManifest(kManifestUrl, kData.c_str(), kData.length(), |
| 567 PARSE_MANIFEST_ALLOWING_INTERCEPTS, manifest)); | 567 PARSE_MANIFEST_ALLOWING_INTERCEPTS, manifest)); |
| 568 cache->InitializeWithManifest(&manifest); | 568 cache->InitializeWithManifest(&manifest); |
| 569 EXPECT_EQ(APPCACHE_NETWORK_NAMESPACE, | 569 EXPECT_EQ(APPCACHE_NETWORK_NAMESPACE, |
| 570 cache->online_whitelist_namespaces_[0].type); | 570 cache->online_whitelist_namespaces_[0].type); |
| 571 EXPECT_TRUE(cache->online_whitelist_namespaces_[0].is_pattern); | 571 EXPECT_TRUE(cache->online_whitelist_namespaces_[0].is_pattern); |
| 572 EXPECT_EQ(kWhitelistUrl, | 572 EXPECT_EQ(kWhitelistUrl, |
| 573 cache->online_whitelist_namespaces_[0].namespace_url); | 573 cache->online_whitelist_namespaces_[0].namespace_url); |
| 574 cache->AddEntry( | 574 cache->AddEntry( |
| 575 kManifestUrl, | 575 kManifestUrl, |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 692 EXPECT_TRUE(star_greediness.IsMatch( | 692 EXPECT_TRUE(star_greediness.IsMatch( |
| 693 GURL("http://foo.com/a/b/01234567890abcdef/b"))); | 693 GURL("http://foo.com/a/b/01234567890abcdef/b"))); |
| 694 EXPECT_TRUE(star_greediness.IsMatch( | 694 EXPECT_TRUE(star_greediness.IsMatch( |
| 695 GURL("http://foo.com/a/b/01234567890abcdef/b01234567890abcdef/b"))); | 695 GURL("http://foo.com/a/b/01234567890abcdef/b01234567890abcdef/b"))); |
| 696 EXPECT_TRUE(star_greediness.IsMatch( | 696 EXPECT_TRUE(star_greediness.IsMatch( |
| 697 GURL("http://foo.com/a/b/01234567890abcdef_eat_some_more_characters_" | 697 GURL("http://foo.com/a/b/01234567890abcdef_eat_some_more_characters_" |
| 698 "/and_even_more_for_the_heck_of_it/01234567890abcdef/b"))); | 698 "/and_even_more_for_the_heck_of_it/01234567890abcdef/b"))); |
| 699 } | 699 } |
| 700 | 700 |
| 701 } // namespace content | 701 } // namespace content |
| OLD | NEW |