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 <stddef.h> |
| 6 #include <stdint.h> |
| 7 |
5 #include "content/browser/appcache/appcache.h" | 8 #include "content/browser/appcache/appcache.h" |
6 #include "content/browser/appcache/appcache_host.h" | 9 #include "content/browser/appcache/appcache_host.h" |
7 #include "content/browser/appcache/mock_appcache_service.h" | 10 #include "content/browser/appcache/mock_appcache_service.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
9 | 12 |
10 namespace content { | 13 namespace content { |
11 | 14 |
12 namespace { | 15 namespace { |
13 | 16 |
14 class MockAppCacheFrontend : public AppCacheFrontend { | 17 class MockAppCacheFrontend : public AppCacheFrontend { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 } | 58 } |
56 | 59 |
57 TEST(AppCacheTest, AddModifyRemoveEntry) { | 60 TEST(AppCacheTest, AddModifyRemoveEntry) { |
58 MockAppCacheService service; | 61 MockAppCacheService service; |
59 scoped_refptr<AppCache> cache(new AppCache(service.storage(), 111)); | 62 scoped_refptr<AppCache> cache(new AppCache(service.storage(), 111)); |
60 | 63 |
61 EXPECT_TRUE(cache->entries().empty()); | 64 EXPECT_TRUE(cache->entries().empty()); |
62 EXPECT_EQ(0L, cache->cache_size()); | 65 EXPECT_EQ(0L, cache->cache_size()); |
63 | 66 |
64 const GURL kFooUrl("http://foo.com"); | 67 const GURL kFooUrl("http://foo.com"); |
65 const int64 kFooResponseId = 1; | 68 const int64_t kFooResponseId = 1; |
66 const int64 kFooSize = 100; | 69 const int64_t kFooSize = 100; |
67 AppCacheEntry entry1(AppCacheEntry::MASTER, kFooResponseId, kFooSize); | 70 AppCacheEntry entry1(AppCacheEntry::MASTER, kFooResponseId, kFooSize); |
68 cache->AddEntry(kFooUrl, entry1); | 71 cache->AddEntry(kFooUrl, entry1); |
69 EXPECT_EQ(entry1.types(), cache->GetEntry(kFooUrl)->types()); | 72 EXPECT_EQ(entry1.types(), cache->GetEntry(kFooUrl)->types()); |
70 EXPECT_EQ(1UL, cache->entries().size()); | 73 EXPECT_EQ(1UL, cache->entries().size()); |
71 EXPECT_EQ(kFooSize, cache->cache_size()); | 74 EXPECT_EQ(kFooSize, cache->cache_size()); |
72 | 75 |
73 const GURL kBarUrl("http://bar.com"); | 76 const GURL kBarUrl("http://bar.com"); |
74 const int64 kBarResponseId = 2; | 77 const int64_t kBarResponseId = 2; |
75 const int64 kBarSize = 200; | 78 const int64_t kBarSize = 200; |
76 AppCacheEntry entry2(AppCacheEntry::FALLBACK, kBarResponseId, kBarSize); | 79 AppCacheEntry entry2(AppCacheEntry::FALLBACK, kBarResponseId, kBarSize); |
77 EXPECT_TRUE(cache->AddOrModifyEntry(kBarUrl, entry2)); | 80 EXPECT_TRUE(cache->AddOrModifyEntry(kBarUrl, entry2)); |
78 EXPECT_EQ(entry2.types(), cache->GetEntry(kBarUrl)->types()); | 81 EXPECT_EQ(entry2.types(), cache->GetEntry(kBarUrl)->types()); |
79 EXPECT_EQ(2UL, cache->entries().size()); | 82 EXPECT_EQ(2UL, cache->entries().size()); |
80 EXPECT_EQ(kFooSize + kBarSize, cache->cache_size()); | 83 EXPECT_EQ(kFooSize + kBarSize, cache->cache_size()); |
81 | 84 |
82 // Expected to return false when an existing entry is modified. | 85 // Expected to return false when an existing entry is modified. |
83 AppCacheEntry entry3(AppCacheEntry::EXPLICIT); | 86 AppCacheEntry entry3(AppCacheEntry::EXPLICIT); |
84 EXPECT_FALSE(cache->AddOrModifyEntry(kFooUrl, entry3)); | 87 EXPECT_FALSE(cache->AddOrModifyEntry(kFooUrl, entry3)); |
85 EXPECT_EQ((AppCacheEntry::MASTER | AppCacheEntry::EXPLICIT), | 88 EXPECT_EQ((AppCacheEntry::MASTER | AppCacheEntry::EXPLICIT), |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 "http://blah/online_namespace/explicit"); | 161 "http://blah/online_namespace/explicit"); |
159 const GURL kFallbackTestUrl1("http://blah/fallback_namespace/1"); | 162 const GURL kFallbackTestUrl1("http://blah/fallback_namespace/1"); |
160 const GURL kFallbackTestUrl2("http://blah/fallback_namespace/longer2"); | 163 const GURL kFallbackTestUrl2("http://blah/fallback_namespace/longer2"); |
161 const GURL kInterceptNamespace("http://blah/intercept_namespace/"); | 164 const GURL kInterceptNamespace("http://blah/intercept_namespace/"); |
162 const GURL kInterceptNamespaceWithinFallback( | 165 const GURL kInterceptNamespaceWithinFallback( |
163 "http://blah/fallback_namespace/intercept_namespace/"); | 166 "http://blah/fallback_namespace/intercept_namespace/"); |
164 const GURL kInterceptNamespaceEntry("http://blah/intercept_entry"); | 167 const GURL kInterceptNamespaceEntry("http://blah/intercept_entry"); |
165 const GURL kOnlineNamespaceWithinOtherNamespaces( | 168 const GURL kOnlineNamespaceWithinOtherNamespaces( |
166 "http://blah/fallback_namespace/intercept_namespace/1/online"); | 169 "http://blah/fallback_namespace/intercept_namespace/1/online"); |
167 | 170 |
168 const int64 kFallbackResponseId1 = 1; | 171 const int64_t kFallbackResponseId1 = 1; |
169 const int64 kFallbackResponseId2 = 2; | 172 const int64_t kFallbackResponseId2 = 2; |
170 const int64 kManifestResponseId = 3; | 173 const int64_t kManifestResponseId = 3; |
171 const int64 kForeignExplicitResponseId = 4; | 174 const int64_t kForeignExplicitResponseId = 4; |
172 const int64 kExplicitInOnlineNamespaceResponseId = 5; | 175 const int64_t kExplicitInOnlineNamespaceResponseId = 5; |
173 const int64 kInterceptResponseId = 6; | 176 const int64_t kInterceptResponseId = 6; |
174 | 177 |
175 AppCacheManifest manifest; | 178 AppCacheManifest manifest; |
176 manifest.online_whitelist_namespaces.push_back( | 179 manifest.online_whitelist_namespaces.push_back( |
177 AppCacheNamespace(APPCACHE_NETWORK_NAMESPACE, kOnlineNamespaceUrl, | 180 AppCacheNamespace(APPCACHE_NETWORK_NAMESPACE, kOnlineNamespaceUrl, |
178 GURL(), false)); | 181 GURL(), false)); |
179 manifest.online_whitelist_namespaces.push_back( | 182 manifest.online_whitelist_namespaces.push_back( |
180 AppCacheNamespace(APPCACHE_NETWORK_NAMESPACE, | 183 AppCacheNamespace(APPCACHE_NETWORK_NAMESPACE, |
181 kOnlineNamespaceWithinOtherNamespaces, GURL(), false)); | 184 kOnlineNamespaceWithinOtherNamespaces, GURL(), false)); |
182 manifest.fallback_namespaces.push_back( | 185 manifest.fallback_namespaces.push_back( |
183 AppCacheNamespace(APPCACHE_FALLBACK_NAMESPACE, kFallbackNamespaceUrl1, | 186 AppCacheNamespace(APPCACHE_FALLBACK_NAMESPACE, kFallbackNamespaceUrl1, |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 } | 358 } |
356 | 359 |
357 TEST(AppCacheTest, FindInterceptPatternResponseForRequest) { | 360 TEST(AppCacheTest, FindInterceptPatternResponseForRequest) { |
358 MockAppCacheService service; | 361 MockAppCacheService service; |
359 | 362 |
360 // Setup an appcache with an intercept namespace that uses pattern matching. | 363 // Setup an appcache with an intercept namespace that uses pattern matching. |
361 const GURL kInterceptNamespaceBase("http://blah/intercept_namespace/"); | 364 const GURL kInterceptNamespaceBase("http://blah/intercept_namespace/"); |
362 const GURL kInterceptPatternNamespace( | 365 const GURL kInterceptPatternNamespace( |
363 kInterceptNamespaceBase.Resolve("*.hit*")); | 366 kInterceptNamespaceBase.Resolve("*.hit*")); |
364 const GURL kInterceptNamespaceEntry("http://blah/intercept_resource"); | 367 const GURL kInterceptNamespaceEntry("http://blah/intercept_resource"); |
365 const int64 kInterceptResponseId = 1; | 368 const int64_t kInterceptResponseId = 1; |
366 AppCacheManifest manifest; | 369 AppCacheManifest manifest; |
367 manifest.intercept_namespaces.push_back( | 370 manifest.intercept_namespaces.push_back( |
368 AppCacheNamespace(APPCACHE_INTERCEPT_NAMESPACE, | 371 AppCacheNamespace(APPCACHE_INTERCEPT_NAMESPACE, |
369 kInterceptPatternNamespace, kInterceptNamespaceEntry, true)); | 372 kInterceptPatternNamespace, kInterceptNamespaceEntry, true)); |
370 scoped_refptr<AppCache> cache(new AppCache(service.storage(), 1234)); | 373 scoped_refptr<AppCache> cache(new AppCache(service.storage(), 1234)); |
371 cache->InitializeWithManifest(&manifest); | 374 cache->InitializeWithManifest(&manifest); |
372 cache->AddEntry( | 375 cache->AddEntry( |
373 kInterceptNamespaceEntry, | 376 kInterceptNamespaceEntry, |
374 AppCacheEntry(AppCacheEntry::INTERCEPT, kInterceptResponseId)); | 377 AppCacheEntry(AppCacheEntry::INTERCEPT, kInterceptResponseId)); |
375 cache->set_complete(true); | 378 cache->set_complete(true); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 } | 429 } |
427 | 430 |
428 TEST(AppCacheTest, FindFallbackPatternResponseForRequest) { | 431 TEST(AppCacheTest, FindFallbackPatternResponseForRequest) { |
429 MockAppCacheService service; | 432 MockAppCacheService service; |
430 | 433 |
431 // Setup an appcache with a fallback namespace that uses pattern matching. | 434 // Setup an appcache with a fallback namespace that uses pattern matching. |
432 const GURL kFallbackNamespaceBase("http://blah/fallback_namespace/"); | 435 const GURL kFallbackNamespaceBase("http://blah/fallback_namespace/"); |
433 const GURL kFallbackPatternNamespace( | 436 const GURL kFallbackPatternNamespace( |
434 kFallbackNamespaceBase.Resolve("*.hit*")); | 437 kFallbackNamespaceBase.Resolve("*.hit*")); |
435 const GURL kFallbackNamespaceEntry("http://blah/fallback_resource"); | 438 const GURL kFallbackNamespaceEntry("http://blah/fallback_resource"); |
436 const int64 kFallbackResponseId = 1; | 439 const int64_t kFallbackResponseId = 1; |
437 AppCacheManifest manifest; | 440 AppCacheManifest manifest; |
438 manifest.fallback_namespaces.push_back( | 441 manifest.fallback_namespaces.push_back( |
439 AppCacheNamespace(APPCACHE_FALLBACK_NAMESPACE, kFallbackPatternNamespace, | 442 AppCacheNamespace(APPCACHE_FALLBACK_NAMESPACE, kFallbackPatternNamespace, |
440 kFallbackNamespaceEntry, true)); | 443 kFallbackNamespaceEntry, true)); |
441 scoped_refptr<AppCache> cache(new AppCache(service.storage(), 1234)); | 444 scoped_refptr<AppCache> cache(new AppCache(service.storage(), 1234)); |
442 cache->InitializeWithManifest(&manifest); | 445 cache->InitializeWithManifest(&manifest); |
443 cache->AddEntry( | 446 cache->AddEntry( |
444 kFallbackNamespaceEntry, | 447 kFallbackNamespaceEntry, |
445 AppCacheEntry(AppCacheEntry::FALLBACK, kFallbackResponseId)); | 448 AppCacheEntry(AppCacheEntry::FALLBACK, kFallbackResponseId)); |
446 cache->set_complete(true); | 449 cache->set_complete(true); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
534 &fallback_entry, &fallback_namespace, | 537 &fallback_entry, &fallback_namespace, |
535 &network_namespace); | 538 &network_namespace); |
536 EXPECT_TRUE(found); | 539 EXPECT_TRUE(found); |
537 EXPECT_TRUE(network_namespace); | 540 EXPECT_TRUE(network_namespace); |
538 EXPECT_FALSE(entry.has_response_id()); | 541 EXPECT_FALSE(entry.has_response_id()); |
539 EXPECT_FALSE(fallback_entry.has_response_id()); | 542 EXPECT_FALSE(fallback_entry.has_response_id()); |
540 } | 543 } |
541 | 544 |
542 TEST(AppCacheTest, ToFromDatabaseRecords) { | 545 TEST(AppCacheTest, ToFromDatabaseRecords) { |
543 // Setup a cache with some entries. | 546 // Setup a cache with some entries. |
544 const int64 kCacheId = 1234; | 547 const int64_t kCacheId = 1234; |
545 const int64 kGroupId = 4321; | 548 const int64_t kGroupId = 4321; |
546 const GURL kManifestUrl("http://foo.com/manifest"); | 549 const GURL kManifestUrl("http://foo.com/manifest"); |
547 const GURL kInterceptUrl("http://foo.com/intercept.html"); | 550 const GURL kInterceptUrl("http://foo.com/intercept.html"); |
548 const GURL kFallbackUrl("http://foo.com/fallback.html"); | 551 const GURL kFallbackUrl("http://foo.com/fallback.html"); |
549 const GURL kWhitelistUrl("http://foo.com/whitelist*"); | 552 const GURL kWhitelistUrl("http://foo.com/whitelist*"); |
550 const std::string kData( | 553 const std::string kData( |
551 "CACHE MANIFEST\r" | 554 "CACHE MANIFEST\r" |
552 "CHROMIUM-INTERCEPT:\r" | 555 "CHROMIUM-INTERCEPT:\r" |
553 "/intercept return /intercept.html\r" | 556 "/intercept return /intercept.html\r" |
554 "FALLBACK:\r" | 557 "FALLBACK:\r" |
555 "/ /fallback.html\r" | 558 "/ /fallback.html\r" |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
690 EXPECT_TRUE(star_greediness.IsMatch( | 693 EXPECT_TRUE(star_greediness.IsMatch( |
691 GURL("http://foo.com/a/b/01234567890abcdef/b"))); | 694 GURL("http://foo.com/a/b/01234567890abcdef/b"))); |
692 EXPECT_TRUE(star_greediness.IsMatch( | 695 EXPECT_TRUE(star_greediness.IsMatch( |
693 GURL("http://foo.com/a/b/01234567890abcdef/b01234567890abcdef/b"))); | 696 GURL("http://foo.com/a/b/01234567890abcdef/b01234567890abcdef/b"))); |
694 EXPECT_TRUE(star_greediness.IsMatch( | 697 EXPECT_TRUE(star_greediness.IsMatch( |
695 GURL("http://foo.com/a/b/01234567890abcdef_eat_some_more_characters_" | 698 GURL("http://foo.com/a/b/01234567890abcdef_eat_some_more_characters_" |
696 "/and_even_more_for_the_heck_of_it/01234567890abcdef/b"))); | 699 "/and_even_more_for_the_heck_of_it/01234567890abcdef/b"))); |
697 } | 700 } |
698 | 701 |
699 } // namespace content | 702 } // namespace content |
OLD | NEW |