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

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

Issue 2455373002: Add implicit trailing dot domain matching support to URLPattern. (Closed)
Patch Set: Add a comment with additional links to an external spec, cleanup test. Created 4 years, 1 month 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
« no previous file with comments | « extensions/common/url_pattern_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/pickle.h" 10 #include "base/pickle.h"
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 97
98 URLPattern exclude(kAllSchemes); 98 URLPattern exclude(kAllSchemes);
99 ASSERT_EQ(URLPattern::PARSE_SUCCESS, exclude.Parse("*://*/*business*")); 99 ASSERT_EQ(URLPattern::PARSE_SUCCESS, exclude.Parse("*://*/*business*"));
100 script.add_exclude_url_pattern(exclude); 100 script.add_exclude_url_pattern(exclude);
101 101
102 EXPECT_TRUE(script.MatchesURL(GURL("http://www.nytimes.com/health"))); 102 EXPECT_TRUE(script.MatchesURL(GURL("http://www.nytimes.com/health")));
103 EXPECT_FALSE(script.MatchesURL(GURL("http://www.nytimes.com/business"))); 103 EXPECT_FALSE(script.MatchesURL(GURL("http://www.nytimes.com/business")));
104 EXPECT_TRUE(script.MatchesURL(GURL("http://business.nytimes.com"))); 104 EXPECT_TRUE(script.MatchesURL(GURL("http://business.nytimes.com")));
105 } 105 }
106 106
107 TEST(ExtensionUserScriptTest, ExcludeUrlPatternWithTrailingDot) {
108 UserScript script;
109
110 URLPattern pattern(kAllSchemes);
111 ASSERT_EQ(URLPattern::PARSE_SUCCESS, pattern.Parse("*://*/*"));
112 script.add_url_pattern(pattern);
113
114 URLPattern exclude(kAllSchemes);
115 ASSERT_EQ(URLPattern::PARSE_SUCCESS, exclude.Parse("*://mail.nytimes.com/*"));
116 script.add_exclude_url_pattern(exclude);
117
118 EXPECT_TRUE(script.MatchesURL(GURL("http://www.nytimes.com/health")));
119 EXPECT_TRUE(script.MatchesURL(GURL("http://business.nytimes.com")));
120 EXPECT_FALSE(script.MatchesURL(GURL("http://mail.nytimes.com")));
121 EXPECT_FALSE(script.MatchesURL(GURL("http://mail.nytimes.com.")));
122 EXPECT_FALSE(script.MatchesURL(GURL("http://mail.nytimes.com/login")));
123 EXPECT_FALSE(script.MatchesURL(GURL("http://mail.nytimes.com./login")));
124 }
125
107 TEST(ExtensionUserScriptTest, UrlPatternAndIncludeGlobs) { 126 TEST(ExtensionUserScriptTest, UrlPatternAndIncludeGlobs) {
108 UserScript script; 127 UserScript script;
109 128
110 URLPattern pattern(kAllSchemes); 129 URLPattern pattern(kAllSchemes);
111 ASSERT_EQ(URLPattern::PARSE_SUCCESS, pattern.Parse("http://*.nytimes.com/*")); 130 ASSERT_EQ(URLPattern::PARSE_SUCCESS, pattern.Parse("http://*.nytimes.com/*"));
112 script.add_url_pattern(pattern); 131 script.add_url_pattern(pattern);
113 132
114 script.add_glob("*nytimes.com/???s/*"); 133 script.add_glob("*nytimes.com/???s/*");
115 134
116 EXPECT_TRUE(script.MatchesURL(GURL("http://www.nytimes.com/arts/1.html"))); 135 EXPECT_TRUE(script.MatchesURL(GURL("http://www.nytimes.com/arts/1.html")));
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 EXPECT_EQ(kExtensionId, script2.extension_id()); 244 EXPECT_EQ(kExtensionId, script2.extension_id());
226 EXPECT_EQ(kId, script2.id()); 245 EXPECT_EQ(kId, script2.id());
227 } 246 }
228 247
229 TEST(ExtensionUserScriptTest, Defaults) { 248 TEST(ExtensionUserScriptTest, Defaults) {
230 UserScript script; 249 UserScript script;
231 ASSERT_EQ(UserScript::DOCUMENT_IDLE, script.run_location()); 250 ASSERT_EQ(UserScript::DOCUMENT_IDLE, script.run_location());
232 } 251 }
233 252
234 } // namespace extensions 253 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/common/url_pattern_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698