| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "testing/gtest/include/gtest/gtest.h" | 5 #include "testing/gtest/include/gtest/gtest.h" |
| 6 #include "webkit/appcache/appcache.h" | 6 #include "webkit/appcache/appcache.h" |
| 7 #include "webkit/appcache/appcache_frontend_impl.h" | 7 #include "webkit/appcache/appcache_frontend_impl.h" |
| 8 #include "webkit/appcache/appcache_host.h" | 8 #include "webkit/appcache/appcache_host.h" |
| 9 #include "webkit/appcache/mock_appcache_service.h" | 9 #include "webkit/appcache/mock_appcache_service.h" |
| 10 | 10 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 | 27 |
| 28 host1.AssociateCache(cache.get()); | 28 host1.AssociateCache(cache.get()); |
| 29 host2.AssociateCache(cache.get()); | 29 host2.AssociateCache(cache.get()); |
| 30 | 30 |
| 31 host1.AssociateCache(NULL); | 31 host1.AssociateCache(NULL); |
| 32 host2.AssociateCache(NULL); | 32 host2.AssociateCache(NULL); |
| 33 } | 33 } |
| 34 | 34 |
| 35 TEST(AppCacheTest, AddModifyRemoveEntry) { | 35 TEST(AppCacheTest, AddModifyRemoveEntry) { |
| 36 MockAppCacheService service; | 36 MockAppCacheService service; |
| 37 scoped_refptr<AppCache> cache = new AppCache(&service, 111); | 37 scoped_refptr<AppCache> cache(new AppCache(&service, 111)); |
| 38 | 38 |
| 39 EXPECT_TRUE(cache->entries().empty()); | 39 EXPECT_TRUE(cache->entries().empty()); |
| 40 EXPECT_EQ(0L, cache->cache_size()); | 40 EXPECT_EQ(0L, cache->cache_size()); |
| 41 | 41 |
| 42 const GURL kFooUrl("http://foo.com"); | 42 const GURL kFooUrl("http://foo.com"); |
| 43 const int64 kFooResponseId = 1; | 43 const int64 kFooResponseId = 1; |
| 44 const int64 kFooSize = 100; | 44 const int64 kFooSize = 100; |
| 45 AppCacheEntry entry1(AppCacheEntry::MASTER, kFooResponseId, kFooSize); | 45 AppCacheEntry entry1(AppCacheEntry::MASTER, kFooResponseId, kFooSize); |
| 46 cache->AddEntry(kFooUrl, entry1); | 46 cache->AddEntry(kFooUrl, entry1); |
| 47 EXPECT_EQ(entry1.types(), cache->GetEntry(kFooUrl)->types()); | 47 EXPECT_EQ(entry1.types(), cache->GetEntry(kFooUrl)->types()); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 72 cache->RemoveEntry(kBarUrl); | 72 cache->RemoveEntry(kBarUrl); |
| 73 EXPECT_EQ(kFooSize, cache->cache_size()); | 73 EXPECT_EQ(kFooSize, cache->cache_size()); |
| 74 cache->RemoveEntry(kFooUrl); | 74 cache->RemoveEntry(kFooUrl); |
| 75 EXPECT_EQ(0L, cache->cache_size()); | 75 EXPECT_EQ(0L, cache->cache_size()); |
| 76 EXPECT_TRUE(cache->entries().empty()); | 76 EXPECT_TRUE(cache->entries().empty()); |
| 77 } | 77 } |
| 78 | 78 |
| 79 TEST(AppCacheTest, InitializeWithManifest) { | 79 TEST(AppCacheTest, InitializeWithManifest) { |
| 80 MockAppCacheService service; | 80 MockAppCacheService service; |
| 81 | 81 |
| 82 scoped_refptr<AppCache> cache = new AppCache(&service, 1234); | 82 scoped_refptr<AppCache> cache(new AppCache(&service, 1234)); |
| 83 EXPECT_TRUE(cache->fallback_namespaces_.empty()); | 83 EXPECT_TRUE(cache->fallback_namespaces_.empty()); |
| 84 EXPECT_TRUE(cache->online_whitelist_namespaces_.empty()); | 84 EXPECT_TRUE(cache->online_whitelist_namespaces_.empty()); |
| 85 EXPECT_FALSE(cache->online_whitelist_all_); | 85 EXPECT_FALSE(cache->online_whitelist_all_); |
| 86 | 86 |
| 87 Manifest manifest; | 87 Manifest manifest; |
| 88 manifest.explicit_urls.insert("http://one.com"); | 88 manifest.explicit_urls.insert("http://one.com"); |
| 89 manifest.explicit_urls.insert("http://two.com"); | 89 manifest.explicit_urls.insert("http://two.com"); |
| 90 manifest.fallback_namespaces.push_back( | 90 manifest.fallback_namespaces.push_back( |
| 91 FallbackNamespace(GURL("http://fb1.com"), GURL("http://fbone.com"))); | 91 FallbackNamespace(GURL("http://fb1.com"), GURL("http://fbone.com"))); |
| 92 manifest.online_whitelist_namespaces.push_back(GURL("http://w1.com")); | 92 manifest.online_whitelist_namespaces.push_back(GURL("http://w1.com")); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 const int64 kExplicitInOnlineNamespaceResponseId = 5; | 137 const int64 kExplicitInOnlineNamespaceResponseId = 5; |
| 138 | 138 |
| 139 Manifest manifest; | 139 Manifest manifest; |
| 140 manifest.online_whitelist_namespaces.push_back(kOnlineNamespaceUrl); | 140 manifest.online_whitelist_namespaces.push_back(kOnlineNamespaceUrl); |
| 141 manifest.fallback_namespaces.push_back( | 141 manifest.fallback_namespaces.push_back( |
| 142 FallbackNamespace(kFallbackNamespaceUrl1, kFallbackEntryUrl1)); | 142 FallbackNamespace(kFallbackNamespaceUrl1, kFallbackEntryUrl1)); |
| 143 manifest.fallback_namespaces.push_back( | 143 manifest.fallback_namespaces.push_back( |
| 144 FallbackNamespace(kFallbackNamespaceUrl2, kFallbackEntryUrl2)); | 144 FallbackNamespace(kFallbackNamespaceUrl2, kFallbackEntryUrl2)); |
| 145 | 145 |
| 146 // Create a cache with some namespaces and entries. | 146 // Create a cache with some namespaces and entries. |
| 147 scoped_refptr<AppCache> cache = new AppCache(&service, 1234); | 147 scoped_refptr<AppCache> cache(new AppCache(&service, 1234)); |
| 148 cache->InitializeWithManifest(&manifest); | 148 cache->InitializeWithManifest(&manifest); |
| 149 cache->AddEntry( | 149 cache->AddEntry( |
| 150 kFallbackEntryUrl1, | 150 kFallbackEntryUrl1, |
| 151 AppCacheEntry(AppCacheEntry::FALLBACK, kFallbackResponseId1)); | 151 AppCacheEntry(AppCacheEntry::FALLBACK, kFallbackResponseId1)); |
| 152 cache->AddEntry( | 152 cache->AddEntry( |
| 153 kFallbackEntryUrl2, | 153 kFallbackEntryUrl2, |
| 154 AppCacheEntry(AppCacheEntry::FALLBACK, kFallbackResponseId2)); | 154 AppCacheEntry(AppCacheEntry::FALLBACK, kFallbackResponseId2)); |
| 155 cache->AddEntry( | 155 cache->AddEntry( |
| 156 kManifestUrl, | 156 kManifestUrl, |
| 157 AppCacheEntry(AppCacheEntry::MANIFEST, kManifestResponseId)); | 157 AppCacheEntry(AppCacheEntry::MANIFEST, kManifestResponseId)); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 found = cache->FindResponseForRequest(kFallbackTestUrl2, | 225 found = cache->FindResponseForRequest(kFallbackTestUrl2, |
| 226 &entry, &fallback_entry, &fallback_namespace, &network_namespace); | 226 &entry, &fallback_entry, &fallback_namespace, &network_namespace); |
| 227 EXPECT_TRUE(found); | 227 EXPECT_TRUE(found); |
| 228 EXPECT_FALSE(entry.has_response_id()); | 228 EXPECT_FALSE(entry.has_response_id()); |
| 229 EXPECT_EQ(kFallbackResponseId2, fallback_entry.response_id()); | 229 EXPECT_EQ(kFallbackResponseId2, fallback_entry.response_id()); |
| 230 EXPECT_FALSE(network_namespace); | 230 EXPECT_FALSE(network_namespace); |
| 231 } | 231 } |
| 232 | 232 |
| 233 } // namespace appacache | 233 } // namespace appacache |
| 234 | 234 |
| OLD | NEW |