Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(631)

Side by Side Diff: extensions/common/url_pattern_unittest.cc

Issue 226663003: Allow content script insertion on about:-URLs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove permission warning for about:-scheme Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "extensions/common/url_pattern.h" 6 #include "extensions/common/url_pattern.h"
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 9
10 namespace { 10 namespace {
11 11
12 // See url_pattern.h for examples of valid and invalid patterns. 12 // See url_pattern.h for examples of valid and invalid patterns.
13 13
14 static const int kAllSchemes = 14 static const int kAllSchemes =
15 URLPattern::SCHEME_HTTP | 15 URLPattern::SCHEME_HTTP |
16 URLPattern::SCHEME_HTTPS | 16 URLPattern::SCHEME_HTTPS |
17 URLPattern::SCHEME_FILE | 17 URLPattern::SCHEME_FILE |
18 URLPattern::SCHEME_FTP | 18 URLPattern::SCHEME_FTP |
19 URLPattern::SCHEME_CHROMEUI | 19 URLPattern::SCHEME_CHROMEUI |
20 URLPattern::SCHEME_EXTENSION | 20 URLPattern::SCHEME_EXTENSION |
21 URLPattern::SCHEME_FILESYSTEM; 21 URLPattern::SCHEME_FILESYSTEM|
22 URLPattern::SCHEME_ABOUT;
22 23
23 TEST(ExtensionURLPatternTest, ParseInvalid) { 24 TEST(ExtensionURLPatternTest, ParseInvalid) {
24 const struct { 25 const struct {
25 const char* pattern; 26 const char* pattern;
26 URLPattern::ParseResult expected_result; 27 URLPattern::ParseResult expected_result;
27 } kInvalidPatterns[] = { 28 } kInvalidPatterns[] = {
28 { "http", URLPattern::PARSE_ERROR_MISSING_SCHEME_SEPARATOR }, 29 { "http", URLPattern::PARSE_ERROR_MISSING_SCHEME_SEPARATOR },
29 { "http:", URLPattern::PARSE_ERROR_WRONG_SCHEME_SEPARATOR }, 30 { "http:", URLPattern::PARSE_ERROR_WRONG_SCHEME_SEPARATOR },
30 { "http:/", URLPattern::PARSE_ERROR_WRONG_SCHEME_SEPARATOR }, 31 { "http:/", URLPattern::PARSE_ERROR_WRONG_SCHEME_SEPARATOR },
31 { "about://", URLPattern::PARSE_ERROR_WRONG_SCHEME_SEPARATOR }, 32 { "about://", URLPattern::PARSE_ERROR_WRONG_SCHEME_SEPARATOR },
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 // <all_urls> 230 // <all_urls>
230 TEST(ExtensionURLPatternTest, Match11) { 231 TEST(ExtensionURLPatternTest, Match11) {
231 URLPattern pattern(kAllSchemes); 232 URLPattern pattern(kAllSchemes);
232 EXPECT_EQ(URLPattern::PARSE_SUCCESS, pattern.Parse("<all_urls>")); 233 EXPECT_EQ(URLPattern::PARSE_SUCCESS, pattern.Parse("<all_urls>"));
233 EXPECT_TRUE(pattern.MatchesScheme("chrome")); 234 EXPECT_TRUE(pattern.MatchesScheme("chrome"));
234 EXPECT_TRUE(pattern.MatchesScheme("http")); 235 EXPECT_TRUE(pattern.MatchesScheme("http"));
235 EXPECT_TRUE(pattern.MatchesScheme("https")); 236 EXPECT_TRUE(pattern.MatchesScheme("https"));
236 EXPECT_TRUE(pattern.MatchesScheme("file")); 237 EXPECT_TRUE(pattern.MatchesScheme("file"));
237 EXPECT_TRUE(pattern.MatchesScheme("filesystem")); 238 EXPECT_TRUE(pattern.MatchesScheme("filesystem"));
238 EXPECT_TRUE(pattern.MatchesScheme("chrome-extension")); 239 EXPECT_TRUE(pattern.MatchesScheme("chrome-extension"));
240 EXPECT_TRUE(pattern.MatchesScheme("about"));
239 EXPECT_TRUE(pattern.match_subdomains()); 241 EXPECT_TRUE(pattern.match_subdomains());
240 EXPECT_TRUE(pattern.match_all_urls()); 242 EXPECT_TRUE(pattern.match_all_urls());
241 EXPECT_EQ("/*", pattern.path()); 243 EXPECT_EQ("/*", pattern.path());
242 EXPECT_TRUE(pattern.MatchesURL(GURL("chrome://favicon/http://google.com"))); 244 EXPECT_TRUE(pattern.MatchesURL(GURL("chrome://favicon/http://google.com")));
243 EXPECT_TRUE(pattern.MatchesURL(GURL("http://127.0.0.1"))); 245 EXPECT_TRUE(pattern.MatchesURL(GURL("http://127.0.0.1")));
244 EXPECT_TRUE(pattern.MatchesURL(GURL("file:///foo/bar"))); 246 EXPECT_TRUE(pattern.MatchesURL(GURL("file:///foo/bar")));
245 EXPECT_TRUE(pattern.MatchesURL(GURL("file://localhost/foo/bar"))); 247 EXPECT_TRUE(pattern.MatchesURL(GURL("file://localhost/foo/bar")));
248 EXPECT_TRUE(pattern.MatchesURL(GURL("about:blank")));
246 249
247 // 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
248 // via SetMatchAllURLs and by parsing <all_urls>. 251 // via SetMatchAllURLs and by parsing <all_urls>.
249 URLPattern pattern2(kAllSchemes); 252 URLPattern pattern2(kAllSchemes);
250 pattern2.SetMatchAllURLs(true); 253 pattern2.SetMatchAllURLs(true);
251 254
252 EXPECT_EQ(pattern.valid_schemes(), pattern2.valid_schemes()); 255 EXPECT_EQ(pattern.valid_schemes(), pattern2.valid_schemes());
253 EXPECT_EQ(pattern.match_subdomains(), pattern2.match_subdomains()); 256 EXPECT_EQ(pattern.match_subdomains(), pattern2.match_subdomains());
254 EXPECT_EQ(pattern.path(), pattern2.path()); 257 EXPECT_EQ(pattern.path(), pattern2.path());
255 EXPECT_EQ(pattern.match_all_urls(), pattern2.match_all_urls()); 258 EXPECT_EQ(pattern.match_all_urls(), pattern2.match_all_urls());
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 EXPECT_TRUE(pattern.MatchesURL(GURL("chrome-extension://ftw"))); 418 EXPECT_TRUE(pattern.MatchesURL(GURL("chrome-extension://ftw")));
416 EXPECT_TRUE(pattern.MatchesURL( 419 EXPECT_TRUE(pattern.MatchesURL(
417 GURL("chrome-extension://ftw/http://google.com"))); 420 GURL("chrome-extension://ftw/http://google.com")));
418 EXPECT_TRUE(pattern.MatchesURL( 421 EXPECT_TRUE(pattern.MatchesURL(
419 GURL("chrome-extension://ftw/https://google.com"))); 422 GURL("chrome-extension://ftw/https://google.com")));
420 EXPECT_FALSE(pattern.MatchesURL(GURL("chrome-extension://foobar"))); 423 EXPECT_FALSE(pattern.MatchesURL(GURL("chrome-extension://foobar")));
421 EXPECT_TRUE(pattern.MatchesURL( 424 EXPECT_TRUE(pattern.MatchesURL(
422 GURL("filesystem:chrome-extension://ftw/t/file.txt"))); 425 GURL("filesystem:chrome-extension://ftw/t/file.txt")));
423 }; 426 };
424 427
428 // about:
429 TEST(ExtensionURLPatternTest, Match20) {
430 URLPattern pattern(URLPattern::SCHEME_ABOUT);
431 EXPECT_EQ(URLPattern::PARSE_SUCCESS, pattern.Parse("about:blank"));
432 EXPECT_EQ("about", pattern.scheme());
433 EXPECT_EQ("", pattern.host());
434 EXPECT_FALSE(pattern.match_subdomains());
435 EXPECT_FALSE(pattern.match_all_urls());
436 EXPECT_EQ("blank", pattern.path());
437 EXPECT_TRUE(pattern.MatchesURL(GURL("about:blank")));
438 EXPECT_FALSE(pattern.MatchesURL(GURL("about:srcdoc")));
439 };
440
425 static const struct GetAsStringPatterns { 441 static const struct GetAsStringPatterns {
426 const char* pattern; 442 const char* pattern;
427 } kGetAsStringTestCases[] = { 443 } kGetAsStringTestCases[] = {
428 { "http://www/" }, 444 { "http://www/" },
429 { "http://*/*" }, 445 { "http://*/*" },
430 { "chrome://*/*" }, 446 { "chrome://*/*" },
431 { "chrome://newtab/" }, 447 { "chrome://newtab/" },
432 { "about:*" }, 448 { "about:*" },
433 { "about:blank" }, 449 { "about:blank" },
434 { "chrome-extension://*/*" }, 450 { "chrome-extension://*/*" },
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 536
521 URLPatternList all_schemes(URLPattern( 537 URLPatternList all_schemes(URLPattern(
522 kAllSchemes, 538 kAllSchemes,
523 "*://google.com/foo").ConvertToExplicitSchemes()); 539 "*://google.com/foo").ConvertToExplicitSchemes());
524 540
525 URLPatternList monkey(URLPattern( 541 URLPatternList monkey(URLPattern(
526 URLPattern::SCHEME_HTTP | URLPattern::SCHEME_HTTPS | 542 URLPattern::SCHEME_HTTP | URLPattern::SCHEME_HTTPS |
527 URLPattern::SCHEME_FTP, 543 URLPattern::SCHEME_FTP,
528 "http://google.com/monkey").ConvertToExplicitSchemes()); 544 "http://google.com/monkey").ConvertToExplicitSchemes());
529 545
530 ASSERT_EQ(7u, all_urls.size()); 546 ASSERT_EQ(8u, all_urls.size());
531 ASSERT_EQ(2u, all_schemes.size()); 547 ASSERT_EQ(2u, all_schemes.size());
532 ASSERT_EQ(1u, monkey.size()); 548 ASSERT_EQ(1u, monkey.size());
533 549
534 EXPECT_EQ("http://*/*", all_urls[0].GetAsString()); 550 EXPECT_EQ("http://*/*", all_urls[0].GetAsString());
535 EXPECT_EQ("https://*/*", all_urls[1].GetAsString()); 551 EXPECT_EQ("https://*/*", all_urls[1].GetAsString());
536 EXPECT_EQ("file:///*", all_urls[2].GetAsString()); 552 EXPECT_EQ("file:///*", all_urls[2].GetAsString());
537 EXPECT_EQ("ftp://*/*", all_urls[3].GetAsString()); 553 EXPECT_EQ("ftp://*/*", all_urls[3].GetAsString());
538 EXPECT_EQ("chrome://*/*", all_urls[4].GetAsString()); 554 EXPECT_EQ("chrome://*/*", all_urls[4].GetAsString());
555 EXPECT_EQ("about:/*", all_urls[7].GetAsString());
539 556
540 EXPECT_EQ("http://google.com/foo", all_schemes[0].GetAsString()); 557 EXPECT_EQ("http://google.com/foo", all_schemes[0].GetAsString());
541 EXPECT_EQ("https://google.com/foo", all_schemes[1].GetAsString()); 558 EXPECT_EQ("https://google.com/foo", all_schemes[1].GetAsString());
542 559
543 EXPECT_EQ("http://google.com/monkey", monkey[0].GetAsString()); 560 EXPECT_EQ("http://google.com/monkey", monkey[0].GetAsString());
544 } 561 }
545 562
546 TEST(ExtensionURLPatternTest, IgnorePorts) { 563 TEST(ExtensionURLPatternTest, IgnorePorts) {
547 std::string pattern_str = "http://www.example.com:8080/foo"; 564 std::string pattern_str = "http://www.example.com:8080/foo";
548 GURL url("http://www.example.com:1234/foo"); 565 GURL url("http://www.example.com:1234/foo");
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
794 EXPECT_TRUE(StrictlyContains(pattern10, pattern12)); 811 EXPECT_TRUE(StrictlyContains(pattern10, pattern12));
795 EXPECT_TRUE(StrictlyContains(pattern10, pattern13)); 812 EXPECT_TRUE(StrictlyContains(pattern10, pattern13));
796 813
797 // More... 814 // More...
798 EXPECT_TRUE(StrictlyContains(pattern12, pattern11)); 815 EXPECT_TRUE(StrictlyContains(pattern12, pattern11));
799 EXPECT_TRUE(NeitherContains(pattern11, pattern13)); 816 EXPECT_TRUE(NeitherContains(pattern11, pattern13));
800 EXPECT_TRUE(StrictlyContains(pattern12, pattern13)); 817 EXPECT_TRUE(StrictlyContains(pattern12, pattern13));
801 } 818 }
802 819
803 } // namespace 820 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698