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 |
34 " CACHE MANIFEST\r", // begins with whitespace | 34 " CACHE MANIFEST\r", // begins with whitespace |
35 "\xEF\xBE\xBF" "CACHE MANIFEST\r", // bad UTF-8 BOM value | 35 "\xEF\xBE\xBF" "CACHE MANIFEST\r", // bad UTF-8 BOM value |
36 }; | 36 }; |
37 | 37 |
38 for (size_t i = 0; i < arraysize(kBadSignatures); ++i) { | 38 for (size_t i = 0; i < arraysize(kBadSignatures); ++i) { |
39 const std::string bad = kBadSignatures[i]; | 39 const std::string bad = kBadSignatures[i]; |
40 EXPECT_FALSE(ParseManifest(url, bad.c_str(), bad.length(), manifest)); | 40 EXPECT_FALSE(ParseManifest(url, bad.c_str(), bad.length(), manifest)); |
41 } | 41 } |
42 | 42 |
43 const std::string kGoodSignatures[] = { | 43 const std::string kGoodSignatures[] = { |
44 "CACHE MANIFEST", | 44 "CACHE MANIFEST", |
45 "CACHE MANIFEST ", | 45 "CACHE MANIFEST ", |
46 "CACHE MANIFEST\r", | 46 "CACHE MANIFEST\r", |
47 "CACHE MANIFEST\n", | 47 "CACHE MANIFEST\n", |
48 "CACHE MANIFEST\r\n", | 48 "CACHE MANIFEST\r\n", |
49 "CACHE MANIFEST\t# ignore me\r", | 49 "CACHE MANIFEST\t# ignore me\r", |
50 "CACHE MANIFEST ignore\r\n", | 50 "CACHE MANIFEST ignore\r\n", |
| 51 "CHROMIUM CACHE MANIFEST\r\n", |
51 "\xEF\xBB\xBF" "CACHE MANIFEST \r\n", // BOM present | 52 "\xEF\xBB\xBF" "CACHE MANIFEST \r\n", // BOM present |
52 }; | 53 }; |
53 | 54 |
54 for (size_t i = 0; i < arraysize(kGoodSignatures); ++i) { | 55 for (size_t i = 0; i < arraysize(kGoodSignatures); ++i) { |
55 const std::string good = kGoodSignatures[i]; | 56 const std::string good = kGoodSignatures[i]; |
56 EXPECT_TRUE(ParseManifest(url, good.c_str(), good.length(), manifest)); | 57 EXPECT_TRUE(ParseManifest(url, good.c_str(), good.length(), manifest)); |
57 } | 58 } |
58 } | 59 } |
59 | 60 |
60 TEST(ManifestParserTest, NoManifestUrl) { | 61 TEST(AppCacheManifestParserTest, NoManifestUrl) { |
61 Manifest manifest; | 62 Manifest manifest; |
62 const std::string kData("CACHE MANIFEST\r" | 63 const std::string kData("CACHE MANIFEST\r" |
63 "relative/tobase.com\r" | 64 "relative/tobase.com\r" |
64 "http://absolute.com/addme.com"); | 65 "http://absolute.com/addme.com"); |
65 const GURL kUrl; | 66 const GURL kUrl; |
66 EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), manifest)); | 67 EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), manifest)); |
67 EXPECT_TRUE(manifest.explicit_urls.empty()); | 68 EXPECT_TRUE(manifest.explicit_urls.empty()); |
68 EXPECT_TRUE(manifest.fallback_namespaces.empty()); | 69 EXPECT_TRUE(manifest.fallback_namespaces.empty()); |
69 EXPECT_TRUE(manifest.online_whitelist_namespaces.empty()); | 70 EXPECT_TRUE(manifest.online_whitelist_namespaces.empty()); |
70 EXPECT_FALSE(manifest.online_whitelist_all); | 71 EXPECT_FALSE(manifest.online_whitelist_all); |
71 } | 72 } |
72 | 73 |
73 TEST(ManifestParserTest, ExplicitUrls) { | 74 TEST(AppCacheManifestParserTest, ExplicitUrls) { |
74 Manifest manifest; | 75 Manifest manifest; |
75 const GURL kUrl("http://www.foo.com"); | 76 const GURL kUrl("http://www.foo.com"); |
76 const std::string kData("CACHE MANIFEST\r" | 77 const std::string kData("CACHE MANIFEST\r" |
77 "relative/one\r" | 78 "relative/one\r" |
78 "# some comment\r" | 79 "# some comment\r" |
79 "http://www.foo.com/two#strip\r\n" | 80 "http://www.foo.com/two#strip\r\n" |
80 "NETWORK:\r" | 81 "NETWORK:\r" |
81 " \t CACHE:\r" | 82 " \t CACHE:\r" |
82 "HTTP://www.diff.com/three\r" | 83 "HTTP://www.diff.com/three\r" |
83 "FALLBACK:\r" | 84 "FALLBACK:\r" |
(...skipping 16 matching lines...) Expand all Loading... |
100 ASSERT_EQ(kExpected, urls.size()); | 101 ASSERT_EQ(kExpected, urls.size()); |
101 EXPECT_TRUE(urls.find("http://www.foo.com/relative/one") != urls.end()); | 102 EXPECT_TRUE(urls.find("http://www.foo.com/relative/one") != urls.end()); |
102 EXPECT_TRUE(urls.find("http://www.foo.com/two") != urls.end()); | 103 EXPECT_TRUE(urls.find("http://www.foo.com/two") != urls.end()); |
103 EXPECT_TRUE(urls.find("http://www.diff.com/three") != urls.end()); | 104 EXPECT_TRUE(urls.find("http://www.diff.com/three") != urls.end()); |
104 EXPECT_TRUE(urls.find("http://www.foo.com/relative/four") != urls.end()); | 105 EXPECT_TRUE(urls.find("http://www.foo.com/relative/four") != urls.end()); |
105 | 106 |
106 // Wildcard is treated as a relative URL in explicit section. | 107 // Wildcard is treated as a relative URL in explicit section. |
107 EXPECT_TRUE(urls.find("http://www.foo.com/*") != urls.end()); | 108 EXPECT_TRUE(urls.find("http://www.foo.com/*") != urls.end()); |
108 } | 109 } |
109 | 110 |
110 TEST(ManifestParserTest, WhitelistUrls) { | 111 TEST(AppCacheManifestParserTest, WhitelistUrls) { |
111 Manifest manifest; | 112 Manifest manifest; |
112 const GURL kUrl("http://www.bar.com"); | 113 const GURL kUrl("http://www.bar.com"); |
113 const std::string kData("CACHE MANIFEST\r" | 114 const std::string kData("CACHE MANIFEST\r" |
114 "NETWORK:\r" | 115 "NETWORK:\r" |
115 "relative/one\r" | 116 "relative/one\r" |
116 "# a comment\r" | 117 "# a comment\r" |
117 "http://www.bar.com/two\r" | 118 "http://www.bar.com/two\r" |
118 "HTTP://www.diff.com/three#strip\n\r" | 119 "HTTP://www.diff.com/three#strip\n\r" |
119 "FALLBACK:\r" | 120 "FALLBACK:\r" |
120 "garbage\r" | 121 "garbage\r" |
121 "UNKNOWN:\r" | 122 "UNKNOWN:\r" |
122 "http://www.bar.com/ignore\r" | 123 "http://www.bar.com/ignore\r" |
123 "CACHE:\r" | 124 "CACHE:\r" |
124 "NETWORK:\r" | 125 "NETWORK:\r" |
125 "https://www.wrongscheme.com\n" | 126 "https://www.wrongscheme.com\n" |
126 "relative/four#stripref \t \r" | 127 "relative/four#stripref \t \r" |
127 "http://www.five.com\r\n" | 128 "http://www.five.com\r\n" |
128 "*foo\r"); | 129 "*foo\r"); |
129 | 130 |
130 EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), manifest)); | 131 EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), manifest)); |
131 EXPECT_TRUE(manifest.explicit_urls.empty()); | 132 EXPECT_TRUE(manifest.explicit_urls.empty()); |
132 EXPECT_TRUE(manifest.fallback_namespaces.empty()); | 133 EXPECT_TRUE(manifest.fallback_namespaces.empty()); |
| 134 EXPECT_TRUE(manifest.intercept_namespaces.empty()); |
133 EXPECT_FALSE(manifest.online_whitelist_all); | 135 EXPECT_FALSE(manifest.online_whitelist_all); |
134 | 136 |
135 std::vector<GURL> online = manifest.online_whitelist_namespaces; | 137 std::vector<GURL> online = manifest.online_whitelist_namespaces; |
136 const size_t kExpected = 6; | 138 const size_t kExpected = 6; |
137 ASSERT_EQ(kExpected, online.size()); | 139 ASSERT_EQ(kExpected, online.size()); |
138 EXPECT_EQ(GURL("http://www.bar.com/relative/one"), online[0]); | 140 EXPECT_EQ(GURL("http://www.bar.com/relative/one"), online[0]); |
139 EXPECT_EQ(GURL("http://www.bar.com/two"), online[1]); | 141 EXPECT_EQ(GURL("http://www.bar.com/two"), online[1]); |
140 EXPECT_EQ(GURL("http://www.diff.com/three"), online[2]); | 142 EXPECT_EQ(GURL("http://www.diff.com/three"), online[2]); |
141 EXPECT_EQ(GURL("http://www.bar.com/relative/four"), online[3]); | 143 EXPECT_EQ(GURL("http://www.bar.com/relative/four"), online[3]); |
142 EXPECT_EQ(GURL("http://www.five.com"), online[4]); | 144 EXPECT_EQ(GURL("http://www.five.com"), online[4]); |
143 EXPECT_EQ(GURL("http://www.bar.com/*foo"), online[5]); | 145 EXPECT_EQ(GURL("http://www.bar.com/*foo"), online[5]); |
144 } | 146 } |
145 | 147 |
146 TEST(ManifestParserTest, FallbackUrls) { | 148 TEST(AppCacheManifestParserTest, FallbackUrls) { |
147 Manifest manifest; | 149 Manifest manifest; |
148 const GURL kUrl("http://glorp.com"); | 150 const GURL kUrl("http://glorp.com"); |
149 const std::string kData("CACHE MANIFEST\r" | 151 const std::string kData("CACHE MANIFEST\r" |
150 "# a comment\r" | 152 "# a comment\r" |
151 "CACHE:\r" | 153 "CACHE:\r" |
152 "NETWORK:\r" | 154 "NETWORK:\r" |
153 "UNKNOWN:\r" | 155 "UNKNOWN:\r" |
154 "FALLBACK:\r" | 156 "FALLBACK:\r" |
155 "relative/one \t \t http://glorp.com/onefb \t \r" | 157 "relative/one \t \t http://glorp.com/onefb \t \r" |
156 "*\r" | 158 "*\r" |
(...skipping 10 matching lines...) Expand all Loading... |
167 "# only fallback urls in this test\r" | 169 "# only fallback urls in this test\r" |
168 "FALLBACK:\n" | 170 "FALLBACK:\n" |
169 "relative/four#strip relative/fourfb#strip\r" | 171 "relative/four#strip relative/fourfb#strip\r" |
170 "http://www.glorp.com/notsame relative/skipped\r"); | 172 "http://www.glorp.com/notsame relative/skipped\r"); |
171 | 173 |
172 EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), manifest)); | 174 EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), manifest)); |
173 EXPECT_TRUE(manifest.explicit_urls.empty()); | 175 EXPECT_TRUE(manifest.explicit_urls.empty()); |
174 EXPECT_TRUE(manifest.online_whitelist_namespaces.empty()); | 176 EXPECT_TRUE(manifest.online_whitelist_namespaces.empty()); |
175 EXPECT_FALSE(manifest.online_whitelist_all); | 177 EXPECT_FALSE(manifest.online_whitelist_all); |
176 | 178 |
177 std::vector<FallbackNamespace> fallbacks = manifest.fallback_namespaces; | 179 const NamespaceVector& fallbacks = manifest.fallback_namespaces; |
178 const size_t kExpected = 5; | 180 const size_t kExpected = 5; |
179 ASSERT_EQ(kExpected, fallbacks.size()); | 181 ASSERT_EQ(kExpected, fallbacks.size()); |
| 182 EXPECT_EQ(FALLBACK_NAMESPACE, fallbacks[0].type); |
| 183 EXPECT_EQ(FALLBACK_NAMESPACE, fallbacks[1].type); |
| 184 EXPECT_EQ(FALLBACK_NAMESPACE, fallbacks[2].type); |
| 185 EXPECT_EQ(FALLBACK_NAMESPACE, fallbacks[3].type); |
| 186 EXPECT_EQ(FALLBACK_NAMESPACE, fallbacks[4].type); |
180 EXPECT_EQ(GURL("http://glorp.com/relative/one"), | 187 EXPECT_EQ(GURL("http://glorp.com/relative/one"), |
181 fallbacks[0].first); | 188 fallbacks[0].namespace_url); |
182 EXPECT_EQ(GURL("http://glorp.com/onefb"), | 189 EXPECT_EQ(GURL("http://glorp.com/onefb"), |
183 fallbacks[0].second); | 190 fallbacks[0].target_url); |
184 EXPECT_EQ(GURL("http://glorp.com/two"), | 191 EXPECT_EQ(GURL("http://glorp.com/two"), |
185 fallbacks[1].first); | 192 fallbacks[1].namespace_url); |
186 EXPECT_EQ(GURL("http://glorp.com/relative/twofb"), | 193 EXPECT_EQ(GURL("http://glorp.com/relative/twofb"), |
187 fallbacks[1].second); | 194 fallbacks[1].target_url); |
188 EXPECT_EQ(GURL("http://glorp.com/three"), | 195 EXPECT_EQ(GURL("http://glorp.com/three"), |
189 fallbacks[2].first); | 196 fallbacks[2].namespace_url); |
190 EXPECT_EQ(GURL("http://glorp.com/relative/threefb"), | 197 EXPECT_EQ(GURL("http://glorp.com/relative/threefb"), |
191 fallbacks[2].second); | 198 fallbacks[2].target_url); |
192 EXPECT_EQ(GURL("http://glorp.com/three"), // duplicates are stored | 199 EXPECT_EQ(GURL("http://glorp.com/three"), // duplicates are stored |
193 fallbacks[3].first); | 200 fallbacks[3].namespace_url); |
194 EXPECT_EQ(GURL("http://glorp.com/three-dup"), | 201 EXPECT_EQ(GURL("http://glorp.com/three-dup"), |
195 fallbacks[3].second); | 202 fallbacks[3].target_url); |
196 EXPECT_EQ(GURL("http://glorp.com/relative/four"), | 203 EXPECT_EQ(GURL("http://glorp.com/relative/four"), |
197 fallbacks[4].first); | 204 fallbacks[4].namespace_url); |
198 EXPECT_EQ(GURL("http://glorp.com/relative/fourfb"), | 205 EXPECT_EQ(GURL("http://glorp.com/relative/fourfb"), |
199 fallbacks[4].second); | 206 fallbacks[4].target_url); |
| 207 |
| 208 EXPECT_TRUE(manifest.intercept_namespaces.empty()); |
200 } | 209 } |
201 | 210 |
202 TEST(ManifestParserTest, FallbackUrlsWithPort) { | 211 TEST(AppCacheManifestParserTest, FallbackUrlsWithPort) { |
203 Manifest manifest; | 212 Manifest manifest; |
204 const GURL kUrl("http://www.portme.com:1234"); | 213 const GURL kUrl("http://www.portme.com:1234"); |
205 const std::string kData("CACHE MANIFEST\r" | 214 const std::string kData("CACHE MANIFEST\r" |
206 "FALLBACK:\r" | 215 "FALLBACK:\r" |
207 "http://www.portme.com:1234/one relative/onefb\r" | 216 "http://www.portme.com:1234/one relative/onefb\r" |
208 "HTTP://www.portme.com:9876/wrong http://www.portme.com:1234/ignore\r" | 217 "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" | 218 "http://www.portme.com:1234/stillwrong http://www.portme.com:42/boo\r" |
210 "relative/two relative/twofb\r" | 219 "relative/two relative/twofb\r" |
211 "http://www.portme.com:1234/three HTTP://www.portme.com:1234/threefb\r" | 220 "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" | 221 "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"); | 222 "http://www.portme.com:1234/skipme http://www.portme.com/noport\r"); |
214 | 223 |
215 EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), manifest)); | 224 EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), manifest)); |
216 EXPECT_TRUE(manifest.explicit_urls.empty()); | 225 EXPECT_TRUE(manifest.explicit_urls.empty()); |
217 EXPECT_TRUE(manifest.online_whitelist_namespaces.empty()); | 226 EXPECT_TRUE(manifest.online_whitelist_namespaces.empty()); |
218 EXPECT_FALSE(manifest.online_whitelist_all); | 227 EXPECT_FALSE(manifest.online_whitelist_all); |
219 | 228 |
220 std::vector<FallbackNamespace> fallbacks = manifest.fallback_namespaces; | 229 const NamespaceVector& fallbacks = manifest.fallback_namespaces; |
221 const size_t kExpected = 3; | 230 const size_t kExpected = 3; |
222 ASSERT_EQ(kExpected, fallbacks.size()); | 231 ASSERT_EQ(kExpected, fallbacks.size()); |
| 232 EXPECT_EQ(FALLBACK_NAMESPACE, fallbacks[0].type); |
| 233 EXPECT_EQ(FALLBACK_NAMESPACE, fallbacks[1].type); |
| 234 EXPECT_EQ(FALLBACK_NAMESPACE, fallbacks[2].type); |
223 EXPECT_EQ(GURL("http://www.portme.com:1234/one"), | 235 EXPECT_EQ(GURL("http://www.portme.com:1234/one"), |
224 fallbacks[0].first); | 236 fallbacks[0].namespace_url); |
225 EXPECT_EQ(GURL("http://www.portme.com:1234/relative/onefb"), | 237 EXPECT_EQ(GURL("http://www.portme.com:1234/relative/onefb"), |
226 fallbacks[0].second); | 238 fallbacks[0].target_url); |
227 EXPECT_EQ(GURL("http://www.portme.com:1234/relative/two"), | 239 EXPECT_EQ(GURL("http://www.portme.com:1234/relative/two"), |
228 fallbacks[1].first); | 240 fallbacks[1].namespace_url); |
229 EXPECT_EQ(GURL("http://www.portme.com:1234/relative/twofb"), | 241 EXPECT_EQ(GURL("http://www.portme.com:1234/relative/twofb"), |
230 fallbacks[1].second); | 242 fallbacks[1].target_url); |
231 EXPECT_EQ(GURL("http://www.portme.com:1234/three"), | 243 EXPECT_EQ(GURL("http://www.portme.com:1234/three"), |
232 fallbacks[2].first); | 244 fallbacks[2].namespace_url); |
233 EXPECT_EQ(GURL("http://www.portme.com:1234/threefb"), | 245 EXPECT_EQ(GURL("http://www.portme.com:1234/threefb"), |
234 fallbacks[2].second); | 246 fallbacks[2].target_url); |
| 247 |
| 248 EXPECT_TRUE(manifest.intercept_namespaces.empty()); |
235 } | 249 } |
236 | 250 |
237 TEST(ManifestParserTest, ComboUrls) { | 251 TEST(AppCacheManifestParserTest, InterceptUrls) { |
| 252 Manifest manifest; |
| 253 const GURL kUrl("http://www.portme.com:1234"); |
| 254 const std::string kData("CHROMIUM CACHE MANIFEST\r" |
| 255 "CHROMIUM-INTERCEPT:\r" |
| 256 "http://www.portme.com:1234/one return relative/int1\r" |
| 257 "HTTP://www.portme.com:9/wrong return http://www.portme.com:1234/ignore\r" |
| 258 "http://www.portme.com:1234/wrong return http://www.portme.com:9/boo\r" |
| 259 "relative/two return relative/int2\r" |
| 260 "relative/three wrong relative/threefb\r" |
| 261 "http://www.portme.com:1234/three return HTTP://www.portme.com:1234/int3\r" |
| 262 "http://www.portme.com/noport return http://www.portme.com:1234/skipped\r" |
| 263 "http://www.portme.com:1234/skipme return http://www.portme.com/noport\r" |
| 264 "relative/wrong/again missing/intercept_type\r"); |
| 265 |
| 266 EXPECT_TRUE(ParseManifest(kUrl, kData.c_str(), kData.length(), manifest)); |
| 267 EXPECT_TRUE(manifest.fallback_namespaces.empty()); |
| 268 EXPECT_TRUE(manifest.explicit_urls.empty()); |
| 269 EXPECT_TRUE(manifest.online_whitelist_namespaces.empty()); |
| 270 EXPECT_FALSE(manifest.online_whitelist_all); |
| 271 |
| 272 const NamespaceVector& intercepts = manifest.intercept_namespaces; |
| 273 const size_t kExpected = 3; |
| 274 ASSERT_EQ(kExpected, intercepts.size()); |
| 275 EXPECT_EQ(INTERCEPT_NAMESPACE, intercepts[0].type); |
| 276 EXPECT_EQ(INTERCEPT_NAMESPACE, intercepts[1].type); |
| 277 EXPECT_EQ(INTERCEPT_NAMESPACE, intercepts[2].type); |
| 278 EXPECT_EQ(GURL("http://www.portme.com:1234/one"), |
| 279 intercepts[0].namespace_url); |
| 280 EXPECT_EQ(GURL("http://www.portme.com:1234/relative/int1"), |
| 281 intercepts[0].target_url); |
| 282 EXPECT_EQ(GURL("http://www.portme.com:1234/relative/two"), |
| 283 intercepts[1].namespace_url); |
| 284 EXPECT_EQ(GURL("http://www.portme.com:1234/relative/int2"), |
| 285 intercepts[1].target_url); |
| 286 EXPECT_EQ(GURL("http://www.portme.com:1234/three"), |
| 287 intercepts[2].namespace_url); |
| 288 EXPECT_EQ(GURL("http://www.portme.com:1234/int3"), |
| 289 intercepts[2].target_url); |
| 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 |