| 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/appcache_service.h" | 9 #include "webkit/appcache/appcache_service.h" |
| 10 | 10 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 EXPECT_EQ(entry1.types(), cache->GetEntry(kUrl1)->types()); | 39 EXPECT_EQ(entry1.types(), cache->GetEntry(kUrl1)->types()); |
| 40 | 40 |
| 41 const GURL kUrl2("http://bar.com"); | 41 const GURL kUrl2("http://bar.com"); |
| 42 AppCacheEntry entry2(AppCacheEntry::FALLBACK); | 42 AppCacheEntry entry2(AppCacheEntry::FALLBACK); |
| 43 cache->AddOrModifyEntry(kUrl2, entry2); | 43 cache->AddOrModifyEntry(kUrl2, entry2); |
| 44 EXPECT_EQ(entry2.types(), cache->GetEntry(kUrl2)->types()); | 44 EXPECT_EQ(entry2.types(), cache->GetEntry(kUrl2)->types()); |
| 45 | 45 |
| 46 AppCacheEntry entry3(AppCacheEntry::EXPLICIT); | 46 AppCacheEntry entry3(AppCacheEntry::EXPLICIT); |
| 47 cache->AddOrModifyEntry(kUrl1, entry3); | 47 cache->AddOrModifyEntry(kUrl1, entry3); |
| 48 EXPECT_EQ((AppCacheEntry::MASTER | AppCacheEntry::EXPLICIT), | 48 EXPECT_EQ((AppCacheEntry::MASTER | AppCacheEntry::EXPLICIT), |
| 49 cache->GetEntry(kUrl1)->types()); | 49 cache->GetEntry(kUrl1)->types()); |
| 50 EXPECT_EQ(entry2.types(), cache->GetEntry(kUrl2)->types()); // unchanged | 50 EXPECT_EQ(entry2.types(), cache->GetEntry(kUrl2)->types()); // unchanged |
| 51 } | 51 } |
| 52 | 52 |
| 53 TEST(AppCacheTest, InitializeWithManifest) { |
| 54 AppCacheService service; |
| 55 |
| 56 scoped_refptr<AppCache> cache = new AppCache(&service, 1234); |
| 57 EXPECT_TRUE(cache->fallback_namespaces_.empty()); |
| 58 EXPECT_TRUE(cache->online_whitelist_namespaces_.empty()); |
| 59 EXPECT_FALSE(cache->online_whitelist_all_); |
| 60 |
| 61 Manifest manifest; |
| 62 manifest.explicit_urls.insert("http://one.com"); |
| 63 manifest.explicit_urls.insert("http://two.com"); |
| 64 manifest.fallback_namespaces.push_back( |
| 65 FallbackNamespace(GURL("http://fb1.com"), GURL("http://fbone.com"))); |
| 66 manifest.online_whitelist_namespaces.push_back(GURL("http://w1.com")); |
| 67 manifest.online_whitelist_namespaces.push_back(GURL("http://w2.com")); |
| 68 manifest.online_whitelist_all = true; |
| 69 |
| 70 cache->InitializeWithManifest(&manifest); |
| 71 const std::vector<FallbackNamespace>& fallbacks = |
| 72 cache->fallback_namespaces_; |
| 73 size_t expected = 1; |
| 74 EXPECT_EQ(expected, fallbacks.size()); |
| 75 EXPECT_EQ(GURL("http://fb1.com"), fallbacks[0].first); |
| 76 EXPECT_EQ(GURL("http://fbone.com"), fallbacks[0].second); |
| 77 const std::vector<GURL>& whitelist = cache->online_whitelist_namespaces_; |
| 78 expected = 2; |
| 79 EXPECT_EQ(expected, whitelist.size()); |
| 80 EXPECT_EQ(GURL("http://w1.com"), whitelist[0]); |
| 81 EXPECT_EQ(GURL("http://w2.com"), whitelist[1]); |
| 82 EXPECT_TRUE(cache->online_whitelist_all_); |
| 83 |
| 84 // Ensure collections in manifest were taken over by the cache rather than |
| 85 // copied. |
| 86 EXPECT_TRUE(manifest.fallback_namespaces.empty()); |
| 87 EXPECT_TRUE(manifest.online_whitelist_namespaces.empty()); |
| 88 } |
| 89 |
| 53 } // namespace appacache | 90 } // namespace appacache |
| 54 | 91 |
| OLD | NEW |