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