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

Side by Side Diff: chrome/browser/content_settings/content_settings_origin_identifier_value_map_unittest.cc

Issue 2666093002: Remove base::FundamentalValue (Closed)
Patch Set: Rebase Created 3 years, 9 months 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
OLDNEW
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 "components/content_settings/core/browser/content_settings_origin_ident ifier_value_map.h" 5 #include "components/content_settings/core/browser/content_settings_origin_ident ifier_value_map.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "components/content_settings/core/browser/content_settings_rule.h" 10 #include "components/content_settings/core/browser/content_settings_rule.h"
11 #include "components/content_settings/core/browser/content_settings_utils.h" 11 #include "components/content_settings/core/browser/content_settings_utils.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "url/gurl.h" 13 #include "url/gurl.h"
14 14
15 TEST(OriginIdentifierValueMapTest, SetGetValue) { 15 TEST(OriginIdentifierValueMapTest, SetGetValue) {
16 content_settings::OriginIdentifierValueMap map; 16 content_settings::OriginIdentifierValueMap map;
17 17
18 EXPECT_EQ(NULL, 18 EXPECT_EQ(NULL,
19 map.GetValue(GURL("http://www.google.com"), 19 map.GetValue(GURL("http://www.google.com"),
20 GURL("http://www.google.com"), 20 GURL("http://www.google.com"),
21 CONTENT_SETTINGS_TYPE_COOKIES, 21 CONTENT_SETTINGS_TYPE_COOKIES,
22 std::string())); 22 std::string()));
23 map.SetValue(ContentSettingsPattern::FromString("[*.]google.com"), 23 map.SetValue(ContentSettingsPattern::FromString("[*.]google.com"),
24 ContentSettingsPattern::FromString("[*.]google.com"), 24 ContentSettingsPattern::FromString("[*.]google.com"),
25 CONTENT_SETTINGS_TYPE_COOKIES, 25 CONTENT_SETTINGS_TYPE_COOKIES, std::string(),
26 std::string(), 26 new base::Value(1));
27 new base::FundamentalValue(1));
28 27
29 std::unique_ptr<base::Value> expected_value(new base::FundamentalValue(1)); 28 std::unique_ptr<base::Value> expected_value(new base::Value(1));
30 EXPECT_TRUE(expected_value->Equals(map.GetValue(GURL("http://www.google.com"), 29 EXPECT_TRUE(expected_value->Equals(map.GetValue(GURL("http://www.google.com"),
31 GURL("http://www.google.com"), 30 GURL("http://www.google.com"),
32 CONTENT_SETTINGS_TYPE_COOKIES, 31 CONTENT_SETTINGS_TYPE_COOKIES,
33 std::string()))); 32 std::string())));
34 33
35 EXPECT_EQ(NULL, 34 EXPECT_EQ(NULL,
36 map.GetValue(GURL("http://www.google.com"), 35 map.GetValue(GURL("http://www.google.com"),
37 GURL("http://www.youtube.com"), 36 GURL("http://www.youtube.com"),
38 CONTENT_SETTINGS_TYPE_COOKIES, 37 CONTENT_SETTINGS_TYPE_COOKIES,
39 std::string())); 38 std::string()));
(...skipping 20 matching lines...) Expand all
60 content_settings::OriginIdentifierValueMap map; 59 content_settings::OriginIdentifierValueMap map;
61 60
62 EXPECT_EQ(NULL, map.GetValue(GURL("http://www.google.com"), 61 EXPECT_EQ(NULL, map.GetValue(GURL("http://www.google.com"),
63 GURL("http://www.google.com"), 62 GURL("http://www.google.com"),
64 CONTENT_SETTINGS_TYPE_PLUGINS, 63 CONTENT_SETTINGS_TYPE_PLUGINS,
65 "java-plugin")); 64 "java-plugin"));
66 65
67 // Set sample values. 66 // Set sample values.
68 map.SetValue(ContentSettingsPattern::FromString("[*.]google.com"), 67 map.SetValue(ContentSettingsPattern::FromString("[*.]google.com"),
69 ContentSettingsPattern::FromString("[*.]google.com"), 68 ContentSettingsPattern::FromString("[*.]google.com"),
70 CONTENT_SETTINGS_TYPE_PLUGINS, 69 CONTENT_SETTINGS_TYPE_PLUGINS, "java-plugin",
71 "java-plugin", 70 new base::Value(1));
72 new base::FundamentalValue(1));
73 71
74 int actual_value; 72 int actual_value;
75 EXPECT_TRUE(map.GetValue(GURL("http://www.google.com"), 73 EXPECT_TRUE(map.GetValue(GURL("http://www.google.com"),
76 GURL("http://www.google.com"), 74 GURL("http://www.google.com"),
77 CONTENT_SETTINGS_TYPE_PLUGINS, 75 CONTENT_SETTINGS_TYPE_PLUGINS,
78 "java-plugin")->GetAsInteger(&actual_value)); 76 "java-plugin")->GetAsInteger(&actual_value));
79 EXPECT_EQ(1, actual_value); 77 EXPECT_EQ(1, actual_value);
80 EXPECT_EQ(NULL, map.GetValue(GURL("http://www.google.com"), 78 EXPECT_EQ(NULL, map.GetValue(GURL("http://www.google.com"),
81 GURL("http://www.google.com"), 79 GURL("http://www.google.com"),
82 CONTENT_SETTINGS_TYPE_PLUGINS, 80 CONTENT_SETTINGS_TYPE_PLUGINS,
(...skipping 27 matching lines...) Expand all
110 "java-plugin")); 108 "java-plugin"));
111 } 109 }
112 110
113 TEST(OriginIdentifierValueMapTest, Clear) { 111 TEST(OriginIdentifierValueMapTest, Clear) {
114 content_settings::OriginIdentifierValueMap map; 112 content_settings::OriginIdentifierValueMap map;
115 EXPECT_TRUE(map.empty()); 113 EXPECT_TRUE(map.empty());
116 114
117 // Set two values. 115 // Set two values.
118 map.SetValue(ContentSettingsPattern::FromString("[*.]google.com"), 116 map.SetValue(ContentSettingsPattern::FromString("[*.]google.com"),
119 ContentSettingsPattern::FromString("[*.]google.com"), 117 ContentSettingsPattern::FromString("[*.]google.com"),
120 CONTENT_SETTINGS_TYPE_PLUGINS, 118 CONTENT_SETTINGS_TYPE_PLUGINS, "java-plugin",
121 "java-plugin", 119 new base::Value(1));
122 new base::FundamentalValue(1));
123 map.SetValue(ContentSettingsPattern::FromString("[*.]google.com"), 120 map.SetValue(ContentSettingsPattern::FromString("[*.]google.com"),
124 ContentSettingsPattern::FromString("[*.]google.com"), 121 ContentSettingsPattern::FromString("[*.]google.com"),
125 CONTENT_SETTINGS_TYPE_COOKIES, 122 CONTENT_SETTINGS_TYPE_COOKIES, std::string(),
126 std::string(), 123 new base::Value(1));
127 new base::FundamentalValue(1));
128 EXPECT_FALSE(map.empty()); 124 EXPECT_FALSE(map.empty());
129 int actual_value; 125 int actual_value;
130 EXPECT_TRUE(map.GetValue(GURL("http://www.google.com"), 126 EXPECT_TRUE(map.GetValue(GURL("http://www.google.com"),
131 GURL("http://www.google.com"), 127 GURL("http://www.google.com"),
132 CONTENT_SETTINGS_TYPE_PLUGINS, 128 CONTENT_SETTINGS_TYPE_PLUGINS,
133 "java-plugin")->GetAsInteger(&actual_value)); 129 "java-plugin")->GetAsInteger(&actual_value));
134 EXPECT_EQ(1, actual_value); 130 EXPECT_EQ(1, actual_value);
135 131
136 // Clear the map. 132 // Clear the map.
137 map.clear(); 133 map.clear();
138 EXPECT_TRUE(map.empty()); 134 EXPECT_TRUE(map.empty());
139 EXPECT_EQ(NULL, map.GetValue(GURL("http://www.google.com"), 135 EXPECT_EQ(NULL, map.GetValue(GURL("http://www.google.com"),
140 GURL("http://www.google.com"), 136 GURL("http://www.google.com"),
141 CONTENT_SETTINGS_TYPE_PLUGINS, 137 CONTENT_SETTINGS_TYPE_PLUGINS,
142 "java-plugin")); 138 "java-plugin"));
143 } 139 }
144 140
145 TEST(OriginIdentifierValueMapTest, ListEntryPrecedences) { 141 TEST(OriginIdentifierValueMapTest, ListEntryPrecedences) {
146 content_settings::OriginIdentifierValueMap map; 142 content_settings::OriginIdentifierValueMap map;
147 143
148 map.SetValue(ContentSettingsPattern::FromString("[*.]google.com"), 144 map.SetValue(ContentSettingsPattern::FromString("[*.]google.com"),
149 ContentSettingsPattern::FromString("[*.]google.com"), 145 ContentSettingsPattern::FromString("[*.]google.com"),
150 CONTENT_SETTINGS_TYPE_COOKIES, 146 CONTENT_SETTINGS_TYPE_COOKIES, std::string(),
151 std::string(), 147 new base::Value(1));
152 new base::FundamentalValue(1));
153 148
154 map.SetValue(ContentSettingsPattern::FromString("www.google.com"), 149 map.SetValue(ContentSettingsPattern::FromString("www.google.com"),
155 ContentSettingsPattern::FromString("[*.]google.com"), 150 ContentSettingsPattern::FromString("[*.]google.com"),
156 CONTENT_SETTINGS_TYPE_COOKIES, 151 CONTENT_SETTINGS_TYPE_COOKIES, std::string(),
157 std::string(), 152 new base::Value(2));
158 new base::FundamentalValue(2));
159 153
160 int actual_value; 154 int actual_value;
161 EXPECT_TRUE(map.GetValue(GURL("http://mail.google.com"), 155 EXPECT_TRUE(map.GetValue(GURL("http://mail.google.com"),
162 GURL("http://www.google.com"), 156 GURL("http://www.google.com"),
163 CONTENT_SETTINGS_TYPE_COOKIES, 157 CONTENT_SETTINGS_TYPE_COOKIES,
164 std::string())->GetAsInteger(&actual_value)); 158 std::string())->GetAsInteger(&actual_value));
165 EXPECT_EQ(1, actual_value); 159 EXPECT_EQ(1, actual_value);
166 160
167 EXPECT_TRUE(map.GetValue(GURL("http://www.google.com"), 161 EXPECT_TRUE(map.GetValue(GURL("http://www.google.com"),
168 GURL("http://www.google.com"), 162 GURL("http://www.google.com"),
(...skipping 10 matching lines...) Expand all
179 EXPECT_FALSE(rule_iterator); 173 EXPECT_FALSE(rule_iterator);
180 } 174 }
181 175
182 TEST(OriginIdentifierValueMapTest, IterateNonempty) { 176 TEST(OriginIdentifierValueMapTest, IterateNonempty) {
183 // Verify the precedence order. 177 // Verify the precedence order.
184 content_settings::OriginIdentifierValueMap map; 178 content_settings::OriginIdentifierValueMap map;
185 ContentSettingsPattern pattern = 179 ContentSettingsPattern pattern =
186 ContentSettingsPattern::FromString("[*.]google.com"); 180 ContentSettingsPattern::FromString("[*.]google.com");
187 ContentSettingsPattern sub_pattern = 181 ContentSettingsPattern sub_pattern =
188 ContentSettingsPattern::FromString("sub.google.com"); 182 ContentSettingsPattern::FromString("sub.google.com");
189 map.SetValue(pattern, 183 map.SetValue(pattern, ContentSettingsPattern::Wildcard(),
190 ContentSettingsPattern::Wildcard(), 184 CONTENT_SETTINGS_TYPE_COOKIES, std::string(),
191 CONTENT_SETTINGS_TYPE_COOKIES, 185 new base::Value(1));
192 std::string(), 186 map.SetValue(sub_pattern, ContentSettingsPattern::Wildcard(),
193 new base::FundamentalValue(1)); 187 CONTENT_SETTINGS_TYPE_COOKIES, std::string(),
194 map.SetValue(sub_pattern, 188 new base::Value(2));
195 ContentSettingsPattern::Wildcard(),
196 CONTENT_SETTINGS_TYPE_COOKIES,
197 std::string(),
198 new base::FundamentalValue(2));
199 189
200 std::unique_ptr<content_settings::RuleIterator> rule_iterator( 190 std::unique_ptr<content_settings::RuleIterator> rule_iterator(
201 map.GetRuleIterator(CONTENT_SETTINGS_TYPE_COOKIES, std::string(), NULL)); 191 map.GetRuleIterator(CONTENT_SETTINGS_TYPE_COOKIES, std::string(), NULL));
202 ASSERT_TRUE(rule_iterator->HasNext()); 192 ASSERT_TRUE(rule_iterator->HasNext());
203 content_settings::Rule rule = rule_iterator->Next(); 193 content_settings::Rule rule = rule_iterator->Next();
204 EXPECT_EQ(sub_pattern, rule.primary_pattern); 194 EXPECT_EQ(sub_pattern, rule.primary_pattern);
205 EXPECT_EQ(2, content_settings::ValueToContentSetting(rule.value.get())); 195 EXPECT_EQ(2, content_settings::ValueToContentSetting(rule.value.get()));
206 196
207 ASSERT_TRUE(rule_iterator->HasNext()); 197 ASSERT_TRUE(rule_iterator->HasNext());
208 rule = rule_iterator->Next(); 198 rule = rule_iterator->Next();
209 EXPECT_EQ(pattern, rule.primary_pattern); 199 EXPECT_EQ(pattern, rule.primary_pattern);
210 EXPECT_EQ(1, content_settings::ValueToContentSetting(rule.value.get())); 200 EXPECT_EQ(1, content_settings::ValueToContentSetting(rule.value.get()));
211 } 201 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698