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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 EXPECT_EQ(URLPattern::PARSE_SUCCESS, pattern.Parse("https://*/foo*")); | 103 EXPECT_EQ(URLPattern::PARSE_SUCCESS, pattern.Parse("https://*/foo*")); |
104 EXPECT_EQ("https", pattern.scheme()); | 104 EXPECT_EQ("https", pattern.scheme()); |
105 EXPECT_EQ("", pattern.host()); | 105 EXPECT_EQ("", pattern.host()); |
106 EXPECT_TRUE(pattern.match_subdomains()); | 106 EXPECT_TRUE(pattern.match_subdomains()); |
107 EXPECT_FALSE(pattern.match_all_urls()); | 107 EXPECT_FALSE(pattern.match_all_urls()); |
108 EXPECT_EQ("/foo*", pattern.path()); | 108 EXPECT_EQ("/foo*", pattern.path()); |
109 EXPECT_TRUE(pattern.MatchesURL(GURL("https://www.google.com/foo"))); | 109 EXPECT_TRUE(pattern.MatchesURL(GURL("https://www.google.com/foo"))); |
110 EXPECT_TRUE(pattern.MatchesURL(GURL("https://www.google.com/foobar"))); | 110 EXPECT_TRUE(pattern.MatchesURL(GURL("https://www.google.com/foobar"))); |
111 EXPECT_FALSE(pattern.MatchesURL(GURL("http://www.google.com/foo"))); | 111 EXPECT_FALSE(pattern.MatchesURL(GURL("http://www.google.com/foo"))); |
112 EXPECT_FALSE(pattern.MatchesURL(GURL("https://www.google.com/"))); | 112 EXPECT_FALSE(pattern.MatchesURL(GURL("https://www.google.com/"))); |
113 EXPECT_FALSE(pattern.MatchesURL( | 113 EXPECT_TRUE(pattern.MatchesURL( |
114 GURL("filesystem:https://www.google.com/foobar/"))); | 114 GURL("filesystem:https://www.google.com/foobar/"))); |
115 pattern.set_partial_filesystem_support_hack(true); | |
116 EXPECT_TRUE(pattern.MatchesURL( | |
117 GURL("filesystem:https://www.google.com/foobar/bas"))); | |
118 } | 115 } |
119 | 116 |
120 // subdomains | 117 // subdomains |
121 TEST(URLPatternTest, Match3) { | 118 TEST(URLPatternTest, Match3) { |
122 URLPattern pattern(kAllSchemes); | 119 URLPattern pattern(kAllSchemes); |
123 EXPECT_EQ(URLPattern::PARSE_SUCCESS, | 120 EXPECT_EQ(URLPattern::PARSE_SUCCESS, |
124 pattern.Parse("http://*.google.com/foo*bar")); | 121 pattern.Parse("http://*.google.com/foo*bar")); |
125 EXPECT_EQ("http", pattern.scheme()); | 122 EXPECT_EQ("http", pattern.scheme()); |
126 EXPECT_EQ("google.com", pattern.host()); | 123 EXPECT_EQ("google.com", pattern.host()); |
127 EXPECT_TRUE(pattern.match_subdomains()); | 124 EXPECT_TRUE(pattern.match_subdomains()); |
128 EXPECT_FALSE(pattern.match_all_urls()); | 125 EXPECT_FALSE(pattern.match_all_urls()); |
129 EXPECT_EQ("/foo*bar", pattern.path()); | 126 EXPECT_EQ("/foo*bar", pattern.path()); |
130 EXPECT_TRUE(pattern.MatchesURL(GURL("http://google.com/foobar"))); | 127 EXPECT_TRUE(pattern.MatchesURL(GURL("http://google.com/foobar"))); |
131 EXPECT_TRUE(pattern.MatchesURL(GURL("http://www.google.com/foo?bar"))); | 128 EXPECT_TRUE(pattern.MatchesURL(GURL("http://www.google.com/foo?bar"))); |
132 EXPECT_TRUE(pattern.MatchesURL( | 129 EXPECT_TRUE(pattern.MatchesURL( |
133 GURL("http://monkey.images.google.com/foooobar"))); | 130 GURL("http://monkey.images.google.com/foooobar"))); |
134 EXPECT_FALSE(pattern.MatchesURL(GURL("http://yahoo.com/foobar"))); | 131 EXPECT_FALSE(pattern.MatchesURL(GURL("http://yahoo.com/foobar"))); |
135 EXPECT_FALSE(pattern.MatchesURL( | 132 EXPECT_TRUE(pattern.MatchesURL( |
136 GURL("filesystem:http://google.com/foobar/"))); | 133 GURL("filesystem:http://google.com/foo/bar"))); |
137 pattern.set_partial_filesystem_support_hack(true); | |
138 EXPECT_FALSE(pattern.MatchesURL( | 134 EXPECT_FALSE(pattern.MatchesURL( |
139 GURL("filesystem:http://google.com/temporary/foobar"))); | 135 GURL("filesystem:http://google.com/temporary/foobar"))); |
140 } | 136 } |
141 | 137 |
142 // glob escaping | 138 // glob escaping |
143 TEST(ExtensionURLPatternTest, Match5) { | 139 TEST(ExtensionURLPatternTest, Match5) { |
144 URLPattern pattern(kAllSchemes); | 140 URLPattern pattern(kAllSchemes); |
145 EXPECT_EQ(URLPattern::PARSE_SUCCESS, pattern.Parse("file:///foo?bar\\*baz")); | 141 EXPECT_EQ(URLPattern::PARSE_SUCCESS, pattern.Parse("file:///foo?bar\\*baz")); |
146 EXPECT_EQ("file", pattern.scheme()); | 142 EXPECT_EQ("file", pattern.scheme()); |
147 EXPECT_EQ("", pattern.host()); | 143 EXPECT_EQ("", pattern.host()); |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 EXPECT_FALSE(pattern.match_subdomains()); | 372 EXPECT_FALSE(pattern.match_subdomains()); |
377 EXPECT_FALSE(pattern.match_all_urls()); | 373 EXPECT_FALSE(pattern.match_all_urls()); |
378 EXPECT_EQ("/foo", pattern.path()); | 374 EXPECT_EQ("/foo", pattern.path()); |
379 EXPECT_EQ("80", pattern.port()); | 375 EXPECT_EQ("80", pattern.port()); |
380 EXPECT_TRUE(pattern.MatchesURL(GURL("http://www.example.com:80/foo"))); | 376 EXPECT_TRUE(pattern.MatchesURL(GURL("http://www.example.com:80/foo"))); |
381 EXPECT_TRUE(pattern.MatchesURL(GURL("http://www.example.com/foo"))); | 377 EXPECT_TRUE(pattern.MatchesURL(GURL("http://www.example.com/foo"))); |
382 EXPECT_FALSE(pattern.MatchesURL(GURL("http://www.example.com:8080/foo"))); | 378 EXPECT_FALSE(pattern.MatchesURL(GURL("http://www.example.com:8080/foo"))); |
383 EXPECT_FALSE(pattern.MatchesURL( | 379 EXPECT_FALSE(pattern.MatchesURL( |
384 GURL("filesystem:http://www.example.com:8080/foo/"))); | 380 GURL("filesystem:http://www.example.com:8080/foo/"))); |
385 EXPECT_FALSE(pattern.MatchesURL(GURL("filesystem:http://www.example.com/f/foo"
))); | 381 EXPECT_FALSE(pattern.MatchesURL(GURL("filesystem:http://www.example.com/f/foo"
))); |
386 pattern.set_partial_filesystem_support_hack(true); | |
387 EXPECT_FALSE(pattern.MatchesURL(GURL("filesystem:http://www.example.com/f/foo"
))); | |
388 } | 382 } |
389 | 383 |
390 // Explicit port wildcard | 384 // Explicit port wildcard |
391 TEST(ExtensionURLPatternTest, Match18) { | 385 TEST(ExtensionURLPatternTest, Match18) { |
392 URLPattern pattern(kAllSchemes); | 386 URLPattern pattern(kAllSchemes); |
393 EXPECT_EQ(URLPattern::PARSE_SUCCESS, | 387 EXPECT_EQ(URLPattern::PARSE_SUCCESS, |
394 pattern.Parse("http://www.example.com:*/foo")); | 388 pattern.Parse("http://www.example.com:*/foo")); |
395 EXPECT_EQ("http", pattern.scheme()); | 389 EXPECT_EQ("http", pattern.scheme()); |
396 EXPECT_EQ("www.example.com", pattern.host()); | 390 EXPECT_EQ("www.example.com", pattern.host()); |
397 EXPECT_FALSE(pattern.match_subdomains()); | 391 EXPECT_FALSE(pattern.match_subdomains()); |
(...skipping 16 matching lines...) Expand all Loading... |
414 EXPECT_EQ("ftw", pattern.host()); | 408 EXPECT_EQ("ftw", pattern.host()); |
415 EXPECT_FALSE(pattern.match_subdomains()); | 409 EXPECT_FALSE(pattern.match_subdomains()); |
416 EXPECT_FALSE(pattern.match_all_urls()); | 410 EXPECT_FALSE(pattern.match_all_urls()); |
417 EXPECT_EQ("/*", pattern.path()); | 411 EXPECT_EQ("/*", pattern.path()); |
418 EXPECT_TRUE(pattern.MatchesURL(GURL("chrome-extension://ftw"))); | 412 EXPECT_TRUE(pattern.MatchesURL(GURL("chrome-extension://ftw"))); |
419 EXPECT_TRUE(pattern.MatchesURL( | 413 EXPECT_TRUE(pattern.MatchesURL( |
420 GURL("chrome-extension://ftw/http://google.com"))); | 414 GURL("chrome-extension://ftw/http://google.com"))); |
421 EXPECT_TRUE(pattern.MatchesURL( | 415 EXPECT_TRUE(pattern.MatchesURL( |
422 GURL("chrome-extension://ftw/https://google.com"))); | 416 GURL("chrome-extension://ftw/https://google.com"))); |
423 EXPECT_FALSE(pattern.MatchesURL(GURL("chrome-extension://foobar"))); | 417 EXPECT_FALSE(pattern.MatchesURL(GURL("chrome-extension://foobar"))); |
424 EXPECT_FALSE(pattern.MatchesURL( | |
425 GURL("filesystem:chrome-extension://ftw/t/file.txt"))); | |
426 pattern.set_partial_filesystem_support_hack(true); | |
427 EXPECT_TRUE(pattern.MatchesURL( | 418 EXPECT_TRUE(pattern.MatchesURL( |
428 GURL("filesystem:chrome-extension://ftw/t/file.txt"))); | 419 GURL("filesystem:chrome-extension://ftw/t/file.txt"))); |
429 }; | 420 }; |
430 | 421 |
431 static const struct GetAsStringPatterns { | 422 static const struct GetAsStringPatterns { |
432 const char* pattern; | 423 const char* pattern; |
433 } kGetAsStringTestCases[] = { | 424 } kGetAsStringTestCases[] = { |
434 { "http://www/" }, | 425 { "http://www/" }, |
435 { "http://*/*" }, | 426 { "http://*/*" }, |
436 { "chrome://*/*" }, | 427 { "chrome://*/*" }, |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
659 | 650 |
660 EXPECT_FALSE(pattern2.MatchesURL(GURL("http://bb.com/path"))); | 651 EXPECT_FALSE(pattern2.MatchesURL(GURL("http://bb.com/path"))); |
661 EXPECT_TRUE(pattern2.MatchesURL(GURL("http://aa.com/path"))); | 652 EXPECT_TRUE(pattern2.MatchesURL(GURL("http://aa.com/path"))); |
662 EXPECT_FALSE(pattern2.MatchesURL(GURL("http://sub.aa.com/path"))); | 653 EXPECT_FALSE(pattern2.MatchesURL(GURL("http://sub.aa.com/path"))); |
663 | 654 |
664 URLPattern pattern3(URLPattern::SCHEME_ALL, "http://aa.com/*"); | 655 URLPattern pattern3(URLPattern::SCHEME_ALL, "http://aa.com/*"); |
665 EXPECT_EQ(URLPattern::PARSE_SUCCESS, pattern3.Parse("http://aa.com:88/*")); | 656 EXPECT_EQ(URLPattern::PARSE_SUCCESS, pattern3.Parse("http://aa.com:88/*")); |
666 EXPECT_FALSE(pattern3.MatchesURL(GURL("http://aa.com/path"))); | 657 EXPECT_FALSE(pattern3.MatchesURL(GURL("http://aa.com/path"))); |
667 EXPECT_TRUE(pattern3.MatchesURL(GURL("http://aa.com:88/path"))); | 658 EXPECT_TRUE(pattern3.MatchesURL(GURL("http://aa.com:88/path"))); |
668 } | 659 } |
OLD | NEW |