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

Side by Side Diff: chrome/browser/extensions/api/declarative/rules_registry_with_cache_unittest.cc

Issue 28273006: <webview>: Implement declarativeWebRequest API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed browser_tests build Created 7 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) 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/declarative/rules_registry.h" 5 #include "chrome/browser/extensions/api/declarative/rules_registry.h"
6 6
7 // Here we test the TestRulesRegistry which is the simplest possible 7 // Here we test the TestRulesRegistry which is the simplest possible
8 // implementation of RulesRegistryWithCache as a proxy for 8 // implementation of RulesRegistryWithCache as a proxy for
9 // RulesRegistryWithCache. 9 // RulesRegistryWithCache.
10 10
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 // Prime registry. 207 // Prime registry.
208 EXPECT_EQ("", AddRule(kExtensionId, kRuleId)); 208 EXPECT_EQ("", AddRule(kExtensionId, kRuleId));
209 EXPECT_EQ("", AddRule(kExtension2Id, kRuleId)); 209 EXPECT_EQ("", AddRule(kExtension2Id, kRuleId));
210 210
211 // Check that the correct rules are removed. 211 // Check that the correct rules are removed.
212 registry_->OnExtensionUnloaded(kExtensionId); 212 registry_->OnExtensionUnloaded(kExtensionId);
213 EXPECT_EQ(0, GetNumberOfRules(kExtensionId)); 213 EXPECT_EQ(0, GetNumberOfRules(kExtensionId));
214 EXPECT_EQ(1, GetNumberOfRules(kExtension2Id)); 214 EXPECT_EQ(1, GetNumberOfRules(kExtension2Id));
215 } 215 }
216 216
217 TEST_F(RulesRegistryWithCacheTest, DeclarativeRulesStored) { 217 TEST_F(RulesRegistryWithCacheTest, DeclarativeRulesStored) {
Jeffrey Yasskin 2013/11/09 02:47:22 We should also have a test that for webview regist
Fady Samuel 2013/11/10 03:39:56 This is enforced by the RulesRegistryService. I ad
218 TestingProfile profile; 218 TestingProfile profile;
219 // TestingProfile::Init makes sure that the factory method for a corresponding 219 // TestingProfile::Init makes sure that the factory method for a corresponding
220 // extension system creates a TestExtensionSystem. 220 // extension system creates a TestExtensionSystem.
221 extensions::TestExtensionSystem* system = 221 extensions::TestExtensionSystem* system =
222 static_cast<extensions::TestExtensionSystem*>( 222 static_cast<extensions::TestExtensionSystem*>(
223 extensions::ExtensionSystem::Get(&profile)); 223 extensions::ExtensionSystem::Get(&profile));
224 ExtensionPrefs* extension_prefs = system->CreateExtensionPrefs( 224 ExtensionPrefs* extension_prefs = system->CreateExtensionPrefs(
225 CommandLine::ForCurrentProcess(), base::FilePath()); 225 CommandLine::ForCurrentProcess(), base::FilePath());
226 system->CreateExtensionService( 226 system->CreateExtensionService(
227 CommandLine::ForCurrentProcess(), base::FilePath(), false); 227 CommandLine::ForCurrentProcess(), base::FilePath(), false);
228 // The value store is first created during CreateExtensionService. 228 // The value store is first created during CreateExtensionService.
229 TestingValueStore* store = system->value_store(); 229 TestingValueStore* store = system->value_store();
230 230
231 const std::string event_name("testEvent"); 231 const std::string event_name("testEvent");
232 const RulesRegistry::WebViewKey key(0, 0);
232 const std::string rules_stored_key( 233 const std::string rules_stored_key(
233 RulesCacheDelegate::GetRulesStoredKey( 234 RulesCacheDelegate::GetRulesStoredKey(
234 event_name, profile.IsOffTheRecord())); 235 event_name, profile.IsOffTheRecord()));
235 scoped_ptr<RulesCacheDelegate> cache_delegate(new RulesCacheDelegate(false)); 236 scoped_ptr<RulesCacheDelegate> cache_delegate(new RulesCacheDelegate(false));
236 scoped_refptr<RulesRegistry> registry(new TestRulesRegistry( 237 scoped_refptr<RulesRegistry> registry(new TestRulesRegistry(
237 &profile, event_name, content::BrowserThread::UI, cache_delegate.get())); 238 &profile, event_name, content::BrowserThread::UI,
239 cache_delegate.get()));
238 240
239 // 1. Test the handling of preferences. 241 // 1. Test the handling of preferences.
240 // Default value is always true. 242 // Default value is always true.
241 EXPECT_TRUE(cache_delegate->GetDeclarativeRulesStored(kExtensionId)); 243 EXPECT_TRUE(cache_delegate->GetDeclarativeRulesStored(kExtensionId));
242 244
243 extension_prefs->UpdateExtensionPref( 245 extension_prefs->UpdateExtensionPref(
244 kExtensionId, rules_stored_key, new base::FundamentalValue(false)); 246 kExtensionId, rules_stored_key, new base::FundamentalValue(false));
245 EXPECT_FALSE(cache_delegate->GetDeclarativeRulesStored(kExtensionId)); 247 EXPECT_FALSE(cache_delegate->GetDeclarativeRulesStored(kExtensionId));
246 248
247 extension_prefs->UpdateExtensionPref( 249 extension_prefs->UpdateExtensionPref(
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 // TestingProfile::Init makes sure that the factory method for a corresponding 296 // TestingProfile::Init makes sure that the factory method for a corresponding
295 // extension system creates a TestExtensionSystem. 297 // extension system creates a TestExtensionSystem.
296 extensions::TestExtensionSystem* system = 298 extensions::TestExtensionSystem* system =
297 static_cast<extensions::TestExtensionSystem*>( 299 static_cast<extensions::TestExtensionSystem*>(
298 extensions::ExtensionSystem::Get(&profile)); 300 extensions::ExtensionSystem::Get(&profile));
299 ExtensionPrefs* extension_prefs = system->CreateExtensionPrefs( 301 ExtensionPrefs* extension_prefs = system->CreateExtensionPrefs(
300 CommandLine::ForCurrentProcess(), base::FilePath()); 302 CommandLine::ForCurrentProcess(), base::FilePath());
301 303
302 const std::string event_name1("testEvent1"); 304 const std::string event_name1("testEvent1");
303 const std::string event_name2("testEvent2"); 305 const std::string event_name2("testEvent2");
306 const RulesRegistry::WebViewKey key(0, 0);
304 const std::string rules_stored_key1( 307 const std::string rules_stored_key1(
305 RulesCacheDelegate::GetRulesStoredKey( 308 RulesCacheDelegate::GetRulesStoredKey(
306 event_name1, profile.IsOffTheRecord())); 309 event_name1, profile.IsOffTheRecord()));
307 const std::string rules_stored_key2( 310 const std::string rules_stored_key2(
308 RulesCacheDelegate::GetRulesStoredKey( 311 RulesCacheDelegate::GetRulesStoredKey(
309 event_name2, profile.IsOffTheRecord())); 312 event_name2, profile.IsOffTheRecord()));
310 scoped_ptr<RulesCacheDelegate> cache_delegate1(new RulesCacheDelegate(false)); 313 scoped_ptr<RulesCacheDelegate> cache_delegate1(new RulesCacheDelegate(false));
311 scoped_refptr<RulesRegistry> registry1(new TestRulesRegistry( 314 scoped_refptr<RulesRegistry> registry1(new TestRulesRegistry(
312 &profile, event_name1, content::BrowserThread::UI, 315 &profile, event_name1, content::BrowserThread::UI,
313 cache_delegate1.get())); 316 cache_delegate1.get()));
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 // 2. First run, adding a rule for the extension. 358 // 2. First run, adding a rule for the extension.
356 scoped_ptr<RulesCacheDelegate> cache_delegate(new RulesCacheDelegate(false)); 359 scoped_ptr<RulesCacheDelegate> cache_delegate(new RulesCacheDelegate(false));
357 scoped_refptr<TestRulesRegistry> registry(new TestRulesRegistry( 360 scoped_refptr<TestRulesRegistry> registry(new TestRulesRegistry(
358 &profile, "testEvent", content::BrowserThread::UI, cache_delegate.get())); 361 &profile, "testEvent", content::BrowserThread::UI, cache_delegate.get()));
359 362
360 AddRule(kExtensionId, kRuleId, registry.get()); 363 AddRule(kExtensionId, kRuleId, registry.get());
361 message_loop_.RunUntilIdle(); // Posted tasks store the added rule. 364 message_loop_.RunUntilIdle(); // Posted tasks store the added rule.
362 EXPECT_EQ(1, GetNumberOfRules(kExtensionId, registry.get())); 365 EXPECT_EQ(1, GetNumberOfRules(kExtensionId, registry.get()));
363 366
364 // 3. Restart the TestRulesRegistry and see the rule still there. 367 // 3. Restart the TestRulesRegistry and see the rule still there.
365 cache_delegate.reset( 368 cache_delegate.reset(new RulesCacheDelegate(false));
366 new RulesCacheDelegate(false));
367 registry = new TestRulesRegistry( 369 registry = new TestRulesRegistry(
368 &profile, "testEvent", content::BrowserThread::UI, cache_delegate.get()); 370 &profile, "testEvent", content::BrowserThread::UI, cache_delegate.get());
369 371
370 message_loop_.RunUntilIdle(); // Posted tasks retrieve the stored rule. 372 message_loop_.RunUntilIdle(); // Posted tasks retrieve the stored rule.
371 EXPECT_EQ(1, GetNumberOfRules(kExtensionId, registry.get())); 373 EXPECT_EQ(1, GetNumberOfRules(kExtensionId, registry.get()));
372 } 374 }
373 375
374 } // namespace extensions 376 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698