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

Unified Diff: chrome/browser/content_settings/content_settings_pattern_unittest.cc

Issue 5574001: Move ContentSettingsDetails and Pattern out of HostContentSettingsMap as separate classes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/chrome/browser/content_settings
Patch Set: updates Created 10 years 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/content_settings/content_settings_pattern_unittest.cc
diff --git a/chrome/browser/content_settings/content_settings_pattern_unittest.cc b/chrome/browser/content_settings/content_settings_pattern_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..88b42dcfe998e00a3016e768cabe27866d8cd1f2
--- /dev/null
+++ b/chrome/browser/content_settings/content_settings_pattern_unittest.cc
@@ -0,0 +1,69 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/content_settings/content_settings_pattern.h"
+
+#include "googleurl/src/gurl.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace {
+
+TEST(ContentSettingsPatternTest, PatternSupport) {
+ EXPECT_TRUE(ContentSettingsPattern("[*.]example.com").IsValid());
+ EXPECT_TRUE(ContentSettingsPattern("example.com").IsValid());
+ EXPECT_TRUE(ContentSettingsPattern("192.168.0.1").IsValid());
+ EXPECT_TRUE(ContentSettingsPattern("[::1]").IsValid());
+ EXPECT_FALSE(ContentSettingsPattern("*example.com").IsValid());
+ EXPECT_FALSE(ContentSettingsPattern("example.*").IsValid());
+ EXPECT_FALSE(ContentSettingsPattern("http://example.com").IsValid());
+
+ EXPECT_TRUE(ContentSettingsPattern("[*.]example.com").Matches(
+ GURL("http://example.com/")));
+ EXPECT_TRUE(ContentSettingsPattern("[*.]example.com").Matches(
+ GURL("http://www.example.com/")));
+ EXPECT_TRUE(ContentSettingsPattern("www.example.com").Matches(
+ GURL("http://www.example.com/")));
+ EXPECT_FALSE(ContentSettingsPattern("").Matches(
+ GURL("http://www.example.com/")));
+ EXPECT_FALSE(ContentSettingsPattern("[*.]example.com").Matches(
+ GURL("http://example.org/")));
+ EXPECT_FALSE(ContentSettingsPattern("example.com").Matches(
+ GURL("http://example.org/")));
+}
+
+TEST(ContentSettingsPatternTest, CanonicalizePattern) {
+ // Basic patterns.
+ EXPECT_STREQ("[*.]ikea.com", ContentSettingsPattern("[*.]ikea.com")
+ .CanonicalizePattern().c_str());
+ EXPECT_STREQ("example.com", ContentSettingsPattern("example.com")
+ .CanonicalizePattern().c_str());
+ EXPECT_STREQ("192.168.1.1", ContentSettingsPattern("192.168.1.1")
+ .CanonicalizePattern().c_str());
+ EXPECT_STREQ("[::1]", ContentSettingsPattern("[::1]")
+ .CanonicalizePattern().c_str());
+ // IsValid returns false for file:/// patterns.
+ EXPECT_STREQ("", ContentSettingsPattern(
+ "file:///temp/file.html").CanonicalizePattern().c_str());
+
+ // UTF-8 patterns.
+ EXPECT_STREQ("[*.]xn--ira-ppa.com", ContentSettingsPattern(
+ "[*.]\xC4\x87ira.com").CanonicalizePattern().c_str());
+ EXPECT_STREQ("xn--ira-ppa.com", ContentSettingsPattern(
+ "\xC4\x87ira.com").CanonicalizePattern().c_str());
+ // IsValid returns false for file:/// patterns.
+ EXPECT_STREQ("", ContentSettingsPattern(
+ "file:///\xC4\x87ira.html").CanonicalizePattern().c_str());
+
+ // Invalid patterns.
+ EXPECT_STREQ("", ContentSettingsPattern(
+ "*example.com").CanonicalizePattern().c_str());
+ EXPECT_STREQ("", ContentSettingsPattern(
+ "example.*").CanonicalizePattern().c_str());
+ EXPECT_STREQ("", ContentSettingsPattern(
+ "*\xC4\x87ira.com").CanonicalizePattern().c_str());
+ EXPECT_STREQ("", ContentSettingsPattern(
+ "\xC4\x87ira.*").CanonicalizePattern().c_str());
+}
+
+} // namespace

Powered by Google App Engine
This is Rietveld 408576698