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

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

Issue 2476493003: Remove FundamentalValue
Patch Set: Fix Created 4 years, 1 month 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,
26 std::string(), 26 std::string(),
27 new base::FundamentalValue(1)); 27 new base::Value(1));
28 28
29 std::unique_ptr<base::Value> expected_value(new base::FundamentalValue(1)); 29 std::unique_ptr<base::Value> expected_value(new base::Value(1));
30 EXPECT_TRUE(expected_value->Equals(map.GetValue(GURL("http://www.google.com"), 30 EXPECT_TRUE(expected_value->Equals(map.GetValue(GURL("http://www.google.com"),
31 GURL("http://www.google.com"), 31 GURL("http://www.google.com"),
32 CONTENT_SETTINGS_TYPE_COOKIES, 32 CONTENT_SETTINGS_TYPE_COOKIES,
33 std::string()))); 33 std::string())));
34 34
35 EXPECT_EQ(NULL, 35 EXPECT_EQ(NULL,
36 map.GetValue(GURL("http://www.google.com"), 36 map.GetValue(GURL("http://www.google.com"),
37 GURL("http://www.youtube.com"), 37 GURL("http://www.youtube.com"),
38 CONTENT_SETTINGS_TYPE_COOKIES, 38 CONTENT_SETTINGS_TYPE_COOKIES,
39 std::string())); 39 std::string()));
(...skipping 22 matching lines...) Expand all
62 EXPECT_EQ(NULL, map.GetValue(GURL("http://www.google.com"), 62 EXPECT_EQ(NULL, map.GetValue(GURL("http://www.google.com"),
63 GURL("http://www.google.com"), 63 GURL("http://www.google.com"),
64 CONTENT_SETTINGS_TYPE_PLUGINS, 64 CONTENT_SETTINGS_TYPE_PLUGINS,
65 "java-plugin")); 65 "java-plugin"));
66 66
67 // Set sample values. 67 // Set sample values.
68 map.SetValue(ContentSettingsPattern::FromString("[*.]google.com"), 68 map.SetValue(ContentSettingsPattern::FromString("[*.]google.com"),
69 ContentSettingsPattern::FromString("[*.]google.com"), 69 ContentSettingsPattern::FromString("[*.]google.com"),
70 CONTENT_SETTINGS_TYPE_PLUGINS, 70 CONTENT_SETTINGS_TYPE_PLUGINS,
71 "java-plugin", 71 "java-plugin",
72 new base::FundamentalValue(1)); 72 new base::Value(1));
73 73
74 int actual_value; 74 int actual_value;
75 EXPECT_TRUE(map.GetValue(GURL("http://www.google.com"), 75 EXPECT_TRUE(map.GetValue(GURL("http://www.google.com"),
76 GURL("http://www.google.com"), 76 GURL("http://www.google.com"),
77 CONTENT_SETTINGS_TYPE_PLUGINS, 77 CONTENT_SETTINGS_TYPE_PLUGINS,
78 "java-plugin")->GetAsInteger(&actual_value)); 78 "java-plugin")->GetAsInteger(&actual_value));
79 EXPECT_EQ(1, actual_value); 79 EXPECT_EQ(1, actual_value);
80 EXPECT_EQ(NULL, map.GetValue(GURL("http://www.google.com"), 80 EXPECT_EQ(NULL, map.GetValue(GURL("http://www.google.com"),
81 GURL("http://www.google.com"), 81 GURL("http://www.google.com"),
82 CONTENT_SETTINGS_TYPE_PLUGINS, 82 CONTENT_SETTINGS_TYPE_PLUGINS,
(...skipping 29 matching lines...) Expand all
112 112
113 TEST(OriginIdentifierValueMapTest, Clear) { 113 TEST(OriginIdentifierValueMapTest, Clear) {
114 content_settings::OriginIdentifierValueMap map; 114 content_settings::OriginIdentifierValueMap map;
115 EXPECT_TRUE(map.empty()); 115 EXPECT_TRUE(map.empty());
116 116
117 // Set two values. 117 // Set two values.
118 map.SetValue(ContentSettingsPattern::FromString("[*.]google.com"), 118 map.SetValue(ContentSettingsPattern::FromString("[*.]google.com"),
119 ContentSettingsPattern::FromString("[*.]google.com"), 119 ContentSettingsPattern::FromString("[*.]google.com"),
120 CONTENT_SETTINGS_TYPE_PLUGINS, 120 CONTENT_SETTINGS_TYPE_PLUGINS,
121 "java-plugin", 121 "java-plugin",
122 new base::FundamentalValue(1)); 122 new base::Value(1));
123 map.SetValue(ContentSettingsPattern::FromString("[*.]google.com"), 123 map.SetValue(ContentSettingsPattern::FromString("[*.]google.com"),
124 ContentSettingsPattern::FromString("[*.]google.com"), 124 ContentSettingsPattern::FromString("[*.]google.com"),
125 CONTENT_SETTINGS_TYPE_COOKIES, 125 CONTENT_SETTINGS_TYPE_COOKIES,
126 std::string(), 126 std::string(),
127 new base::FundamentalValue(1)); 127 new base::Value(1));
128 EXPECT_FALSE(map.empty()); 128 EXPECT_FALSE(map.empty());
129 int actual_value; 129 int actual_value;
130 EXPECT_TRUE(map.GetValue(GURL("http://www.google.com"), 130 EXPECT_TRUE(map.GetValue(GURL("http://www.google.com"),
131 GURL("http://www.google.com"), 131 GURL("http://www.google.com"),
132 CONTENT_SETTINGS_TYPE_PLUGINS, 132 CONTENT_SETTINGS_TYPE_PLUGINS,
133 "java-plugin")->GetAsInteger(&actual_value)); 133 "java-plugin")->GetAsInteger(&actual_value));
134 EXPECT_EQ(1, actual_value); 134 EXPECT_EQ(1, actual_value);
135 135
136 // Clear the map. 136 // Clear the map.
137 map.clear(); 137 map.clear();
138 EXPECT_TRUE(map.empty()); 138 EXPECT_TRUE(map.empty());
139 EXPECT_EQ(NULL, map.GetValue(GURL("http://www.google.com"), 139 EXPECT_EQ(NULL, map.GetValue(GURL("http://www.google.com"),
140 GURL("http://www.google.com"), 140 GURL("http://www.google.com"),
141 CONTENT_SETTINGS_TYPE_PLUGINS, 141 CONTENT_SETTINGS_TYPE_PLUGINS,
142 "java-plugin")); 142 "java-plugin"));
143 } 143 }
144 144
145 TEST(OriginIdentifierValueMapTest, ListEntryPrecedences) { 145 TEST(OriginIdentifierValueMapTest, ListEntryPrecedences) {
146 content_settings::OriginIdentifierValueMap map; 146 content_settings::OriginIdentifierValueMap map;
147 147
148 map.SetValue(ContentSettingsPattern::FromString("[*.]google.com"), 148 map.SetValue(ContentSettingsPattern::FromString("[*.]google.com"),
149 ContentSettingsPattern::FromString("[*.]google.com"), 149 ContentSettingsPattern::FromString("[*.]google.com"),
150 CONTENT_SETTINGS_TYPE_COOKIES, 150 CONTENT_SETTINGS_TYPE_COOKIES,
151 std::string(), 151 std::string(),
152 new base::FundamentalValue(1)); 152 new base::Value(1));
153 153
154 map.SetValue(ContentSettingsPattern::FromString("www.google.com"), 154 map.SetValue(ContentSettingsPattern::FromString("www.google.com"),
155 ContentSettingsPattern::FromString("[*.]google.com"), 155 ContentSettingsPattern::FromString("[*.]google.com"),
156 CONTENT_SETTINGS_TYPE_COOKIES, 156 CONTENT_SETTINGS_TYPE_COOKIES,
157 std::string(), 157 std::string(),
158 new base::FundamentalValue(2)); 158 new base::Value(2));
159 159
160 int actual_value; 160 int actual_value;
161 EXPECT_TRUE(map.GetValue(GURL("http://mail.google.com"), 161 EXPECT_TRUE(map.GetValue(GURL("http://mail.google.com"),
162 GURL("http://www.google.com"), 162 GURL("http://www.google.com"),
163 CONTENT_SETTINGS_TYPE_COOKIES, 163 CONTENT_SETTINGS_TYPE_COOKIES,
164 std::string())->GetAsInteger(&actual_value)); 164 std::string())->GetAsInteger(&actual_value));
165 EXPECT_EQ(1, actual_value); 165 EXPECT_EQ(1, actual_value);
166 166
167 EXPECT_TRUE(map.GetValue(GURL("http://www.google.com"), 167 EXPECT_TRUE(map.GetValue(GURL("http://www.google.com"),
168 GURL("http://www.google.com"), 168 GURL("http://www.google.com"),
(...skipping 14 matching lines...) Expand all
183 // Verify the precedence order. 183 // Verify the precedence order.
184 content_settings::OriginIdentifierValueMap map; 184 content_settings::OriginIdentifierValueMap map;
185 ContentSettingsPattern pattern = 185 ContentSettingsPattern pattern =
186 ContentSettingsPattern::FromString("[*.]google.com"); 186 ContentSettingsPattern::FromString("[*.]google.com");
187 ContentSettingsPattern sub_pattern = 187 ContentSettingsPattern sub_pattern =
188 ContentSettingsPattern::FromString("sub.google.com"); 188 ContentSettingsPattern::FromString("sub.google.com");
189 map.SetValue(pattern, 189 map.SetValue(pattern,
190 ContentSettingsPattern::Wildcard(), 190 ContentSettingsPattern::Wildcard(),
191 CONTENT_SETTINGS_TYPE_COOKIES, 191 CONTENT_SETTINGS_TYPE_COOKIES,
192 std::string(), 192 std::string(),
193 new base::FundamentalValue(1)); 193 new base::Value(1));
194 map.SetValue(sub_pattern, 194 map.SetValue(sub_pattern,
195 ContentSettingsPattern::Wildcard(), 195 ContentSettingsPattern::Wildcard(),
196 CONTENT_SETTINGS_TYPE_COOKIES, 196 CONTENT_SETTINGS_TYPE_COOKIES,
197 std::string(), 197 std::string(),
198 new base::FundamentalValue(2)); 198 new base::Value(2));
199 199
200 std::unique_ptr<content_settings::RuleIterator> rule_iterator( 200 std::unique_ptr<content_settings::RuleIterator> rule_iterator(
201 map.GetRuleIterator(CONTENT_SETTINGS_TYPE_COOKIES, std::string(), NULL)); 201 map.GetRuleIterator(CONTENT_SETTINGS_TYPE_COOKIES, std::string(), NULL));
202 ASSERT_TRUE(rule_iterator->HasNext()); 202 ASSERT_TRUE(rule_iterator->HasNext());
203 content_settings::Rule rule = rule_iterator->Next(); 203 content_settings::Rule rule = rule_iterator->Next();
204 EXPECT_EQ(sub_pattern, rule.primary_pattern); 204 EXPECT_EQ(sub_pattern, rule.primary_pattern);
205 EXPECT_EQ(2, content_settings::ValueToContentSetting(rule.value.get())); 205 EXPECT_EQ(2, content_settings::ValueToContentSetting(rule.value.get()));
206 206
207 ASSERT_TRUE(rule_iterator->HasNext()); 207 ASSERT_TRUE(rule_iterator->HasNext());
208 rule = rule_iterator->Next(); 208 rule = rule_iterator->Next();
209 EXPECT_EQ(pattern, rule.primary_pattern); 209 EXPECT_EQ(pattern, rule.primary_pattern);
210 EXPECT_EQ(1, content_settings::ValueToContentSetting(rule.value.get())); 210 EXPECT_EQ(1, content_settings::ValueToContentSetting(rule.value.get()));
211 } 211 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698