| 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 "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 #include "url/gurl.h" | 8 #include "url/gurl.h" |
| 9 #include "webkit/browser/appcache/manifest_parser.h" | 9 #include "webkit/browser/appcache/manifest_parser.h" |
| 10 | 10 |
| 11 using appcache::Manifest; | 11 using appcache::Manifest; |
| 12 using appcache::NamespaceVector; | 12 using appcache::NamespaceVector; |
| 13 using appcache::FALLBACK_NAMESPACE; | 13 using appcache::FALLBACK_NAMESPACE; |
| 14 using appcache::INTERCEPT_NAMESPACE; | 14 using appcache::INTERCEPT_NAMESPACE; |
| 15 using appcache::NETWORK_NAMESPACE; | 15 using appcache::NETWORK_NAMESPACE; |
| 16 | 16 |
| 17 namespace content { | 17 namespace content { |
| 18 | 18 |
| 19 class AppCacheManifestParserTest : public testing::Test { | 19 class AppCacheManifestParserTest : public testing::Test { |
| 20 }; | 20 }; |
| 21 | 21 |
| 22 TEST(AppCacheManifestParserTest, NoData) { | 22 TEST(AppCacheManifestParserTest, NoData) { |
| 23 GURL url; | 23 GURL url; |
| 24 Manifest manifest; | 24 Manifest manifest; |
| 25 EXPECT_FALSE(ParseManifest(url, "", 0, manifest)); | 25 EXPECT_FALSE(ParseManifest(url, "", 0, true, manifest)); |
| 26 EXPECT_FALSE(ParseManifest(url, "CACHE MANIFEST\r", 0, manifest)); // 0 len | 26 EXPECT_FALSE(ParseManifest(url, "CACHE MANIFEST\r", 0, |
| 27 true, manifest)); // 0 len |
| 27 } | 28 } |
| 28 | 29 |
| 29 TEST(AppCacheManifestParserTest, CheckSignature) { | 30 TEST(AppCacheManifestParserTest, CheckSignature) { |
| 30 GURL url; | 31 GURL url; |
| 31 Manifest manifest; | 32 Manifest manifest; |
| 32 | 33 |
| 33 const std::string kBadSignatures[] = { | 34 const std::string kBadSignatures[] = { |
| 34 "foo", | 35 "foo", |
| 35 "CACHE MANIFEST;V2\r", // not followed by whitespace | 36 "CACHE MANIFEST;V2\r", // not followed by whitespace |
| 36 "CACHE MANIFEST#bad\r", // no whitespace before comment | 37 "CACHE MANIFEST#bad\r", // no whitespace before comment |
| 37 "cache manifest ", // wrong case | 38 "cache manifest ", // wrong case |
| 38 "#CACHE MANIFEST\r", // comment | 39 "#CACHE MANIFEST\r", // comment |
| 39 "xCACHE MANIFEST\n", // bad first char | 40 "xCACHE MANIFEST\n", // bad first char |
| 40 " CACHE MANIFEST\r", // begins with whitespace | 41 " CACHE MANIFEST\r", // begins with whitespace |
| 41 "\xEF\xBE\xBF" "CACHE MANIFEST\r", // bad UTF-8 BOM value | 42 "\xEF\xBE\xBF" "CACHE MANIFEST\r", // bad UTF-8 BOM value |
| 42 }; | 43 }; |
| 43 | 44 |
| 44 for (size_t i = 0; i < arraysize(kBadSignatures); ++i) { | 45 for (size_t i = 0; i < arraysize(kBadSignatures); ++i) { |
| 45 const std::string bad = kBadSignatures[i]; | 46 const std::string bad = kBadSignatures[i]; |
| 46 EXPECT_FALSE(ParseManifest(url, bad.c_str(), bad.length(), manifest)); | 47 EXPECT_FALSE(ParseManifest(url, bad.c_str(), bad.length(), |
| 48 true, manifest)); |
| 47 } | 49 } |
| 48 | 50 |
| 49 const std::string kGoodSignatures[] = { | 51 const std::string kGoodSignatures[] = { |
| 50 "CACHE MANIFEST", | 52 "CACHE MANIFEST", |
| 51 "CACHE MANIFEST ", | 53 "CACHE MANIFEST ", |
| 52 "CACHE MANIFEST\r", | 54 "CACHE MANIFEST\r", |
| 53 "CACHE MANIFEST\n", | 55 "CACHE MANIFEST\n", |
| 54 "CACHE MANIFEST\r\n", | 56 "CACHE MANIFEST\r\n", |
| 55 "CACHE MANIFEST\t# ignore me\r", | 57 "CACHE MANIFEST\t# ignore me\r", |
| 56 "CACHE MANIFEST ignore\r\n", | 58 "CACHE MANIFEST ignore\r\n", |
| 57 "CHROMIUM CACHE MANIFEST\r\n", | 59 "CHROMIUM CACHE MANIFEST\r\n", |
| 58 "\xEF\xBB\xBF" "CACHE MANIFEST \r\n", // BOM present | 60 "\xEF\xBB\xBF" "CACHE MANIFEST \r\n", // BOM present |
| 59 }; | 61 }; |
| 60 | 62 |
| 61 for (size_t i = 0; i < arraysize(kGoodSignatures); ++i) { | 63 for (size_t i = 0; i < arraysize(kGoodSignatures); ++i) { |
| 62 const std::string good = kGoodSignatures[i]; | 64 const std::string good = kGoodSignatures[i]; |
| 63 EXPECT_TRUE(ParseManifest(url, good.c_str(), good.length(), manifest)); | 65 EXPECT_TRUE(ParseManifest(url, good.c_str(), good.length(), |
| 66 true, manifest)); |
| 64 } | 67 } |
| 65 } | 68 } |
| 66 | 69 |
| 67 TEST(AppCacheManifestParserTest, NoManifestUrl) { | 70 TEST(AppCacheManifestParserTest, NoManifestUrl) { |
| 68 Manifest manifest; | 71 Manifest manifest; |
| 69 const std::string kData("CACHE MANIFEST\r" | 72 const std::string kData("CACHE MANIFEST\r" |
| 70 "relative/tobase.com\r" | 73 "relative/tobase.com\r" |
| 71 "http://absolute.com/addme.com"); | 74 "http://absolute.com/addme.com"); |
| 72 const GURL kUrl; | 75 const GURL kUrl; |
| 73 EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), manifest)); | 76 EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), |
| 77 true, manifest)); |
| 74 EXPECT_TRUE(manifest.explicit_urls.empty()); | 78 EXPECT_TRUE(manifest.explicit_urls.empty()); |
| 75 EXPECT_TRUE(manifest.fallback_namespaces.empty()); | 79 EXPECT_TRUE(manifest.fallback_namespaces.empty()); |
| 76 EXPECT_TRUE(manifest.online_whitelist_namespaces.empty()); | 80 EXPECT_TRUE(manifest.online_whitelist_namespaces.empty()); |
| 77 EXPECT_FALSE(manifest.online_whitelist_all); | 81 EXPECT_FALSE(manifest.online_whitelist_all); |
| 78 } | 82 } |
| 79 | 83 |
| 80 TEST(AppCacheManifestParserTest, ExplicitUrls) { | 84 TEST(AppCacheManifestParserTest, ExplicitUrls) { |
| 81 Manifest manifest; | 85 Manifest manifest; |
| 82 const GURL kUrl("http://www.foo.com"); | 86 const GURL kUrl("http://www.foo.com"); |
| 83 const std::string kData("CACHE MANIFEST\r" | 87 const std::string kData("CACHE MANIFEST\r" |
| 84 "relative/one\r" | 88 "relative/one\r" |
| 85 "# some comment\r" | 89 "# some comment\r" |
| 86 "http://www.foo.com/two#strip\r\n" | 90 "http://www.foo.com/two#strip\r\n" |
| 87 "NETWORK:\r" | 91 "NETWORK:\r" |
| 88 " \t CACHE:\r" | 92 " \t CACHE:\r" |
| 89 "HTTP://www.diff.com/three\r" | 93 "HTTP://www.diff.com/three\r" |
| 90 "FALLBACK:\r" | 94 "FALLBACK:\r" |
| 91 " \t # another comment with leading whitespace\n" | 95 " \t # another comment with leading whitespace\n" |
| 92 "IGNORE:\r" | 96 "IGNORE:\r" |
| 93 "http://www.foo.com/ignore\r" | 97 "http://www.foo.com/ignore\r" |
| 94 "CACHE: \r" | 98 "CACHE: \r" |
| 95 "garbage:#!@\r" | 99 "garbage:#!@\r" |
| 96 "https://www.foo.com/diffscheme \t \r" | 100 "https://www.foo.com/diffscheme \t \r" |
| 97 " \t relative/four#stripme\n\r" | 101 " \t relative/four#stripme\n\r" |
| 98 "*\r"); | 102 "*\r"); |
| 99 | 103 |
| 100 EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), manifest)); | 104 EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), |
| 105 true, manifest)); |
| 101 EXPECT_TRUE(manifest.fallback_namespaces.empty()); | 106 EXPECT_TRUE(manifest.fallback_namespaces.empty()); |
| 102 EXPECT_TRUE(manifest.online_whitelist_namespaces.empty()); | 107 EXPECT_TRUE(manifest.online_whitelist_namespaces.empty()); |
| 103 EXPECT_FALSE(manifest.online_whitelist_all); | 108 EXPECT_FALSE(manifest.online_whitelist_all); |
| 104 | 109 |
| 105 base::hash_set<std::string> urls = manifest.explicit_urls; | 110 base::hash_set<std::string> urls = manifest.explicit_urls; |
| 106 const size_t kExpected = 5; | 111 const size_t kExpected = 5; |
| 107 ASSERT_EQ(kExpected, urls.size()); | 112 ASSERT_EQ(kExpected, urls.size()); |
| 108 EXPECT_TRUE(urls.find("http://www.foo.com/relative/one") != urls.end()); | 113 EXPECT_TRUE(urls.find("http://www.foo.com/relative/one") != urls.end()); |
| 109 EXPECT_TRUE(urls.find("http://www.foo.com/two") != urls.end()); | 114 EXPECT_TRUE(urls.find("http://www.foo.com/two") != urls.end()); |
| 110 EXPECT_TRUE(urls.find("http://www.diff.com/three") != urls.end()); | 115 EXPECT_TRUE(urls.find("http://www.diff.com/three") != urls.end()); |
| 111 EXPECT_TRUE(urls.find("http://www.foo.com/relative/four") != urls.end()); | 116 EXPECT_TRUE(urls.find("http://www.foo.com/relative/four") != urls.end()); |
| 112 | 117 |
| 113 // Wildcard is treated as a relative URL in explicit section. | 118 // Wildcard is treated as a relative URL in explicit section. |
| 114 EXPECT_TRUE(urls.find("http://www.foo.com/*") != urls.end()); | 119 EXPECT_TRUE(urls.find("http://www.foo.com/*") != urls.end()); |
| 120 |
| 121 // We should get the same results with intercepts disallowed. |
| 122 manifest = Manifest(); |
| 123 EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), |
| 124 false, manifest)); |
| 125 EXPECT_TRUE(manifest.fallback_namespaces.empty()); |
| 126 EXPECT_TRUE(manifest.online_whitelist_namespaces.empty()); |
| 127 EXPECT_FALSE(manifest.online_whitelist_all); |
| 128 |
| 129 urls = manifest.explicit_urls; |
| 130 ASSERT_EQ(kExpected, urls.size()); |
| 131 EXPECT_TRUE(urls.find("http://www.foo.com/relative/one") != urls.end()); |
| 132 EXPECT_TRUE(urls.find("http://www.foo.com/two") != urls.end()); |
| 133 EXPECT_TRUE(urls.find("http://www.diff.com/three") != urls.end()); |
| 134 EXPECT_TRUE(urls.find("http://www.foo.com/relative/four") != urls.end()); |
| 135 |
| 136 // Wildcard is treated as a relative URL in explicit section. |
| 137 EXPECT_TRUE(urls.find("http://www.foo.com/*") != urls.end()); |
| 115 } | 138 } |
| 116 | 139 |
| 117 TEST(AppCacheManifestParserTest, WhitelistUrls) { | 140 TEST(AppCacheManifestParserTest, WhitelistUrls) { |
| 118 Manifest manifest; | 141 Manifest manifest; |
| 119 const GURL kUrl("http://www.bar.com"); | 142 const GURL kUrl("http://www.bar.com"); |
| 120 const std::string kData("CACHE MANIFEST\r" | 143 const std::string kData("CACHE MANIFEST\r" |
| 121 "NETWORK:\r" | 144 "NETWORK:\r" |
| 122 "relative/one\r" | 145 "relative/one\r" |
| 123 "# a comment\r" | 146 "# a comment\r" |
| 124 "http://www.bar.com/two\r" | 147 "http://www.bar.com/two\r" |
| 125 "HTTP://www.diff.com/three#strip\n\r" | 148 "HTTP://www.diff.com/three#strip\n\r" |
| 126 "FALLBACK:\r" | 149 "FALLBACK:\r" |
| 127 "garbage\r" | 150 "garbage\r" |
| 128 "UNKNOWN:\r" | 151 "UNKNOWN:\r" |
| 129 "http://www.bar.com/ignore\r" | 152 "http://www.bar.com/ignore\r" |
| 130 "CACHE:\r" | 153 "CACHE:\r" |
| 131 "NETWORK:\r" | 154 "NETWORK:\r" |
| 132 "https://www.wrongscheme.com\n" | 155 "https://www.wrongscheme.com\n" |
| 133 "relative/four#stripref \t \r" | 156 "relative/four#stripref \t \r" |
| 134 "http://www.five.com\r\n" | 157 "http://www.five.com\r\n" |
| 135 "*foo\r"); | 158 "*foo\r"); |
| 136 | 159 |
| 137 EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), manifest)); | 160 EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), |
| 161 true, manifest)); |
| 138 EXPECT_TRUE(manifest.explicit_urls.empty()); | 162 EXPECT_TRUE(manifest.explicit_urls.empty()); |
| 139 EXPECT_TRUE(manifest.fallback_namespaces.empty()); | 163 EXPECT_TRUE(manifest.fallback_namespaces.empty()); |
| 140 EXPECT_TRUE(manifest.intercept_namespaces.empty()); | 164 EXPECT_TRUE(manifest.intercept_namespaces.empty()); |
| 141 EXPECT_FALSE(manifest.online_whitelist_all); | 165 EXPECT_FALSE(manifest.online_whitelist_all); |
| 142 | 166 |
| 143 const NamespaceVector& online = manifest.online_whitelist_namespaces; | 167 const NamespaceVector& online = manifest.online_whitelist_namespaces; |
| 144 const size_t kExpected = 6; | 168 const size_t kExpected = 6; |
| 145 ASSERT_EQ(kExpected, online.size()); | 169 ASSERT_EQ(kExpected, online.size()); |
| 146 EXPECT_EQ(NETWORK_NAMESPACE, online[0].type); | 170 EXPECT_EQ(NETWORK_NAMESPACE, online[0].type); |
| 147 EXPECT_FALSE(online[0].is_pattern); | 171 EXPECT_FALSE(online[0].is_pattern); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 173 "http://diff.com/ignore http://glorp.com/wronghost\r" | 197 "http://diff.com/ignore http://glorp.com/wronghost\r" |
| 174 "http://glorp.com/wronghost http://diff.com/ohwell\r" | 198 "http://glorp.com/wronghost http://diff.com/ohwell\r" |
| 175 "relative/badscheme ftp://glorp.com/ignored\r" | 199 "relative/badscheme ftp://glorp.com/ignored\r" |
| 176 "garbage\r\n" | 200 "garbage\r\n" |
| 177 "CACHE:\r" | 201 "CACHE:\r" |
| 178 "# only fallback urls in this test\r" | 202 "# only fallback urls in this test\r" |
| 179 "FALLBACK:\n" | 203 "FALLBACK:\n" |
| 180 "relative/four#strip relative/fourfb#strip\r" | 204 "relative/four#strip relative/fourfb#strip\r" |
| 181 "http://www.glorp.com/notsame relative/skipped\r"); | 205 "http://www.glorp.com/notsame relative/skipped\r"); |
| 182 | 206 |
| 183 EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), manifest)); | 207 EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), |
| 208 true, manifest)); |
| 184 EXPECT_TRUE(manifest.explicit_urls.empty()); | 209 EXPECT_TRUE(manifest.explicit_urls.empty()); |
| 185 EXPECT_TRUE(manifest.online_whitelist_namespaces.empty()); | 210 EXPECT_TRUE(manifest.online_whitelist_namespaces.empty()); |
| 186 EXPECT_FALSE(manifest.online_whitelist_all); | 211 EXPECT_FALSE(manifest.online_whitelist_all); |
| 187 | 212 |
| 188 const NamespaceVector& fallbacks = manifest.fallback_namespaces; | 213 const NamespaceVector& fallbacks = manifest.fallback_namespaces; |
| 189 const size_t kExpected = 5; | 214 const size_t kExpected = 5; |
| 190 ASSERT_EQ(kExpected, fallbacks.size()); | 215 ASSERT_EQ(kExpected, fallbacks.size()); |
| 191 EXPECT_EQ(FALLBACK_NAMESPACE, fallbacks[0].type); | 216 EXPECT_EQ(FALLBACK_NAMESPACE, fallbacks[0].type); |
| 192 EXPECT_EQ(FALLBACK_NAMESPACE, fallbacks[1].type); | 217 EXPECT_EQ(FALLBACK_NAMESPACE, fallbacks[1].type); |
| 193 EXPECT_EQ(FALLBACK_NAMESPACE, fallbacks[2].type); | 218 EXPECT_EQ(FALLBACK_NAMESPACE, fallbacks[2].type); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 223 const std::string kData("CACHE MANIFEST\r" | 248 const std::string kData("CACHE MANIFEST\r" |
| 224 "FALLBACK:\r" | 249 "FALLBACK:\r" |
| 225 "http://www.portme.com:1234/one relative/onefb\r" | 250 "http://www.portme.com:1234/one relative/onefb\r" |
| 226 "HTTP://www.portme.com:9876/wrong http://www.portme.com:1234/ignore\r" | 251 "HTTP://www.portme.com:9876/wrong http://www.portme.com:1234/ignore\r" |
| 227 "http://www.portme.com:1234/stillwrong http://www.portme.com:42/boo\r" | 252 "http://www.portme.com:1234/stillwrong http://www.portme.com:42/boo\r" |
| 228 "relative/two relative/twofb\r" | 253 "relative/two relative/twofb\r" |
| 229 "http://www.portme.com:1234/three HTTP://www.portme.com:1234/threefb\r" | 254 "http://www.portme.com:1234/three HTTP://www.portme.com:1234/threefb\r" |
| 230 "http://www.portme.com/noport http://www.portme.com:1234/skipped\r" | 255 "http://www.portme.com/noport http://www.portme.com:1234/skipped\r" |
| 231 "http://www.portme.com:1234/skipme http://www.portme.com/noport\r"); | 256 "http://www.portme.com:1234/skipme http://www.portme.com/noport\r"); |
| 232 | 257 |
| 233 EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), manifest)); | 258 EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), |
| 259 true, manifest)); |
| 234 EXPECT_TRUE(manifest.explicit_urls.empty()); | 260 EXPECT_TRUE(manifest.explicit_urls.empty()); |
| 235 EXPECT_TRUE(manifest.online_whitelist_namespaces.empty()); | 261 EXPECT_TRUE(manifest.online_whitelist_namespaces.empty()); |
| 236 EXPECT_FALSE(manifest.online_whitelist_all); | 262 EXPECT_FALSE(manifest.online_whitelist_all); |
| 237 | 263 |
| 238 const NamespaceVector& fallbacks = manifest.fallback_namespaces; | 264 const NamespaceVector& fallbacks = manifest.fallback_namespaces; |
| 239 const size_t kExpected = 3; | 265 const size_t kExpected = 3; |
| 240 ASSERT_EQ(kExpected, fallbacks.size()); | 266 ASSERT_EQ(kExpected, fallbacks.size()); |
| 241 EXPECT_EQ(FALLBACK_NAMESPACE, fallbacks[0].type); | 267 EXPECT_EQ(FALLBACK_NAMESPACE, fallbacks[0].type); |
| 242 EXPECT_EQ(FALLBACK_NAMESPACE, fallbacks[1].type); | 268 EXPECT_EQ(FALLBACK_NAMESPACE, fallbacks[1].type); |
| 243 EXPECT_EQ(FALLBACK_NAMESPACE, fallbacks[2].type); | 269 EXPECT_EQ(FALLBACK_NAMESPACE, fallbacks[2].type); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 265 "http://www.portme.com:1234/one return relative/int1\r" | 291 "http://www.portme.com:1234/one return relative/int1\r" |
| 266 "HTTP://www.portme.com:9/wrong return http://www.portme.com:1234/ignore\r" | 292 "HTTP://www.portme.com:9/wrong return http://www.portme.com:1234/ignore\r" |
| 267 "http://www.portme.com:1234/wrong return http://www.portme.com:9/boo\r" | 293 "http://www.portme.com:1234/wrong return http://www.portme.com:9/boo\r" |
| 268 "relative/two return relative/int2\r" | 294 "relative/two return relative/int2\r" |
| 269 "relative/three wrong relative/threefb\r" | 295 "relative/three wrong relative/threefb\r" |
| 270 "http://www.portme.com:1234/three return HTTP://www.portme.com:1234/int3\r" | 296 "http://www.portme.com:1234/three return HTTP://www.portme.com:1234/int3\r" |
| 271 "http://www.portme.com/noport return http://www.portme.com:1234/skipped\r" | 297 "http://www.portme.com/noport return http://www.portme.com:1234/skipped\r" |
| 272 "http://www.portme.com:1234/skipme return http://www.portme.com/noport\r" | 298 "http://www.portme.com:1234/skipme return http://www.portme.com/noport\r" |
| 273 "relative/wrong/again missing/intercept_type\r"); | 299 "relative/wrong/again missing/intercept_type\r"); |
| 274 | 300 |
| 275 EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), manifest)); | 301 EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), |
| 302 true, manifest)); |
| 276 EXPECT_TRUE(manifest.fallback_namespaces.empty()); | 303 EXPECT_TRUE(manifest.fallback_namespaces.empty()); |
| 277 EXPECT_TRUE(manifest.explicit_urls.empty()); | 304 EXPECT_TRUE(manifest.explicit_urls.empty()); |
| 278 EXPECT_TRUE(manifest.online_whitelist_namespaces.empty()); | 305 EXPECT_TRUE(manifest.online_whitelist_namespaces.empty()); |
| 279 EXPECT_FALSE(manifest.online_whitelist_all); | 306 EXPECT_FALSE(manifest.online_whitelist_all); |
| 280 | 307 |
| 281 const NamespaceVector& intercepts = manifest.intercept_namespaces; | 308 const NamespaceVector& intercepts = manifest.intercept_namespaces; |
| 282 const size_t kExpected = 3; | 309 const size_t kExpected = 3; |
| 283 ASSERT_EQ(kExpected, intercepts.size()); | 310 ASSERT_EQ(kExpected, intercepts.size()); |
| 284 EXPECT_EQ(INTERCEPT_NAMESPACE, intercepts[0].type); | 311 EXPECT_EQ(INTERCEPT_NAMESPACE, intercepts[0].type); |
| 285 EXPECT_EQ(INTERCEPT_NAMESPACE, intercepts[1].type); | 312 EXPECT_EQ(INTERCEPT_NAMESPACE, intercepts[1].type); |
| 286 EXPECT_EQ(INTERCEPT_NAMESPACE, intercepts[2].type); | 313 EXPECT_EQ(INTERCEPT_NAMESPACE, intercepts[2].type); |
| 287 EXPECT_EQ(GURL("http://www.portme.com:1234/one"), | 314 EXPECT_EQ(GURL("http://www.portme.com:1234/one"), |
| 288 intercepts[0].namespace_url); | 315 intercepts[0].namespace_url); |
| 289 EXPECT_EQ(GURL("http://www.portme.com:1234/relative/int1"), | 316 EXPECT_EQ(GURL("http://www.portme.com:1234/relative/int1"), |
| 290 intercepts[0].target_url); | 317 intercepts[0].target_url); |
| 291 EXPECT_EQ(GURL("http://www.portme.com:1234/relative/two"), | 318 EXPECT_EQ(GURL("http://www.portme.com:1234/relative/two"), |
| 292 intercepts[1].namespace_url); | 319 intercepts[1].namespace_url); |
| 293 EXPECT_EQ(GURL("http://www.portme.com:1234/relative/int2"), | 320 EXPECT_EQ(GURL("http://www.portme.com:1234/relative/int2"), |
| 294 intercepts[1].target_url); | 321 intercepts[1].target_url); |
| 295 EXPECT_EQ(GURL("http://www.portme.com:1234/three"), | 322 EXPECT_EQ(GURL("http://www.portme.com:1234/three"), |
| 296 intercepts[2].namespace_url); | 323 intercepts[2].namespace_url); |
| 297 EXPECT_EQ(GURL("http://www.portme.com:1234/int3"), | 324 EXPECT_EQ(GURL("http://www.portme.com:1234/int3"), |
| 298 intercepts[2].target_url); | 325 intercepts[2].target_url); |
| 326 |
| 327 // Disallow intercepts ths time. |
| 328 manifest = Manifest(); |
| 329 EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), |
| 330 false, manifest)); |
| 331 EXPECT_TRUE(manifest.fallback_namespaces.empty()); |
| 332 EXPECT_TRUE(manifest.explicit_urls.empty()); |
| 333 EXPECT_TRUE(manifest.online_whitelist_namespaces.empty()); |
| 334 EXPECT_TRUE(manifest.intercept_namespaces.empty()); |
| 335 EXPECT_FALSE(manifest.online_whitelist_all); |
| 299 } | 336 } |
| 300 | 337 |
| 301 TEST(AppCacheManifestParserTest, ComboUrls) { | 338 TEST(AppCacheManifestParserTest, ComboUrls) { |
| 302 Manifest manifest; | 339 Manifest manifest; |
| 303 const GURL kUrl("http://combo.com:42"); | 340 const GURL kUrl("http://combo.com:42"); |
| 304 const std::string kData("CACHE MANIFEST\r" | 341 const std::string kData("CACHE MANIFEST\r" |
| 305 "relative/explicit-1\r" | 342 "relative/explicit-1\r" |
| 306 "# some comment\r" | 343 "# some comment\r" |
| 307 "http://combo.com:99/explicit-2#strip\r" | 344 "http://combo.com:99/explicit-2#strip\r" |
| 308 "NETWORK:\r" | 345 "NETWORK:\r" |
| 309 "http://combo.com/whitelist-1\r" | 346 "http://combo.com/whitelist-1\r" |
| 310 "HTTP://www.diff.com/whitelist-2#strip\r" | 347 "HTTP://www.diff.com/whitelist-2#strip\r" |
| 311 "*\r" | 348 "*\r" |
| 312 "CACHE:\n\r" | 349 "CACHE:\n\r" |
| 313 "http://www.diff.com/explicit-3\r" | 350 "http://www.diff.com/explicit-3\r" |
| 314 "FALLBACK:\r" | 351 "FALLBACK:\r" |
| 315 "http://combo.com:42/fallback-1 http://combo.com:42/fallback-1b\r" | 352 "http://combo.com:42/fallback-1 http://combo.com:42/fallback-1b\r" |
| 316 "relative/fallback-2 relative/fallback-2b\r" | 353 "relative/fallback-2 relative/fallback-2b\r" |
| 317 "UNKNOWN:\r\n" | 354 "UNKNOWN:\r\n" |
| 318 "http://combo.com/ignoreme\r" | 355 "http://combo.com/ignoreme\r" |
| 319 "relative/still-ignored\r" | 356 "relative/still-ignored\r" |
| 320 "NETWORK:\r\n" | 357 "NETWORK:\r\n" |
| 321 "relative/whitelist-3#strip\r" | 358 "relative/whitelist-3#strip\r" |
| 322 "http://combo.com:99/whitelist-4\r"); | 359 "http://combo.com:99/whitelist-4\r"); |
| 323 EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), manifest)); | 360 EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), |
| 361 true, manifest)); |
| 324 EXPECT_TRUE(manifest.online_whitelist_all); | 362 EXPECT_TRUE(manifest.online_whitelist_all); |
| 325 | 363 |
| 326 base::hash_set<std::string> urls = manifest.explicit_urls; | 364 base::hash_set<std::string> urls = manifest.explicit_urls; |
| 327 size_t expected = 3; | 365 size_t expected = 3; |
| 328 ASSERT_EQ(expected, urls.size()); | 366 ASSERT_EQ(expected, urls.size()); |
| 329 EXPECT_TRUE(urls.find("http://combo.com:42/relative/explicit-1") != | 367 EXPECT_TRUE(urls.find("http://combo.com:42/relative/explicit-1") != |
| 330 urls.end()); | 368 urls.end()); |
| 331 EXPECT_TRUE(urls.find("http://combo.com:99/explicit-2") != urls.end()); | 369 EXPECT_TRUE(urls.find("http://combo.com:99/explicit-2") != urls.end()); |
| 332 EXPECT_TRUE(urls.find("http://www.diff.com/explicit-3") != urls.end()); | 370 EXPECT_TRUE(urls.find("http://www.diff.com/explicit-3") != urls.end()); |
| 333 | 371 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 359 | 397 |
| 360 EXPECT_TRUE(manifest.intercept_namespaces.empty()); | 398 EXPECT_TRUE(manifest.intercept_namespaces.empty()); |
| 361 } | 399 } |
| 362 | 400 |
| 363 TEST(AppCacheManifestParserTest, UnusualUtf8) { | 401 TEST(AppCacheManifestParserTest, UnusualUtf8) { |
| 364 Manifest manifest; | 402 Manifest manifest; |
| 365 const GURL kUrl("http://bad.com"); | 403 const GURL kUrl("http://bad.com"); |
| 366 const std::string kData("CACHE MANIFEST\r" | 404 const std::string kData("CACHE MANIFEST\r" |
| 367 "\xC0" "invalidutf8\r" | 405 "\xC0" "invalidutf8\r" |
| 368 "nonbmp" "\xF1\x84\xAB\xBC\r"); | 406 "nonbmp" "\xF1\x84\xAB\xBC\r"); |
| 369 EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), manifest)); | 407 EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), |
| 370 | 408 true, manifest)); |
| 371 base::hash_set<std::string> urls = manifest.explicit_urls; | 409 base::hash_set<std::string> urls = manifest.explicit_urls; |
| 372 EXPECT_TRUE(urls.find("http://bad.com/%EF%BF%BDinvalidutf8") != urls.end()); | 410 EXPECT_TRUE(urls.find("http://bad.com/%EF%BF%BDinvalidutf8") != urls.end()); |
| 373 EXPECT_TRUE(urls.find("http://bad.com/nonbmp%F1%84%AB%BC") != urls.end()); | 411 EXPECT_TRUE(urls.find("http://bad.com/nonbmp%F1%84%AB%BC") != urls.end()); |
| 374 } | 412 } |
| 375 | 413 |
| 376 TEST(AppCacheManifestParserTest, IgnoreAfterSpace) { | 414 TEST(AppCacheManifestParserTest, IgnoreAfterSpace) { |
| 377 Manifest manifest; | 415 Manifest manifest; |
| 378 const GURL kUrl("http://smorg.borg"); | 416 const GURL kUrl("http://smorg.borg"); |
| 379 const std::string kData( | 417 const std::string kData( |
| 380 "CACHE MANIFEST\r" | 418 "CACHE MANIFEST\r" |
| 381 "resource.txt this stuff after the white space should be ignored\r"); | 419 "resource.txt this stuff after the white space should be ignored\r"); |
| 382 EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), manifest)); | 420 EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), |
| 421 true, manifest)); |
| 383 | 422 |
| 384 base::hash_set<std::string> urls = manifest.explicit_urls; | 423 base::hash_set<std::string> urls = manifest.explicit_urls; |
| 385 EXPECT_TRUE(urls.find("http://smorg.borg/resource.txt") != urls.end()); | 424 EXPECT_TRUE(urls.find("http://smorg.borg/resource.txt") != urls.end()); |
| 386 } | 425 } |
| 387 | 426 |
| 388 TEST(AppCacheManifestParserTest, DifferentOriginUrlWithSecureScheme) { | 427 TEST(AppCacheManifestParserTest, DifferentOriginUrlWithSecureScheme) { |
| 389 Manifest manifest; | 428 Manifest manifest; |
| 390 const GURL kUrl("https://www.foo.com"); | 429 const GURL kUrl("https://www.foo.com"); |
| 391 const std::string kData("CACHE MANIFEST\r" | 430 const std::string kData("CACHE MANIFEST\r" |
| 392 "CACHE: \r" | 431 "CACHE: \r" |
| 393 "relative/secureschemesameorigin\r" | 432 "relative/secureschemesameorigin\r" |
| 394 "https://www.foo.com/secureschemesameorigin\r" | 433 "https://www.foo.com/secureschemesameorigin\r" |
| 395 "http://www.xyz.com/secureschemedifforigin\r" | 434 "http://www.xyz.com/secureschemedifforigin\r" |
| 396 "https://www.xyz.com/secureschemedifforigin\r"); | 435 "https://www.xyz.com/secureschemedifforigin\r"); |
| 397 | 436 |
| 398 EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), manifest)); | 437 EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), |
| 438 true, manifest)); |
| 399 EXPECT_TRUE(manifest.fallback_namespaces.empty()); | 439 EXPECT_TRUE(manifest.fallback_namespaces.empty()); |
| 400 EXPECT_TRUE(manifest.online_whitelist_namespaces.empty()); | 440 EXPECT_TRUE(manifest.online_whitelist_namespaces.empty()); |
| 401 | 441 |
| 402 base::hash_set<std::string> urls = manifest.explicit_urls; | 442 base::hash_set<std::string> urls = manifest.explicit_urls; |
| 403 const size_t kExpected = 3; | 443 const size_t kExpected = 3; |
| 404 ASSERT_EQ(kExpected, urls.size()); | 444 ASSERT_EQ(kExpected, urls.size()); |
| 405 EXPECT_TRUE(urls.find("https://www.foo.com/relative/secureschemesameorigin") | 445 EXPECT_TRUE(urls.find("https://www.foo.com/relative/secureschemesameorigin") |
| 406 != urls.end()); | 446 != urls.end()); |
| 407 EXPECT_TRUE(urls.find("https://www.foo.com/secureschemesameorigin") != | 447 EXPECT_TRUE(urls.find("https://www.foo.com/secureschemesameorigin") != |
| 408 urls.end()); | 448 urls.end()); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 426 "http://foo.com/fallback_prefix /prefix wrongAnnotation\r" | 466 "http://foo.com/fallback_prefix /prefix wrongAnnotation\r" |
| 427 "http://foo.com/fallback_pattern* /pattern\tisPattern \r" | 467 "http://foo.com/fallback_pattern* /pattern\tisPattern \r" |
| 428 "NETWORK:\r" | 468 "NETWORK:\r" |
| 429 "*\r" | 469 "*\r" |
| 430 "isPattern\r" // should not be interpretted as a pattern | 470 "isPattern\r" // should not be interpretted as a pattern |
| 431 "http://foo.com/network_pattern* isPattern\r"); | 471 "http://foo.com/network_pattern* isPattern\r"); |
| 432 | 472 |
| 433 | 473 |
| 434 Manifest manifest; | 474 Manifest manifest; |
| 435 EXPECT_TRUE(ParseManifest(kUrl, kManifestBody.c_str(), | 475 EXPECT_TRUE(ParseManifest(kUrl, kManifestBody.c_str(), |
| 436 kManifestBody.length(), manifest)); | 476 kManifestBody.length(), true, manifest)); |
| 437 EXPECT_TRUE(manifest.online_whitelist_all); | 477 EXPECT_TRUE(manifest.online_whitelist_all); |
| 438 EXPECT_EQ(1u, manifest.explicit_urls.size()); | 478 EXPECT_EQ(1u, manifest.explicit_urls.size()); |
| 439 EXPECT_EQ(3u, manifest.intercept_namespaces.size()); | 479 EXPECT_EQ(3u, manifest.intercept_namespaces.size()); |
| 440 EXPECT_EQ(2u, manifest.fallback_namespaces.size()); | 480 EXPECT_EQ(2u, manifest.fallback_namespaces.size()); |
| 441 EXPECT_EQ(2u, manifest.online_whitelist_namespaces.size()); | 481 EXPECT_EQ(2u, manifest.online_whitelist_namespaces.size()); |
| 442 EXPECT_EQ(INTERCEPT_NAMESPACE, manifest.intercept_namespaces[0].type); | 482 EXPECT_EQ(INTERCEPT_NAMESPACE, manifest.intercept_namespaces[0].type); |
| 443 EXPECT_EQ(FALLBACK_NAMESPACE, manifest.fallback_namespaces[0].type); | 483 EXPECT_EQ(FALLBACK_NAMESPACE, manifest.fallback_namespaces[0].type); |
| 444 EXPECT_EQ(NETWORK_NAMESPACE, manifest.online_whitelist_namespaces[0].type); | 484 EXPECT_EQ(NETWORK_NAMESPACE, manifest.online_whitelist_namespaces[0].type); |
| 445 EXPECT_FALSE(manifest.intercept_namespaces[0].is_pattern); | 485 EXPECT_FALSE(manifest.intercept_namespaces[0].is_pattern); |
| 446 EXPECT_TRUE(manifest.intercept_namespaces[1].is_pattern); | 486 EXPECT_TRUE(manifest.intercept_namespaces[1].is_pattern); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 469 manifest.online_whitelist_namespaces[0].target_url); | 509 manifest.online_whitelist_namespaces[0].target_url); |
| 470 EXPECT_EQ( | 510 EXPECT_EQ( |
| 471 GURL("http://foo.com/network_pattern*"), | 511 GURL("http://foo.com/network_pattern*"), |
| 472 manifest.online_whitelist_namespaces[1].namespace_url); | 512 manifest.online_whitelist_namespaces[1].namespace_url); |
| 473 EXPECT_EQ( | 513 EXPECT_EQ( |
| 474 GURL(), | 514 GURL(), |
| 475 manifest.online_whitelist_namespaces[1].target_url); | 515 manifest.online_whitelist_namespaces[1].target_url); |
| 476 } | 516 } |
| 477 | 517 |
| 478 } // namespace content | 518 } // namespace content |
| OLD | NEW |