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