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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/content_settings/content_settings_pattern.h"
6
7 #include "googleurl/src/gurl.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9
10 namespace {
11
12 TEST(ContentSettingsPatternTest, PatternSupport) {
13 EXPECT_TRUE(ContentSettingsPattern("[*.]example.com").IsValid());
14 EXPECT_TRUE(ContentSettingsPattern("example.com").IsValid());
15 EXPECT_TRUE(ContentSettingsPattern("192.168.0.1").IsValid());
16 EXPECT_TRUE(ContentSettingsPattern("[::1]").IsValid());
17 EXPECT_FALSE(ContentSettingsPattern("*example.com").IsValid());
18 EXPECT_FALSE(ContentSettingsPattern("example.*").IsValid());
19 EXPECT_FALSE(ContentSettingsPattern("http://example.com").IsValid());
20
21 EXPECT_TRUE(ContentSettingsPattern("[*.]example.com").Matches(
22 GURL("http://example.com/")));
23 EXPECT_TRUE(ContentSettingsPattern("[*.]example.com").Matches(
24 GURL("http://www.example.com/")));
25 EXPECT_TRUE(ContentSettingsPattern("www.example.com").Matches(
26 GURL("http://www.example.com/")));
27 EXPECT_FALSE(ContentSettingsPattern("").Matches(
28 GURL("http://www.example.com/")));
29 EXPECT_FALSE(ContentSettingsPattern("[*.]example.com").Matches(
30 GURL("http://example.org/")));
31 EXPECT_FALSE(ContentSettingsPattern("example.com").Matches(
32 GURL("http://example.org/")));
33 }
34
35 TEST(ContentSettingsPatternTest, CanonicalizePattern) {
36 // Basic patterns.
37 EXPECT_STREQ("[*.]ikea.com", ContentSettingsPattern("[*.]ikea.com")
38 .CanonicalizePattern().c_str());
39 EXPECT_STREQ("example.com", ContentSettingsPattern("example.com")
40 .CanonicalizePattern().c_str());
41 EXPECT_STREQ("192.168.1.1", ContentSettingsPattern("192.168.1.1")
42 .CanonicalizePattern().c_str());
43 EXPECT_STREQ("[::1]", ContentSettingsPattern("[::1]")
44 .CanonicalizePattern().c_str());
45 // IsValid returns false for file:/// patterns.
46 EXPECT_STREQ("", ContentSettingsPattern(
47 "file:///temp/file.html").CanonicalizePattern().c_str());
48
49 // UTF-8 patterns.
50 EXPECT_STREQ("[*.]xn--ira-ppa.com", ContentSettingsPattern(
51 "[*.]\xC4\x87ira.com").CanonicalizePattern().c_str());
52 EXPECT_STREQ("xn--ira-ppa.com", ContentSettingsPattern(
53 "\xC4\x87ira.com").CanonicalizePattern().c_str());
54 // IsValid returns false for file:/// patterns.
55 EXPECT_STREQ("", ContentSettingsPattern(
56 "file:///\xC4\x87ira.html").CanonicalizePattern().c_str());
57
58 // Invalid patterns.
59 EXPECT_STREQ("", ContentSettingsPattern(
60 "*example.com").CanonicalizePattern().c_str());
61 EXPECT_STREQ("", ContentSettingsPattern(
62 "example.*").CanonicalizePattern().c_str());
63 EXPECT_STREQ("", ContentSettingsPattern(
64 "*\xC4\x87ira.com").CanonicalizePattern().c_str());
65 EXPECT_STREQ("", ContentSettingsPattern(
66 "\xC4\x87ira.*").CanonicalizePattern().c_str());
67 }
68
69 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698