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 "chrome/common/content_settings_pattern.h" | 5 #include "chrome/common/content_settings_pattern.h" |
6 | 6 |
7 #include "googleurl/src/gurl.h" | 7 #include "googleurl/src/gurl.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 | 9 |
10 namespace { | 10 namespace { |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 EXPECT_FALSE(pattern.Matches(GURL("http://foo.www.example.com"))); | 151 EXPECT_FALSE(pattern.Matches(GURL("http://foo.www.example.com"))); |
152 | 152 |
153 pattern = ContentSettingsPattern::FromURLNoWildcard( | 153 pattern = ContentSettingsPattern::FromURLNoWildcard( |
154 GURL("https://www.example.com")); | 154 GURL("https://www.example.com")); |
155 EXPECT_TRUE(pattern.IsValid()); | 155 EXPECT_TRUE(pattern.IsValid()); |
156 EXPECT_STREQ("https://www.example.com:443", pattern.ToString().c_str()); | 156 EXPECT_STREQ("https://www.example.com:443", pattern.ToString().c_str()); |
157 EXPECT_FALSE(pattern.Matches(GURL("http://www.example.com"))); | 157 EXPECT_FALSE(pattern.Matches(GURL("http://www.example.com"))); |
158 EXPECT_TRUE(pattern.Matches(GURL("https://www.example.com"))); | 158 EXPECT_TRUE(pattern.Matches(GURL("https://www.example.com"))); |
159 EXPECT_FALSE(pattern.Matches(GURL("http://foo.www.example.com"))); | 159 EXPECT_FALSE(pattern.Matches(GURL("http://foo.www.example.com"))); |
160 | 160 |
161 // Pattern for filesystem URLs | 161 // Pattern for filesystem URLs |
162 pattern = | 162 pattern = |
163 ContentSettingsPattern::FromURLNoWildcard( | 163 ContentSettingsPattern::FromURLNoWildcard( |
164 GURL("filesystem:http://www.google.com/temporary/")); | 164 GURL("filesystem:http://www.google.com/temporary/")); |
165 EXPECT_TRUE(pattern.IsValid()); | 165 EXPECT_TRUE(pattern.IsValid()); |
166 EXPECT_TRUE(pattern.Matches(GURL("http://www.google.com"))); | 166 EXPECT_TRUE(pattern.Matches(GURL("http://www.google.com"))); |
167 EXPECT_FALSE(pattern.Matches(GURL("http://foo.www.google.com"))); | 167 EXPECT_FALSE(pattern.Matches(GURL("http://foo.www.google.com"))); |
168 EXPECT_TRUE(pattern.Matches( | 168 EXPECT_TRUE(pattern.Matches( |
169 GURL("filesystem:http://www.google.com/persistent/"))); | 169 GURL("filesystem:http://www.google.com/persistent/"))); |
170 EXPECT_FALSE(pattern.Matches( | 170 EXPECT_FALSE(pattern.Matches( |
171 GURL("filesystem:https://www.google.com/persistent/"))); | 171 GURL("filesystem:https://www.google.com/persistent/"))); |
(...skipping 27 matching lines...) Expand all Loading... |
199 EXPECT_TRUE(Pattern("www.example.com").Matches( | 199 EXPECT_TRUE(Pattern("www.example.com").Matches( |
200 GURL("http://www.example.com"))); | 200 GURL("http://www.example.com"))); |
201 EXPECT_TRUE(Pattern("www.example.com").Matches( | 201 EXPECT_TRUE(Pattern("www.example.com").Matches( |
202 GURL("http://www.example.com."))); | 202 GURL("http://www.example.com."))); |
203 | 203 |
204 EXPECT_TRUE(Pattern("www.example.com.").IsValid()); | 204 EXPECT_TRUE(Pattern("www.example.com.").IsValid()); |
205 EXPECT_STREQ("www.example.com", | 205 EXPECT_STREQ("www.example.com", |
206 Pattern("www.example.com.").ToString().c_str()); | 206 Pattern("www.example.com.").ToString().c_str()); |
207 | 207 |
208 EXPECT_TRUE(Pattern("www.example.com.") == Pattern("www.example.com")); | 208 EXPECT_TRUE(Pattern("www.example.com.") == Pattern("www.example.com")); |
| 209 |
| 210 EXPECT_TRUE(Pattern(".").IsValid()); |
| 211 EXPECT_STREQ(".", Pattern(".").ToString().c_str()); |
209 } | 212 } |
210 | 213 |
211 TEST(ContentSettingsPatternTest, FromString_WithNoWildcards) { | 214 TEST(ContentSettingsPatternTest, FromString_WithNoWildcards) { |
212 // HTTP patterns with default port. | 215 // HTTP patterns with default port. |
213 EXPECT_TRUE(Pattern("http://www.example.com:80").IsValid()); | 216 EXPECT_TRUE(Pattern("http://www.example.com:80").IsValid()); |
214 EXPECT_STREQ("http://www.example.com:80", | 217 EXPECT_STREQ("http://www.example.com:80", |
215 Pattern("http://www.example.com:80").ToString().c_str()); | 218 Pattern("http://www.example.com:80").ToString().c_str()); |
216 // HTTP patterns with none default port. | 219 // HTTP patterns with none default port. |
217 EXPECT_TRUE(Pattern("http://www.example.com:81").IsValid()); | 220 EXPECT_TRUE(Pattern("http://www.example.com:81").IsValid()); |
218 EXPECT_STREQ("http://www.example.com:81", | 221 EXPECT_STREQ("http://www.example.com:81", |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 | 439 |
437 // Pattern strings with invalid port parts. | 440 // Pattern strings with invalid port parts. |
438 EXPECT_FALSE(Pattern("example.com:abc").IsValid()); | 441 EXPECT_FALSE(Pattern("example.com:abc").IsValid()); |
439 EXPECT_STREQ("", Pattern("example.com:abc").ToString().c_str()); | 442 EXPECT_STREQ("", Pattern("example.com:abc").ToString().c_str()); |
440 | 443 |
441 // Invalid file pattern strings. | 444 // Invalid file pattern strings. |
442 EXPECT_FALSE(Pattern("file://").IsValid()); | 445 EXPECT_FALSE(Pattern("file://").IsValid()); |
443 EXPECT_STREQ("", Pattern("file://").ToString().c_str()); | 446 EXPECT_STREQ("", Pattern("file://").ToString().c_str()); |
444 EXPECT_FALSE(Pattern("file:///foo/bar.html:8080").IsValid()); | 447 EXPECT_FALSE(Pattern("file:///foo/bar.html:8080").IsValid()); |
445 EXPECT_STREQ("", Pattern("file:///foo/bar.html:8080").ToString().c_str()); | 448 EXPECT_STREQ("", Pattern("file:///foo/bar.html:8080").ToString().c_str()); |
| 449 |
| 450 // Host having multiple ending dots. |
| 451 EXPECT_FALSE(Pattern("www.example.com..").IsValid()); |
| 452 EXPECT_STREQ("", Pattern("www.example.com..").ToString().c_str()); |
446 } | 453 } |
447 | 454 |
448 TEST(ContentSettingsPatternTest, UnequalOperator) { | 455 TEST(ContentSettingsPatternTest, UnequalOperator) { |
449 EXPECT_TRUE(Pattern("http://www.foo.com") != Pattern("http://www.foo.com*")); | 456 EXPECT_TRUE(Pattern("http://www.foo.com") != Pattern("http://www.foo.com*")); |
450 EXPECT_TRUE(Pattern("http://www.foo.com*") != | 457 EXPECT_TRUE(Pattern("http://www.foo.com*") != |
451 ContentSettingsPattern::Wildcard()); | 458 ContentSettingsPattern::Wildcard()); |
452 | 459 |
453 EXPECT_TRUE(Pattern("http://www.foo.com") != | 460 EXPECT_TRUE(Pattern("http://www.foo.com") != |
454 ContentSettingsPattern::Wildcard()); | 461 ContentSettingsPattern::Wildcard()); |
455 | 462 |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
657 // file:/// normalization. | 664 // file:/// normalization. |
658 EXPECT_STREQ("file:///tmp/test.html", | 665 EXPECT_STREQ("file:///tmp/test.html", |
659 Pattern("file:///tmp/bar/../test.html").ToString().c_str()); | 666 Pattern("file:///tmp/bar/../test.html").ToString().c_str()); |
660 | 667 |
661 // Invalid patterns. | 668 // Invalid patterns. |
662 EXPECT_STREQ("", Pattern("*example.com").ToString().c_str()); | 669 EXPECT_STREQ("", Pattern("*example.com").ToString().c_str()); |
663 EXPECT_STREQ("", Pattern("example.*").ToString().c_str()); | 670 EXPECT_STREQ("", Pattern("example.*").ToString().c_str()); |
664 EXPECT_STREQ("", Pattern("*\xC4\x87ira.com").ToString().c_str()); | 671 EXPECT_STREQ("", Pattern("*\xC4\x87ira.com").ToString().c_str()); |
665 EXPECT_STREQ("", Pattern("\xC4\x87ira.*").ToString().c_str()); | 672 EXPECT_STREQ("", Pattern("\xC4\x87ira.*").ToString().c_str()); |
666 } | 673 } |
OLD | NEW |