Fix "#if defined(DEBUG)" statements
[chromium-blink-merge.git] / net / tools / tld_cleanup / tld_cleanup_util_unittest.cc
blob6b1d02a84712779483c728c0f3b619736ec5b912
1 // Copyright 2013 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.
5 #include "net/tools/tld_cleanup/tld_cleanup_util.h"
7 #include "base/files/file_path.h"
8 #include "base/path_service.h"
9 #include "testing/gtest/include/gtest/gtest.h"
11 namespace net {
12 namespace tld_cleanup {
14 std::string SetupData(std::string icann_domains, std::string private_domains) {
15 return "// ===BEGIN ICANN DOMAINS===\n" +
16 icann_domains +
17 "// ===END ICANN DOMAINS===\n" +
18 "// ===BEGIN PRIVATE DOMAINS===\n" +
19 private_domains +
20 "// ===END PRIVATE DOMAINS===\n";
23 TEST(TldCleanupUtilTest, TwoRealTldsSuccessfullyRead) {
24 std::string icann_domains = "foo\n"
25 "bar\n";
26 std::string private_domains = "";
27 std::string data = SetupData(icann_domains, private_domains);
28 RuleMap rules;
29 NormalizeResult result = NormalizeDataToRuleMap(data, &rules);
30 ASSERT_EQ(kSuccess, result);
31 ASSERT_EQ(2U, rules.size());
32 RuleMap::const_iterator foo_iter = rules.find("foo");
33 ASSERT_FALSE(rules.end() == foo_iter);
34 EXPECT_FALSE(foo_iter->second.wildcard);
35 EXPECT_FALSE(foo_iter->second.exception);
36 EXPECT_FALSE(foo_iter->second.is_private);
37 RuleMap::const_iterator bar_iter = rules.find("bar");
38 ASSERT_FALSE(rules.end() == bar_iter);
39 EXPECT_FALSE(bar_iter->second.wildcard);
40 EXPECT_FALSE(bar_iter->second.exception);
41 EXPECT_FALSE(bar_iter->second.is_private);
44 TEST(TldCleanupUtilTest, RealTldAutomaticallyAddedForSubdomain) {
45 std::string icann_domains = "foo.bar\n";
46 std::string private_domains = "";
47 std::string data = SetupData(icann_domains, private_domains);
48 RuleMap rules;
49 NormalizeResult result = NormalizeDataToRuleMap(data, &rules);
50 ASSERT_EQ(kSuccess, result);
51 ASSERT_EQ(2U, rules.size());
52 RuleMap::const_iterator foo_bar_iter = rules.find("foo.bar");
53 ASSERT_FALSE(rules.end() == foo_bar_iter);
54 EXPECT_FALSE(foo_bar_iter->second.wildcard);
55 EXPECT_FALSE(foo_bar_iter->second.exception);
56 EXPECT_FALSE(foo_bar_iter->second.is_private);
57 RuleMap::const_iterator bar_iter = rules.find("bar");
58 ASSERT_FALSE(rules.end() == bar_iter);
59 EXPECT_FALSE(bar_iter->second.wildcard);
60 EXPECT_FALSE(bar_iter->second.exception);
61 EXPECT_FALSE(bar_iter->second.is_private);
64 TEST(TldCleanupUtilTest, PrivateTldMarkedAsPrivate) {
65 std::string icann_domains = "foo\n"
66 "bar\n";
67 std::string private_domains = "baz\n";
68 std::string data = SetupData(icann_domains, private_domains);
69 RuleMap rules;
70 NormalizeResult result = NormalizeDataToRuleMap(data, &rules);
71 ASSERT_EQ(kSuccess, result);
72 ASSERT_EQ(3U, rules.size());
73 RuleMap::const_iterator foo_iter = rules.find("foo");
74 ASSERT_FALSE(rules.end() == foo_iter);
75 EXPECT_FALSE(foo_iter->second.wildcard);
76 EXPECT_FALSE(foo_iter->second.exception);
77 EXPECT_FALSE(foo_iter->second.is_private);
78 RuleMap::const_iterator bar_iter = rules.find("bar");
79 ASSERT_FALSE(rules.end() == bar_iter);
80 EXPECT_FALSE(bar_iter->second.wildcard);
81 EXPECT_FALSE(bar_iter->second.exception);
82 EXPECT_FALSE(bar_iter->second.is_private);
83 RuleMap::const_iterator baz_iter = rules.find("baz");
84 ASSERT_FALSE(rules.end() == baz_iter);
85 EXPECT_FALSE(baz_iter->second.wildcard);
86 EXPECT_FALSE(baz_iter->second.exception);
87 EXPECT_TRUE(baz_iter->second.is_private);
90 TEST(TldCleanupUtilTest, PrivateDomainMarkedAsPrivate) {
91 std::string icann_domains = "bar\n";
92 std::string private_domains = "foo.bar\n";
93 std::string data = SetupData(icann_domains, private_domains);
94 RuleMap rules;
95 NormalizeResult result = NormalizeDataToRuleMap(data, &rules);
96 ASSERT_EQ(kSuccess, result);
97 ASSERT_EQ(2U, rules.size());
98 RuleMap::const_iterator bar_iter = rules.find("bar");
99 ASSERT_FALSE(rules.end() == bar_iter);
100 EXPECT_FALSE(bar_iter->second.wildcard);
101 EXPECT_FALSE(bar_iter->second.exception);
102 EXPECT_FALSE(bar_iter->second.is_private);
103 RuleMap::const_iterator foo_bar_iter = rules.find("foo.bar");
104 ASSERT_FALSE(rules.end() == foo_bar_iter);
105 EXPECT_FALSE(foo_bar_iter->second.wildcard);
106 EXPECT_FALSE(foo_bar_iter->second.exception);
107 EXPECT_TRUE(foo_bar_iter->second.is_private);
110 TEST(TldCleanupUtilTest, ExtraTldRuleIsNotMarkedPrivate) {
111 std::string icann_domains = "foo.bar\n"
112 "baz.bar\n";
113 std::string private_domains = "qux.bar\n";
114 std::string data = SetupData(icann_domains, private_domains);
115 RuleMap rules;
116 NormalizeResult result = NormalizeDataToRuleMap(data, &rules);
117 ASSERT_EQ(kSuccess, result);
118 ASSERT_EQ(4U, rules.size());
119 RuleMap::const_iterator foo_bar_iter = rules.find("foo.bar");
120 ASSERT_FALSE(rules.end() == foo_bar_iter);
121 EXPECT_FALSE(foo_bar_iter->second.wildcard);
122 EXPECT_FALSE(foo_bar_iter->second.exception);
123 EXPECT_FALSE(foo_bar_iter->second.is_private);
124 RuleMap::const_iterator baz_bar_iter = rules.find("baz.bar");
125 ASSERT_FALSE(rules.end() == baz_bar_iter);
126 EXPECT_FALSE(baz_bar_iter->second.wildcard);
127 EXPECT_FALSE(baz_bar_iter->second.exception);
128 EXPECT_FALSE(baz_bar_iter->second.is_private);
129 RuleMap::const_iterator bar_iter = rules.find("bar");
130 ASSERT_FALSE(rules.end() == bar_iter);
131 EXPECT_FALSE(bar_iter->second.wildcard);
132 EXPECT_FALSE(bar_iter->second.exception);
133 EXPECT_FALSE(bar_iter->second.is_private);
134 RuleMap::const_iterator qux_bar_iter = rules.find("qux.bar");
135 ASSERT_FALSE(rules.end() == qux_bar_iter);
136 EXPECT_FALSE(qux_bar_iter->second.wildcard);
137 EXPECT_FALSE(qux_bar_iter->second.exception);
138 EXPECT_TRUE(qux_bar_iter->second.is_private);
141 TEST(TldCleanupUtilTest, WildcardAndExceptionParsedCorrectly) {
142 std::string icann_domains = "*.bar\n"
143 "!foo.bar\n";
144 std::string private_domains = "!baz.bar\n";
145 std::string data = SetupData(icann_domains, private_domains);
146 RuleMap rules;
147 NormalizeResult result = NormalizeDataToRuleMap(data, &rules);
148 ASSERT_EQ(kSuccess, result);
149 ASSERT_EQ(3U, rules.size());
150 RuleMap::const_iterator foo_bar_iter = rules.find("bar");
151 ASSERT_FALSE(rules.end() == foo_bar_iter);
152 EXPECT_TRUE(foo_bar_iter->second.wildcard);
153 EXPECT_FALSE(foo_bar_iter->second.exception);
154 EXPECT_FALSE(foo_bar_iter->second.is_private);
155 RuleMap::const_iterator bar_iter = rules.find("foo.bar");
156 ASSERT_FALSE(rules.end() == bar_iter);
157 EXPECT_FALSE(bar_iter->second.wildcard);
158 EXPECT_TRUE(bar_iter->second.exception);
159 EXPECT_FALSE(bar_iter->second.is_private);
160 RuleMap::const_iterator baz_bar_iter = rules.find("baz.bar");
161 ASSERT_FALSE(rules.end() == baz_bar_iter);
162 EXPECT_FALSE(baz_bar_iter->second.wildcard);
163 EXPECT_TRUE(baz_bar_iter->second.exception);
164 EXPECT_TRUE(baz_bar_iter->second.is_private);
167 } // namespace tld_cleanup
168 } // namespace net