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

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: Added tests 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_with_cache.h" 5 #include "chrome/browser/extensions/api/declarative/rules_registry_with_cache.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 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 static_cast<extensions::TestExtensionSystem*>( 221 static_cast<extensions::TestExtensionSystem*>(
222 extensions::ExtensionSystem::Get(&profile)); 222 extensions::ExtensionSystem::Get(&profile));
223 ExtensionPrefs* extension_prefs = system->CreateExtensionPrefs( 223 ExtensionPrefs* extension_prefs = system->CreateExtensionPrefs(
224 CommandLine::ForCurrentProcess(), base::FilePath()); 224 CommandLine::ForCurrentProcess(), base::FilePath());
225 system->CreateExtensionService( 225 system->CreateExtensionService(
226 CommandLine::ForCurrentProcess(), base::FilePath(), false); 226 CommandLine::ForCurrentProcess(), base::FilePath(), false);
227 // The value store is first created during CreateExtensionService. 227 // The value store is first created during CreateExtensionService.
228 TestingValueStore* store = system->value_store(); 228 TestingValueStore* store = system->value_store();
229 229
230 const std::string event_name("testEvent"); 230 const std::string event_name("testEvent");
231 const RulesRegistry::WebViewKey key(0, 0);
231 const std::string rules_stored_key( 232 const std::string rules_stored_key(
232 RulesRegistryWithCache::RuleStorageOnUI::GetRulesStoredKey( 233 RulesRegistryWithCache::RuleStorageOnUI::GetRulesStoredKey(
233 event_name, profile.IsOffTheRecord())); 234 event_name, profile.IsOffTheRecord(), key));
234 scoped_ptr<RulesRegistryWithCache::RuleStorageOnUI> ui_part; 235 scoped_ptr<RulesRegistryWithCache::RuleStorageOnUI> ui_part;
235 scoped_refptr<RulesRegistryWithCache> registry(new TestRulesRegistry( 236 scoped_refptr<RulesRegistryWithCache> registry(new TestRulesRegistry(
236 &profile, event_name, content::BrowserThread::UI, &ui_part)); 237 &profile, event_name, content::BrowserThread::UI, &ui_part));
237 238
238 // 1. Test the handling of preferences. 239 // 1. Test the handling of preferences.
239 // Default value is always true. 240 // Default value is always true.
240 EXPECT_TRUE(ui_part->GetDeclarativeRulesStored(kExtensionId)); 241 EXPECT_TRUE(ui_part->GetDeclarativeRulesStored(kExtensionId));
241 242
242 extension_prefs->UpdateExtensionPref( 243 extension_prefs->UpdateExtensionPref(
243 kExtensionId, rules_stored_key, new base::FundamentalValue(false)); 244 kExtensionId, rules_stored_key, new base::FundamentalValue(false));
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 // TestingProfile::Init makes sure that the factory method for a corresponding 294 // TestingProfile::Init makes sure that the factory method for a corresponding
294 // extension system creates a TestExtensionSystem. 295 // extension system creates a TestExtensionSystem.
295 extensions::TestExtensionSystem* system = 296 extensions::TestExtensionSystem* system =
296 static_cast<extensions::TestExtensionSystem*>( 297 static_cast<extensions::TestExtensionSystem*>(
297 extensions::ExtensionSystem::Get(&profile)); 298 extensions::ExtensionSystem::Get(&profile));
298 ExtensionPrefs* extension_prefs = system->CreateExtensionPrefs( 299 ExtensionPrefs* extension_prefs = system->CreateExtensionPrefs(
299 CommandLine::ForCurrentProcess(), base::FilePath()); 300 CommandLine::ForCurrentProcess(), base::FilePath());
300 301
301 const std::string event_name1("testEvent1"); 302 const std::string event_name1("testEvent1");
302 const std::string event_name2("testEvent2"); 303 const std::string event_name2("testEvent2");
304 const RulesRegistry::WebViewKey key(0, 0);
303 const std::string rules_stored_key1( 305 const std::string rules_stored_key1(
304 RulesRegistryWithCache::RuleStorageOnUI::GetRulesStoredKey( 306 RulesRegistryWithCache::RuleStorageOnUI::GetRulesStoredKey(
305 event_name1, profile.IsOffTheRecord())); 307 event_name1, profile.IsOffTheRecord(), key));
306 const std::string rules_stored_key2( 308 const std::string rules_stored_key2(
307 RulesRegistryWithCache::RuleStorageOnUI::GetRulesStoredKey( 309 RulesRegistryWithCache::RuleStorageOnUI::GetRulesStoredKey(
308 event_name2, profile.IsOffTheRecord())); 310 event_name2, profile.IsOffTheRecord(), key));
309 scoped_ptr<RulesRegistryWithCache::RuleStorageOnUI> ui_part1; 311 scoped_ptr<RulesRegistryWithCache::RuleStorageOnUI> ui_part1;
310 scoped_refptr<RulesRegistryWithCache> registry1(new TestRulesRegistry( 312 scoped_refptr<RulesRegistryWithCache> registry1(new TestRulesRegistry(
311 &profile, event_name1, content::BrowserThread::UI, &ui_part1)); 313 &profile, event_name1, content::BrowserThread::UI, &ui_part1));
312 scoped_ptr<RulesRegistryWithCache::RuleStorageOnUI> ui_part2; 314 scoped_ptr<RulesRegistryWithCache::RuleStorageOnUI> ui_part2;
313 scoped_refptr<RulesRegistryWithCache> registry2(new TestRulesRegistry( 315 scoped_refptr<RulesRegistryWithCache> registry2(new TestRulesRegistry(
314 &profile, event_name2, content::BrowserThread::UI, &ui_part2)); 316 &profile, event_name2, content::BrowserThread::UI, &ui_part2));
315 317
316 // Checkt the correct default values. 318 // Checkt the correct default values.
317 EXPECT_TRUE(ui_part1->GetDeclarativeRulesStored(kExtensionId)); 319 EXPECT_TRUE(ui_part1->GetDeclarativeRulesStored(kExtensionId));
318 EXPECT_TRUE(ui_part2->GetDeclarativeRulesStored(kExtensionId)); 320 EXPECT_TRUE(ui_part2->GetDeclarativeRulesStored(kExtensionId));
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 EXPECT_EQ(1, GetNumberOfRules(kExtensionId, registry.get())); 359 EXPECT_EQ(1, GetNumberOfRules(kExtensionId, registry.get()));
358 360
359 // 3. Restart the TestRulesRegistry and see the rule still there. 361 // 3. Restart the TestRulesRegistry and see the rule still there.
360 registry = new TestRulesRegistry( 362 registry = new TestRulesRegistry(
361 &profile, "testEvent", content::BrowserThread::UI, &ui_part); 363 &profile, "testEvent", content::BrowserThread::UI, &ui_part);
362 message_loop_.RunUntilIdle(); // Posted tasks retrieve the stored rule. 364 message_loop_.RunUntilIdle(); // Posted tasks retrieve the stored rule.
363 EXPECT_EQ(1, GetNumberOfRules(kExtensionId, registry.get())); 365 EXPECT_EQ(1, GetNumberOfRules(kExtensionId, registry.get()));
364 } 366 }
365 367
366 } // namespace extensions 368 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698