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

Side by Side Diff: chrome/browser/extensions/api/content_settings/content_settings_store_unittest.cc

Issue 2318223002: Remove EmptyRuleIterators with nullptrs. (Closed)
Patch Set: Fix failing unit test Created 4 years, 3 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/extensions/api/content_settings/content_settings_store. h" 5 #include "chrome/browser/extensions/api/content_settings/content_settings_store. h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <memory> 9 #include <memory>
10 10
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 ContentSetting GetContentSettingFromStore( 53 ContentSetting GetContentSettingFromStore(
54 const ContentSettingsStore* store, 54 const ContentSettingsStore* store,
55 const GURL& primary_url, const GURL& secondary_url, 55 const GURL& primary_url, const GURL& secondary_url,
56 ContentSettingsType content_type, 56 ContentSettingsType content_type,
57 const std::string& resource_identifier, 57 const std::string& resource_identifier,
58 bool incognito) { 58 bool incognito) {
59 std::unique_ptr<content_settings::RuleIterator> rule_iterator( 59 std::unique_ptr<content_settings::RuleIterator> rule_iterator(
60 store->GetRuleIterator(content_type, resource_identifier, incognito)); 60 store->GetRuleIterator(content_type, resource_identifier, incognito));
61 std::unique_ptr<base::Value> setting( 61 std::unique_ptr<base::Value> setting(
62 content_settings::TestUtils::GetContentSettingValueAndPatterns( 62 content_settings::TestUtils::GetContentSettingValueAndPatterns(
63 rule_iterator.get(), primary_url, secondary_url, NULL, NULL)); 63 rule_iterator.get(), primary_url, secondary_url, nullptr, nullptr));
64 return content_settings::ValueToContentSetting(setting.get()); 64 return content_settings::ValueToContentSetting(setting.get());
65 } 65 }
66 66
67 void GetSettingsForOneTypeFromStore( 67 std::vector<content_settings::Rule> GetSettingsForOneTypeFromStore(
68 const ContentSettingsStore* store, 68 const ContentSettingsStore* store,
69 ContentSettingsType content_type, 69 ContentSettingsType content_type,
70 const std::string& resource_identifier, 70 const std::string& resource_identifier,
71 bool incognito, 71 bool incognito) {
72 std::vector<content_settings::Rule>* rules) { 72 std::vector<content_settings::Rule> rules;
73 rules->clear();
74 std::unique_ptr<content_settings::RuleIterator> rule_iterator( 73 std::unique_ptr<content_settings::RuleIterator> rule_iterator(
75 store->GetRuleIterator(content_type, resource_identifier, incognito)); 74 store->GetRuleIterator(content_type, resource_identifier, incognito));
76 while (rule_iterator->HasNext()) 75 if (rule_iterator) {
77 rules->push_back(rule_iterator->Next()); 76 while (rule_iterator->HasNext())
77 rules.push_back(rule_iterator->Next());
78 }
79 return rules;
78 } 80 }
79 81
80 } // namespace 82 } // namespace
81 83
82 class ContentSettingsStoreTest : public ::testing::Test { 84 class ContentSettingsStoreTest : public ::testing::Test {
83 public: 85 public:
84 ContentSettingsStoreTest() : 86 ContentSettingsStoreTest() :
85 store_(new ContentSettingsStore()) { 87 store_(new ContentSettingsStore()) {
86 } 88 }
87 89
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 url, 189 url,
188 url, 190 url,
189 CONTENT_SETTINGS_TYPE_COOKIES, 191 CONTENT_SETTINGS_TYPE_COOKIES,
190 std::string(), 192 std::string(),
191 false)); 193 false));
192 194
193 store()->RemoveObserver(&observer); 195 store()->RemoveObserver(&observer);
194 } 196 }
195 197
196 TEST_F(ContentSettingsStoreTest, GetAllSettings) { 198 TEST_F(ContentSettingsStoreTest, GetAllSettings) {
197 bool incognito = false; 199 const bool incognito = false;
198 std::vector<content_settings::Rule> rules; 200 std::vector<content_settings::Rule> rules = GetSettingsForOneTypeFromStore(
199 GetSettingsForOneTypeFromStore( 201 store(), CONTENT_SETTINGS_TYPE_COOKIES, std::string(), incognito);
200 store(), CONTENT_SETTINGS_TYPE_COOKIES, std::string(), incognito, &rules);
201 ASSERT_EQ(0u, rules.size()); 202 ASSERT_EQ(0u, rules.size());
202 203
203 // Register first extension. 204 // Register first extension.
204 std::string ext_id("my_extension"); 205 std::string ext_id("my_extension");
205 RegisterExtension(ext_id); 206 RegisterExtension(ext_id);
206 ContentSettingsPattern pattern = 207 ContentSettingsPattern pattern =
207 ContentSettingsPattern::FromURL(GURL("http://www.youtube.com")); 208 ContentSettingsPattern::FromURL(GURL("http://www.youtube.com"));
208 store()->SetExtensionContentSetting(ext_id, 209 store()->SetExtensionContentSetting(ext_id,
209 pattern, 210 pattern,
210 pattern, 211 pattern,
211 CONTENT_SETTINGS_TYPE_COOKIES, 212 CONTENT_SETTINGS_TYPE_COOKIES,
212 std::string(), 213 std::string(),
213 CONTENT_SETTING_ALLOW, 214 CONTENT_SETTING_ALLOW,
214 kExtensionPrefsScopeRegular); 215 kExtensionPrefsScopeRegular);
215 216
216 GetSettingsForOneTypeFromStore( 217 rules = GetSettingsForOneTypeFromStore(store(), CONTENT_SETTINGS_TYPE_COOKIES,
217 store(), CONTENT_SETTINGS_TYPE_COOKIES, std::string(), incognito, &rules); 218 std::string(), incognito);
218 ASSERT_EQ(1u, rules.size()); 219 ASSERT_EQ(1u, rules.size());
219 CheckRule(rules[0], pattern, pattern, CONTENT_SETTING_ALLOW); 220 CheckRule(rules[0], pattern, pattern, CONTENT_SETTING_ALLOW);
220 221
221 // Register second extension. 222 // Register second extension.
222 std::string ext_id_2("my_second_extension"); 223 std::string ext_id_2("my_second_extension");
223 RegisterExtension(ext_id_2); 224 RegisterExtension(ext_id_2);
224 ContentSettingsPattern pattern_2 = 225 ContentSettingsPattern pattern_2 =
225 ContentSettingsPattern::FromURL(GURL("http://www.example.com")); 226 ContentSettingsPattern::FromURL(GURL("http://www.example.com"));
226 store()->SetExtensionContentSetting(ext_id_2, 227 store()->SetExtensionContentSetting(ext_id_2,
227 pattern_2, 228 pattern_2,
228 pattern_2, 229 pattern_2,
229 CONTENT_SETTINGS_TYPE_COOKIES, 230 CONTENT_SETTINGS_TYPE_COOKIES,
230 std::string(), 231 std::string(),
231 CONTENT_SETTING_BLOCK, 232 CONTENT_SETTING_BLOCK,
232 kExtensionPrefsScopeRegular); 233 kExtensionPrefsScopeRegular);
233 234
234 GetSettingsForOneTypeFromStore( 235 rules = GetSettingsForOneTypeFromStore(store(), CONTENT_SETTINGS_TYPE_COOKIES,
235 store(), CONTENT_SETTINGS_TYPE_COOKIES, std::string(), incognito, &rules); 236 std::string(), incognito);
236 ASSERT_EQ(2u, rules.size()); 237 ASSERT_EQ(2u, rules.size());
237 // Rules appear in the reverse installation order of the extensions. 238 // Rules appear in the reverse installation order of the extensions.
238 CheckRule(rules[0], pattern_2, pattern_2, CONTENT_SETTING_BLOCK); 239 CheckRule(rules[0], pattern_2, pattern_2, CONTENT_SETTING_BLOCK);
239 CheckRule(rules[1], pattern, pattern, CONTENT_SETTING_ALLOW); 240 CheckRule(rules[1], pattern, pattern, CONTENT_SETTING_ALLOW);
240 241
241 // Disable first extension. 242 // Disable first extension.
242 store()->SetExtensionState(ext_id, false); 243 store()->SetExtensionState(ext_id, false);
243 244
244 GetSettingsForOneTypeFromStore( 245 rules = GetSettingsForOneTypeFromStore(store(), CONTENT_SETTINGS_TYPE_COOKIES,
245 store(), CONTENT_SETTINGS_TYPE_COOKIES, std::string(), incognito, &rules); 246 std::string(), incognito);
246 ASSERT_EQ(1u, rules.size()); 247 ASSERT_EQ(1u, rules.size());
247 CheckRule(rules[0], pattern_2, pattern_2, CONTENT_SETTING_BLOCK); 248 CheckRule(rules[0], pattern_2, pattern_2, CONTENT_SETTING_BLOCK);
248 249
249 // Uninstall second extension. 250 // Uninstall second extension.
250 store()->UnregisterExtension(ext_id_2); 251 store()->UnregisterExtension(ext_id_2);
251 252
252 GetSettingsForOneTypeFromStore( 253 rules = GetSettingsForOneTypeFromStore(store(), CONTENT_SETTINGS_TYPE_COOKIES,
253 store(), CONTENT_SETTINGS_TYPE_COOKIES, std::string(), incognito, &rules); 254 std::string(), incognito);
254 ASSERT_EQ(0u, rules.size()); 255 ASSERT_EQ(0u, rules.size());
255 } 256 }
256 257
257 } // namespace extensions 258 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698