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

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

Issue 149619: Various minor extension fixes (Closed)
Patch Set: One more test Created 11 years, 5 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) 2006-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2009 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 "chrome/common/extensions/url_pattern.h" 5 #include "chrome/common/extensions/url_pattern.h"
6 #include "testing/gtest/include/gtest/gtest.h" 6 #include "testing/gtest/include/gtest/gtest.h"
7 7
8 // See url_pattern.h for examples of valid and invalid patterns. 8 // See url_pattern.h for examples of valid and invalid patterns.
9 9
10 TEST(URLPatternTest, ParseInvalid) { 10 TEST(URLPatternTest, ParseInvalid) {
11 const char* kInvalidPatterns[] = { 11 const char* kInvalidPatterns[] = {
12 "http", // no scheme 12 "http", // no scheme
13 "http://", // no path separator 13 "http://", // no path separator
14 "http://foo", // no path separator 14 "http://foo", // no path separator
15 "http://*foo/bar", // not allowed as substring of host component 15 "http://*foo/bar", // not allowed as substring of host component
16 "http://foo.*.bar/baz", // must be first component 16 "http://foo.*.bar/baz", // must be first component
17 "http:/bar", // scheme separator not found 17 "http:/bar", // scheme separator not found
18 "foo://*", // invalid scheme 18 "foo://*", // invalid scheme
19 "chrome://*/*", // we don't support internal chrome URLs
19 }; 20 };
20 21
21 for (size_t i = 0; i < arraysize(kInvalidPatterns); ++i) { 22 for (size_t i = 0; i < arraysize(kInvalidPatterns); ++i) {
22 URLPattern pattern; 23 URLPattern pattern;
23 EXPECT_FALSE(pattern.Parse(kInvalidPatterns[i])); 24 EXPECT_FALSE(pattern.Parse(kInvalidPatterns[i]));
24 } 25 }
25 }; 26 };
26 27
27 // all pages for a given scheme 28 // all pages for a given scheme
28 TEST(URLPatternTest, Match1) { 29 TEST(URLPatternTest, Match1) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 EXPECT_EQ("google.com", pattern.host()); 61 EXPECT_EQ("google.com", pattern.host());
61 EXPECT_TRUE(pattern.match_subdomains()); 62 EXPECT_TRUE(pattern.match_subdomains());
62 EXPECT_EQ("/foo*bar", pattern.path()); 63 EXPECT_EQ("/foo*bar", pattern.path());
63 EXPECT_TRUE(pattern.MatchesUrl(GURL("http://google.com/foobar"))); 64 EXPECT_TRUE(pattern.MatchesUrl(GURL("http://google.com/foobar")));
64 EXPECT_TRUE(pattern.MatchesUrl(GURL("http://www.google.com/foo?bar"))); 65 EXPECT_TRUE(pattern.MatchesUrl(GURL("http://www.google.com/foo?bar")));
65 EXPECT_TRUE(pattern.MatchesUrl( 66 EXPECT_TRUE(pattern.MatchesUrl(
66 GURL("http://monkey.images.google.com/foooobar"))); 67 GURL("http://monkey.images.google.com/foooobar")));
67 EXPECT_FALSE(pattern.MatchesUrl(GURL("http://yahoo.com/foobar"))); 68 EXPECT_FALSE(pattern.MatchesUrl(GURL("http://yahoo.com/foobar")));
68 } 69 }
69 70
70 // odd schemes and normalization
71 TEST(URLPatternTest, Match4) {
72 URLPattern pattern;
73 EXPECT_TRUE(pattern.Parse("chrome://thinger/*"));
74 EXPECT_EQ("chrome", pattern.scheme());
75 EXPECT_EQ("thinger", pattern.host());
76 EXPECT_FALSE(pattern.match_subdomains());
77 EXPECT_EQ("/*", pattern.path());
78 EXPECT_TRUE(pattern.MatchesUrl(GURL("chrome://thinger/foobar")));
79 EXPECT_TRUE(pattern.MatchesUrl(GURL("CHROME://thinger/")));
80 EXPECT_FALSE(pattern.MatchesUrl(GURL("http://thinger/")));
81 }
82
83 // glob escaping 71 // glob escaping
84 TEST(URLPatternTest, Match5) { 72 TEST(URLPatternTest, Match5) {
85 URLPattern pattern; 73 URLPattern pattern;
86 EXPECT_TRUE(pattern.Parse("file:///foo?bar\\*baz")); 74 EXPECT_TRUE(pattern.Parse("file:///foo?bar\\*baz"));
87 EXPECT_EQ("file", pattern.scheme()); 75 EXPECT_EQ("file", pattern.scheme());
88 EXPECT_EQ("", pattern.host()); 76 EXPECT_EQ("", pattern.host());
89 EXPECT_FALSE(pattern.match_subdomains()); 77 EXPECT_FALSE(pattern.match_subdomains());
90 EXPECT_EQ("/foo?bar\\*baz", pattern.path()); 78 EXPECT_EQ("/foo?bar\\*baz", pattern.path());
91 EXPECT_TRUE(pattern.MatchesUrl(GURL("file:///foo?bar\\hellobaz"))); 79 EXPECT_TRUE(pattern.MatchesUrl(GURL("file:///foo?bar\\hellobaz")));
92 EXPECT_FALSE(pattern.MatchesUrl(GURL("file:///fooXbar\\hellobaz"))); 80 EXPECT_FALSE(pattern.MatchesUrl(GURL("file:///fooXbar\\hellobaz")));
(...skipping 30 matching lines...) Expand all
123 EXPECT_TRUE(pattern.Parse("http://*.xn--gkd/a%C2%81%E1*")); 111 EXPECT_TRUE(pattern.Parse("http://*.xn--gkd/a%C2%81%E1*"));
124 EXPECT_EQ("http", pattern.scheme()); 112 EXPECT_EQ("http", pattern.scheme());
125 EXPECT_EQ("xn--gkd", pattern.host()); 113 EXPECT_EQ("xn--gkd", pattern.host());
126 EXPECT_TRUE(pattern.match_subdomains()); 114 EXPECT_TRUE(pattern.match_subdomains());
127 EXPECT_EQ("/a%C2%81%E1*", pattern.path()); 115 EXPECT_EQ("/a%C2%81%E1*", pattern.path());
128 EXPECT_TRUE(pattern.MatchesUrl( 116 EXPECT_TRUE(pattern.MatchesUrl(
129 GURL("http://abc.\xe1\x80\xbf/a\xc2\x81\xe1xyz"))); 117 GURL("http://abc.\xe1\x80\xbf/a\xc2\x81\xe1xyz")));
130 EXPECT_TRUE(pattern.MatchesUrl( 118 EXPECT_TRUE(pattern.MatchesUrl(
131 GURL("http://\xe1\x80\xbf/a\xc2\x81\xe1\xe1"))); 119 GURL("http://\xe1\x80\xbf/a\xc2\x81\xe1\xe1")));
132 }; 120 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698