| 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/browser/content_settings/content_settings_pattern.h" | 5 #include "chrome/browser/content_settings/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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 EXPECT_TRUE(ContentSettingsPattern::Wildcard().Matches( | 130 EXPECT_TRUE(ContentSettingsPattern::Wildcard().Matches( |
| 131 GURL("file:///foo/bar.txt"))); | 131 GURL("file:///foo/bar.txt"))); |
| 132 | 132 |
| 133 EXPECT_STREQ("*", ContentSettingsPattern::Wildcard().ToString().c_str()); | 133 EXPECT_STREQ("*", ContentSettingsPattern::Wildcard().ToString().c_str()); |
| 134 | 134 |
| 135 EXPECT_EQ(ContentSettingsPattern::IDENTITY, | 135 EXPECT_EQ(ContentSettingsPattern::IDENTITY, |
| 136 ContentSettingsPattern::Wildcard().Compare( | 136 ContentSettingsPattern::Wildcard().Compare( |
| 137 ContentSettingsPattern::Wildcard())); | 137 ContentSettingsPattern::Wildcard())); |
| 138 } | 138 } |
| 139 | 139 |
| 140 TEST(ContentSettingsPatternTest, TrimEndingDotFromHost) { |
| 141 EXPECT_TRUE(Pattern("www.example.com").IsValid()); |
| 142 EXPECT_TRUE(Pattern("www.example.com").Matches( |
| 143 GURL("http://www.example.com"))); |
| 144 EXPECT_TRUE(Pattern("www.example.com").Matches( |
| 145 GURL("http://www.example.com."))); |
| 146 |
| 147 EXPECT_TRUE(Pattern("www.example.com.").IsValid()); |
| 148 EXPECT_STREQ("www.example.com", |
| 149 Pattern("www.example.com.").ToString().c_str()); |
| 150 |
| 151 EXPECT_TRUE(Pattern("www.example.com.") == Pattern("www.example.com")); |
| 152 } |
| 153 |
| 140 TEST(ContentSettingsPatternTest, FromString_WithNoWildcards) { | 154 TEST(ContentSettingsPatternTest, FromString_WithNoWildcards) { |
| 141 // HTTP patterns with default port. | 155 // HTTP patterns with default port. |
| 142 EXPECT_TRUE(Pattern("http://www.example.com:80").IsValid()); | 156 EXPECT_TRUE(Pattern("http://www.example.com:80").IsValid()); |
| 143 EXPECT_STREQ("http://www.example.com:80", | 157 EXPECT_STREQ("http://www.example.com:80", |
| 144 Pattern("http://www.example.com:80").ToString().c_str()); | 158 Pattern("http://www.example.com:80").ToString().c_str()); |
| 145 // HTTP patterns with none default port. | 159 // HTTP patterns with none default port. |
| 146 EXPECT_TRUE(Pattern("http://www.example.com:81").IsValid()); | 160 EXPECT_TRUE(Pattern("http://www.example.com:81").IsValid()); |
| 147 EXPECT_STREQ("http://www.example.com:81", | 161 EXPECT_STREQ("http://www.example.com:81", |
| 148 Pattern("http://www.example.com:81").ToString().c_str()); | 162 Pattern("http://www.example.com:81").ToString().c_str()); |
| 149 | 163 |
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 502 // file:/// normalization. | 516 // file:/// normalization. |
| 503 EXPECT_STREQ("file:///tmp/test.html", | 517 EXPECT_STREQ("file:///tmp/test.html", |
| 504 Pattern("file:///tmp/bar/../test.html").ToString().c_str()); | 518 Pattern("file:///tmp/bar/../test.html").ToString().c_str()); |
| 505 | 519 |
| 506 // Invalid patterns. | 520 // Invalid patterns. |
| 507 EXPECT_STREQ("", Pattern("*example.com").ToString().c_str()); | 521 EXPECT_STREQ("", Pattern("*example.com").ToString().c_str()); |
| 508 EXPECT_STREQ("", Pattern("example.*").ToString().c_str()); | 522 EXPECT_STREQ("", Pattern("example.*").ToString().c_str()); |
| 509 EXPECT_STREQ("", Pattern("*\xC4\x87ira.com").ToString().c_str()); | 523 EXPECT_STREQ("", Pattern("*\xC4\x87ira.com").ToString().c_str()); |
| 510 EXPECT_STREQ("", Pattern("\xC4\x87ira.*").ToString().c_str()); | 524 EXPECT_STREQ("", Pattern("\xC4\x87ira.*").ToString().c_str()); |
| 511 } | 525 } |
| OLD | NEW |