| 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "content/browser/appcache/appcache_manifest_parser.h" | 7 #include "content/browser/appcache/appcache_manifest_parser.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "url/gurl.h" | 9 #include "url/gurl.h" |
| 10 | 10 |
| 11 namespace content { | 11 namespace content { |
| 12 | 12 |
| 13 class AppCacheManifestParserTest : public testing::Test { | 13 class AppCacheManifestParserTest : public testing::Test { |
| 14 }; | 14 }; |
| 15 | 15 |
| 16 TEST(AppCacheManifestParserTest, NoData) { | 16 TEST(AppCacheManifestParserTest, NoData) { |
| 17 GURL url; | 17 GURL url; |
| 18 Manifest manifest; | 18 AppCacheManifest manifest; |
| 19 EXPECT_FALSE(ParseManifest(url, "", 0, | 19 EXPECT_FALSE(ParseManifest(url, "", 0, |
| 20 PARSE_MANIFEST_ALLOWING_INTERCEPTS, manifest)); | 20 PARSE_MANIFEST_ALLOWING_INTERCEPTS, manifest)); |
| 21 EXPECT_FALSE(ParseManifest(url, "CACHE MANIFEST\r", 0, // Len is 0. | 21 EXPECT_FALSE(ParseManifest(url, "CACHE MANIFEST\r", 0, // Len is 0. |
| 22 PARSE_MANIFEST_ALLOWING_INTERCEPTS, manifest)); | 22 PARSE_MANIFEST_ALLOWING_INTERCEPTS, manifest)); |
| 23 } | 23 } |
| 24 | 24 |
| 25 TEST(AppCacheManifestParserTest, CheckSignature) { | 25 TEST(AppCacheManifestParserTest, CheckSignature) { |
| 26 GURL url; | 26 GURL url; |
| 27 Manifest manifest; | 27 AppCacheManifest manifest; |
| 28 | 28 |
| 29 const std::string kBadSignatures[] = { | 29 const std::string kBadSignatures[] = { |
| 30 "foo", | 30 "foo", |
| 31 "CACHE MANIFEST;V2\r", // not followed by whitespace | 31 "CACHE MANIFEST;V2\r", // not followed by whitespace |
| 32 "CACHE MANIFEST#bad\r", // no whitespace before comment | 32 "CACHE MANIFEST#bad\r", // no whitespace before comment |
| 33 "cache manifest ", // wrong case | 33 "cache manifest ", // wrong case |
| 34 "#CACHE MANIFEST\r", // comment | 34 "#CACHE MANIFEST\r", // comment |
| 35 "xCACHE MANIFEST\n", // bad first char | 35 "xCACHE MANIFEST\n", // bad first char |
| 36 " CACHE MANIFEST\r", // begins with whitespace | 36 " CACHE MANIFEST\r", // begins with whitespace |
| 37 "\xEF\xBE\xBF" "CACHE MANIFEST\r", // bad UTF-8 BOM value | 37 "\xEF\xBE\xBF" "CACHE MANIFEST\r", // bad UTF-8 BOM value |
| (...skipping 18 matching lines...) Expand all Loading... |
| 56 }; | 56 }; |
| 57 | 57 |
| 58 for (size_t i = 0; i < arraysize(kGoodSignatures); ++i) { | 58 for (size_t i = 0; i < arraysize(kGoodSignatures); ++i) { |
| 59 const std::string good = kGoodSignatures[i]; | 59 const std::string good = kGoodSignatures[i]; |
| 60 EXPECT_TRUE(ParseManifest(url, good.c_str(), good.length(), | 60 EXPECT_TRUE(ParseManifest(url, good.c_str(), good.length(), |
| 61 PARSE_MANIFEST_ALLOWING_INTERCEPTS, manifest)); | 61 PARSE_MANIFEST_ALLOWING_INTERCEPTS, manifest)); |
| 62 } | 62 } |
| 63 } | 63 } |
| 64 | 64 |
| 65 TEST(AppCacheManifestParserTest, NoManifestUrl) { | 65 TEST(AppCacheManifestParserTest, NoManifestUrl) { |
| 66 Manifest manifest; | 66 AppCacheManifest manifest; |
| 67 const std::string kData("CACHE MANIFEST\r" | 67 const std::string kData("CACHE MANIFEST\r" |
| 68 "relative/tobase.com\r" | 68 "relative/tobase.com\r" |
| 69 "http://absolute.com/addme.com"); | 69 "http://absolute.com/addme.com"); |
| 70 const GURL kUrl; | 70 const GURL kUrl; |
| 71 EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), | 71 EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), |
| 72 PARSE_MANIFEST_ALLOWING_INTERCEPTS, manifest)); | 72 PARSE_MANIFEST_ALLOWING_INTERCEPTS, manifest)); |
| 73 EXPECT_TRUE(manifest.explicit_urls.empty()); | 73 EXPECT_TRUE(manifest.explicit_urls.empty()); |
| 74 EXPECT_TRUE(manifest.fallback_namespaces.empty()); | 74 EXPECT_TRUE(manifest.fallback_namespaces.empty()); |
| 75 EXPECT_TRUE(manifest.online_whitelist_namespaces.empty()); | 75 EXPECT_TRUE(manifest.online_whitelist_namespaces.empty()); |
| 76 EXPECT_FALSE(manifest.online_whitelist_all); | 76 EXPECT_FALSE(manifest.online_whitelist_all); |
| 77 } | 77 } |
| 78 | 78 |
| 79 TEST(AppCacheManifestParserTest, ExplicitUrls) { | 79 TEST(AppCacheManifestParserTest, ExplicitUrls) { |
| 80 Manifest manifest; | 80 AppCacheManifest manifest; |
| 81 const GURL kUrl("http://www.foo.com"); | 81 const GURL kUrl("http://www.foo.com"); |
| 82 const std::string kData("CACHE MANIFEST\r" | 82 const std::string kData("CACHE MANIFEST\r" |
| 83 "relative/one\r" | 83 "relative/one\r" |
| 84 "# some comment\r" | 84 "# some comment\r" |
| 85 "http://www.foo.com/two#strip\r\n" | 85 "http://www.foo.com/two#strip\r\n" |
| 86 "NETWORK:\r" | 86 "NETWORK:\r" |
| 87 " \t CACHE:\r" | 87 " \t CACHE:\r" |
| 88 "HTTP://www.diff.com/three\r" | 88 "HTTP://www.diff.com/three\r" |
| 89 "FALLBACK:\r" | 89 "FALLBACK:\r" |
| 90 " \t # another comment with leading whitespace\n" | 90 " \t # another comment with leading whitespace\n" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 107 ASSERT_EQ(kExpected, urls.size()); | 107 ASSERT_EQ(kExpected, urls.size()); |
| 108 EXPECT_TRUE(urls.find("http://www.foo.com/relative/one") != urls.end()); | 108 EXPECT_TRUE(urls.find("http://www.foo.com/relative/one") != urls.end()); |
| 109 EXPECT_TRUE(urls.find("http://www.foo.com/two") != urls.end()); | 109 EXPECT_TRUE(urls.find("http://www.foo.com/two") != urls.end()); |
| 110 EXPECT_TRUE(urls.find("http://www.diff.com/three") != urls.end()); | 110 EXPECT_TRUE(urls.find("http://www.diff.com/three") != urls.end()); |
| 111 EXPECT_TRUE(urls.find("http://www.foo.com/relative/four") != urls.end()); | 111 EXPECT_TRUE(urls.find("http://www.foo.com/relative/four") != urls.end()); |
| 112 | 112 |
| 113 // Wildcard is treated as a relative URL in explicit section. | 113 // Wildcard is treated as a relative URL in explicit section. |
| 114 EXPECT_TRUE(urls.find("http://www.foo.com/*") != urls.end()); | 114 EXPECT_TRUE(urls.find("http://www.foo.com/*") != urls.end()); |
| 115 | 115 |
| 116 // We should get the same results with intercepts disallowed. | 116 // We should get the same results with intercepts disallowed. |
| 117 manifest = Manifest(); | 117 manifest = AppCacheManifest(); |
| 118 EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), | 118 EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), |
| 119 PARSE_MANIFEST_PER_STANDARD, manifest)); | 119 PARSE_MANIFEST_PER_STANDARD, manifest)); |
| 120 EXPECT_TRUE(manifest.fallback_namespaces.empty()); | 120 EXPECT_TRUE(manifest.fallback_namespaces.empty()); |
| 121 EXPECT_TRUE(manifest.online_whitelist_namespaces.empty()); | 121 EXPECT_TRUE(manifest.online_whitelist_namespaces.empty()); |
| 122 EXPECT_FALSE(manifest.online_whitelist_all); | 122 EXPECT_FALSE(manifest.online_whitelist_all); |
| 123 | 123 |
| 124 urls = manifest.explicit_urls; | 124 urls = manifest.explicit_urls; |
| 125 ASSERT_EQ(kExpected, urls.size()); | 125 ASSERT_EQ(kExpected, urls.size()); |
| 126 EXPECT_TRUE(urls.find("http://www.foo.com/relative/one") != urls.end()); | 126 EXPECT_TRUE(urls.find("http://www.foo.com/relative/one") != urls.end()); |
| 127 EXPECT_TRUE(urls.find("http://www.foo.com/two") != urls.end()); | 127 EXPECT_TRUE(urls.find("http://www.foo.com/two") != urls.end()); |
| 128 EXPECT_TRUE(urls.find("http://www.diff.com/three") != urls.end()); | 128 EXPECT_TRUE(urls.find("http://www.diff.com/three") != urls.end()); |
| 129 EXPECT_TRUE(urls.find("http://www.foo.com/relative/four") != urls.end()); | 129 EXPECT_TRUE(urls.find("http://www.foo.com/relative/four") != urls.end()); |
| 130 | 130 |
| 131 // Wildcard is treated as a relative URL in explicit section. | 131 // Wildcard is treated as a relative URL in explicit section. |
| 132 EXPECT_TRUE(urls.find("http://www.foo.com/*") != urls.end()); | 132 EXPECT_TRUE(urls.find("http://www.foo.com/*") != urls.end()); |
| 133 } | 133 } |
| 134 | 134 |
| 135 TEST(AppCacheManifestParserTest, WhitelistUrls) { | 135 TEST(AppCacheManifestParserTest, WhitelistUrls) { |
| 136 Manifest manifest; | 136 AppCacheManifest manifest; |
| 137 const GURL kUrl("http://www.bar.com"); | 137 const GURL kUrl("http://www.bar.com"); |
| 138 const std::string kData("CACHE MANIFEST\r" | 138 const std::string kData("CACHE MANIFEST\r" |
| 139 "NETWORK:\r" | 139 "NETWORK:\r" |
| 140 "relative/one\r" | 140 "relative/one\r" |
| 141 "# a comment\r" | 141 "# a comment\r" |
| 142 "http://www.bar.com/two\r" | 142 "http://www.bar.com/two\r" |
| 143 "HTTP://www.diff.com/three#strip\n\r" | 143 "HTTP://www.diff.com/three#strip\n\r" |
| 144 "FALLBACK:\r" | 144 "FALLBACK:\r" |
| 145 "garbage\r" | 145 "garbage\r" |
| 146 "UNKNOWN:\r" | 146 "UNKNOWN:\r" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 167 EXPECT_TRUE(online[0].target_url.is_empty()); | 167 EXPECT_TRUE(online[0].target_url.is_empty()); |
| 168 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); |
| 169 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); |
| 170 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); |
| 171 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); |
| 172 EXPECT_EQ(GURL("http://www.five.com"), online[4].namespace_url); | 172 EXPECT_EQ(GURL("http://www.five.com"), online[4].namespace_url); |
| 173 EXPECT_EQ(GURL("http://www.bar.com/*foo"), online[5].namespace_url); | 173 EXPECT_EQ(GURL("http://www.bar.com/*foo"), online[5].namespace_url); |
| 174 } | 174 } |
| 175 | 175 |
| 176 TEST(AppCacheManifestParserTest, FallbackUrls) { | 176 TEST(AppCacheManifestParserTest, FallbackUrls) { |
| 177 Manifest manifest; | 177 AppCacheManifest manifest; |
| 178 const GURL kUrl("http://glorp.com"); | 178 const GURL kUrl("http://glorp.com"); |
| 179 const std::string kData("CACHE MANIFEST\r" | 179 const std::string kData("CACHE MANIFEST\r" |
| 180 "# a comment\r" | 180 "# a comment\r" |
| 181 "CACHE:\r" | 181 "CACHE:\r" |
| 182 "NETWORK:\r" | 182 "NETWORK:\r" |
| 183 "UNKNOWN:\r" | 183 "UNKNOWN:\r" |
| 184 "FALLBACK:\r" | 184 "FALLBACK:\r" |
| 185 "relative/one \t \t http://glorp.com/onefb \t \r" | 185 "relative/one \t \t http://glorp.com/onefb \t \r" |
| 186 "*\r" | 186 "*\r" |
| 187 "https://glorp.com/wrong http://glorp.com/wrongfb\r" | 187 "https://glorp.com/wrong http://glorp.com/wrongfb\r" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 fallbacks[3].target_url); | 231 fallbacks[3].target_url); |
| 232 EXPECT_EQ(GURL("http://glorp.com/relative/four"), | 232 EXPECT_EQ(GURL("http://glorp.com/relative/four"), |
| 233 fallbacks[4].namespace_url); | 233 fallbacks[4].namespace_url); |
| 234 EXPECT_EQ(GURL("http://glorp.com/relative/fourfb"), | 234 EXPECT_EQ(GURL("http://glorp.com/relative/fourfb"), |
| 235 fallbacks[4].target_url); | 235 fallbacks[4].target_url); |
| 236 | 236 |
| 237 EXPECT_TRUE(manifest.intercept_namespaces.empty()); | 237 EXPECT_TRUE(manifest.intercept_namespaces.empty()); |
| 238 } | 238 } |
| 239 | 239 |
| 240 TEST(AppCacheManifestParserTest, FallbackUrlsWithPort) { | 240 TEST(AppCacheManifestParserTest, FallbackUrlsWithPort) { |
| 241 Manifest manifest; | 241 AppCacheManifest manifest; |
| 242 const GURL kUrl("http://www.portme.com:1234"); | 242 const GURL kUrl("http://www.portme.com:1234"); |
| 243 const std::string kData("CACHE MANIFEST\r" | 243 const std::string kData("CACHE MANIFEST\r" |
| 244 "FALLBACK:\r" | 244 "FALLBACK:\r" |
| 245 "http://www.portme.com:1234/one relative/onefb\r" | 245 "http://www.portme.com:1234/one relative/onefb\r" |
| 246 "HTTP://www.portme.com:9876/wrong http://www.portme.com:1234/ignore\r" | 246 "HTTP://www.portme.com:9876/wrong http://www.portme.com:1234/ignore\r" |
| 247 "http://www.portme.com:1234/stillwrong http://www.portme.com:42/boo\r" | 247 "http://www.portme.com:1234/stillwrong http://www.portme.com:42/boo\r" |
| 248 "relative/two relative/twofb\r" | 248 "relative/two relative/twofb\r" |
| 249 "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" |
| 250 "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" |
| 251 "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"); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 272 fallbacks[1].target_url); | 272 fallbacks[1].target_url); |
| 273 EXPECT_EQ(GURL("http://www.portme.com:1234/three"), | 273 EXPECT_EQ(GURL("http://www.portme.com:1234/three"), |
| 274 fallbacks[2].namespace_url); | 274 fallbacks[2].namespace_url); |
| 275 EXPECT_EQ(GURL("http://www.portme.com:1234/threefb"), | 275 EXPECT_EQ(GURL("http://www.portme.com:1234/threefb"), |
| 276 fallbacks[2].target_url); | 276 fallbacks[2].target_url); |
| 277 | 277 |
| 278 EXPECT_TRUE(manifest.intercept_namespaces.empty()); | 278 EXPECT_TRUE(manifest.intercept_namespaces.empty()); |
| 279 } | 279 } |
| 280 | 280 |
| 281 TEST(AppCacheManifestParserTest, InterceptUrls) { | 281 TEST(AppCacheManifestParserTest, InterceptUrls) { |
| 282 Manifest manifest; | 282 AppCacheManifest manifest; |
| 283 const GURL kUrl("http://www.portme.com:1234"); | 283 const GURL kUrl("http://www.portme.com:1234"); |
| 284 const std::string kData("CHROMIUM CACHE MANIFEST\r" | 284 const std::string kData("CHROMIUM CACHE MANIFEST\r" |
| 285 "CHROMIUM-INTERCEPT:\r" | 285 "CHROMIUM-INTERCEPT:\r" |
| 286 "http://www.portme.com:1234/one return relative/int1\r" | 286 "http://www.portme.com:1234/one return relative/int1\r" |
| 287 "HTTP://www.portme.com:9/wrong return http://www.portme.com:1234/ignore\r" | 287 "HTTP://www.portme.com:9/wrong return http://www.portme.com:1234/ignore\r" |
| 288 "http://www.portme.com:1234/wrong return http://www.portme.com:9/boo\r" | 288 "http://www.portme.com:1234/wrong return http://www.portme.com:9/boo\r" |
| 289 "relative/two return relative/int2\r" | 289 "relative/two return relative/int2\r" |
| 290 "relative/three wrong relative/threefb\r" | 290 "relative/three wrong relative/threefb\r" |
| 291 "http://www.portme.com:1234/three return HTTP://www.portme.com:1234/int3\r" | 291 "http://www.portme.com:1234/three return HTTP://www.portme.com:1234/int3\r" |
| 292 "http://www.portme.com/noport return http://www.portme.com:1234/skipped\r" | 292 "http://www.portme.com/noport return http://www.portme.com:1234/skipped\r" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 313 EXPECT_EQ(GURL("http://www.portme.com:1234/relative/two"), | 313 EXPECT_EQ(GURL("http://www.portme.com:1234/relative/two"), |
| 314 intercepts[1].namespace_url); | 314 intercepts[1].namespace_url); |
| 315 EXPECT_EQ(GURL("http://www.portme.com:1234/relative/int2"), | 315 EXPECT_EQ(GURL("http://www.portme.com:1234/relative/int2"), |
| 316 intercepts[1].target_url); | 316 intercepts[1].target_url); |
| 317 EXPECT_EQ(GURL("http://www.portme.com:1234/three"), | 317 EXPECT_EQ(GURL("http://www.portme.com:1234/three"), |
| 318 intercepts[2].namespace_url); | 318 intercepts[2].namespace_url); |
| 319 EXPECT_EQ(GURL("http://www.portme.com:1234/int3"), | 319 EXPECT_EQ(GURL("http://www.portme.com:1234/int3"), |
| 320 intercepts[2].target_url); | 320 intercepts[2].target_url); |
| 321 | 321 |
| 322 // Disallow intercepts ths time. | 322 // Disallow intercepts ths time. |
| 323 manifest = Manifest(); | 323 manifest = AppCacheManifest(); |
| 324 EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), | 324 EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), |
| 325 PARSE_MANIFEST_PER_STANDARD, manifest)); | 325 PARSE_MANIFEST_PER_STANDARD, manifest)); |
| 326 EXPECT_TRUE(manifest.fallback_namespaces.empty()); | 326 EXPECT_TRUE(manifest.fallback_namespaces.empty()); |
| 327 EXPECT_TRUE(manifest.explicit_urls.empty()); | 327 EXPECT_TRUE(manifest.explicit_urls.empty()); |
| 328 EXPECT_TRUE(manifest.online_whitelist_namespaces.empty()); | 328 EXPECT_TRUE(manifest.online_whitelist_namespaces.empty()); |
| 329 EXPECT_TRUE(manifest.intercept_namespaces.empty()); | 329 EXPECT_TRUE(manifest.intercept_namespaces.empty()); |
| 330 EXPECT_FALSE(manifest.online_whitelist_all); | 330 EXPECT_FALSE(manifest.online_whitelist_all); |
| 331 } | 331 } |
| 332 | 332 |
| 333 TEST(AppCacheManifestParserTest, ComboUrls) { | 333 TEST(AppCacheManifestParserTest, ComboUrls) { |
| 334 Manifest manifest; | 334 AppCacheManifest manifest; |
| 335 const GURL kUrl("http://combo.com:42"); | 335 const GURL kUrl("http://combo.com:42"); |
| 336 const std::string kData("CACHE MANIFEST\r" | 336 const std::string kData("CACHE MANIFEST\r" |
| 337 "relative/explicit-1\r" | 337 "relative/explicit-1\r" |
| 338 "# some comment\r" | 338 "# some comment\r" |
| 339 "http://combo.com:99/explicit-2#strip\r" | 339 "http://combo.com:99/explicit-2#strip\r" |
| 340 "NETWORK:\r" | 340 "NETWORK:\r" |
| 341 "http://combo.com/whitelist-1\r" | 341 "http://combo.com/whitelist-1\r" |
| 342 "HTTP://www.diff.com/whitelist-2#strip\r" | 342 "HTTP://www.diff.com/whitelist-2#strip\r" |
| 343 "*\r" | 343 "*\r" |
| 344 "CACHE:\n\r" | 344 "CACHE:\n\r" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 fallbacks[0].target_url); | 387 fallbacks[0].target_url); |
| 388 EXPECT_EQ(GURL("http://combo.com:42/relative/fallback-2"), | 388 EXPECT_EQ(GURL("http://combo.com:42/relative/fallback-2"), |
| 389 fallbacks[1].namespace_url); | 389 fallbacks[1].namespace_url); |
| 390 EXPECT_EQ(GURL("http://combo.com:42/relative/fallback-2b"), | 390 EXPECT_EQ(GURL("http://combo.com:42/relative/fallback-2b"), |
| 391 fallbacks[1].target_url); | 391 fallbacks[1].target_url); |
| 392 | 392 |
| 393 EXPECT_TRUE(manifest.intercept_namespaces.empty()); | 393 EXPECT_TRUE(manifest.intercept_namespaces.empty()); |
| 394 } | 394 } |
| 395 | 395 |
| 396 TEST(AppCacheManifestParserTest, UnusualUtf8) { | 396 TEST(AppCacheManifestParserTest, UnusualUtf8) { |
| 397 Manifest manifest; | 397 AppCacheManifest manifest; |
| 398 const GURL kUrl("http://bad.com"); | 398 const GURL kUrl("http://bad.com"); |
| 399 const std::string kData("CACHE MANIFEST\r" | 399 const std::string kData("CACHE MANIFEST\r" |
| 400 "\xC0" "invalidutf8\r" | 400 "\xC0" "invalidutf8\r" |
| 401 "nonbmp" "\xF1\x84\xAB\xBC\r"); | 401 "nonbmp" "\xF1\x84\xAB\xBC\r"); |
| 402 EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), | 402 EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), |
| 403 PARSE_MANIFEST_ALLOWING_INTERCEPTS, manifest)); | 403 PARSE_MANIFEST_ALLOWING_INTERCEPTS, manifest)); |
| 404 base::hash_set<std::string> urls = manifest.explicit_urls; | 404 base::hash_set<std::string> urls = manifest.explicit_urls; |
| 405 EXPECT_TRUE(urls.find("http://bad.com/%EF%BF%BDinvalidutf8") != urls.end()); | 405 EXPECT_TRUE(urls.find("http://bad.com/%EF%BF%BDinvalidutf8") != urls.end()); |
| 406 EXPECT_TRUE(urls.find("http://bad.com/nonbmp%F1%84%AB%BC") != urls.end()); | 406 EXPECT_TRUE(urls.find("http://bad.com/nonbmp%F1%84%AB%BC") != urls.end()); |
| 407 } | 407 } |
| 408 | 408 |
| 409 TEST(AppCacheManifestParserTest, IgnoreAfterSpace) { | 409 TEST(AppCacheManifestParserTest, IgnoreAfterSpace) { |
| 410 Manifest manifest; | 410 AppCacheManifest manifest; |
| 411 const GURL kUrl("http://smorg.borg"); | 411 const GURL kUrl("http://smorg.borg"); |
| 412 const std::string kData( | 412 const std::string kData( |
| 413 "CACHE MANIFEST\r" | 413 "CACHE MANIFEST\r" |
| 414 "resource.txt this stuff after the white space should be ignored\r"); | 414 "resource.txt this stuff after the white space should be ignored\r"); |
| 415 EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), | 415 EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), |
| 416 PARSE_MANIFEST_ALLOWING_INTERCEPTS, manifest)); | 416 PARSE_MANIFEST_ALLOWING_INTERCEPTS, manifest)); |
| 417 | 417 |
| 418 base::hash_set<std::string> urls = manifest.explicit_urls; | 418 base::hash_set<std::string> urls = manifest.explicit_urls; |
| 419 EXPECT_TRUE(urls.find("http://smorg.borg/resource.txt") != urls.end()); | 419 EXPECT_TRUE(urls.find("http://smorg.borg/resource.txt") != urls.end()); |
| 420 } | 420 } |
| 421 | 421 |
| 422 TEST(AppCacheManifestParserTest, DifferentOriginUrlWithSecureScheme) { | 422 TEST(AppCacheManifestParserTest, DifferentOriginUrlWithSecureScheme) { |
| 423 Manifest manifest; | 423 AppCacheManifest manifest; |
| 424 const GURL kUrl("https://www.foo.com"); | 424 const GURL kUrl("https://www.foo.com"); |
| 425 const std::string kData("CACHE MANIFEST\r" | 425 const std::string kData("CACHE MANIFEST\r" |
| 426 "CACHE: \r" | 426 "CACHE: \r" |
| 427 "relative/secureschemesameorigin\r" | 427 "relative/secureschemesameorigin\r" |
| 428 "https://www.foo.com/secureschemesameorigin\r" | 428 "https://www.foo.com/secureschemesameorigin\r" |
| 429 "http://www.xyz.com/secureschemedifforigin\r" | 429 "http://www.xyz.com/secureschemedifforigin\r" |
| 430 "https://www.xyz.com/secureschemedifforigin\r"); | 430 "https://www.xyz.com/secureschemedifforigin\r"); |
| 431 | 431 |
| 432 EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), | 432 EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), |
| 433 PARSE_MANIFEST_ALLOWING_INTERCEPTS, manifest)); | 433 PARSE_MANIFEST_ALLOWING_INTERCEPTS, manifest)); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 459 "http://foo.com/*/intercept_pattern?query return /pattern isPattern\r" | 459 "http://foo.com/*/intercept_pattern?query return /pattern isPattern\r" |
| 460 "FALLBACK:\r" | 460 "FALLBACK:\r" |
| 461 "http://foo.com/fallback_prefix /prefix wrongAnnotation\r" | 461 "http://foo.com/fallback_prefix /prefix wrongAnnotation\r" |
| 462 "http://foo.com/fallback_pattern* /pattern\tisPattern \r" | 462 "http://foo.com/fallback_pattern* /pattern\tisPattern \r" |
| 463 "NETWORK:\r" | 463 "NETWORK:\r" |
| 464 "*\r" | 464 "*\r" |
| 465 "isPattern\r" // should not be interpretted as a pattern | 465 "isPattern\r" // should not be interpretted as a pattern |
| 466 "http://foo.com/network_pattern* isPattern\r"); | 466 "http://foo.com/network_pattern* isPattern\r"); |
| 467 | 467 |
| 468 | 468 |
| 469 Manifest manifest; | 469 AppCacheManifest manifest; |
| 470 EXPECT_TRUE(ParseManifest(kUrl, kManifestBody.c_str(), | 470 EXPECT_TRUE(ParseManifest(kUrl, kManifestBody.c_str(), |
| 471 kManifestBody.length(), | 471 kManifestBody.length(), |
| 472 PARSE_MANIFEST_ALLOWING_INTERCEPTS, manifest)); | 472 PARSE_MANIFEST_ALLOWING_INTERCEPTS, manifest)); |
| 473 EXPECT_TRUE(manifest.online_whitelist_all); | 473 EXPECT_TRUE(manifest.online_whitelist_all); |
| 474 EXPECT_EQ(1u, manifest.explicit_urls.size()); | 474 EXPECT_EQ(1u, manifest.explicit_urls.size()); |
| 475 EXPECT_EQ(3u, manifest.intercept_namespaces.size()); | 475 EXPECT_EQ(3u, manifest.intercept_namespaces.size()); |
| 476 EXPECT_EQ(2u, manifest.fallback_namespaces.size()); | 476 EXPECT_EQ(2u, manifest.fallback_namespaces.size()); |
| 477 EXPECT_EQ(2u, manifest.online_whitelist_namespaces.size()); | 477 EXPECT_EQ(2u, manifest.online_whitelist_namespaces.size()); |
| 478 EXPECT_EQ(APPCACHE_INTERCEPT_NAMESPACE, | 478 EXPECT_EQ(APPCACHE_INTERCEPT_NAMESPACE, |
| 479 manifest.intercept_namespaces[0].type); | 479 manifest.intercept_namespaces[0].type); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 507 manifest.online_whitelist_namespaces[0].target_url); | 507 manifest.online_whitelist_namespaces[0].target_url); |
| 508 EXPECT_EQ( | 508 EXPECT_EQ( |
| 509 GURL("http://foo.com/network_pattern*"), | 509 GURL("http://foo.com/network_pattern*"), |
| 510 manifest.online_whitelist_namespaces[1].namespace_url); | 510 manifest.online_whitelist_namespaces[1].namespace_url); |
| 511 EXPECT_EQ( | 511 EXPECT_EQ( |
| 512 GURL(), | 512 GURL(), |
| 513 manifest.online_whitelist_namespaces[1].target_url); | 513 manifest.online_whitelist_namespaces[1].target_url); |
| 514 } | 514 } |
| 515 | 515 |
| 516 } // namespace content | 516 } // namespace content |
| OLD | NEW |