OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
6 #include "chrome/common/extensions/url_pattern.h" | 6 #include "chrome/common/extensions/url_pattern.h" |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 #include "googleurl/src/gurl.h" | 8 #include "googleurl/src/gurl.h" |
9 | 9 |
10 // See url_pattern.h for examples of valid and invalid patterns. | 10 // See url_pattern.h for examples of valid and invalid patterns. |
(...skipping 16 matching lines...) Expand all Loading... |
27 { "http:", URLPattern::PARSE_ERROR_WRONG_SCHEME_SEPARATOR }, | 27 { "http:", URLPattern::PARSE_ERROR_WRONG_SCHEME_SEPARATOR }, |
28 { "http:/", URLPattern::PARSE_ERROR_WRONG_SCHEME_SEPARATOR }, | 28 { "http:/", URLPattern::PARSE_ERROR_WRONG_SCHEME_SEPARATOR }, |
29 { "about://", URLPattern::PARSE_ERROR_WRONG_SCHEME_SEPARATOR }, | 29 { "about://", URLPattern::PARSE_ERROR_WRONG_SCHEME_SEPARATOR }, |
30 { "http://", URLPattern::PARSE_ERROR_EMPTY_HOST }, | 30 { "http://", URLPattern::PARSE_ERROR_EMPTY_HOST }, |
31 { "http:///", URLPattern::PARSE_ERROR_EMPTY_HOST }, | 31 { "http:///", URLPattern::PARSE_ERROR_EMPTY_HOST }, |
32 { "http://*foo/bar", URLPattern::PARSE_ERROR_INVALID_HOST_WILDCARD }, | 32 { "http://*foo/bar", URLPattern::PARSE_ERROR_INVALID_HOST_WILDCARD }, |
33 { "http://foo.*.bar/baz", URLPattern::PARSE_ERROR_INVALID_HOST_WILDCARD }, | 33 { "http://foo.*.bar/baz", URLPattern::PARSE_ERROR_INVALID_HOST_WILDCARD }, |
34 { "http://fo.*.ba:123/baz", URLPattern::PARSE_ERROR_INVALID_HOST_WILDCARD }, | 34 { "http://fo.*.ba:123/baz", URLPattern::PARSE_ERROR_INVALID_HOST_WILDCARD }, |
35 { "http:/bar", URLPattern::PARSE_ERROR_WRONG_SCHEME_SEPARATOR }, | 35 { "http:/bar", URLPattern::PARSE_ERROR_WRONG_SCHEME_SEPARATOR }, |
36 { "http://bar", URLPattern::PARSE_ERROR_EMPTY_PATH }, | 36 { "http://bar", URLPattern::PARSE_ERROR_EMPTY_PATH }, |
| 37 { "http:filesystem://bar", URLPattern::PARSE_ERROR_WRONG_SCHEME_SEPARATOR }, |
| 38 { "filesystem://bar", URLPattern::PARSE_ERROR_MISSING_SCHEME_SEPARATOR }, |
| 39 { "filesystem:filesystem:///bar", URLPattern::PARSE_ERROR_INVALID_SCHEME }, |
37 }; | 40 }; |
38 | 41 |
39 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kInvalidPatterns); ++i) { | 42 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kInvalidPatterns); ++i) { |
40 URLPattern pattern(URLPattern::SCHEME_ALL); | 43 URLPattern pattern(URLPattern::SCHEME_ALL); |
41 EXPECT_EQ(kInvalidPatterns[i].expected_result, | 44 EXPECT_EQ(kInvalidPatterns[i].expected_result, |
42 pattern.Parse(kInvalidPatterns[i].pattern)) | 45 pattern.Parse(kInvalidPatterns[i].pattern)) |
43 << kInvalidPatterns[i].pattern; | 46 << kInvalidPatterns[i].pattern; |
44 } | 47 } |
45 }; | 48 }; |
46 | 49 |
47 TEST(ExtensionURLPatternTest, Ports) { | 50 TEST(ExtensionURLPatternTest, Ports) { |
48 const struct { | 51 const struct { |
49 const char* pattern; | 52 const char* pattern; |
50 URLPattern::ParseResult expected_result; | 53 URLPattern::ParseResult expected_result; |
51 const char* expected_port; | 54 const char* expected_port; |
52 } kTestPatterns[] = { | 55 } kTestPatterns[] = { |
53 { "http://foo:1234/", URLPattern::PARSE_SUCCESS, "1234" }, | 56 { "http://foo:1234/", URLPattern::PARSE_SUCCESS, "1234" }, |
54 { "http://foo:1234/bar", URLPattern::PARSE_SUCCESS, "1234" }, | 57 { "http://foo:1234/bar", URLPattern::PARSE_SUCCESS, "1234" }, |
55 { "http://*.foo:1234/", URLPattern::PARSE_SUCCESS, "1234" }, | 58 { "http://*.foo:1234/", URLPattern::PARSE_SUCCESS, "1234" }, |
56 { "http://*.foo:1234/bar", URLPattern::PARSE_SUCCESS,"1234" }, | 59 { "http://*.foo:1234/bar", URLPattern::PARSE_SUCCESS,"1234" }, |
57 { "http://:1234/", URLPattern::PARSE_SUCCESS, "1234" }, | 60 { "http://:1234/", URLPattern::PARSE_SUCCESS, "1234" }, |
58 { "http://foo:/", URLPattern::PARSE_ERROR_INVALID_PORT, "*" }, | 61 { "http://foo:/", URLPattern::PARSE_ERROR_INVALID_PORT, "*" }, |
59 { "http://foo:*/", URLPattern::PARSE_SUCCESS, "*" }, | 62 { "http://foo:*/", URLPattern::PARSE_SUCCESS, "*" }, |
60 { "http://*.foo:/", URLPattern::PARSE_ERROR_INVALID_PORT, "*" }, | 63 { "http://*.foo:/", URLPattern::PARSE_ERROR_INVALID_PORT, "*" }, |
61 { "http://foo:com/", URLPattern::PARSE_ERROR_INVALID_PORT, "*" }, | 64 { "http://foo:com/", URLPattern::PARSE_ERROR_INVALID_PORT, "*" }, |
62 { "http://foo:123456/", URLPattern::PARSE_ERROR_INVALID_PORT, "*" }, | 65 { "http://foo:123456/", URLPattern::PARSE_ERROR_INVALID_PORT, "*" }, |
63 { "http://foo:80:80/monkey", URLPattern::PARSE_ERROR_INVALID_PORT, "*" }, | 66 { "http://foo:80:80/monkey", URLPattern::PARSE_ERROR_INVALID_PORT, "*" }, |
64 { "file://foo:1234/bar", URLPattern::PARSE_SUCCESS, "*" }, | 67 { "file://foo:1234/bar", URLPattern::PARSE_SUCCESS, "*" }, |
65 { "chrome://foo:1234/bar", URLPattern::PARSE_ERROR_INVALID_PORT, "*" }, | 68 { "chrome://foo:1234/bar", URLPattern::PARSE_ERROR_INVALID_PORT, "*" }, |
| 69 { "filesystem:http://foo:1234/", URLPattern::PARSE_SUCCESS, "1234" }, |
66 | 70 |
67 // Port-like strings in the path should not trigger a warning. | 71 // Port-like strings in the path should not trigger a warning. |
68 { "http://*/:1234", URLPattern::PARSE_SUCCESS, "*" }, | 72 { "http://*/:1234", URLPattern::PARSE_SUCCESS, "*" }, |
69 { "http://*.foo/bar:1234", URLPattern::PARSE_SUCCESS, "*" }, | 73 { "http://*.foo/bar:1234", URLPattern::PARSE_SUCCESS, "*" }, |
70 { "http://foo/bar:1234/path", URLPattern::PARSE_SUCCESS,"*" }, | 74 { "http://foo/bar:1234/path", URLPattern::PARSE_SUCCESS,"*" }, |
71 }; | 75 }; |
72 | 76 |
73 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestPatterns); ++i) { | 77 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestPatterns); ++i) { |
74 URLPattern pattern(URLPattern::SCHEME_ALL); | 78 URLPattern pattern(URLPattern::SCHEME_ALL); |
75 EXPECT_EQ(kTestPatterns[i].expected_result, | 79 EXPECT_EQ(kTestPatterns[i].expected_result, |
(...skipping 12 matching lines...) Expand all Loading... |
88 EXPECT_EQ("http", pattern.scheme()); | 92 EXPECT_EQ("http", pattern.scheme()); |
89 EXPECT_EQ("", pattern.host()); | 93 EXPECT_EQ("", pattern.host()); |
90 EXPECT_TRUE(pattern.match_subdomains()); | 94 EXPECT_TRUE(pattern.match_subdomains()); |
91 EXPECT_FALSE(pattern.match_all_urls()); | 95 EXPECT_FALSE(pattern.match_all_urls()); |
92 EXPECT_EQ("/*", pattern.path()); | 96 EXPECT_EQ("/*", pattern.path()); |
93 EXPECT_TRUE(pattern.MatchesURL(GURL("http://google.com"))); | 97 EXPECT_TRUE(pattern.MatchesURL(GURL("http://google.com"))); |
94 EXPECT_TRUE(pattern.MatchesURL(GURL("http://yahoo.com"))); | 98 EXPECT_TRUE(pattern.MatchesURL(GURL("http://yahoo.com"))); |
95 EXPECT_TRUE(pattern.MatchesURL(GURL("http://google.com/foo"))); | 99 EXPECT_TRUE(pattern.MatchesURL(GURL("http://google.com/foo"))); |
96 EXPECT_FALSE(pattern.MatchesURL(GURL("https://google.com"))); | 100 EXPECT_FALSE(pattern.MatchesURL(GURL("https://google.com"))); |
97 EXPECT_TRUE(pattern.MatchesURL(GURL("http://74.125.127.100/search"))); | 101 EXPECT_TRUE(pattern.MatchesURL(GURL("http://74.125.127.100/search"))); |
| 102 EXPECT_FALSE(pattern.MatchesURL(GURL("filesystem:http://google.com"))); |
98 } | 103 } |
99 | 104 |
100 // all domains | 105 // all domains |
101 TEST(ExtensionURLPatternTest, Match2) { | 106 TEST(ExtensionURLPatternTest, Match2) { |
102 URLPattern pattern(kAllSchemes); | 107 URLPattern pattern(kAllSchemes); |
103 EXPECT_EQ(URLPattern::PARSE_SUCCESS, pattern.Parse("https://*/foo*")); | 108 EXPECT_EQ(URLPattern::PARSE_SUCCESS, pattern.Parse("https://*/foo*")); |
104 EXPECT_EQ("https", pattern.scheme()); | 109 EXPECT_EQ("https", pattern.scheme()); |
105 EXPECT_EQ("", pattern.host()); | 110 EXPECT_EQ("", pattern.host()); |
106 EXPECT_TRUE(pattern.match_subdomains()); | 111 EXPECT_TRUE(pattern.match_subdomains()); |
107 EXPECT_FALSE(pattern.match_all_urls()); | 112 EXPECT_FALSE(pattern.match_all_urls()); |
108 EXPECT_EQ("/foo*", pattern.path()); | 113 EXPECT_EQ("/foo*", pattern.path()); |
109 EXPECT_TRUE(pattern.MatchesURL(GURL("https://www.google.com/foo"))); | 114 EXPECT_TRUE(pattern.MatchesURL(GURL("https://www.google.com/foo"))); |
| 115 EXPECT_FALSE( |
| 116 pattern.MatchesURL(GURL("filesystem:https://www.google.com/foo"))); |
110 EXPECT_TRUE(pattern.MatchesURL(GURL("https://www.google.com/foobar"))); | 117 EXPECT_TRUE(pattern.MatchesURL(GURL("https://www.google.com/foobar"))); |
111 EXPECT_FALSE(pattern.MatchesURL(GURL("http://www.google.com/foo"))); | 118 EXPECT_FALSE(pattern.MatchesURL(GURL("http://www.google.com/foo"))); |
112 EXPECT_FALSE(pattern.MatchesURL(GURL("https://www.google.com/"))); | 119 EXPECT_FALSE(pattern.MatchesURL(GURL("https://www.google.com/"))); |
113 } | 120 } |
114 | 121 |
115 // subdomains | 122 // subdomains |
116 TEST(URLPatternTest, Match3) { | 123 TEST(URLPatternTest, Match3) { |
117 URLPattern pattern(kAllSchemes); | 124 URLPattern pattern(kAllSchemes); |
118 EXPECT_EQ(URLPattern::PARSE_SUCCESS, | 125 EXPECT_EQ(URLPattern::PARSE_SUCCESS, |
119 pattern.Parse("http://*.google.com/foo*bar")); | 126 pattern.Parse("http://*.google.com/foo*bar")); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 | 209 |
203 // *:// | 210 // *:// |
204 TEST(ExtensionURLPatternTest, Match10) { | 211 TEST(ExtensionURLPatternTest, Match10) { |
205 URLPattern pattern(kAllSchemes); | 212 URLPattern pattern(kAllSchemes); |
206 EXPECT_EQ(URLPattern::PARSE_SUCCESS, pattern.Parse("*://*/*")); | 213 EXPECT_EQ(URLPattern::PARSE_SUCCESS, pattern.Parse("*://*/*")); |
207 EXPECT_TRUE(pattern.MatchesScheme("http")); | 214 EXPECT_TRUE(pattern.MatchesScheme("http")); |
208 EXPECT_TRUE(pattern.MatchesScheme("https")); | 215 EXPECT_TRUE(pattern.MatchesScheme("https")); |
209 EXPECT_FALSE(pattern.MatchesScheme("chrome")); | 216 EXPECT_FALSE(pattern.MatchesScheme("chrome")); |
210 EXPECT_FALSE(pattern.MatchesScheme("file")); | 217 EXPECT_FALSE(pattern.MatchesScheme("file")); |
211 EXPECT_FALSE(pattern.MatchesScheme("ftp")); | 218 EXPECT_FALSE(pattern.MatchesScheme("ftp")); |
| 219 EXPECT_FALSE(pattern.MatchesScheme("filesystem")); |
212 EXPECT_TRUE(pattern.match_subdomains()); | 220 EXPECT_TRUE(pattern.match_subdomains()); |
213 EXPECT_FALSE(pattern.match_all_urls()); | 221 EXPECT_FALSE(pattern.match_all_urls()); |
214 EXPECT_EQ("/*", pattern.path()); | 222 EXPECT_EQ("/*", pattern.path()); |
215 EXPECT_TRUE(pattern.MatchesURL(GURL("http://127.0.0.1"))); | 223 EXPECT_TRUE(pattern.MatchesURL(GURL("http://127.0.0.1"))); |
216 EXPECT_FALSE(pattern.MatchesURL(GURL("chrome://favicon/http://google.com"))); | 224 EXPECT_FALSE(pattern.MatchesURL(GURL("chrome://favicon/http://google.com"))); |
217 EXPECT_FALSE(pattern.MatchesURL(GURL("file:///foo/bar"))); | 225 EXPECT_FALSE(pattern.MatchesURL(GURL("file:///foo/bar"))); |
218 EXPECT_FALSE(pattern.MatchesURL(GURL("file://localhost/foo/bar"))); | 226 EXPECT_FALSE(pattern.MatchesURL(GURL("file://localhost/foo/bar"))); |
219 }; | 227 }; |
220 | 228 |
221 // <all_urls> | 229 // <all_urls> |
222 TEST(ExtensionURLPatternTest, Match11) { | 230 TEST(ExtensionURLPatternTest, Match11) { |
223 URLPattern pattern(kAllSchemes); | 231 URLPattern pattern(kAllSchemes); |
224 EXPECT_EQ(URLPattern::PARSE_SUCCESS, pattern.Parse("<all_urls>")); | 232 EXPECT_EQ(URLPattern::PARSE_SUCCESS, pattern.Parse("<all_urls>")); |
225 EXPECT_TRUE(pattern.MatchesScheme("chrome")); | 233 EXPECT_TRUE(pattern.MatchesScheme("chrome")); |
226 EXPECT_TRUE(pattern.MatchesScheme("http")); | 234 EXPECT_TRUE(pattern.MatchesScheme("http")); |
227 EXPECT_TRUE(pattern.MatchesScheme("https")); | 235 EXPECT_TRUE(pattern.MatchesScheme("https")); |
228 EXPECT_TRUE(pattern.MatchesScheme("file")); | 236 EXPECT_TRUE(pattern.MatchesScheme("file")); |
| 237 EXPECT_TRUE(pattern.MatchesScheme("filesystem")); |
229 EXPECT_TRUE(pattern.MatchesScheme("chrome-extension")); | 238 EXPECT_TRUE(pattern.MatchesScheme("chrome-extension")); |
230 EXPECT_TRUE(pattern.match_subdomains()); | 239 EXPECT_TRUE(pattern.match_subdomains()); |
231 EXPECT_TRUE(pattern.match_all_urls()); | 240 EXPECT_TRUE(pattern.match_all_urls()); |
232 EXPECT_EQ("/*", pattern.path()); | 241 EXPECT_EQ("/*", pattern.path()); |
233 EXPECT_TRUE(pattern.MatchesURL(GURL("chrome://favicon/http://google.com"))); | 242 EXPECT_TRUE(pattern.MatchesURL(GURL("chrome://favicon/http://google.com"))); |
234 EXPECT_TRUE(pattern.MatchesURL(GURL("http://127.0.0.1"))); | 243 EXPECT_TRUE(pattern.MatchesURL(GURL("http://127.0.0.1"))); |
235 EXPECT_TRUE(pattern.MatchesURL(GURL("file:///foo/bar"))); | 244 EXPECT_TRUE(pattern.MatchesURL(GURL("file:///foo/bar"))); |
236 EXPECT_TRUE(pattern.MatchesURL(GURL("file://localhost/foo/bar"))); | 245 EXPECT_TRUE(pattern.MatchesURL(GURL("file://localhost/foo/bar"))); |
| 246 EXPECT_TRUE(pattern.MatchesURL(GURL("filesystem:file:///temporary/foo/bar"))); |
| 247 EXPECT_TRUE(pattern.MatchesURL( |
| 248 GURL("filesystem:http://google.com/temporary/foo/bar"))); |
237 | 249 |
238 // Make sure the properties are the same when creating an <all_urls> pattern | 250 // Make sure the properties are the same when creating an <all_urls> pattern |
239 // via SetMatchAllURLs and by parsing <all_urls>. | 251 // via SetMatchAllURLs and by parsing <all_urls>. |
240 URLPattern pattern2(kAllSchemes); | 252 URLPattern pattern2(kAllSchemes); |
241 pattern2.SetMatchAllURLs(true); | 253 pattern2.SetMatchAllURLs(true); |
242 | 254 |
243 EXPECT_EQ(pattern.valid_schemes(), pattern2.valid_schemes()); | 255 EXPECT_EQ(pattern.valid_schemes(), pattern2.valid_schemes()); |
244 EXPECT_EQ(pattern.match_subdomains(), pattern2.match_subdomains()); | 256 EXPECT_EQ(pattern.match_subdomains(), pattern2.match_subdomains()); |
245 EXPECT_EQ(pattern.path(), pattern2.path()); | 257 EXPECT_EQ(pattern.path(), pattern2.path()); |
246 EXPECT_EQ(pattern.match_all_urls(), pattern2.match_all_urls()); | 258 EXPECT_EQ(pattern.match_all_urls(), pattern2.match_all_urls()); |
247 EXPECT_EQ(pattern.scheme(), pattern2.scheme()); | 259 EXPECT_EQ(pattern.scheme(), pattern2.scheme()); |
248 EXPECT_EQ(pattern.port(), pattern2.port()); | 260 EXPECT_EQ(pattern.port(), pattern2.port()); |
249 EXPECT_EQ(pattern.GetAsString(), pattern2.GetAsString()); | 261 EXPECT_EQ(pattern.GetAsString(), pattern2.GetAsString()); |
250 }; | 262 }; |
251 | 263 |
252 // SCHEME_ALL matches all schemes. | 264 // SCHEME_ALL matches all schemes. |
253 TEST(ExtensionURLPatternTest, Match12) { | 265 TEST(ExtensionURLPatternTest, Match12) { |
254 URLPattern pattern(URLPattern::SCHEME_ALL); | 266 URLPattern pattern(URLPattern::SCHEME_ALL); |
255 EXPECT_EQ(URLPattern::PARSE_SUCCESS, pattern.Parse("<all_urls>")); | 267 EXPECT_EQ(URLPattern::PARSE_SUCCESS, pattern.Parse("<all_urls>")); |
256 EXPECT_TRUE(pattern.MatchesScheme("chrome")); | 268 EXPECT_TRUE(pattern.MatchesScheme("chrome")); |
257 EXPECT_TRUE(pattern.MatchesScheme("http")); | 269 EXPECT_TRUE(pattern.MatchesScheme("http")); |
258 EXPECT_TRUE(pattern.MatchesScheme("https")); | 270 EXPECT_TRUE(pattern.MatchesScheme("https")); |
259 EXPECT_TRUE(pattern.MatchesScheme("file")); | 271 EXPECT_TRUE(pattern.MatchesScheme("file")); |
| 272 EXPECT_TRUE(pattern.MatchesScheme("filesystem")); |
260 EXPECT_TRUE(pattern.MatchesScheme("javascript")); | 273 EXPECT_TRUE(pattern.MatchesScheme("javascript")); |
261 EXPECT_TRUE(pattern.MatchesScheme("data")); | 274 EXPECT_TRUE(pattern.MatchesScheme("data")); |
262 EXPECT_TRUE(pattern.MatchesScheme("about")); | 275 EXPECT_TRUE(pattern.MatchesScheme("about")); |
263 EXPECT_TRUE(pattern.MatchesScheme("chrome-extension")); | 276 EXPECT_TRUE(pattern.MatchesScheme("chrome-extension")); |
264 EXPECT_TRUE(pattern.match_subdomains()); | 277 EXPECT_TRUE(pattern.match_subdomains()); |
265 EXPECT_TRUE(pattern.match_all_urls()); | 278 EXPECT_TRUE(pattern.match_all_urls()); |
266 EXPECT_EQ("/*", pattern.path()); | 279 EXPECT_EQ("/*", pattern.path()); |
267 EXPECT_TRUE(pattern.MatchesURL(GURL("chrome://favicon/http://google.com"))); | 280 EXPECT_TRUE(pattern.MatchesURL(GURL("chrome://favicon/http://google.com"))); |
268 EXPECT_TRUE(pattern.MatchesURL(GURL("http://127.0.0.1"))); | 281 EXPECT_TRUE(pattern.MatchesURL(GURL("http://127.0.0.1"))); |
269 EXPECT_TRUE(pattern.MatchesURL(GURL("file:///foo/bar"))); | 282 EXPECT_TRUE(pattern.MatchesURL(GURL("file:///foo/bar"))); |
270 EXPECT_TRUE(pattern.MatchesURL(GURL("file://localhost/foo/bar"))); | 283 EXPECT_TRUE(pattern.MatchesURL(GURL("file://localhost/foo/bar"))); |
| 284 EXPECT_TRUE(pattern.MatchesURL( |
| 285 GURL("filesystem:file:///persistent/foo/bar"))); |
271 EXPECT_TRUE(pattern.MatchesURL(GURL("chrome://newtab"))); | 286 EXPECT_TRUE(pattern.MatchesURL(GURL("chrome://newtab"))); |
272 EXPECT_TRUE(pattern.MatchesURL(GURL("about:blank"))); | 287 EXPECT_TRUE(pattern.MatchesURL(GURL("about:blank"))); |
273 EXPECT_TRUE(pattern.MatchesURL(GURL("about:version"))); | 288 EXPECT_TRUE(pattern.MatchesURL(GURL("about:version"))); |
274 EXPECT_TRUE(pattern.MatchesURL( | 289 EXPECT_TRUE(pattern.MatchesURL( |
275 GURL("data:text/html;charset=utf-8,<html>asdf</html>"))); | 290 GURL("data:text/html;charset=utf-8,<html>asdf</html>"))); |
276 }; | 291 }; |
277 | 292 |
278 static const struct MatchPatterns { | 293 static const struct MatchPatterns { |
279 const char* pattern; | 294 const char* pattern; |
280 const char* matches; | 295 const char* matches; |
281 } kMatch13UrlPatternTestCases[] = { | 296 } kMatch13UrlPatternTestCases[] = { |
282 {"about:*", "about:blank"}, | 297 {"about:*", "about:blank"}, |
283 {"about:blank", "about:blank"}, | 298 {"about:blank", "about:blank"}, |
284 {"about:*", "about:version"}, | 299 {"about:*", "about:version"}, |
285 {"chrome-extension://*/*", "chrome-extension://FTW"}, | 300 {"chrome-extension://*/*", "chrome-extension://FTW"}, |
286 {"data:*", "data:monkey"}, | 301 {"data:*", "data:monkey"}, |
| 302 {"filesystem:http://*/*", "filesystem:http://monkey.com/t/f.txt"}, |
287 {"javascript:*", "javascript:atemyhomework"}, | 303 {"javascript:*", "javascript:atemyhomework"}, |
288 }; | 304 }; |
289 | 305 |
290 // SCHEME_ALL and specific schemes. | 306 // SCHEME_ALL and specific schemes. |
291 TEST(ExtensionURLPatternTest, Match13) { | 307 TEST(ExtensionURLPatternTest, Match13) { |
292 for (size_t i = 0; i < arraysize(kMatch13UrlPatternTestCases); ++i) { | 308 for (size_t i = 0; i < arraysize(kMatch13UrlPatternTestCases); ++i) { |
293 URLPattern pattern(URLPattern::SCHEME_ALL); | 309 URLPattern pattern(URLPattern::SCHEME_ALL); |
294 EXPECT_EQ(URLPattern::PARSE_SUCCESS, | 310 EXPECT_EQ(URLPattern::PARSE_SUCCESS, |
295 pattern.Parse(kMatch13UrlPatternTestCases[i].pattern)) | 311 pattern.Parse(kMatch13UrlPatternTestCases[i].pattern)) |
296 << " while parsing " << kMatch13UrlPatternTestCases[i].pattern; | 312 << " while parsing " << kMatch13UrlPatternTestCases[i].pattern; |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 EXPECT_FALSE(pattern.match_all_urls()); | 413 EXPECT_FALSE(pattern.match_all_urls()); |
398 EXPECT_EQ("/*", pattern.path()); | 414 EXPECT_EQ("/*", pattern.path()); |
399 EXPECT_TRUE(pattern.MatchesURL(GURL("chrome-extension://ftw"))); | 415 EXPECT_TRUE(pattern.MatchesURL(GURL("chrome-extension://ftw"))); |
400 EXPECT_TRUE(pattern.MatchesURL( | 416 EXPECT_TRUE(pattern.MatchesURL( |
401 GURL("chrome-extension://ftw/http://google.com"))); | 417 GURL("chrome-extension://ftw/http://google.com"))); |
402 EXPECT_TRUE(pattern.MatchesURL( | 418 EXPECT_TRUE(pattern.MatchesURL( |
403 GURL("chrome-extension://ftw/https://google.com"))); | 419 GURL("chrome-extension://ftw/https://google.com"))); |
404 EXPECT_FALSE(pattern.MatchesURL(GURL("chrome-extension://foobar"))); | 420 EXPECT_FALSE(pattern.MatchesURL(GURL("chrome-extension://foobar"))); |
405 }; | 421 }; |
406 | 422 |
| 423 // filesystem:http:// |
| 424 TEST(ExtensionURLPatternTest, Match20) { |
| 425 URLPattern pattern(kAllSchemes); |
| 426 EXPECT_EQ(URLPattern::PARSE_SUCCESS, |
| 427 pattern.Parse("filesystem:http://foo.com/t/*")); |
| 428 EXPECT_EQ("filesystem", pattern.scheme()); |
| 429 EXPECT_EQ("http", pattern.inner_scheme()); |
| 430 EXPECT_EQ("foo.com", pattern.host()); |
| 431 EXPECT_FALSE(pattern.match_subdomains()); |
| 432 EXPECT_FALSE(pattern.match_all_urls()); |
| 433 EXPECT_EQ("/t/*", pattern.path()); |
| 434 EXPECT_TRUE(pattern.MatchesURL(GURL("filesystem:http://foo.com/t/blah"))); |
| 435 EXPECT_TRUE(pattern.MatchesURL(GURL("filesystem:http://foo.com/t/bar"))); |
| 436 EXPECT_FALSE(pattern.MatchesURL(GURL("filesystem:https://foo.com/t/bar"))); |
| 437 EXPECT_FALSE(pattern.MatchesURL(GURL("filesystem:file://foo.com/t/bar"))); |
| 438 EXPECT_FALSE(pattern.MatchesURL(GURL("filesystem:http://bar.com/t/bar"))); |
| 439 EXPECT_FALSE(pattern.MatchesURL(GURL("filesystem:http://foo.com/p/bar"))); |
| 440 EXPECT_FALSE(pattern.MatchesURL(GURL("filesystem:http://foo.com/t"))); |
| 441 }; |
| 442 |
| 443 // filesystem:chrome-extension:// |
| 444 TEST(ExtensionURLPatternTest, Match22) { |
| 445 URLPattern pattern(kAllSchemes); |
| 446 EXPECT_EQ(URLPattern::PARSE_SUCCESS, |
| 447 pattern.Parse("filesystem:chrome-extension://*/*.txt")); |
| 448 EXPECT_EQ("filesystem", pattern.scheme()); |
| 449 EXPECT_EQ("chrome-extension", pattern.inner_scheme()); |
| 450 EXPECT_EQ("", pattern.host()); |
| 451 EXPECT_TRUE(pattern.match_subdomains()); |
| 452 EXPECT_FALSE(pattern.match_all_urls()); |
| 453 EXPECT_EQ("/*.txt", pattern.path()); |
| 454 EXPECT_FALSE(pattern.MatchesURL( |
| 455 GURL("filesystem:chrome-extension://39804298/t/blah"))); |
| 456 // This is FALSE because 't' becomes the host [the extension id], which makes |
| 457 // 'bar.txt' the storage specifier of the filesystem URL, so there's no path |
| 458 // left. |
| 459 EXPECT_FALSE(pattern.MatchesURL( |
| 460 GURL("filesystem:chrome-extension://t/bar.txt"))); |
| 461 EXPECT_TRUE(pattern.MatchesURL( |
| 462 GURL("filesystem:chrome-extension://t/t/bar.txt"))); |
| 463 }; |
| 464 |
407 static const struct GetAsStringPatterns { | 465 static const struct GetAsStringPatterns { |
408 const char* pattern; | 466 const char* pattern; |
409 } kGetAsStringTestCases[] = { | 467 } kGetAsStringTestCases[] = { |
410 { "http://www/" }, | 468 { "http://www/" }, |
411 { "http://*/*" }, | 469 { "http://*/*" }, |
412 { "chrome://*/*" }, | 470 { "chrome://*/*" }, |
413 { "chrome://newtab/" }, | 471 { "chrome://newtab/" }, |
414 { "about:*" }, | 472 { "about:*" }, |
415 { "about:blank" }, | 473 { "about:blank" }, |
416 { "chrome-extension://*/*" }, | 474 { "chrome-extension://*/*" }, |
417 { "chrome-extension://FTW/" }, | 475 { "chrome-extension://FTW/" }, |
418 { "data:*" }, | 476 { "data:*" }, |
419 { "data:monkey" }, | 477 { "data:monkey" }, |
420 { "javascript:*" }, | 478 { "javascript:*" }, |
421 { "javascript:atemyhomework" }, | 479 { "javascript:atemyhomework" }, |
422 { "http://www.example.com:8080/foo" }, | 480 { "http://www.example.com:8080/foo" }, |
| 481 { "filesystem:http://www.example.com:8080/foo" }, |
| 482 { "filesystem:file:///foo" }, |
| 483 { "filesystem:*://foo/bar" }, |
| 484 { "file:///foo" }, |
423 }; | 485 }; |
424 | 486 |
425 TEST(ExtensionURLPatternTest, GetAsString) { | 487 TEST(ExtensionURLPatternTest, GetAsString) { |
426 for (size_t i = 0; i < arraysize(kGetAsStringTestCases); ++i) { | 488 for (size_t i = 0; i < arraysize(kGetAsStringTestCases); ++i) { |
427 URLPattern pattern(URLPattern::SCHEME_ALL); | 489 URLPattern pattern(URLPattern::SCHEME_ALL); |
428 EXPECT_EQ(URLPattern::PARSE_SUCCESS, | 490 EXPECT_EQ(URLPattern::PARSE_SUCCESS, |
429 pattern.Parse(kGetAsStringTestCases[i].pattern)) | 491 pattern.Parse(kGetAsStringTestCases[i].pattern)) |
430 << "Error parsing " << kGetAsStringTestCases[i].pattern; | 492 << "Error parsing " << kGetAsStringTestCases[i].pattern; |
431 EXPECT_EQ(kGetAsStringTestCases[i].pattern, | 493 EXPECT_EQ(kGetAsStringTestCases[i].pattern, |
432 pattern.GetAsString()); | 494 pattern.GetAsString()); |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
597 }, | 659 }, |
598 | 660 |
599 // all_urls | 661 // all_urls |
600 { "<all_urls>", | 662 { "<all_urls>", |
601 "<all_urls>", | 663 "<all_urls>", |
602 true | 664 true |
603 }, | 665 }, |
604 { "<all_urls>", | 666 { "<all_urls>", |
605 "http://*/*", | 667 "http://*/*", |
606 false | 668 false |
| 669 }, |
| 670 |
| 671 // filesystem inner_schemes |
| 672 { "filesystem:file://foo/*", |
| 673 "filesystem:file://foo/*", |
| 674 true |
| 675 }, |
| 676 { "filesystem:http://foo/*", |
| 677 "filesystem:file://foo/*", |
| 678 false |
607 } | 679 } |
608 }; | 680 }; |
609 | 681 |
610 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kEqualsTestCases); ++i) { | 682 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kEqualsTestCases); ++i) { |
611 std::string message = kEqualsTestCases[i].pattern1; | 683 std::string message = kEqualsTestCases[i].pattern1; |
612 message += " "; | 684 message += " "; |
613 message += kEqualsTestCases[i].pattern2; | 685 message += kEqualsTestCases[i].pattern2; |
614 | 686 |
615 URLPattern pattern1(URLPattern::SCHEME_ALL); | 687 URLPattern pattern1(URLPattern::SCHEME_ALL); |
616 URLPattern pattern2(URLPattern::SCHEME_ALL); | 688 URLPattern pattern2(URLPattern::SCHEME_ALL); |
(...skipping 18 matching lines...) Expand all Loading... |
635 | 707 |
636 EXPECT_FALSE(pattern2.MatchesURL(GURL("http://bb.com/path"))); | 708 EXPECT_FALSE(pattern2.MatchesURL(GURL("http://bb.com/path"))); |
637 EXPECT_TRUE(pattern2.MatchesURL(GURL("http://aa.com/path"))); | 709 EXPECT_TRUE(pattern2.MatchesURL(GURL("http://aa.com/path"))); |
638 EXPECT_FALSE(pattern2.MatchesURL(GURL("http://sub.aa.com/path"))); | 710 EXPECT_FALSE(pattern2.MatchesURL(GURL("http://sub.aa.com/path"))); |
639 | 711 |
640 URLPattern pattern3(URLPattern::SCHEME_ALL, "http://aa.com/*"); | 712 URLPattern pattern3(URLPattern::SCHEME_ALL, "http://aa.com/*"); |
641 EXPECT_EQ(URLPattern::PARSE_SUCCESS, pattern3.Parse("http://aa.com:88/*")); | 713 EXPECT_EQ(URLPattern::PARSE_SUCCESS, pattern3.Parse("http://aa.com:88/*")); |
642 EXPECT_FALSE(pattern3.MatchesURL(GURL("http://aa.com/path"))); | 714 EXPECT_FALSE(pattern3.MatchesURL(GURL("http://aa.com/path"))); |
643 EXPECT_TRUE(pattern3.MatchesURL(GURL("http://aa.com:88/path"))); | 715 EXPECT_TRUE(pattern3.MatchesURL(GURL("http://aa.com:88/path"))); |
644 } | 716 } |
OLD | NEW |