OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "googleurl/src/gurl.h" | 7 #include "googleurl/src/gurl.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 #include "webkit/appcache/manifest_parser.h" | 9 #include "webkit/appcache/manifest_parser.h" |
10 | 10 |
11 namespace appcache { | 11 namespace appcache { |
12 | 12 |
13 class ManifestParserTest : public testing::Test { | 13 class AppCacheManifestParserTest : public testing::Test { |
14 }; | 14 }; |
15 | 15 |
16 TEST(ManifestParserTest, NoData) { | 16 TEST(AppCacheManifestParserTest, NoData) { |
17 GURL url; | 17 GURL url; |
18 Manifest manifest; | 18 Manifest manifest; |
19 EXPECT_FALSE(ParseManifest(url, "", 0, manifest)); | 19 EXPECT_FALSE(ParseManifest(url, "", 0, manifest)); |
20 EXPECT_FALSE(ParseManifest(url, "CACHE MANIFEST\r", 0, manifest)); // 0 len | 20 EXPECT_FALSE(ParseManifest(url, "CACHE MANIFEST\r", 0, manifest)); // 0 len |
21 } | 21 } |
22 | 22 |
23 TEST(ManifestParserTest, CheckSignature) { | 23 TEST(AppCacheManifestParserTest, CheckSignature) { |
24 GURL url; | 24 GURL url; |
25 Manifest manifest; | 25 Manifest manifest; |
26 | 26 |
27 const std::string kBadSignatures[] = { | 27 const std::string kBadSignatures[] = { |
28 "foo", | 28 "foo", |
29 "CACHE MANIFEST;V2\r", // not followed by whitespace | 29 "CACHE MANIFEST;V2\r", // not followed by whitespace |
30 "CACHE MANIFEST#bad\r", // no whitespace before comment | 30 "CACHE MANIFEST#bad\r", // no whitespace before comment |
31 "cache manifest ", // wrong case | 31 "cache manifest ", // wrong case |
32 "#CACHE MANIFEST\r", // comment | 32 "#CACHE MANIFEST\r", // comment |
33 "xCACHE MANIFEST\n", // bad first char | 33 "xCACHE MANIFEST\n", // bad first char |
(...skipping 16 matching lines...) Expand all Loading... | |
50 "CACHE MANIFEST ignore\r\n", | 50 "CACHE MANIFEST ignore\r\n", |
51 "\xEF\xBB\xBF" "CACHE MANIFEST \r\n", // BOM present | 51 "\xEF\xBB\xBF" "CACHE MANIFEST \r\n", // BOM present |
52 }; | 52 }; |
53 | 53 |
54 for (size_t i = 0; i < arraysize(kGoodSignatures); ++i) { | 54 for (size_t i = 0; i < arraysize(kGoodSignatures); ++i) { |
55 const std::string good = kGoodSignatures[i]; | 55 const std::string good = kGoodSignatures[i]; |
56 EXPECT_TRUE(ParseManifest(url, good.c_str(), good.length(), manifest)); | 56 EXPECT_TRUE(ParseManifest(url, good.c_str(), good.length(), manifest)); |
57 } | 57 } |
58 } | 58 } |
59 | 59 |
60 TEST(ManifestParserTest, NoManifestUrl) { | 60 TEST(AppCacheManifestParserTest, NoManifestUrl) { |
61 Manifest manifest; | 61 Manifest manifest; |
62 const std::string kData("CACHE MANIFEST\r" | 62 const std::string kData("CACHE MANIFEST\r" |
63 "relative/tobase.com\r" | 63 "relative/tobase.com\r" |
64 "http://absolute.com/addme.com"); | 64 "http://absolute.com/addme.com"); |
65 const GURL kUrl; | 65 const GURL kUrl; |
66 EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), manifest)); | 66 EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), manifest)); |
67 EXPECT_TRUE(manifest.explicit_urls.empty()); | 67 EXPECT_TRUE(manifest.explicit_urls.empty()); |
68 EXPECT_TRUE(manifest.fallback_namespaces.empty()); | 68 EXPECT_TRUE(manifest.fallback_namespaces.empty()); |
69 EXPECT_TRUE(manifest.online_whitelist_namespaces.empty()); | 69 EXPECT_TRUE(manifest.online_whitelist_namespaces.empty()); |
70 EXPECT_FALSE(manifest.online_whitelist_all); | 70 EXPECT_FALSE(manifest.online_whitelist_all); |
71 } | 71 } |
72 | 72 |
73 TEST(ManifestParserTest, ExplicitUrls) { | 73 TEST(AppCacheManifestParserTest, ExplicitUrls) { |
74 Manifest manifest; | 74 Manifest manifest; |
75 const GURL kUrl("http://www.foo.com"); | 75 const GURL kUrl("http://www.foo.com"); |
76 const std::string kData("CACHE MANIFEST\r" | 76 const std::string kData("CACHE MANIFEST\r" |
77 "relative/one\r" | 77 "relative/one\r" |
78 "# some comment\r" | 78 "# some comment\r" |
79 "http://www.foo.com/two#strip\r\n" | 79 "http://www.foo.com/two#strip\r\n" |
80 "NETWORK:\r" | 80 "NETWORK:\r" |
81 " \t CACHE:\r" | 81 " \t CACHE:\r" |
82 "HTTP://www.diff.com/three\r" | 82 "HTTP://www.diff.com/three\r" |
83 "FALLBACK:\r" | 83 "FALLBACK:\r" |
(...skipping 16 matching lines...) Expand all Loading... | |
100 ASSERT_EQ(kExpected, urls.size()); | 100 ASSERT_EQ(kExpected, urls.size()); |
101 EXPECT_TRUE(urls.find("http://www.foo.com/relative/one") != urls.end()); | 101 EXPECT_TRUE(urls.find("http://www.foo.com/relative/one") != urls.end()); |
102 EXPECT_TRUE(urls.find("http://www.foo.com/two") != urls.end()); | 102 EXPECT_TRUE(urls.find("http://www.foo.com/two") != urls.end()); |
103 EXPECT_TRUE(urls.find("http://www.diff.com/three") != urls.end()); | 103 EXPECT_TRUE(urls.find("http://www.diff.com/three") != urls.end()); |
104 EXPECT_TRUE(urls.find("http://www.foo.com/relative/four") != urls.end()); | 104 EXPECT_TRUE(urls.find("http://www.foo.com/relative/four") != urls.end()); |
105 | 105 |
106 // Wildcard is treated as a relative URL in explicit section. | 106 // Wildcard is treated as a relative URL in explicit section. |
107 EXPECT_TRUE(urls.find("http://www.foo.com/*") != urls.end()); | 107 EXPECT_TRUE(urls.find("http://www.foo.com/*") != urls.end()); |
108 } | 108 } |
109 | 109 |
110 TEST(ManifestParserTest, WhitelistUrls) { | 110 TEST(AppCacheManifestParserTest, WhitelistUrls) { |
111 Manifest manifest; | 111 Manifest manifest; |
112 const GURL kUrl("http://www.bar.com"); | 112 const GURL kUrl("http://www.bar.com"); |
113 const std::string kData("CACHE MANIFEST\r" | 113 const std::string kData("CACHE MANIFEST\r" |
114 "NETWORK:\r" | 114 "NETWORK:\r" |
115 "relative/one\r" | 115 "relative/one\r" |
116 "# a comment\r" | 116 "# a comment\r" |
117 "http://www.bar.com/two\r" | 117 "http://www.bar.com/two\r" |
118 "HTTP://www.diff.com/three#strip\n\r" | 118 "HTTP://www.diff.com/three#strip\n\r" |
119 "FALLBACK:\r" | 119 "FALLBACK:\r" |
120 "garbage\r" | 120 "garbage\r" |
121 "UNKNOWN:\r" | 121 "UNKNOWN:\r" |
122 "http://www.bar.com/ignore\r" | 122 "http://www.bar.com/ignore\r" |
123 "CACHE:\r" | 123 "CACHE:\r" |
124 "NETWORK:\r" | 124 "NETWORK:\r" |
125 "https://www.wrongscheme.com\n" | 125 "https://www.wrongscheme.com\n" |
126 "relative/four#stripref \t \r" | 126 "relative/four#stripref \t \r" |
127 "http://www.five.com\r\n" | 127 "http://www.five.com\r\n" |
128 "*foo\r"); | 128 "*foo\r"); |
129 | 129 |
130 EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), manifest)); | 130 EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), manifest)); |
131 EXPECT_TRUE(manifest.explicit_urls.empty()); | 131 EXPECT_TRUE(manifest.explicit_urls.empty()); |
132 EXPECT_TRUE(manifest.fallback_namespaces.empty()); | 132 EXPECT_TRUE(manifest.fallback_namespaces.empty()); |
133 EXPECT_TRUE(manifest.intercept_namespaces.empty()); | |
133 EXPECT_FALSE(manifest.online_whitelist_all); | 134 EXPECT_FALSE(manifest.online_whitelist_all); |
134 | 135 |
135 std::vector<GURL> online = manifest.online_whitelist_namespaces; | 136 std::vector<GURL> online = manifest.online_whitelist_namespaces; |
136 const size_t kExpected = 6; | 137 const size_t kExpected = 6; |
137 ASSERT_EQ(kExpected, online.size()); | 138 ASSERT_EQ(kExpected, online.size()); |
138 EXPECT_EQ(GURL("http://www.bar.com/relative/one"), online[0]); | 139 EXPECT_EQ(GURL("http://www.bar.com/relative/one"), online[0]); |
139 EXPECT_EQ(GURL("http://www.bar.com/two"), online[1]); | 140 EXPECT_EQ(GURL("http://www.bar.com/two"), online[1]); |
140 EXPECT_EQ(GURL("http://www.diff.com/three"), online[2]); | 141 EXPECT_EQ(GURL("http://www.diff.com/three"), online[2]); |
141 EXPECT_EQ(GURL("http://www.bar.com/relative/four"), online[3]); | 142 EXPECT_EQ(GURL("http://www.bar.com/relative/four"), online[3]); |
142 EXPECT_EQ(GURL("http://www.five.com"), online[4]); | 143 EXPECT_EQ(GURL("http://www.five.com"), online[4]); |
143 EXPECT_EQ(GURL("http://www.bar.com/*foo"), online[5]); | 144 EXPECT_EQ(GURL("http://www.bar.com/*foo"), online[5]); |
144 } | 145 } |
145 | 146 |
146 TEST(ManifestParserTest, FallbackUrls) { | 147 TEST(AppCacheManifestParserTest, FallbackUrls) { |
147 Manifest manifest; | 148 Manifest manifest; |
148 const GURL kUrl("http://glorp.com"); | 149 const GURL kUrl("http://glorp.com"); |
149 const std::string kData("CACHE MANIFEST\r" | 150 const std::string kData("CACHE MANIFEST\r" |
150 "# a comment\r" | 151 "# a comment\r" |
151 "CACHE:\r" | 152 "CACHE:\r" |
152 "NETWORK:\r" | 153 "NETWORK:\r" |
153 "UNKNOWN:\r" | 154 "UNKNOWN:\r" |
154 "FALLBACK:\r" | 155 "FALLBACK:\r" |
155 "relative/one \t \t http://glorp.com/onefb \t \r" | 156 "relative/one \t \t http://glorp.com/onefb \t \r" |
156 "*\r" | 157 "*\r" |
(...skipping 10 matching lines...) Expand all Loading... | |
167 "# only fallback urls in this test\r" | 168 "# only fallback urls in this test\r" |
168 "FALLBACK:\n" | 169 "FALLBACK:\n" |
169 "relative/four#strip relative/fourfb#strip\r" | 170 "relative/four#strip relative/fourfb#strip\r" |
170 "http://www.glorp.com/notsame relative/skipped\r"); | 171 "http://www.glorp.com/notsame relative/skipped\r"); |
171 | 172 |
172 EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), manifest)); | 173 EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), manifest)); |
173 EXPECT_TRUE(manifest.explicit_urls.empty()); | 174 EXPECT_TRUE(manifest.explicit_urls.empty()); |
174 EXPECT_TRUE(manifest.online_whitelist_namespaces.empty()); | 175 EXPECT_TRUE(manifest.online_whitelist_namespaces.empty()); |
175 EXPECT_FALSE(manifest.online_whitelist_all); | 176 EXPECT_FALSE(manifest.online_whitelist_all); |
176 | 177 |
177 std::vector<FallbackNamespace> fallbacks = manifest.fallback_namespaces; | 178 const NamespaceVector& fallbacks = manifest.fallback_namespaces; |
178 const size_t kExpected = 5; | 179 const size_t kExpected = 5; |
179 ASSERT_EQ(kExpected, fallbacks.size()); | 180 ASSERT_EQ(kExpected, fallbacks.size()); |
181 EXPECT_EQ(FALLBACK_NAMESPACE, fallbacks[0].type); | |
182 EXPECT_EQ(FALLBACK_NAMESPACE, fallbacks[1].type); | |
183 EXPECT_EQ(FALLBACK_NAMESPACE, fallbacks[2].type); | |
184 EXPECT_EQ(FALLBACK_NAMESPACE, fallbacks[3].type); | |
185 EXPECT_EQ(FALLBACK_NAMESPACE, fallbacks[4].type); | |
180 EXPECT_EQ(GURL("http://glorp.com/relative/one"), | 186 EXPECT_EQ(GURL("http://glorp.com/relative/one"), |
181 fallbacks[0].first); | 187 fallbacks[0].namespace_url); |
182 EXPECT_EQ(GURL("http://glorp.com/onefb"), | 188 EXPECT_EQ(GURL("http://glorp.com/onefb"), |
183 fallbacks[0].second); | 189 fallbacks[0].target_url); |
184 EXPECT_EQ(GURL("http://glorp.com/two"), | 190 EXPECT_EQ(GURL("http://glorp.com/two"), |
185 fallbacks[1].first); | 191 fallbacks[1].namespace_url); |
186 EXPECT_EQ(GURL("http://glorp.com/relative/twofb"), | 192 EXPECT_EQ(GURL("http://glorp.com/relative/twofb"), |
187 fallbacks[1].second); | 193 fallbacks[1].target_url); |
188 EXPECT_EQ(GURL("http://glorp.com/three"), | 194 EXPECT_EQ(GURL("http://glorp.com/three"), |
189 fallbacks[2].first); | 195 fallbacks[2].namespace_url); |
190 EXPECT_EQ(GURL("http://glorp.com/relative/threefb"), | 196 EXPECT_EQ(GURL("http://glorp.com/relative/threefb"), |
191 fallbacks[2].second); | 197 fallbacks[2].target_url); |
192 EXPECT_EQ(GURL("http://glorp.com/three"), // duplicates are stored | 198 EXPECT_EQ(GURL("http://glorp.com/three"), // duplicates are stored |
193 fallbacks[3].first); | 199 fallbacks[3].namespace_url); |
194 EXPECT_EQ(GURL("http://glorp.com/three-dup"), | 200 EXPECT_EQ(GURL("http://glorp.com/three-dup"), |
195 fallbacks[3].second); | 201 fallbacks[3].target_url); |
196 EXPECT_EQ(GURL("http://glorp.com/relative/four"), | 202 EXPECT_EQ(GURL("http://glorp.com/relative/four"), |
197 fallbacks[4].first); | 203 fallbacks[4].namespace_url); |
198 EXPECT_EQ(GURL("http://glorp.com/relative/fourfb"), | 204 EXPECT_EQ(GURL("http://glorp.com/relative/fourfb"), |
199 fallbacks[4].second); | 205 fallbacks[4].target_url); |
206 | |
207 EXPECT_TRUE(manifest.intercept_namespaces.empty()); | |
200 } | 208 } |
201 | 209 |
202 TEST(ManifestParserTest, FallbackUrlsWithPort) { | 210 TEST(AppCacheManifestParserTest, FallbackUrlsWithPort) { |
203 Manifest manifest; | 211 Manifest manifest; |
204 const GURL kUrl("http://www.portme.com:1234"); | 212 const GURL kUrl("http://www.portme.com:1234"); |
205 const std::string kData("CACHE MANIFEST\r" | 213 const std::string kData("CACHE MANIFEST\r" |
206 "FALLBACK:\r" | 214 "FALLBACK:\r" |
207 "http://www.portme.com:1234/one relative/onefb\r" | 215 "http://www.portme.com:1234/one relative/onefb\r" |
208 "HTTP://www.portme.com:9876/wrong http://www.portme.com:1234/ignore\r" | 216 "HTTP://www.portme.com:9876/wrong http://www.portme.com:1234/ignore\r" |
209 "http://www.portme.com:1234/stillwrong http://www.portme.com:42/boo\r" | 217 "http://www.portme.com:1234/stillwrong http://www.portme.com:42/boo\r" |
210 "relative/two relative/twofb\r" | 218 "relative/two relative/twofb\r" |
211 "http://www.portme.com:1234/three HTTP://www.portme.com:1234/threefb\r" | 219 "http://www.portme.com:1234/three HTTP://www.portme.com:1234/threefb\r" |
212 "http://www.portme.com/noport http://www.portme.com:1234/skipped\r" | 220 "http://www.portme.com/noport http://www.portme.com:1234/skipped\r" |
213 "http://www.portme.com:1234/skipme http://www.portme.com/noport\r"); | 221 "http://www.portme.com:1234/skipme http://www.portme.com/noport\r"); |
214 | 222 |
215 EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), manifest)); | 223 EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), manifest)); |
216 EXPECT_TRUE(manifest.explicit_urls.empty()); | 224 EXPECT_TRUE(manifest.explicit_urls.empty()); |
217 EXPECT_TRUE(manifest.online_whitelist_namespaces.empty()); | 225 EXPECT_TRUE(manifest.online_whitelist_namespaces.empty()); |
218 EXPECT_FALSE(manifest.online_whitelist_all); | 226 EXPECT_FALSE(manifest.online_whitelist_all); |
219 | 227 |
220 std::vector<FallbackNamespace> fallbacks = manifest.fallback_namespaces; | 228 const NamespaceVector& fallbacks = manifest.fallback_namespaces; |
221 const size_t kExpected = 3; | 229 const size_t kExpected = 3; |
222 ASSERT_EQ(kExpected, fallbacks.size()); | 230 ASSERT_EQ(kExpected, fallbacks.size()); |
231 EXPECT_EQ(FALLBACK_NAMESPACE, fallbacks[0].type); | |
232 EXPECT_EQ(FALLBACK_NAMESPACE, fallbacks[1].type); | |
233 EXPECT_EQ(FALLBACK_NAMESPACE, fallbacks[2].type); | |
223 EXPECT_EQ(GURL("http://www.portme.com:1234/one"), | 234 EXPECT_EQ(GURL("http://www.portme.com:1234/one"), |
224 fallbacks[0].first); | 235 fallbacks[0].namespace_url); |
225 EXPECT_EQ(GURL("http://www.portme.com:1234/relative/onefb"), | 236 EXPECT_EQ(GURL("http://www.portme.com:1234/relative/onefb"), |
226 fallbacks[0].second); | 237 fallbacks[0].target_url); |
227 EXPECT_EQ(GURL("http://www.portme.com:1234/relative/two"), | 238 EXPECT_EQ(GURL("http://www.portme.com:1234/relative/two"), |
228 fallbacks[1].first); | 239 fallbacks[1].namespace_url); |
229 EXPECT_EQ(GURL("http://www.portme.com:1234/relative/twofb"), | 240 EXPECT_EQ(GURL("http://www.portme.com:1234/relative/twofb"), |
230 fallbacks[1].second); | 241 fallbacks[1].target_url); |
231 EXPECT_EQ(GURL("http://www.portme.com:1234/three"), | 242 EXPECT_EQ(GURL("http://www.portme.com:1234/three"), |
232 fallbacks[2].first); | 243 fallbacks[2].namespace_url); |
233 EXPECT_EQ(GURL("http://www.portme.com:1234/threefb"), | 244 EXPECT_EQ(GURL("http://www.portme.com:1234/threefb"), |
234 fallbacks[2].second); | 245 fallbacks[2].target_url); |
246 | |
247 EXPECT_TRUE(manifest.intercept_namespaces.empty()); | |
235 } | 248 } |
236 | 249 |
237 TEST(ManifestParserTest, ComboUrls) { | 250 TEST(AppCacheManifestParserTest, InterceptUrls) { |
251 Manifest manifest; | |
252 const GURL kUrl("http://www.portme.com:1234"); | |
253 const std::string kData("CHROMIUM CACHE MANIFEST\r" | |
jennb
2011/12/05 23:23:07
Do we care if the manifest does not use the CHROMI
michaeln
2011/12/06 02:07:06
I was going to allow the intercept namespaces to w
| |
254 "CHROMIUM-INTERCEPT:\r" | |
255 "http://www.portme.com:1234/one return relative/onefb\r" | |
jennb
2011/12/05 23:23:07
the fb in onefb stands for fallback. ;-)
Not tha
michaeln
2011/12/06 02:07:06
oh... its not short for facebook :)
| |
256 "HTTP://www.portme.com:9876/wrong return http://www.portme.com:1234/ignore\r " | |
257 "http://www.portme.com:1234/stillwrong return http://www.portme.com:42/boo\ r" | |
258 "relative/two return relative/twofb\r" | |
259 "relative/three wrong relative/threefb\r" | |
260 "http://www.portme.com:1234/three return HTTP://www.portme.com:1234/threefb\ r" | |
261 "http://www.portme.com/noport return http://www.portme.com:1234/skipped\r" | |
262 "http://www.portme.com:1234/skipme return http://www.portme.com/noport\r" | |
263 "relative/wrong/again missing/intercept_type\r"); | |
264 | |
265 EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), manifest)); | |
266 EXPECT_TRUE(manifest.fallback_namespaces.empty()); | |
267 EXPECT_TRUE(manifest.explicit_urls.empty()); | |
268 EXPECT_TRUE(manifest.online_whitelist_namespaces.empty()); | |
269 EXPECT_FALSE(manifest.online_whitelist_all); | |
270 | |
271 const NamespaceVector& intercepts = manifest.intercept_namespaces; | |
272 const size_t kExpected = 3; | |
273 ASSERT_EQ(kExpected, intercepts.size()); | |
274 EXPECT_EQ(INTERCEPT_NAMESPACE, intercepts[0].type); | |
275 EXPECT_EQ(INTERCEPT_NAMESPACE, intercepts[1].type); | |
276 EXPECT_EQ(INTERCEPT_NAMESPACE, intercepts[2].type); | |
277 EXPECT_EQ(GURL("http://www.portme.com:1234/one"), | |
278 intercepts[0].namespace_url); | |
279 EXPECT_EQ(GURL("http://www.portme.com:1234/relative/onefb"), | |
280 intercepts[0].target_url); | |
281 EXPECT_EQ(GURL("http://www.portme.com:1234/relative/two"), | |
282 intercepts[1].namespace_url); | |
283 EXPECT_EQ(GURL("http://www.portme.com:1234/relative/twofb"), | |
284 intercepts[1].target_url); | |
285 EXPECT_EQ(GURL("http://www.portme.com:1234/three"), | |
286 intercepts[2].namespace_url); | |
287 EXPECT_EQ(GURL("http://www.portme.com:1234/threefb"), | |
288 intercepts[2].target_url); | |
289 | |
290 } | |
291 | |
292 TEST(AppCacheManifestParserTest, ComboUrls) { | |
238 Manifest manifest; | 293 Manifest manifest; |
239 const GURL kUrl("http://combo.com:42"); | 294 const GURL kUrl("http://combo.com:42"); |
240 const std::string kData("CACHE MANIFEST\r" | 295 const std::string kData("CACHE MANIFEST\r" |
241 "relative/explicit-1\r" | 296 "relative/explicit-1\r" |
242 "# some comment\r" | 297 "# some comment\r" |
243 "http://combo.com:99/explicit-2#strip\r" | 298 "http://combo.com:99/explicit-2#strip\r" |
244 "NETWORK:\r" | 299 "NETWORK:\r" |
245 "http://combo.com/whitelist-1\r" | 300 "http://combo.com/whitelist-1\r" |
246 "HTTP://www.diff.com/whitelist-2#strip\r" | 301 "HTTP://www.diff.com/whitelist-2#strip\r" |
247 "*\r" | 302 "*\r" |
(...skipping 20 matching lines...) Expand all Loading... | |
268 EXPECT_TRUE(urls.find("http://www.diff.com/explicit-3") != urls.end()); | 323 EXPECT_TRUE(urls.find("http://www.diff.com/explicit-3") != urls.end()); |
269 | 324 |
270 std::vector<GURL> online = manifest.online_whitelist_namespaces; | 325 std::vector<GURL> online = manifest.online_whitelist_namespaces; |
271 expected = 4; | 326 expected = 4; |
272 ASSERT_EQ(expected, online.size()); | 327 ASSERT_EQ(expected, online.size()); |
273 EXPECT_EQ(GURL("http://combo.com/whitelist-1"), online[0]); | 328 EXPECT_EQ(GURL("http://combo.com/whitelist-1"), online[0]); |
274 EXPECT_EQ(GURL("http://www.diff.com/whitelist-2"), online[1]); | 329 EXPECT_EQ(GURL("http://www.diff.com/whitelist-2"), online[1]); |
275 EXPECT_EQ(GURL("http://combo.com:42/relative/whitelist-3"), online[2]); | 330 EXPECT_EQ(GURL("http://combo.com:42/relative/whitelist-3"), online[2]); |
276 EXPECT_EQ(GURL("http://combo.com:99/whitelist-4"), online[3]); | 331 EXPECT_EQ(GURL("http://combo.com:99/whitelist-4"), online[3]); |
277 | 332 |
278 std::vector<FallbackNamespace> fallbacks = manifest.fallback_namespaces; | 333 const NamespaceVector& fallbacks = manifest.fallback_namespaces; |
279 expected = 2; | 334 expected = 2; |
280 ASSERT_EQ(expected, fallbacks.size()); | 335 ASSERT_EQ(expected, fallbacks.size()); |
336 EXPECT_EQ(FALLBACK_NAMESPACE, fallbacks[0].type); | |
337 EXPECT_EQ(FALLBACK_NAMESPACE, fallbacks[1].type); | |
281 EXPECT_EQ(GURL("http://combo.com:42/fallback-1"), | 338 EXPECT_EQ(GURL("http://combo.com:42/fallback-1"), |
282 fallbacks[0].first); | 339 fallbacks[0].namespace_url); |
283 EXPECT_EQ(GURL("http://combo.com:42/fallback-1b"), | 340 EXPECT_EQ(GURL("http://combo.com:42/fallback-1b"), |
284 fallbacks[0].second); | 341 fallbacks[0].target_url); |
285 EXPECT_EQ(GURL("http://combo.com:42/relative/fallback-2"), | 342 EXPECT_EQ(GURL("http://combo.com:42/relative/fallback-2"), |
286 fallbacks[1].first); | 343 fallbacks[1].namespace_url); |
287 EXPECT_EQ(GURL("http://combo.com:42/relative/fallback-2b"), | 344 EXPECT_EQ(GURL("http://combo.com:42/relative/fallback-2b"), |
288 fallbacks[1].second); | 345 fallbacks[1].target_url); |
346 | |
347 EXPECT_TRUE(manifest.intercept_namespaces.empty()); | |
289 } | 348 } |
290 | 349 |
291 TEST(ManifestParserTest, UnusualUtf8) { | 350 TEST(AppCacheManifestParserTest, UnusualUtf8) { |
292 Manifest manifest; | 351 Manifest manifest; |
293 const GURL kUrl("http://bad.com"); | 352 const GURL kUrl("http://bad.com"); |
294 const std::string kData("CACHE MANIFEST\r" | 353 const std::string kData("CACHE MANIFEST\r" |
295 "\xC0" "invalidutf8\r" | 354 "\xC0" "invalidutf8\r" |
296 "nonbmp" "\xF1\x84\xAB\xBC\r"); | 355 "nonbmp" "\xF1\x84\xAB\xBC\r"); |
297 EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), manifest)); | 356 EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), manifest)); |
298 | 357 |
299 base::hash_set<std::string> urls = manifest.explicit_urls; | 358 base::hash_set<std::string> urls = manifest.explicit_urls; |
300 EXPECT_TRUE(urls.find("http://bad.com/%EF%BF%BDinvalidutf8") != urls.end()); | 359 EXPECT_TRUE(urls.find("http://bad.com/%EF%BF%BDinvalidutf8") != urls.end()); |
301 EXPECT_TRUE(urls.find("http://bad.com/nonbmp%F1%84%AB%BC") != urls.end()); | 360 EXPECT_TRUE(urls.find("http://bad.com/nonbmp%F1%84%AB%BC") != urls.end()); |
302 } | 361 } |
303 | 362 |
304 TEST(ManifestParserTest, IgnoreAfterSpace) { | 363 TEST(AppCacheManifestParserTest, IgnoreAfterSpace) { |
305 Manifest manifest; | 364 Manifest manifest; |
306 const GURL kUrl("http://smorg.borg"); | 365 const GURL kUrl("http://smorg.borg"); |
307 const std::string kData( | 366 const std::string kData( |
308 "CACHE MANIFEST\r" | 367 "CACHE MANIFEST\r" |
309 "resource.txt this stuff after the white space should be ignored\r"); | 368 "resource.txt this stuff after the white space should be ignored\r"); |
310 EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), manifest)); | 369 EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), manifest)); |
311 | 370 |
312 base::hash_set<std::string> urls = manifest.explicit_urls; | 371 base::hash_set<std::string> urls = manifest.explicit_urls; |
313 EXPECT_TRUE(urls.find("http://smorg.borg/resource.txt") != urls.end()); | 372 EXPECT_TRUE(urls.find("http://smorg.borg/resource.txt") != urls.end()); |
314 } | 373 } |
315 | 374 |
316 TEST(ManifestParserTest, DifferentOriginUrlWithSecureScheme) { | 375 TEST(AppCacheManifestParserTest, DifferentOriginUrlWithSecureScheme) { |
317 Manifest manifest; | 376 Manifest manifest; |
318 const GURL kUrl("https://www.foo.com"); | 377 const GURL kUrl("https://www.foo.com"); |
319 const std::string kData("CACHE MANIFEST\r" | 378 const std::string kData("CACHE MANIFEST\r" |
320 "CACHE: \r" | 379 "CACHE: \r" |
321 "relative/secureschemesameorigin\r" | 380 "relative/secureschemesameorigin\r" |
322 "https://www.foo.com/secureschemesameorigin\r" | 381 "https://www.foo.com/secureschemesameorigin\r" |
323 "http://www.xyz.com/secureschemedifforigin\r" | 382 "http://www.xyz.com/secureschemedifforigin\r" |
324 "https://www.xyz.com/secureschemedifforigin\r"); | 383 "https://www.xyz.com/secureschemedifforigin\r"); |
325 | 384 |
326 EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), manifest)); | 385 EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), manifest)); |
327 EXPECT_TRUE(manifest.fallback_namespaces.empty()); | 386 EXPECT_TRUE(manifest.fallback_namespaces.empty()); |
328 EXPECT_TRUE(manifest.online_whitelist_namespaces.empty()); | 387 EXPECT_TRUE(manifest.online_whitelist_namespaces.empty()); |
329 | 388 |
330 base::hash_set<std::string> urls = manifest.explicit_urls; | 389 base::hash_set<std::string> urls = manifest.explicit_urls; |
331 const size_t kExpected = 3; | 390 const size_t kExpected = 3; |
332 ASSERT_EQ(kExpected, urls.size()); | 391 ASSERT_EQ(kExpected, urls.size()); |
333 EXPECT_TRUE(urls.find("https://www.foo.com/relative/secureschemesameorigin") | 392 EXPECT_TRUE(urls.find("https://www.foo.com/relative/secureschemesameorigin") |
334 != urls.end()); | 393 != urls.end()); |
335 EXPECT_TRUE(urls.find("https://www.foo.com/secureschemesameorigin") != | 394 EXPECT_TRUE(urls.find("https://www.foo.com/secureschemesameorigin") != |
336 urls.end()); | 395 urls.end()); |
337 EXPECT_FALSE(urls.find("http://www.xyz.com/secureschemedifforigin") != | 396 EXPECT_FALSE(urls.find("http://www.xyz.com/secureschemedifforigin") != |
338 urls.end()); | 397 urls.end()); |
339 EXPECT_TRUE(urls.find("https://www.xyz.com/secureschemedifforigin") != | 398 EXPECT_TRUE(urls.find("https://www.xyz.com/secureschemedifforigin") != |
340 urls.end()); | 399 urls.end()); |
341 } | 400 } |
342 | 401 |
343 } // namespace appcache | 402 } // namespace appcache |
344 | |
OLD | NEW |