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

Side by Side Diff: webkit/appcache/appcache_unittest.cc

Issue 8396013: AppCache INTERCEPT namespace. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years 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 (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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 Namespace(FALLBACK_NAMESPACE, GURL("http://fb1.com"),
92 GURL("http://fbone.com")));
92 manifest.online_whitelist_namespaces.push_back(GURL("http://w1.com")); 93 manifest.online_whitelist_namespaces.push_back(GURL("http://w1.com"));
93 manifest.online_whitelist_namespaces.push_back(GURL("http://w2.com")); 94 manifest.online_whitelist_namespaces.push_back(GURL("http://w2.com"));
94 manifest.online_whitelist_all = true; 95 manifest.online_whitelist_all = true;
95 96
96 cache->InitializeWithManifest(&manifest); 97 cache->InitializeWithManifest(&manifest);
97 const std::vector<FallbackNamespace>& fallbacks = 98 const std::vector<Namespace>& fallbacks =
98 cache->fallback_namespaces_; 99 cache->fallback_namespaces_;
99 size_t expected = 1; 100 size_t expected = 1;
100 EXPECT_EQ(expected, fallbacks.size()); 101 EXPECT_EQ(expected, fallbacks.size());
101 EXPECT_EQ(GURL("http://fb1.com"), fallbacks[0].first); 102 EXPECT_EQ(GURL("http://fb1.com"), fallbacks[0].namespace_url);
102 EXPECT_EQ(GURL("http://fbone.com"), fallbacks[0].second); 103 EXPECT_EQ(GURL("http://fbone.com"), fallbacks[0].target_url);
103 const std::vector<GURL>& whitelist = cache->online_whitelist_namespaces_; 104 const std::vector<GURL>& whitelist = cache->online_whitelist_namespaces_;
104 expected = 2; 105 expected = 2;
105 EXPECT_EQ(expected, whitelist.size()); 106 EXPECT_EQ(expected, whitelist.size());
106 EXPECT_EQ(GURL("http://w1.com"), whitelist[0]); 107 EXPECT_EQ(GURL("http://w1.com"), whitelist[0]);
107 EXPECT_EQ(GURL("http://w2.com"), whitelist[1]); 108 EXPECT_EQ(GURL("http://w2.com"), whitelist[1]);
108 EXPECT_TRUE(cache->online_whitelist_all_); 109 EXPECT_TRUE(cache->online_whitelist_all_);
109 110
110 // Ensure collections in manifest were taken over by the cache rather than 111 // Ensure collections in manifest were taken over by the cache rather than
111 // copied. 112 // copied.
112 EXPECT_TRUE(manifest.fallback_namespaces.empty()); 113 EXPECT_TRUE(manifest.fallback_namespaces.empty());
113 EXPECT_TRUE(manifest.online_whitelist_namespaces.empty()); 114 EXPECT_TRUE(manifest.online_whitelist_namespaces.empty());
114 } 115 }
115 116
116 TEST(AppCacheTest, FindResponseForRequest) { 117 TEST(AppCacheTest, FindResponseForRequest) {
117 MockAppCacheService service; 118 MockAppCacheService service;
118 119
119 const GURL kOnlineNamespaceUrl("http://blah/online_namespace"); 120 const GURL kOnlineNamespaceUrl("http://blah/online_namespace");
120 const GURL kFallbackEntryUrl1("http://blah/fallback_entry1"); 121 const GURL kFallbackEntryUrl1("http://blah/fallback_entry1");
121 const GURL kFallbackNamespaceUrl1("http://blah/fallback_namespace/"); 122 const GURL kFallbackNamespaceUrl1("http://blah/fallback_namespace/");
122 const GURL kFallbackEntryUrl2("http://blah/fallback_entry2"); 123 const GURL kFallbackEntryUrl2("http://blah/fallback_entry2");
123 const GURL kFallbackNamespaceUrl2("http://blah/fallback_namespace/longer"); 124 const GURL kFallbackNamespaceUrl2("http://blah/fallback_namespace/longer");
124 const GURL kManifestUrl("http://blah/manifest"); 125 const GURL kManifestUrl("http://blah/manifest");
125 const GURL kForeignExplicitEntryUrl("http://blah/foreign"); 126 const GURL kForeignExplicitEntryUrl("http://blah/foreign");
126 const GURL kInOnlineNamespaceUrl( 127 const GURL kInOnlineNamespaceUrl(
127 "http://blah/online_namespace/network"); 128 "http://blah/online_namespace/network");
128 const GURL kExplicitInOnlineNamespaceUrl( 129 const GURL kExplicitInOnlineNamespaceUrl(
129 "http://blah/online_namespace/explicit"); 130 "http://blah/online_namespace/explicit");
130 const GURL kFallbackTestUrl1("http://blah/fallback_namespace/1"); 131 const GURL kFallbackTestUrl1("http://blah/fallback_namespace/1");
131 const GURL kFallbackTestUrl2("http://blah/fallback_namespace/longer2"); 132 const GURL kFallbackTestUrl2("http://blah/fallback_namespace/longer2");
132 const GURL kOnlineNamespaceWithinFallback( 133 const GURL kInterceptNamespace("http://blah/intercept_namespace/");
133 "http://blah/fallback_namespace/1/online"); 134 const GURL kInterceptNamespaceWithinFallback(
135 "http://blah/fallback_namespace/intercept_namespace/");
136 const GURL kInterceptNamespaceEntry("http://blah/intercept_entry");
137 const GURL kOnlineNamespaceWithinOtherNamespaces(
138 "http://blah/fallback_namespace/intercept_namespace/1/online");
134 139
135 const int64 kFallbackResponseId1 = 1; 140 const int64 kFallbackResponseId1 = 1;
136 const int64 kFallbackResponseId2 = 2; 141 const int64 kFallbackResponseId2 = 2;
137 const int64 kManifestResponseId = 3; 142 const int64 kManifestResponseId = 3;
138 const int64 kForeignExplicitResponseId = 4; 143 const int64 kForeignExplicitResponseId = 4;
139 const int64 kExplicitInOnlineNamespaceResponseId = 5; 144 const int64 kExplicitInOnlineNamespaceResponseId = 5;
145 const int64 kInterceptResponseId = 6;
140 146
141 Manifest manifest; 147 Manifest manifest;
142 manifest.online_whitelist_namespaces.push_back(kOnlineNamespaceUrl); 148 manifest.online_whitelist_namespaces.push_back(kOnlineNamespaceUrl);
143 manifest.online_whitelist_namespaces.push_back( 149 manifest.online_whitelist_namespaces.push_back(
144 kOnlineNamespaceWithinFallback); 150 kOnlineNamespaceWithinOtherNamespaces);
145 manifest.fallback_namespaces.push_back( 151 manifest.fallback_namespaces.push_back(
146 FallbackNamespace(kFallbackNamespaceUrl1, kFallbackEntryUrl1)); 152 Namespace(FALLBACK_NAMESPACE, kFallbackNamespaceUrl1,
153 kFallbackEntryUrl1));
147 manifest.fallback_namespaces.push_back( 154 manifest.fallback_namespaces.push_back(
148 FallbackNamespace(kFallbackNamespaceUrl2, kFallbackEntryUrl2)); 155 Namespace(FALLBACK_NAMESPACE, kFallbackNamespaceUrl2,
156 kFallbackEntryUrl2));
157 manifest.intercept_namespaces.push_back(
158 Namespace(INTERCEPT_NAMESPACE, kInterceptNamespace,
159 kInterceptNamespaceEntry));
160 manifest.intercept_namespaces.push_back(
161 Namespace(INTERCEPT_NAMESPACE, kInterceptNamespaceWithinFallback,
162 kInterceptNamespaceEntry));
149 163
150 // Create a cache with some namespaces and entries. 164 // Create a cache with some namespaces and entries.
151 scoped_refptr<AppCache> cache(new AppCache(&service, 1234)); 165 scoped_refptr<AppCache> cache(new AppCache(&service, 1234));
152 cache->InitializeWithManifest(&manifest); 166 cache->InitializeWithManifest(&manifest);
153 cache->AddEntry( 167 cache->AddEntry(
154 kFallbackEntryUrl1, 168 kFallbackEntryUrl1,
155 AppCacheEntry(AppCacheEntry::FALLBACK, kFallbackResponseId1)); 169 AppCacheEntry(AppCacheEntry::FALLBACK, kFallbackResponseId1));
156 cache->AddEntry( 170 cache->AddEntry(
157 kFallbackEntryUrl2, 171 kFallbackEntryUrl2,
158 AppCacheEntry(AppCacheEntry::FALLBACK, kFallbackResponseId2)); 172 AppCacheEntry(AppCacheEntry::FALLBACK, kFallbackResponseId2));
159 cache->AddEntry( 173 cache->AddEntry(
160 kManifestUrl, 174 kManifestUrl,
161 AppCacheEntry(AppCacheEntry::MANIFEST, kManifestResponseId)); 175 AppCacheEntry(AppCacheEntry::MANIFEST, kManifestResponseId));
162 cache->AddEntry( 176 cache->AddEntry(
163 kForeignExplicitEntryUrl, 177 kForeignExplicitEntryUrl,
164 AppCacheEntry(AppCacheEntry::EXPLICIT | AppCacheEntry::FOREIGN, 178 AppCacheEntry(AppCacheEntry::EXPLICIT | AppCacheEntry::FOREIGN,
165 kForeignExplicitResponseId)); 179 kForeignExplicitResponseId));
166 cache->AddEntry( 180 cache->AddEntry(
167 kExplicitInOnlineNamespaceUrl, 181 kExplicitInOnlineNamespaceUrl,
168 AppCacheEntry(AppCacheEntry::EXPLICIT, 182 AppCacheEntry(AppCacheEntry::EXPLICIT,
169 kExplicitInOnlineNamespaceResponseId)); 183 kExplicitInOnlineNamespaceResponseId));
184 cache->AddEntry(
185 kInterceptNamespaceEntry,
186 AppCacheEntry(AppCacheEntry::INTERCEPT, kInterceptResponseId));
170 cache->set_complete(true); 187 cache->set_complete(true);
171 188
172 // See that we get expected results from FindResponseForRequest 189 // See that we get expected results from FindResponseForRequest
173 190
174 bool found = false; 191 bool found = false;
175 AppCacheEntry entry; 192 AppCacheEntry entry;
176 AppCacheEntry fallback_entry; 193 AppCacheEntry fallback_entry;
177 GURL fallback_namespace; 194 GURL fallback_namespace;
178 bool network_namespace = false; 195 bool network_namespace = false;
179 196
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 &entry, &fallback_entry, &fallback_namespace, &network_namespace); 249 &entry, &fallback_entry, &fallback_namespace, &network_namespace);
233 EXPECT_TRUE(found); 250 EXPECT_TRUE(found);
234 EXPECT_FALSE(entry.has_response_id()); 251 EXPECT_FALSE(entry.has_response_id());
235 EXPECT_EQ(kFallbackResponseId2, fallback_entry.response_id()); 252 EXPECT_EQ(kFallbackResponseId2, fallback_entry.response_id());
236 EXPECT_EQ(kFallbackEntryUrl2, 253 EXPECT_EQ(kFallbackEntryUrl2,
237 cache->GetFallbackEntryUrl(fallback_namespace)); 254 cache->GetFallbackEntryUrl(fallback_namespace));
238 EXPECT_FALSE(network_namespace); 255 EXPECT_FALSE(network_namespace);
239 256
240 fallback_entry = AppCacheEntry(); // reset 257 fallback_entry = AppCacheEntry(); // reset
241 258
242 found = cache->FindResponseForRequest(kOnlineNamespaceWithinFallback, 259 found = cache->FindResponseForRequest(kOnlineNamespaceWithinOtherNamespaces,
243 &entry, &fallback_entry, &fallback_namespace, &network_namespace); 260 &entry, &fallback_entry, &fallback_namespace, &network_namespace);
244 EXPECT_TRUE(found); 261 EXPECT_TRUE(found);
245 EXPECT_FALSE(entry.has_response_id()); 262 EXPECT_FALSE(entry.has_response_id());
246 EXPECT_FALSE(fallback_entry.has_response_id()); 263 EXPECT_FALSE(fallback_entry.has_response_id());
247 EXPECT_TRUE(network_namespace); 264 EXPECT_TRUE(network_namespace);
248 265
249 fallback_entry = AppCacheEntry(); // reset 266 fallback_entry = AppCacheEntry(); // reset
250 267
251 found = cache->FindResponseForRequest( 268 found = cache->FindResponseForRequest(
252 kOnlineNamespaceWithinFallback.Resolve("online_resource"), 269 kOnlineNamespaceWithinOtherNamespaces.Resolve("online_resource"),
253 &entry, &fallback_entry, &fallback_namespace, &network_namespace); 270 &entry, &fallback_entry, &fallback_namespace, &network_namespace);
254 EXPECT_TRUE(found); 271 EXPECT_TRUE(found);
255 EXPECT_FALSE(entry.has_response_id()); 272 EXPECT_FALSE(entry.has_response_id());
256 EXPECT_FALSE(fallback_entry.has_response_id()); 273 EXPECT_FALSE(fallback_entry.has_response_id());
257 EXPECT_TRUE(network_namespace); 274 EXPECT_TRUE(network_namespace);
275
276 found = cache->FindResponseForRequest(
277 kInterceptNamespace.Resolve("intercept_me"),
278 &entry, &fallback_entry, &fallback_namespace, &network_namespace);
279 EXPECT_TRUE(found);
280 EXPECT_EQ(kInterceptResponseId, entry.response_id());
281 EXPECT_FALSE(fallback_entry.has_response_id());
282 EXPECT_FALSE(network_namespace);
283
284 entry = AppCacheEntry(); // reset
285
286 found = cache->FindResponseForRequest(
287 kInterceptNamespaceWithinFallback.Resolve("intercept_me"),
288 &entry, &fallback_entry, &fallback_namespace, &network_namespace);
289 EXPECT_TRUE(found);
290 EXPECT_EQ(kInterceptResponseId, entry.response_id());
291 EXPECT_FALSE(fallback_entry.has_response_id());
292 EXPECT_FALSE(network_namespace);
258 } 293 }
259 294
260 } // namespace appacache 295 } // namespace appacache
261 296
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698