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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 EXPECT_FALSE(pattern.Matches(GURL("https://mail.google.com"))); | 66 EXPECT_FALSE(pattern.Matches(GURL("https://mail.google.com"))); |
67 EXPECT_TRUE(pattern.Matches(GURL("https://www.google.com"))); | 67 EXPECT_TRUE(pattern.Matches(GURL("https://www.google.com"))); |
68 | 68 |
69 pattern = ContentSettingsPattern::FromURL(GURL("http://www.google.com:80")); | 69 pattern = ContentSettingsPattern::FromURL(GURL("http://www.google.com:80")); |
70 EXPECT_TRUE(pattern.Matches(GURL("http://www.google.com"))); | 70 EXPECT_TRUE(pattern.Matches(GURL("http://www.google.com"))); |
71 EXPECT_TRUE(pattern.Matches(GURL("http://www.google.com:80"))); | 71 EXPECT_TRUE(pattern.Matches(GURL("http://www.google.com:80"))); |
72 EXPECT_TRUE(pattern.Matches(GURL("http://www.google.com:81"))); | 72 EXPECT_TRUE(pattern.Matches(GURL("http://www.google.com:81"))); |
73 | 73 |
74 pattern = ContentSettingsPattern::FromURL(GURL("https://www.google.com:443")); | 74 pattern = ContentSettingsPattern::FromURL(GURL("https://www.google.com:443")); |
75 EXPECT_TRUE(pattern.Matches(GURL("https://www.google.com"))); | 75 EXPECT_TRUE(pattern.Matches(GURL("https://www.google.com"))); |
| 76 EXPECT_TRUE(pattern.Matches(GURL("https://foo.www.google.com"))); |
76 EXPECT_TRUE(pattern.Matches(GURL("https://www.google.com:443"))); | 77 EXPECT_TRUE(pattern.Matches(GURL("https://www.google.com:443"))); |
77 EXPECT_FALSE(pattern.Matches(GURL("https://www.google.com:444"))); | 78 EXPECT_FALSE(pattern.Matches(GURL("https://www.google.com:444"))); |
78 EXPECT_FALSE(pattern.Matches(GURL("http://www.google.com:443"))); | 79 EXPECT_FALSE(pattern.Matches(GURL("http://www.google.com:443"))); |
79 | 80 |
80 pattern = ContentSettingsPattern::FromURL(GURL("https://127.0.0.1")); | 81 pattern = ContentSettingsPattern::FromURL(GURL("https://127.0.0.1")); |
81 EXPECT_TRUE(pattern.IsValid()); | 82 EXPECT_TRUE(pattern.IsValid()); |
82 EXPECT_STREQ("https://127.0.0.1:443", pattern.ToString().c_str()); | 83 EXPECT_STREQ("https://127.0.0.1:443", pattern.ToString().c_str()); |
83 | 84 |
84 pattern = ContentSettingsPattern::FromURL(GURL("http://[::1]")); | 85 pattern = ContentSettingsPattern::FromURL(GURL("http://[::1]")); |
85 EXPECT_TRUE(pattern.IsValid()); | 86 EXPECT_TRUE(pattern.IsValid()); |
86 | 87 |
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_STREQ("file:///foo/bar.html", pattern.ToString().c_str()); |
90 } | 91 } |
91 | 92 |
| 93 TEST(ContentSettingsPatternTest, FilesystemUrls) { |
| 94 ContentSettingsPattern pattern = |
| 95 ContentSettingsPattern::FromURL(GURL("http://www.google.com")); |
| 96 EXPECT_TRUE(pattern.Matches(GURL("filesystem:http://www.google.com/temporary/"
))); |
| 97 EXPECT_TRUE(pattern.Matches(GURL("filesystem:http://foo.www.google.com/tempora
ry/"))); |
| 98 EXPECT_TRUE(pattern.Matches(GURL("filesystem:http://www.google.com:80/temporar
y/"))); |
| 99 EXPECT_TRUE(pattern.Matches(GURL("filesystem:http://www.google.com:81/temporar
y/"))); |
| 100 |
| 101 pattern = ContentSettingsPattern::FromURL(GURL("https://www.google.com")); |
| 102 EXPECT_TRUE(pattern.Matches(GURL("filesystem:https://www.google.com/temporary/
"))); |
| 103 EXPECT_TRUE(pattern.Matches(GURL("filesystem:https://www.google.com:443/tempor
ary/"))); |
| 104 EXPECT_TRUE(pattern.Matches(GURL("filesystem:https://foo.www.google.com/tempor
ary/"))); |
| 105 EXPECT_FALSE(pattern.Matches(GURL("filesystem:https://www.google.com:81/tempor
ary/"))); |
| 106 |
| 107 // A pattern from a filesystem URLs is equivalent to patterns from the inner |
| 108 // URL of the filesystem URL. |
| 109 ContentSettingsPattern pattern2 = ContentSettingsPattern::FromURL( |
| 110 GURL("filesystem:https://www.google.com/temporary/")); |
| 111 EXPECT_EQ(ContentSettingsPattern::IDENTITY, pattern.Compare(pattern2)); |
| 112 |
| 113 EXPECT_STREQ("https://[*.]www.google.com:443", pattern2.ToString().c_str()); |
| 114 |
| 115 // TODO(markusheintz): This is how it is supposed to work. |
| 116 pattern = |
| 117 ContentSettingsPattern::FromURL( |
| 118 GURL("filesystem:file:///temporary/foo/bar")); |
| 119 EXPECT_TRUE(pattern.Matches(GURL("filesystem:file:///temporary/"))); |
| 120 EXPECT_TRUE(pattern.Matches(GURL("file:///temporary"))); |
| 121 //EXPECT_TRUE(pattern.Matches(GURL("filesystem:file:///temporary/test.txt"))); |
| 122 //EXPECT_TRUE(pattern.Matches(GURL("file://foo/bar"))); |
| 123 //pattern2 = |
| 124 // ContentSettingsPattern::FromURL( |
| 125 // GURL("filesystem:file:///persistent/foo2/bar2")); |
| 126 //EXPECT_EQ(ContentSettingsPattern::IDENTITY, pattern.Compare(pattern2)); |
| 127 } |
| 128 |
92 TEST(ContentSettingsPatternTest, FromURLNoWildcard) { | 129 TEST(ContentSettingsPatternTest, FromURLNoWildcard) { |
93 // If no port is specifed GURLs always use the default port for the schemes | 130 // 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 | 131 // HTTP and HTTPS. Hence a GURL always carries a port specification either |
95 // explicitly or implicitly. Therefore if a content settings pattern is | 132 // explicitly or implicitly. Therefore if a content settings pattern is |
96 // created from a GURL with no wildcard, specific values are used for the | 133 // created from a GURL with no wildcard, specific values are used for the |
97 // scheme, host and port part of the pattern. | 134 // scheme, host and port part of the pattern. |
98 // Creating content settings patterns from strings behaves different. Pattern | 135 // Creating content settings patterns from strings behaves different. Pattern |
99 // parts that are omitted in pattern specifications (strings), are completed | 136 // parts that are omitted in pattern specifications (strings), are completed |
100 // with a wildcard. | 137 // with a wildcard. |
101 ContentSettingsPattern pattern = ContentSettingsPattern::FromURLNoWildcard( | 138 ContentSettingsPattern pattern = ContentSettingsPattern::FromURLNoWildcard( |
102 GURL("http://www.example.com")); | 139 GURL("http://www.example.com")); |
103 EXPECT_TRUE(pattern.IsValid()); | 140 EXPECT_TRUE(pattern.IsValid()); |
104 EXPECT_STREQ("http://www.example.com:80", pattern.ToString().c_str()); | 141 EXPECT_STREQ("http://www.example.com:80", pattern.ToString().c_str()); |
105 EXPECT_TRUE(pattern.Matches(GURL("http://www.example.com"))); | 142 EXPECT_TRUE(pattern.Matches(GURL("http://www.example.com"))); |
106 EXPECT_FALSE(pattern.Matches(GURL("https://www.example.com"))); | 143 EXPECT_FALSE(pattern.Matches(GURL("https://www.example.com"))); |
107 EXPECT_FALSE(pattern.Matches(GURL("http://foo.www.example.com"))); | 144 EXPECT_FALSE(pattern.Matches(GURL("http://foo.www.example.com"))); |
108 | 145 |
109 pattern = ContentSettingsPattern::FromURLNoWildcard( | 146 pattern = ContentSettingsPattern::FromURLNoWildcard( |
110 GURL("https://www.example.com")); | 147 GURL("https://www.example.com")); |
111 EXPECT_TRUE(pattern.IsValid()); | 148 EXPECT_TRUE(pattern.IsValid()); |
112 EXPECT_STREQ("https://www.example.com:443", pattern.ToString().c_str()); | 149 EXPECT_STREQ("https://www.example.com:443", pattern.ToString().c_str()); |
113 EXPECT_FALSE(pattern.Matches(GURL("http://www.example.com"))); | 150 EXPECT_FALSE(pattern.Matches(GURL("http://www.example.com"))); |
114 EXPECT_TRUE(pattern.Matches(GURL("https://www.example.com"))); | 151 EXPECT_TRUE(pattern.Matches(GURL("https://www.example.com"))); |
115 EXPECT_FALSE(pattern.Matches(GURL("http://foo.www.example.com"))); | 152 EXPECT_FALSE(pattern.Matches(GURL("http://foo.www.example.com"))); |
116 | 153 |
117 pattern = ContentSettingsPattern::FromURLNoWildcard( | 154 // Pattern for filesystem URLs |
118 GURL("https://www.example.com")); | 155 pattern = |
| 156 ContentSettingsPattern::FromURLNoWildcard( |
| 157 GURL("filesystem:http://www.google.com/temporary/")); |
| 158 EXPECT_TRUE(pattern.IsValid()); |
| 159 EXPECT_TRUE(pattern.Matches(GURL("http://www.google.com"))); |
| 160 EXPECT_FALSE(pattern.Matches(GURL("http://foo.www.google.com"))); |
| 161 EXPECT_TRUE(pattern.Matches(GURL("filesystem:http://www.google.com/persistent/
"))); |
| 162 EXPECT_FALSE(pattern.Matches(GURL("filesystem:https://www.google.com/persisten
t/"))); |
| 163 EXPECT_FALSE(pattern.Matches(GURL("filesystem:https://www.google.com:81/tempor
ary/"))); |
| 164 EXPECT_FALSE(pattern.Matches(GURL("filesystem:https://foo.www.google.com/tempo
rary/"))); |
119 } | 165 } |
120 | 166 |
121 TEST(ContentSettingsPatternTest, Wildcard) { | 167 TEST(ContentSettingsPatternTest, Wildcard) { |
122 EXPECT_TRUE(ContentSettingsPattern::Wildcard().IsValid()); | 168 EXPECT_TRUE(ContentSettingsPattern::Wildcard().IsValid()); |
123 | 169 |
124 EXPECT_TRUE(ContentSettingsPattern::Wildcard().Matches( | 170 EXPECT_TRUE(ContentSettingsPattern::Wildcard().Matches( |
125 GURL("http://www.google.com"))); | 171 GURL("http://www.google.com"))); |
126 EXPECT_TRUE(ContentSettingsPattern::Wildcard().Matches( | 172 EXPECT_TRUE(ContentSettingsPattern::Wildcard().Matches( |
127 GURL("https://www.google.com"))); | 173 GURL("https://www.google.com"))); |
128 EXPECT_TRUE(ContentSettingsPattern::Wildcard().Matches( | 174 EXPECT_TRUE(ContentSettingsPattern::Wildcard().Matches( |
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
585 // file:/// normalization. | 631 // file:/// normalization. |
586 EXPECT_STREQ("file:///tmp/test.html", | 632 EXPECT_STREQ("file:///tmp/test.html", |
587 Pattern("file:///tmp/bar/../test.html").ToString().c_str()); | 633 Pattern("file:///tmp/bar/../test.html").ToString().c_str()); |
588 | 634 |
589 // Invalid patterns. | 635 // Invalid patterns. |
590 EXPECT_STREQ("", Pattern("*example.com").ToString().c_str()); | 636 EXPECT_STREQ("", Pattern("*example.com").ToString().c_str()); |
591 EXPECT_STREQ("", Pattern("example.*").ToString().c_str()); | 637 EXPECT_STREQ("", Pattern("example.*").ToString().c_str()); |
592 EXPECT_STREQ("", Pattern("*\xC4\x87ira.com").ToString().c_str()); | 638 EXPECT_STREQ("", Pattern("*\xC4\x87ira.com").ToString().c_str()); |
593 EXPECT_STREQ("", Pattern("\xC4\x87ira.*").ToString().c_str()); | 639 EXPECT_STREQ("", Pattern("\xC4\x87ira.*").ToString().c_str()); |
594 } | 640 } |
OLD | NEW |