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

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

Issue 13145003: Rewrite std::string("") to std::string(), Linux edition. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Ugh Created 7 years, 8 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 | Annotate | Revision Log
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 "chrome/browser/content_settings/content_settings_origin_identifier_val ue_map.h" 5 #include "chrome/browser/content_settings/content_settings_origin_identifier_val ue_map.h"
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "chrome/browser/content_settings/content_settings_rule.h" 9 #include "chrome/browser/content_settings/content_settings_rule.h"
10 #include "chrome/browser/content_settings/content_settings_utils.h" 10 #include "chrome/browser/content_settings/content_settings_utils.h"
11 #include "googleurl/src/gurl.h" 11 #include "googleurl/src/gurl.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 13
14 TEST(OriginIdentifierValueMapTest, SetGetValue) { 14 TEST(OriginIdentifierValueMapTest, SetGetValue) {
15 content_settings::OriginIdentifierValueMap map; 15 content_settings::OriginIdentifierValueMap map;
16 16
17 EXPECT_EQ(NULL, map.GetValue(GURL("http://www.google.com"), 17 EXPECT_EQ(NULL,
18 GURL("http://www.google.com"), 18 map.GetValue(GURL("http://www.google.com"),
19 CONTENT_SETTINGS_TYPE_COOKIES, 19 GURL("http://www.google.com"),
20 "")); 20 CONTENT_SETTINGS_TYPE_COOKIES,
21 map.SetValue( 21 std::string()));
22 ContentSettingsPattern::FromString("[*.]google.com"), 22 map.SetValue(ContentSettingsPattern::FromString("[*.]google.com"),
23 ContentSettingsPattern::FromString("[*.]google.com"), 23 ContentSettingsPattern::FromString("[*.]google.com"),
24 CONTENT_SETTINGS_TYPE_COOKIES, 24 CONTENT_SETTINGS_TYPE_COOKIES,
25 "", 25 std::string(),
26 Value::CreateIntegerValue(1)); 26 Value::CreateIntegerValue(1));
27 27
28 scoped_ptr<Value> expected_value(Value::CreateIntegerValue(1)); 28 scoped_ptr<Value> expected_value(Value::CreateIntegerValue(1));
29 EXPECT_TRUE(expected_value->Equals( 29 EXPECT_TRUE(expected_value->Equals(map.GetValue(GURL("http://www.google.com"),
30 map.GetValue(GURL("http://www.google.com"), 30 GURL("http://www.google.com"),
31 GURL("http://www.google.com"), 31 CONTENT_SETTINGS_TYPE_COOKIES,
32 CONTENT_SETTINGS_TYPE_COOKIES, 32 std::string())));
33 "")));
34 33
35 EXPECT_EQ(NULL, map.GetValue(GURL("http://www.google.com"), 34 EXPECT_EQ(NULL,
36 GURL("http://www.youtube.com"), 35 map.GetValue(GURL("http://www.google.com"),
37 CONTENT_SETTINGS_TYPE_COOKIES, 36 GURL("http://www.youtube.com"),
38 "")); 37 CONTENT_SETTINGS_TYPE_COOKIES,
38 std::string()));
39 39
40 EXPECT_EQ(NULL, map.GetValue(GURL("http://www.youtube.com"), 40 EXPECT_EQ(NULL,
41 GURL("http://www.google.com"), 41 map.GetValue(GURL("http://www.youtube.com"),
42 CONTENT_SETTINGS_TYPE_COOKIES, 42 GURL("http://www.google.com"),
43 "")); 43 CONTENT_SETTINGS_TYPE_COOKIES,
44 std::string()));
45
46 EXPECT_EQ(NULL,
47 map.GetValue(GURL("http://www.google.com"),
48 GURL("http://www.google.com"),
49 CONTENT_SETTINGS_TYPE_POPUPS,
50 std::string()));
44 51
45 EXPECT_EQ(NULL, map.GetValue(GURL("http://www.google.com"), 52 EXPECT_EQ(NULL, map.GetValue(GURL("http://www.google.com"),
46 GURL("http://www.google.com"), 53 GURL("http://www.google.com"),
47 CONTENT_SETTINGS_TYPE_POPUPS,
48 ""));
49
50 EXPECT_EQ(NULL, map.GetValue(GURL("http://www.google.com"),
51 GURL("http://www.google.com"),
52 CONTENT_SETTINGS_TYPE_COOKIES, 54 CONTENT_SETTINGS_TYPE_COOKIES,
53 "resource_id")); 55 "resource_id"));
54 } 56 }
55 57
56 TEST(OriginIdentifierValueMapTest, SetDeleteValue) { 58 TEST(OriginIdentifierValueMapTest, SetDeleteValue) {
57 content_settings::OriginIdentifierValueMap map; 59 content_settings::OriginIdentifierValueMap map;
58 60
59 EXPECT_EQ(NULL, map.GetValue(GURL("http://www.google.com"), 61 EXPECT_EQ(NULL, map.GetValue(GURL("http://www.google.com"),
60 GURL("http://www.google.com"), 62 GURL("http://www.google.com"),
61 CONTENT_SETTINGS_TYPE_PLUGINS, 63 CONTENT_SETTINGS_TYPE_PLUGINS,
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 content_settings::OriginIdentifierValueMap map; 114 content_settings::OriginIdentifierValueMap map;
113 EXPECT_TRUE(map.empty()); 115 EXPECT_TRUE(map.empty());
114 116
115 // Set two values. 117 // Set two values.
116 map.SetValue( 118 map.SetValue(
117 ContentSettingsPattern::FromString("[*.]google.com"), 119 ContentSettingsPattern::FromString("[*.]google.com"),
118 ContentSettingsPattern::FromString("[*.]google.com"), 120 ContentSettingsPattern::FromString("[*.]google.com"),
119 CONTENT_SETTINGS_TYPE_PLUGINS, 121 CONTENT_SETTINGS_TYPE_PLUGINS,
120 "java-plugin", 122 "java-plugin",
121 Value::CreateIntegerValue(1)); 123 Value::CreateIntegerValue(1));
122 map.SetValue( 124 map.SetValue(ContentSettingsPattern::FromString("[*.]google.com"),
123 ContentSettingsPattern::FromString("[*.]google.com"), 125 ContentSettingsPattern::FromString("[*.]google.com"),
124 ContentSettingsPattern::FromString("[*.]google.com"), 126 CONTENT_SETTINGS_TYPE_COOKIES,
125 CONTENT_SETTINGS_TYPE_COOKIES, 127 std::string(),
126 "", 128 Value::CreateIntegerValue(1));
127 Value::CreateIntegerValue(1));
128 EXPECT_FALSE(map.empty()); 129 EXPECT_FALSE(map.empty());
129 int actual_value; 130 int actual_value;
130 EXPECT_TRUE(map.GetValue(GURL("http://www.google.com"), 131 EXPECT_TRUE(map.GetValue(GURL("http://www.google.com"),
131 GURL("http://www.google.com"), 132 GURL("http://www.google.com"),
132 CONTENT_SETTINGS_TYPE_PLUGINS, 133 CONTENT_SETTINGS_TYPE_PLUGINS,
133 "java-plugin")->GetAsInteger(&actual_value)); 134 "java-plugin")->GetAsInteger(&actual_value));
134 EXPECT_EQ(1, actual_value); 135 EXPECT_EQ(1, actual_value);
135 136
136 // Clear the map. 137 // Clear the map.
137 map.clear(); 138 map.clear();
138 EXPECT_TRUE(map.empty()); 139 EXPECT_TRUE(map.empty());
139 EXPECT_EQ(NULL, map.GetValue(GURL("http://www.google.com"), 140 EXPECT_EQ(NULL, map.GetValue(GURL("http://www.google.com"),
140 GURL("http://www.google.com"), 141 GURL("http://www.google.com"),
141 CONTENT_SETTINGS_TYPE_PLUGINS, 142 CONTENT_SETTINGS_TYPE_PLUGINS,
142 "java-plugin")); 143 "java-plugin"));
143 } 144 }
144 145
145 TEST(OriginIdentifierValueMapTest, ListEntryPrecedences) { 146 TEST(OriginIdentifierValueMapTest, ListEntryPrecedences) {
146 content_settings::OriginIdentifierValueMap map; 147 content_settings::OriginIdentifierValueMap map;
147 148
148 map.SetValue( 149 map.SetValue(ContentSettingsPattern::FromString("[*.]google.com"),
149 ContentSettingsPattern::FromString("[*.]google.com"), 150 ContentSettingsPattern::FromString("[*.]google.com"),
150 ContentSettingsPattern::FromString("[*.]google.com"), 151 CONTENT_SETTINGS_TYPE_COOKIES,
151 CONTENT_SETTINGS_TYPE_COOKIES, 152 std::string(),
152 "", 153 Value::CreateIntegerValue(1));
153 Value::CreateIntegerValue(1));
154 154
155 map.SetValue( 155 map.SetValue(ContentSettingsPattern::FromString("www.google.com"),
156 ContentSettingsPattern::FromString("www.google.com"), 156 ContentSettingsPattern::FromString("[*.]google.com"),
157 ContentSettingsPattern::FromString("[*.]google.com"), 157 CONTENT_SETTINGS_TYPE_COOKIES,
158 CONTENT_SETTINGS_TYPE_COOKIES, 158 std::string(),
159 "", 159 Value::CreateIntegerValue(2));
160 Value::CreateIntegerValue(2));
161 160
162 int actual_value; 161 int actual_value;
163 EXPECT_TRUE(map.GetValue(GURL("http://mail.google.com"), 162 EXPECT_TRUE(map.GetValue(GURL("http://mail.google.com"),
164 GURL("http://www.google.com"), 163 GURL("http://www.google.com"),
165 CONTENT_SETTINGS_TYPE_COOKIES, 164 CONTENT_SETTINGS_TYPE_COOKIES,
166 "")->GetAsInteger(&actual_value)); 165 std::string())->GetAsInteger(&actual_value));
167 EXPECT_EQ(1, actual_value); 166 EXPECT_EQ(1, actual_value);
168 167
169 EXPECT_TRUE(map.GetValue(GURL("http://www.google.com"), 168 EXPECT_TRUE(map.GetValue(GURL("http://www.google.com"),
170 GURL("http://www.google.com"), 169 GURL("http://www.google.com"),
171 CONTENT_SETTINGS_TYPE_COOKIES, 170 CONTENT_SETTINGS_TYPE_COOKIES,
172 "")->GetAsInteger(&actual_value)); 171 std::string())->GetAsInteger(&actual_value));
173 EXPECT_EQ(2, actual_value); 172 EXPECT_EQ(2, actual_value);
174 } 173 }
175 174
176 TEST(OriginIdentifierValueMapTest, IterateEmpty) { 175 TEST(OriginIdentifierValueMapTest, IterateEmpty) {
177 content_settings::OriginIdentifierValueMap map; 176 content_settings::OriginIdentifierValueMap map;
178 scoped_ptr<content_settings::RuleIterator> rule_iterator( 177 scoped_ptr<content_settings::RuleIterator> rule_iterator(
179 map.GetRuleIterator(CONTENT_SETTINGS_TYPE_COOKIES, "", NULL)); 178 map.GetRuleIterator(CONTENT_SETTINGS_TYPE_COOKIES, std::string(), NULL));
180 EXPECT_FALSE(rule_iterator->HasNext()); 179 EXPECT_FALSE(rule_iterator->HasNext());
181 } 180 }
182 181
183 TEST(OriginIdentifierValueMapTest, IterateNonempty) { 182 TEST(OriginIdentifierValueMapTest, IterateNonempty) {
184 // Verify the precedence order. 183 // Verify the precedence order.
185 content_settings::OriginIdentifierValueMap map; 184 content_settings::OriginIdentifierValueMap map;
186 ContentSettingsPattern pattern = 185 ContentSettingsPattern pattern =
187 ContentSettingsPattern::FromString("[*.]google.com"); 186 ContentSettingsPattern::FromString("[*.]google.com");
188 ContentSettingsPattern sub_pattern = 187 ContentSettingsPattern sub_pattern =
189 ContentSettingsPattern::FromString("sub.google.com"); 188 ContentSettingsPattern::FromString("sub.google.com");
190 map.SetValue( 189 map.SetValue(pattern,
191 pattern, 190 ContentSettingsPattern::Wildcard(),
192 ContentSettingsPattern::Wildcard(), 191 CONTENT_SETTINGS_TYPE_COOKIES,
193 CONTENT_SETTINGS_TYPE_COOKIES, 192 std::string(),
194 "", 193 Value::CreateIntegerValue(1));
195 Value::CreateIntegerValue(1)); 194 map.SetValue(sub_pattern,
196 map.SetValue( 195 ContentSettingsPattern::Wildcard(),
197 sub_pattern, 196 CONTENT_SETTINGS_TYPE_COOKIES,
198 ContentSettingsPattern::Wildcard(), 197 std::string(),
199 CONTENT_SETTINGS_TYPE_COOKIES, 198 Value::CreateIntegerValue(2));
200 "",
201 Value::CreateIntegerValue(2));
202 199
203 scoped_ptr<content_settings::RuleIterator> rule_iterator( 200 scoped_ptr<content_settings::RuleIterator> rule_iterator(
204 map.GetRuleIterator(CONTENT_SETTINGS_TYPE_COOKIES, "", NULL)); 201 map.GetRuleIterator(CONTENT_SETTINGS_TYPE_COOKIES, std::string(), NULL));
205 ASSERT_TRUE(rule_iterator->HasNext()); 202 ASSERT_TRUE(rule_iterator->HasNext());
206 content_settings::Rule rule = rule_iterator->Next(); 203 content_settings::Rule rule = rule_iterator->Next();
207 EXPECT_EQ(sub_pattern, rule.primary_pattern); 204 EXPECT_EQ(sub_pattern, rule.primary_pattern);
208 EXPECT_EQ(2, content_settings::ValueToContentSetting(rule.value.get())); 205 EXPECT_EQ(2, content_settings::ValueToContentSetting(rule.value.get()));
209 206
210 ASSERT_TRUE(rule_iterator->HasNext()); 207 ASSERT_TRUE(rule_iterator->HasNext());
211 rule = rule_iterator->Next(); 208 rule = rule_iterator->Next();
212 EXPECT_EQ(pattern, rule.primary_pattern); 209 EXPECT_EQ(pattern, rule.primary_pattern);
213 EXPECT_EQ(1, content_settings::ValueToContentSetting(rule.value.get())); 210 EXPECT_EQ(1, content_settings::ValueToContentSetting(rule.value.get()));
214 } 211 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698