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

Side by Side Diff: content/browser/appcache/manifest_parser_unittest.cc

Issue 344493002: Move all remaining appcache-related code to content namespace (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 5 months 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 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 <string> 5 #include <string>
6 6
7 #include "content/browser/appcache/manifest_parser.h"
7 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
8 #include "url/gurl.h" 9 #include "url/gurl.h"
9 #include "webkit/browser/appcache/manifest_parser.h"
10
11 using appcache::Manifest;
12 using appcache::NamespaceVector;
13 using appcache::APPCACHE_FALLBACK_NAMESPACE;
14 using appcache::APPCACHE_INTERCEPT_NAMESPACE;
15 using appcache::APPCACHE_NETWORK_NAMESPACE;
16 using appcache::PARSE_MANIFEST_ALLOWING_INTERCEPTS;
17 using appcache::PARSE_MANIFEST_PER_STANDARD;
18 10
19 namespace content { 11 namespace content {
20 12
21 class AppCacheManifestParserTest : public testing::Test { 13 class AppCacheManifestParserTest : public testing::Test {
22 }; 14 };
23 15
24 TEST(AppCacheManifestParserTest, NoData) { 16 TEST(AppCacheManifestParserTest, NoData) {
25 GURL url; 17 GURL url;
26 Manifest manifest; 18 Manifest manifest;
27 EXPECT_FALSE(ParseManifest(url, "", 0, 19 EXPECT_FALSE(ParseManifest(url, "", 0,
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 "http://www.five.com\r\n" 152 "http://www.five.com\r\n"
161 "*foo\r"); 153 "*foo\r");
162 154
163 EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), 155 EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(),
164 PARSE_MANIFEST_ALLOWING_INTERCEPTS, manifest)); 156 PARSE_MANIFEST_ALLOWING_INTERCEPTS, manifest));
165 EXPECT_TRUE(manifest.explicit_urls.empty()); 157 EXPECT_TRUE(manifest.explicit_urls.empty());
166 EXPECT_TRUE(manifest.fallback_namespaces.empty()); 158 EXPECT_TRUE(manifest.fallback_namespaces.empty());
167 EXPECT_TRUE(manifest.intercept_namespaces.empty()); 159 EXPECT_TRUE(manifest.intercept_namespaces.empty());
168 EXPECT_FALSE(manifest.online_whitelist_all); 160 EXPECT_FALSE(manifest.online_whitelist_all);
169 161
170 const NamespaceVector& online = manifest.online_whitelist_namespaces; 162 const AppCacheNamespaceVector& online = manifest.online_whitelist_namespaces;
171 const size_t kExpected = 6; 163 const size_t kExpected = 6;
172 ASSERT_EQ(kExpected, online.size()); 164 ASSERT_EQ(kExpected, online.size());
173 EXPECT_EQ(APPCACHE_NETWORK_NAMESPACE, online[0].type); 165 EXPECT_EQ(APPCACHE_NETWORK_NAMESPACE, online[0].type);
174 EXPECT_FALSE(online[0].is_pattern); 166 EXPECT_FALSE(online[0].is_pattern);
175 EXPECT_TRUE(online[0].target_url.is_empty()); 167 EXPECT_TRUE(online[0].target_url.is_empty());
176 EXPECT_EQ(GURL("http://www.bar.com/relative/one"), online[0].namespace_url); 168 EXPECT_EQ(GURL("http://www.bar.com/relative/one"), online[0].namespace_url);
177 EXPECT_EQ(GURL("http://www.bar.com/two"), online[1].namespace_url); 169 EXPECT_EQ(GURL("http://www.bar.com/two"), online[1].namespace_url);
178 EXPECT_EQ(GURL("http://www.diff.com/three"), online[2].namespace_url); 170 EXPECT_EQ(GURL("http://www.diff.com/three"), online[2].namespace_url);
179 EXPECT_EQ(GURL("http://www.bar.com/relative/four"), online[3].namespace_url); 171 EXPECT_EQ(GURL("http://www.bar.com/relative/four"), online[3].namespace_url);
180 EXPECT_EQ(GURL("http://www.five.com"), online[4].namespace_url); 172 EXPECT_EQ(GURL("http://www.five.com"), online[4].namespace_url);
(...skipping 25 matching lines...) Expand all
206 "FALLBACK:\n" 198 "FALLBACK:\n"
207 "relative/four#strip relative/fourfb#strip\r" 199 "relative/four#strip relative/fourfb#strip\r"
208 "http://www.glorp.com/notsame relative/skipped\r"); 200 "http://www.glorp.com/notsame relative/skipped\r");
209 201
210 EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), 202 EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(),
211 PARSE_MANIFEST_ALLOWING_INTERCEPTS, manifest)); 203 PARSE_MANIFEST_ALLOWING_INTERCEPTS, manifest));
212 EXPECT_TRUE(manifest.explicit_urls.empty()); 204 EXPECT_TRUE(manifest.explicit_urls.empty());
213 EXPECT_TRUE(manifest.online_whitelist_namespaces.empty()); 205 EXPECT_TRUE(manifest.online_whitelist_namespaces.empty());
214 EXPECT_FALSE(manifest.online_whitelist_all); 206 EXPECT_FALSE(manifest.online_whitelist_all);
215 207
216 const NamespaceVector& fallbacks = manifest.fallback_namespaces; 208 const AppCacheNamespaceVector& fallbacks = manifest.fallback_namespaces;
217 const size_t kExpected = 5; 209 const size_t kExpected = 5;
218 ASSERT_EQ(kExpected, fallbacks.size()); 210 ASSERT_EQ(kExpected, fallbacks.size());
219 EXPECT_EQ(APPCACHE_FALLBACK_NAMESPACE, fallbacks[0].type); 211 EXPECT_EQ(APPCACHE_FALLBACK_NAMESPACE, fallbacks[0].type);
220 EXPECT_EQ(APPCACHE_FALLBACK_NAMESPACE, fallbacks[1].type); 212 EXPECT_EQ(APPCACHE_FALLBACK_NAMESPACE, fallbacks[1].type);
221 EXPECT_EQ(APPCACHE_FALLBACK_NAMESPACE, fallbacks[2].type); 213 EXPECT_EQ(APPCACHE_FALLBACK_NAMESPACE, fallbacks[2].type);
222 EXPECT_EQ(APPCACHE_FALLBACK_NAMESPACE, fallbacks[3].type); 214 EXPECT_EQ(APPCACHE_FALLBACK_NAMESPACE, fallbacks[3].type);
223 EXPECT_EQ(APPCACHE_FALLBACK_NAMESPACE, fallbacks[4].type); 215 EXPECT_EQ(APPCACHE_FALLBACK_NAMESPACE, fallbacks[4].type);
224 EXPECT_EQ(GURL("http://glorp.com/relative/one"), 216 EXPECT_EQ(GURL("http://glorp.com/relative/one"),
225 fallbacks[0].namespace_url); 217 fallbacks[0].namespace_url);
226 EXPECT_EQ(GURL("http://glorp.com/onefb"), 218 EXPECT_EQ(GURL("http://glorp.com/onefb"),
(...skipping 30 matching lines...) Expand all
257 "http://www.portme.com:1234/three HTTP://www.portme.com:1234/threefb\r" 249 "http://www.portme.com:1234/three HTTP://www.portme.com:1234/threefb\r"
258 "http://www.portme.com/noport http://www.portme.com:1234/skipped\r" 250 "http://www.portme.com/noport http://www.portme.com:1234/skipped\r"
259 "http://www.portme.com:1234/skipme http://www.portme.com/noport\r"); 251 "http://www.portme.com:1234/skipme http://www.portme.com/noport\r");
260 252
261 EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), 253 EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(),
262 PARSE_MANIFEST_ALLOWING_INTERCEPTS, manifest)); 254 PARSE_MANIFEST_ALLOWING_INTERCEPTS, manifest));
263 EXPECT_TRUE(manifest.explicit_urls.empty()); 255 EXPECT_TRUE(manifest.explicit_urls.empty());
264 EXPECT_TRUE(manifest.online_whitelist_namespaces.empty()); 256 EXPECT_TRUE(manifest.online_whitelist_namespaces.empty());
265 EXPECT_FALSE(manifest.online_whitelist_all); 257 EXPECT_FALSE(manifest.online_whitelist_all);
266 258
267 const NamespaceVector& fallbacks = manifest.fallback_namespaces; 259 const AppCacheNamespaceVector& fallbacks = manifest.fallback_namespaces;
268 const size_t kExpected = 3; 260 const size_t kExpected = 3;
269 ASSERT_EQ(kExpected, fallbacks.size()); 261 ASSERT_EQ(kExpected, fallbacks.size());
270 EXPECT_EQ(APPCACHE_FALLBACK_NAMESPACE, fallbacks[0].type); 262 EXPECT_EQ(APPCACHE_FALLBACK_NAMESPACE, fallbacks[0].type);
271 EXPECT_EQ(APPCACHE_FALLBACK_NAMESPACE, fallbacks[1].type); 263 EXPECT_EQ(APPCACHE_FALLBACK_NAMESPACE, fallbacks[1].type);
272 EXPECT_EQ(APPCACHE_FALLBACK_NAMESPACE, fallbacks[2].type); 264 EXPECT_EQ(APPCACHE_FALLBACK_NAMESPACE, fallbacks[2].type);
273 EXPECT_EQ(GURL("http://www.portme.com:1234/one"), 265 EXPECT_EQ(GURL("http://www.portme.com:1234/one"),
274 fallbacks[0].namespace_url); 266 fallbacks[0].namespace_url);
275 EXPECT_EQ(GURL("http://www.portme.com:1234/relative/onefb"), 267 EXPECT_EQ(GURL("http://www.portme.com:1234/relative/onefb"),
276 fallbacks[0].target_url); 268 fallbacks[0].target_url);
277 EXPECT_EQ(GURL("http://www.portme.com:1234/relative/two"), 269 EXPECT_EQ(GURL("http://www.portme.com:1234/relative/two"),
(...skipping 23 matching lines...) Expand all
301 "http://www.portme.com:1234/skipme return http://www.portme.com/noport\r" 293 "http://www.portme.com:1234/skipme return http://www.portme.com/noport\r"
302 "relative/wrong/again missing/intercept_type\r"); 294 "relative/wrong/again missing/intercept_type\r");
303 295
304 EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), 296 EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(),
305 PARSE_MANIFEST_ALLOWING_INTERCEPTS, manifest)); 297 PARSE_MANIFEST_ALLOWING_INTERCEPTS, manifest));
306 EXPECT_TRUE(manifest.fallback_namespaces.empty()); 298 EXPECT_TRUE(manifest.fallback_namespaces.empty());
307 EXPECT_TRUE(manifest.explicit_urls.empty()); 299 EXPECT_TRUE(manifest.explicit_urls.empty());
308 EXPECT_TRUE(manifest.online_whitelist_namespaces.empty()); 300 EXPECT_TRUE(manifest.online_whitelist_namespaces.empty());
309 EXPECT_FALSE(manifest.online_whitelist_all); 301 EXPECT_FALSE(manifest.online_whitelist_all);
310 302
311 const NamespaceVector& intercepts = manifest.intercept_namespaces; 303 const AppCacheNamespaceVector& intercepts = manifest.intercept_namespaces;
312 const size_t kExpected = 3; 304 const size_t kExpected = 3;
313 ASSERT_EQ(kExpected, intercepts.size()); 305 ASSERT_EQ(kExpected, intercepts.size());
314 EXPECT_EQ(APPCACHE_INTERCEPT_NAMESPACE, intercepts[0].type); 306 EXPECT_EQ(APPCACHE_INTERCEPT_NAMESPACE, intercepts[0].type);
315 EXPECT_EQ(APPCACHE_INTERCEPT_NAMESPACE, intercepts[1].type); 307 EXPECT_EQ(APPCACHE_INTERCEPT_NAMESPACE, intercepts[1].type);
316 EXPECT_EQ(APPCACHE_INTERCEPT_NAMESPACE, intercepts[2].type); 308 EXPECT_EQ(APPCACHE_INTERCEPT_NAMESPACE, intercepts[2].type);
317 EXPECT_EQ(GURL("http://www.portme.com:1234/one"), 309 EXPECT_EQ(GURL("http://www.portme.com:1234/one"),
318 intercepts[0].namespace_url); 310 intercepts[0].namespace_url);
319 EXPECT_EQ(GURL("http://www.portme.com:1234/relative/int1"), 311 EXPECT_EQ(GURL("http://www.portme.com:1234/relative/int1"),
320 intercepts[0].target_url); 312 intercepts[0].target_url);
321 EXPECT_EQ(GURL("http://www.portme.com:1234/relative/two"), 313 EXPECT_EQ(GURL("http://www.portme.com:1234/relative/two"),
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 EXPECT_TRUE(manifest.online_whitelist_all); 357 EXPECT_TRUE(manifest.online_whitelist_all);
366 358
367 base::hash_set<std::string> urls = manifest.explicit_urls; 359 base::hash_set<std::string> urls = manifest.explicit_urls;
368 size_t expected = 3; 360 size_t expected = 3;
369 ASSERT_EQ(expected, urls.size()); 361 ASSERT_EQ(expected, urls.size());
370 EXPECT_TRUE(urls.find("http://combo.com:42/relative/explicit-1") != 362 EXPECT_TRUE(urls.find("http://combo.com:42/relative/explicit-1") !=
371 urls.end()); 363 urls.end());
372 EXPECT_TRUE(urls.find("http://combo.com:99/explicit-2") != urls.end()); 364 EXPECT_TRUE(urls.find("http://combo.com:99/explicit-2") != urls.end());
373 EXPECT_TRUE(urls.find("http://www.diff.com/explicit-3") != urls.end()); 365 EXPECT_TRUE(urls.find("http://www.diff.com/explicit-3") != urls.end());
374 366
375 const NamespaceVector& online = manifest.online_whitelist_namespaces; 367 const AppCacheNamespaceVector& online = manifest.online_whitelist_namespaces;
376 expected = 4; 368 expected = 4;
377 ASSERT_EQ(expected, online.size()); 369 ASSERT_EQ(expected, online.size());
378 EXPECT_EQ(GURL("http://combo.com/whitelist-1"), 370 EXPECT_EQ(GURL("http://combo.com/whitelist-1"),
379 online[0].namespace_url); 371 online[0].namespace_url);
380 EXPECT_EQ(GURL("http://www.diff.com/whitelist-2"), 372 EXPECT_EQ(GURL("http://www.diff.com/whitelist-2"),
381 online[1].namespace_url); 373 online[1].namespace_url);
382 EXPECT_EQ(GURL("http://combo.com:42/relative/whitelist-3"), 374 EXPECT_EQ(GURL("http://combo.com:42/relative/whitelist-3"),
383 online[2].namespace_url); 375 online[2].namespace_url);
384 EXPECT_EQ(GURL("http://combo.com:99/whitelist-4"), 376 EXPECT_EQ(GURL("http://combo.com:99/whitelist-4"),
385 online[3].namespace_url); 377 online[3].namespace_url);
386 378
387 const NamespaceVector& fallbacks = manifest.fallback_namespaces; 379 const AppCacheNamespaceVector& fallbacks = manifest.fallback_namespaces;
388 expected = 2; 380 expected = 2;
389 ASSERT_EQ(expected, fallbacks.size()); 381 ASSERT_EQ(expected, fallbacks.size());
390 EXPECT_EQ(APPCACHE_FALLBACK_NAMESPACE, fallbacks[0].type); 382 EXPECT_EQ(APPCACHE_FALLBACK_NAMESPACE, fallbacks[0].type);
391 EXPECT_EQ(APPCACHE_FALLBACK_NAMESPACE, fallbacks[1].type); 383 EXPECT_EQ(APPCACHE_FALLBACK_NAMESPACE, fallbacks[1].type);
392 EXPECT_EQ(GURL("http://combo.com:42/fallback-1"), 384 EXPECT_EQ(GURL("http://combo.com:42/fallback-1"),
393 fallbacks[0].namespace_url); 385 fallbacks[0].namespace_url);
394 EXPECT_EQ(GURL("http://combo.com:42/fallback-1b"), 386 EXPECT_EQ(GURL("http://combo.com:42/fallback-1b"),
395 fallbacks[0].target_url); 387 fallbacks[0].target_url);
396 EXPECT_EQ(GURL("http://combo.com:42/relative/fallback-2"), 388 EXPECT_EQ(GURL("http://combo.com:42/relative/fallback-2"),
397 fallbacks[1].namespace_url); 389 fallbacks[1].namespace_url);
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 manifest.online_whitelist_namespaces[0].target_url); 507 manifest.online_whitelist_namespaces[0].target_url);
516 EXPECT_EQ( 508 EXPECT_EQ(
517 GURL("http://foo.com/network_pattern*"), 509 GURL("http://foo.com/network_pattern*"),
518 manifest.online_whitelist_namespaces[1].namespace_url); 510 manifest.online_whitelist_namespaces[1].namespace_url);
519 EXPECT_EQ( 511 EXPECT_EQ(
520 GURL(), 512 GURL(),
521 manifest.online_whitelist_namespaces[1].target_url); 513 manifest.online_whitelist_namespaces[1].target_url);
522 } 514 }
523 515
524 } // namespace content 516 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698