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

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

Issue 8800006: Support chrome-extension:// scheme in URLPattern. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed jam's comments Created 9 years 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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.
11 11
12 static const int kAllSchemes = 12 static const int kAllSchemes =
13 URLPattern::SCHEME_HTTP | 13 URLPattern::SCHEME_HTTP |
14 URLPattern::SCHEME_HTTPS | 14 URLPattern::SCHEME_HTTPS |
15 URLPattern::SCHEME_FILE | 15 URLPattern::SCHEME_FILE |
16 URLPattern::SCHEME_FTP | 16 URLPattern::SCHEME_FTP |
17 URLPattern::SCHEME_CHROMEUI; 17 URLPattern::SCHEME_CHROMEUI |
18 URLPattern::SCHEME_EXTENSION |
19 URLPattern::SCHEME_FILESYSTEM;
18 20
19 TEST(ExtensionURLPatternTest, ParseInvalid) { 21 TEST(ExtensionURLPatternTest, ParseInvalid) {
20 const struct { 22 const struct {
21 const char* pattern; 23 const char* pattern;
22 URLPattern::ParseResult expected_result; 24 URLPattern::ParseResult expected_result;
23 } kInvalidPatterns[] = { 25 } kInvalidPatterns[] = {
24 { "http", URLPattern::PARSE_ERROR_MISSING_SCHEME_SEPARATOR }, 26 { "http", URLPattern::PARSE_ERROR_MISSING_SCHEME_SEPARATOR },
25 { "http:", URLPattern::PARSE_ERROR_WRONG_SCHEME_SEPARATOR }, 27 { "http:", URLPattern::PARSE_ERROR_WRONG_SCHEME_SEPARATOR },
26 { "http:/", URLPattern::PARSE_ERROR_WRONG_SCHEME_SEPARATOR }, 28 { "http:/", URLPattern::PARSE_ERROR_WRONG_SCHEME_SEPARATOR },
27 { "about://", URLPattern::PARSE_ERROR_WRONG_SCHEME_SEPARATOR }, 29 { "about://", URLPattern::PARSE_ERROR_WRONG_SCHEME_SEPARATOR },
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 283
282 // <all_urls> 284 // <all_urls>
283 TEST(ExtensionURLPatternTest, Match11) { 285 TEST(ExtensionURLPatternTest, Match11) {
284 URLPattern pattern(kAllSchemes); 286 URLPattern pattern(kAllSchemes);
285 EXPECT_EQ(URLPattern::PARSE_SUCCESS, 287 EXPECT_EQ(URLPattern::PARSE_SUCCESS,
286 pattern.Parse("<all_urls>", URLPattern::ERROR_ON_PORTS)); 288 pattern.Parse("<all_urls>", URLPattern::ERROR_ON_PORTS));
287 EXPECT_TRUE(pattern.MatchesScheme("chrome")); 289 EXPECT_TRUE(pattern.MatchesScheme("chrome"));
288 EXPECT_TRUE(pattern.MatchesScheme("http")); 290 EXPECT_TRUE(pattern.MatchesScheme("http"));
289 EXPECT_TRUE(pattern.MatchesScheme("https")); 291 EXPECT_TRUE(pattern.MatchesScheme("https"));
290 EXPECT_TRUE(pattern.MatchesScheme("file")); 292 EXPECT_TRUE(pattern.MatchesScheme("file"));
293 EXPECT_TRUE(pattern.MatchesScheme("chrome-extension"));
291 EXPECT_TRUE(pattern.match_subdomains()); 294 EXPECT_TRUE(pattern.match_subdomains());
292 EXPECT_TRUE(pattern.match_all_urls()); 295 EXPECT_TRUE(pattern.match_all_urls());
293 EXPECT_EQ("/*", pattern.path()); 296 EXPECT_EQ("/*", pattern.path());
294 EXPECT_TRUE(pattern.MatchesURL(GURL("chrome://favicon/http://google.com"))); 297 EXPECT_TRUE(pattern.MatchesURL(GURL("chrome://favicon/http://google.com")));
295 EXPECT_TRUE(pattern.MatchesURL(GURL("http://127.0.0.1"))); 298 EXPECT_TRUE(pattern.MatchesURL(GURL("http://127.0.0.1")));
296 EXPECT_TRUE(pattern.MatchesURL(GURL("file:///foo/bar"))); 299 EXPECT_TRUE(pattern.MatchesURL(GURL("file:///foo/bar")));
297 EXPECT_TRUE(pattern.MatchesURL(GURL("file://localhost/foo/bar"))); 300 EXPECT_TRUE(pattern.MatchesURL(GURL("file://localhost/foo/bar")));
298 301
299 // Make sure the properties are the same when creating an <all_urls> pattern 302 // Make sure the properties are the same when creating an <all_urls> pattern
300 // via SetMatchAllURLs and by parsing <all_urls>. 303 // via SetMatchAllURLs and by parsing <all_urls>.
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 EXPECT_EQ("www.example.com", pattern.host()); 451 EXPECT_EQ("www.example.com", pattern.host());
449 EXPECT_FALSE(pattern.match_subdomains()); 452 EXPECT_FALSE(pattern.match_subdomains());
450 EXPECT_FALSE(pattern.match_all_urls()); 453 EXPECT_FALSE(pattern.match_all_urls());
451 EXPECT_EQ("/foo", pattern.path()); 454 EXPECT_EQ("/foo", pattern.path());
452 EXPECT_EQ("*", pattern.port()); 455 EXPECT_EQ("*", pattern.port());
453 EXPECT_TRUE(pattern.MatchesURL(GURL("http://www.example.com:80/foo"))); 456 EXPECT_TRUE(pattern.MatchesURL(GURL("http://www.example.com:80/foo")));
454 EXPECT_TRUE(pattern.MatchesURL(GURL("http://www.example.com/foo"))); 457 EXPECT_TRUE(pattern.MatchesURL(GURL("http://www.example.com/foo")));
455 EXPECT_TRUE(pattern.MatchesURL(GURL("http://www.example.com:8080/foo"))); 458 EXPECT_TRUE(pattern.MatchesURL(GURL("http://www.example.com:8080/foo")));
456 } 459 }
457 460
461 // chrome-extension://
462 TEST(ExtensionURLPatternTest, Match19) {
463 URLPattern pattern(URLPattern::SCHEME_EXTENSION);
464 EXPECT_EQ(URLPattern::PARSE_SUCCESS,
465 pattern.Parse("chrome-extension://ftw/*",
466 URLPattern::ERROR_ON_PORTS));
467 EXPECT_EQ("chrome-extension", pattern.scheme());
468 EXPECT_EQ("ftw", pattern.host());
469 EXPECT_FALSE(pattern.match_subdomains());
470 EXPECT_FALSE(pattern.match_all_urls());
471 EXPECT_EQ("/*", pattern.path());
472 EXPECT_TRUE(pattern.MatchesURL(GURL("chrome-extension://ftw")));
473 EXPECT_TRUE(pattern.MatchesURL(
474 GURL("chrome-extension://ftw/http://google.com")));
475 EXPECT_TRUE(pattern.MatchesURL(
476 GURL("chrome-extension://ftw/https://google.com")));
477 EXPECT_FALSE(pattern.MatchesURL(GURL("chrome-extension://foobar")));
478 };
479
458 static const struct GetAsStringPatterns { 480 static const struct GetAsStringPatterns {
459 const char* pattern; 481 const char* pattern;
460 } kGetAsStringTestCases[] = { 482 } kGetAsStringTestCases[] = {
461 { "http://www/" }, 483 { "http://www/" },
462 { "http://*/*" }, 484 { "http://*/*" },
463 { "chrome://*/*" }, 485 { "chrome://*/*" },
464 { "chrome://newtab/" }, 486 { "chrome://newtab/" },
465 { "about:*" }, 487 { "about:*" },
466 { "about:blank" }, 488 { "about:blank" },
467 { "chrome-extension://*/*" }, 489 { "chrome-extension://*/*" },
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 576
555 URLPatternList all_schemes(URLPattern( 577 URLPatternList all_schemes(URLPattern(
556 kAllSchemes, 578 kAllSchemes,
557 "*://google.com/foo").ConvertToExplicitSchemes()); 579 "*://google.com/foo").ConvertToExplicitSchemes());
558 580
559 URLPatternList monkey(URLPattern( 581 URLPatternList monkey(URLPattern(
560 URLPattern::SCHEME_HTTP | URLPattern::SCHEME_HTTPS | 582 URLPattern::SCHEME_HTTP | URLPattern::SCHEME_HTTPS |
561 URLPattern::SCHEME_FTP, 583 URLPattern::SCHEME_FTP,
562 "http://google.com/monkey").ConvertToExplicitSchemes()); 584 "http://google.com/monkey").ConvertToExplicitSchemes());
563 585
564 ASSERT_EQ(5u, all_urls.size()); 586 ASSERT_EQ(7u, all_urls.size());
565 ASSERT_EQ(2u, all_schemes.size()); 587 ASSERT_EQ(2u, all_schemes.size());
566 ASSERT_EQ(1u, monkey.size()); 588 ASSERT_EQ(1u, monkey.size());
567 589
568 EXPECT_EQ("http://*/*", all_urls[0].GetAsString()); 590 EXPECT_EQ("http://*/*", all_urls[0].GetAsString());
569 EXPECT_EQ("https://*/*", all_urls[1].GetAsString()); 591 EXPECT_EQ("https://*/*", all_urls[1].GetAsString());
570 EXPECT_EQ("file:///*", all_urls[2].GetAsString()); 592 EXPECT_EQ("file:///*", all_urls[2].GetAsString());
571 EXPECT_EQ("ftp://*/*", all_urls[3].GetAsString()); 593 EXPECT_EQ("ftp://*/*", all_urls[3].GetAsString());
572 EXPECT_EQ("chrome://*/*", all_urls[4].GetAsString()); 594 EXPECT_EQ("chrome://*/*", all_urls[4].GetAsString());
573 595
574 EXPECT_EQ("http://google.com/foo", all_schemes[0].GetAsString()); 596 EXPECT_EQ("http://google.com/foo", all_schemes[0].GetAsString());
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
680 702
681 URLPattern pattern1(URLPattern::SCHEME_ALL); 703 URLPattern pattern1(URLPattern::SCHEME_ALL);
682 URLPattern pattern2(URLPattern::SCHEME_ALL); 704 URLPattern pattern2(URLPattern::SCHEME_ALL);
683 705
684 pattern1.Parse(kEqualsTestCases[i].pattern1, URLPattern::USE_PORTS); 706 pattern1.Parse(kEqualsTestCases[i].pattern1, URLPattern::USE_PORTS);
685 pattern2.Parse(kEqualsTestCases[i].pattern2, URLPattern::USE_PORTS); 707 pattern2.Parse(kEqualsTestCases[i].pattern2, URLPattern::USE_PORTS);
686 EXPECT_EQ(kEqualsTestCases[i].expected_equal, pattern1 == pattern2) 708 EXPECT_EQ(kEqualsTestCases[i].expected_equal, pattern1 == pattern2)
687 << message; 709 << message;
688 } 710 }
689 } 711 }
OLDNEW
« chrome/common/extensions/url_pattern.cc ('K') | « chrome/common/extensions/url_pattern.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698