Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 77 EXPECT_FALSE(pattern.Matches(GURL("https://www.google.com:444"))); | 77 EXPECT_FALSE(pattern.Matches(GURL("https://www.google.com:444"))); |
| 78 EXPECT_FALSE(pattern.Matches(GURL("http://www.google.com:443"))); | 78 EXPECT_FALSE(pattern.Matches(GURL("http://www.google.com:443"))); |
| 79 | 79 |
| 80 pattern = ContentSettingsPattern::FromURL(GURL("https://127.0.0.1")); | 80 pattern = ContentSettingsPattern::FromURL(GURL("https://127.0.0.1")); |
| 81 EXPECT_TRUE(pattern.IsValid()); | 81 EXPECT_TRUE(pattern.IsValid()); |
| 82 EXPECT_STREQ("https://127.0.0.1:443", pattern.ToString().c_str()); | 82 EXPECT_STREQ("https://127.0.0.1:443", pattern.ToString().c_str()); |
| 83 | 83 |
| 84 pattern = ContentSettingsPattern::FromURL(GURL("http://[::1]")); | 84 pattern = ContentSettingsPattern::FromURL(GURL("http://[::1]")); |
| 85 EXPECT_TRUE(pattern.IsValid()); | 85 EXPECT_TRUE(pattern.IsValid()); |
| 86 | 86 |
| 87 GURL url("file:///foo/bar.html"); | |
| 87 pattern = ContentSettingsPattern::FromURL(GURL("file:///foo/bar.html")); | 88 pattern = ContentSettingsPattern::FromURL(GURL("file:///foo/bar.html")); |
| 88 EXPECT_TRUE(pattern.IsValid()); | 89 EXPECT_TRUE(pattern.IsValid()); |
| 89 EXPECT_STREQ("file:///foo/bar.html", pattern.ToString().c_str()); | 90 EXPECT_EQ("file:///foo/bar.html", pattern.ToString()); |
| 91 | |
| 92 pattern = ContentSettingsPattern::FromURL(GURL("file:///")); | |
| 93 EXPECT_TRUE(pattern.IsValid()); | |
|
markusheintz_
2012/01/18 19:45:24
I should have been more precise here. Sorry.
Thes
Francois
2012/01/19 08:43:07
Done. Also added
EXPECT_EQ("file:///*", pattern.
| |
| 90 } | 94 } |
| 91 | 95 |
| 92 TEST(ContentSettingsPatternTest, FromURLNoWildcard) { | 96 TEST(ContentSettingsPatternTest, FromURLNoWildcard) { |
| 93 // If no port is specifed GURLs always use the default port for the schemes | 97 // If no port is specifed GURLs always use the default port for the schemes |
| 94 // HTTP and HTTPS. Hence a GURL always carries a port specification either | 98 // HTTP and HTTPS. Hence a GURL always carries a port specification either |
| 95 // explicitly or implicitly. Therefore if a content settings pattern is | 99 // explicitly or implicitly. Therefore if a content settings pattern is |
| 96 // created from a GURL with no wildcard, specific values are used for the | 100 // created from a GURL with no wildcard, specific values are used for the |
| 97 // scheme, host and port part of the pattern. | 101 // scheme, host and port part of the pattern. |
| 98 // Creating content settings patterns from strings behaves different. Pattern | 102 // Creating content settings patterns from strings behaves different. Pattern |
| 99 // parts that are omitted in pattern specifications (strings), are completed | 103 // parts that are omitted in pattern specifications (strings), are completed |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 165 EXPECT_TRUE(Pattern("https://www.example.com:443").IsValid()); | 169 EXPECT_TRUE(Pattern("https://www.example.com:443").IsValid()); |
| 166 EXPECT_STREQ("https://www.example.com:443", | 170 EXPECT_STREQ("https://www.example.com:443", |
| 167 Pattern("https://www.example.com:443").ToString().c_str()); | 171 Pattern("https://www.example.com:443").ToString().c_str()); |
| 168 // HTTPS patterns with none default port. | 172 // HTTPS patterns with none default port. |
| 169 EXPECT_TRUE(Pattern("https://www.example.com:8080").IsValid()); | 173 EXPECT_TRUE(Pattern("https://www.example.com:8080").IsValid()); |
| 170 EXPECT_STREQ("https://www.example.com:8080", | 174 EXPECT_STREQ("https://www.example.com:8080", |
| 171 Pattern("https://www.example.com:8080").ToString().c_str()); | 175 Pattern("https://www.example.com:8080").ToString().c_str()); |
| 172 } | 176 } |
| 173 | 177 |
| 174 TEST(ContentSettingsPatternTest, FromString_FilePatterns) { | 178 TEST(ContentSettingsPatternTest, FromString_FilePatterns) { |
| 175 EXPECT_FALSE(Pattern("file:///").IsValid()); | |
| 176 | |
| 177 // Non-empty domains aren't allowed in file patterns. | 179 // Non-empty domains aren't allowed in file patterns. |
| 178 EXPECT_FALSE(Pattern("file://foo/").IsValid()); | 180 EXPECT_FALSE(Pattern("file://foo/").IsValid()); |
| 179 | 181 EXPECT_FALSE(Pattern("file://localhost/foo/bar/test.html").IsValid()); |
| 180 // Domain wildcards aren't allowed in file patterns. | 182 EXPECT_FALSE(Pattern("file://*").IsValid()); |
| 181 EXPECT_FALSE(Pattern("file://*/").IsValid()); | 183 EXPECT_FALSE(Pattern("file://*/").IsValid()); |
| 184 EXPECT_FALSE(Pattern("file://*/*").IsValid()); | |
| 185 EXPECT_FALSE(Pattern("file://*/foo/bar/test.html").IsValid()); | |
| 182 EXPECT_FALSE(Pattern("file://[*.]/").IsValid()); | 186 EXPECT_FALSE(Pattern("file://[*.]/").IsValid()); |
| 183 | 187 |
| 184 // These specify a path that contains '*', which isn't allowed to avoid | 188 // This is the only valid file path wildcard format. |
| 185 // user confusion. | 189 EXPECT_TRUE(Pattern("file:///*").IsValid()); |
| 186 EXPECT_FALSE(Pattern("file:///*").IsValid()); | 190 EXPECT_EQ("file:///*", Pattern("file:///*").ToString()); |
| 191 | |
| 192 // Wildcards are not allowed anywhere in the file path. | |
| 193 EXPECT_FALSE(Pattern("file:///f*o/bar/file.html").IsValid()); | |
| 194 EXPECT_FALSE(Pattern("file:///*/bar/file.html").IsValid()); | |
| 195 EXPECT_FALSE(Pattern("file:///foo/*").IsValid()); | |
| 187 EXPECT_FALSE(Pattern("file:///foo/bar/*").IsValid()); | 196 EXPECT_FALSE(Pattern("file:///foo/bar/*").IsValid()); |
| 197 EXPECT_FALSE(Pattern("file:///foo/*/file.html").IsValid()); | |
| 198 EXPECT_FALSE(Pattern("file:///foo/bar/*.html").IsValid()); | |
| 199 EXPECT_FALSE(Pattern("file:///foo/bar/file.*").IsValid()); | |
| 188 | 200 |
| 189 EXPECT_TRUE(Pattern("file:///tmp/test.html").IsValid()); | 201 EXPECT_TRUE(Pattern("file:///tmp/test.html").IsValid()); |
| 190 EXPECT_STREQ("file:///tmp/file.html", | 202 EXPECT_EQ("file:///tmp/file.html", |
| 191 Pattern("file:///tmp/file.html").ToString().c_str()); | 203 Pattern("file:///tmp/file.html").ToString()); |
| 192 EXPECT_TRUE(Pattern("file:///tmp/test.html").Matches( | 204 EXPECT_TRUE(Pattern("file:///tmp/test.html").Matches( |
| 193 GURL("file:///tmp/test.html"))); | 205 GURL("file:///tmp/test.html"))); |
| 194 EXPECT_FALSE(Pattern("file:///tmp/test.html").Matches( | 206 EXPECT_FALSE(Pattern("file:///tmp/test.html").Matches( |
| 195 GURL("file:///tmp/other.html"))); | 207 GURL("file:///tmp/other.html"))); |
| 196 EXPECT_FALSE(Pattern("file:///tmp/test.html").Matches( | 208 EXPECT_FALSE(Pattern("file:///tmp/test.html").Matches( |
| 197 GURL("http://example.org/"))); | 209 GURL("http://example.org/"))); |
| 210 | |
| 211 EXPECT_TRUE(Pattern("file:///*").Matches(GURL("file:///tmp/test.html"))); | |
| 212 EXPECT_TRUE(Pattern("file:///*").Matches( | |
| 213 GURL("file://localhost/tmp/test.html"))); | |
| 198 } | 214 } |
| 199 | 215 |
| 200 TEST(ContentSettingsPatternTest, FromString_ExtensionPatterns) { | 216 TEST(ContentSettingsPatternTest, FromString_ExtensionPatterns) { |
| 201 EXPECT_TRUE(Pattern("chrome-extension://peoadpeiejnhkmpaakpnompolbglelel/") | 217 EXPECT_TRUE(Pattern("chrome-extension://peoadpeiejnhkmpaakpnompolbglelel/") |
| 202 .IsValid()); | 218 .IsValid()); |
| 203 EXPECT_STREQ("chrome-extension://peoadpeiejnhkmpaakpnompolbglelel/", | 219 EXPECT_EQ("chrome-extension://peoadpeiejnhkmpaakpnompolbglelel/", |
| 204 Pattern("chrome-extension://peoadpeiejnhkmpaakpnompolbglelel/") | 220 Pattern("chrome-extension://peoadpeiejnhkmpaakpnompolbglelel/") |
| 205 .ToString().c_str()); | 221 .ToString()); |
| 206 EXPECT_TRUE(Pattern("chrome-extension://peoadpeiejnhkmpaakpnompolbglelel/") | 222 EXPECT_TRUE(Pattern("chrome-extension://peoadpeiejnhkmpaakpnompolbglelel/") |
| 207 .Matches(GURL("chrome-extension://peoadpeiejnhkmpaakpnompolbglelel/"))); | 223 .Matches(GURL("chrome-extension://peoadpeiejnhkmpaakpnompolbglelel/"))); |
| 208 } | 224 } |
| 209 | 225 |
| 210 TEST(ContentSettingsPatternTest, FromString_WithIPAdresses) { | 226 TEST(ContentSettingsPatternTest, FromString_WithIPAdresses) { |
| 211 // IPv4 | 227 // IPv4 |
| 212 EXPECT_TRUE(Pattern("192.168.0.1").IsValid()); | 228 EXPECT_TRUE(Pattern("192.168.0.1").IsValid()); |
| 213 EXPECT_STREQ("192.168.1.1", Pattern("192.168.1.1").ToString().c_str()); | 229 EXPECT_STREQ("192.168.1.1", Pattern("192.168.1.1").ToString().c_str()); |
| 214 EXPECT_TRUE(Pattern("https://192.168.0.1:8080").IsValid()); | 230 EXPECT_TRUE(Pattern("https://192.168.0.1:8080").IsValid()); |
| 215 EXPECT_STREQ("https://192.168.0.1:8080", | 231 EXPECT_STREQ("https://192.168.0.1:8080", |
| (...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 585 // file:/// normalization. | 601 // file:/// normalization. |
| 586 EXPECT_STREQ("file:///tmp/test.html", | 602 EXPECT_STREQ("file:///tmp/test.html", |
| 587 Pattern("file:///tmp/bar/../test.html").ToString().c_str()); | 603 Pattern("file:///tmp/bar/../test.html").ToString().c_str()); |
| 588 | 604 |
| 589 // Invalid patterns. | 605 // Invalid patterns. |
| 590 EXPECT_STREQ("", Pattern("*example.com").ToString().c_str()); | 606 EXPECT_STREQ("", Pattern("*example.com").ToString().c_str()); |
| 591 EXPECT_STREQ("", Pattern("example.*").ToString().c_str()); | 607 EXPECT_STREQ("", Pattern("example.*").ToString().c_str()); |
| 592 EXPECT_STREQ("", Pattern("*\xC4\x87ira.com").ToString().c_str()); | 608 EXPECT_STREQ("", Pattern("*\xC4\x87ira.com").ToString().c_str()); |
| 593 EXPECT_STREQ("", Pattern("\xC4\x87ira.*").ToString().c_str()); | 609 EXPECT_STREQ("", Pattern("\xC4\x87ira.*").ToString().c_str()); |
| 594 } | 610 } |
| OLD | NEW |