OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
vabr (Chromium)
2013/10/29 16:05:54
Again, the filename of this unittest is slightly c
| |
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.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 |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
13 #include "chrome/browser/extensions/api/declarative/rules_cache_delegate.h" | |
13 #include "chrome/browser/extensions/api/declarative/test_rules_registry.h" | 14 #include "chrome/browser/extensions/api/declarative/test_rules_registry.h" |
14 #include "chrome/browser/extensions/extension_prefs.h" | 15 #include "chrome/browser/extensions/extension_prefs.h" |
15 #include "chrome/browser/extensions/extension_service.h" | 16 #include "chrome/browser/extensions/extension_service.h" |
16 #include "chrome/browser/extensions/test_extension_system.h" | 17 #include "chrome/browser/extensions/test_extension_system.h" |
17 #include "chrome/browser/value_store/testing_value_store.h" | 18 #include "chrome/browser/value_store/testing_value_store.h" |
18 #include "chrome/common/extensions/extension.h" | 19 #include "chrome/common/extensions/extension.h" |
19 #include "chrome/common/extensions/extension_test_util.h" | 20 #include "chrome/common/extensions/extension_test_util.h" |
20 #include "chrome/test/base/testing_profile.h" | 21 #include "chrome/test/base/testing_profile.h" |
21 #include "content/public/test/test_browser_thread.h" | 22 #include "content/public/test/test_browser_thread.h" |
22 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
102 | 103 |
103 TEST_F(RulesRegistryWithCacheTest, AddRules) { | 104 TEST_F(RulesRegistryWithCacheTest, AddRules) { |
104 // Check that nothing happens if the concrete RulesRegistry refuses to insert | 105 // Check that nothing happens if the concrete RulesRegistry refuses to insert |
105 // the rules. | 106 // the rules. |
106 registry_->SetResult("Error"); | 107 registry_->SetResult("Error"); |
107 EXPECT_EQ("Error", AddRule(kExtensionId, kRuleId)); | 108 EXPECT_EQ("Error", AddRule(kExtensionId, kRuleId)); |
108 EXPECT_EQ(0, GetNumberOfRules(kExtensionId)); | 109 EXPECT_EQ(0, GetNumberOfRules(kExtensionId)); |
109 registry_->SetResult(std::string()); | 110 registry_->SetResult(std::string()); |
110 | 111 |
111 // Check that rules can be inserted. | 112 // Check that rules can be inserted. |
112 EXPECT_EQ("", AddRule(kExtensionId, kRuleId)); | 113 EXPECT_EQ("", AddRule(kExtensionId, kRule2Id)); |
vabr (Chromium)
2013/10/29 16:05:54
Just out of curiosity, why this change? :)
(No nee
| |
113 EXPECT_EQ(1, GetNumberOfRules(kExtensionId)); | 114 EXPECT_EQ(1, GetNumberOfRules(kExtensionId)); |
114 | 115 |
115 // Check that rules cannot be inserted twice with the same kRuleId. | 116 // Check that rules cannot be inserted twice with the same kRuleId. |
116 EXPECT_NE("", AddRule(kExtensionId, kRuleId)); | 117 EXPECT_NE("", AddRule(kExtensionId, kRuleId)); |
117 EXPECT_EQ(1, GetNumberOfRules(kExtensionId)); | 118 EXPECT_EQ(1, GetNumberOfRules(kExtensionId)); |
118 | 119 |
119 // Check that different extensions may use the same kRuleId. | 120 // Check that different extensions may use the same kRuleId. |
120 EXPECT_EQ("", AddRule(kExtension2Id, kRuleId)); | 121 EXPECT_EQ("", AddRule(kExtension2Id, kRuleId)); |
121 EXPECT_EQ(1, GetNumberOfRules(kExtensionId)); | 122 EXPECT_EQ(1, GetNumberOfRules(kExtensionId)); |
122 EXPECT_EQ(1, GetNumberOfRules(kExtension2Id)); | 123 EXPECT_EQ(1, GetNumberOfRules(kExtension2Id)); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
222 extensions::ExtensionSystem::Get(&profile)); | 223 extensions::ExtensionSystem::Get(&profile)); |
223 ExtensionPrefs* extension_prefs = system->CreateExtensionPrefs( | 224 ExtensionPrefs* extension_prefs = system->CreateExtensionPrefs( |
224 CommandLine::ForCurrentProcess(), base::FilePath()); | 225 CommandLine::ForCurrentProcess(), base::FilePath()); |
225 system->CreateExtensionService( | 226 system->CreateExtensionService( |
226 CommandLine::ForCurrentProcess(), base::FilePath(), false); | 227 CommandLine::ForCurrentProcess(), base::FilePath(), false); |
227 // The value store is first created during CreateExtensionService. | 228 // The value store is first created during CreateExtensionService. |
228 TestingValueStore* store = system->value_store(); | 229 TestingValueStore* store = system->value_store(); |
229 | 230 |
230 const std::string event_name("testEvent"); | 231 const std::string event_name("testEvent"); |
231 const std::string rules_stored_key( | 232 const std::string rules_stored_key( |
232 RulesRegistryWithCache::RuleStorageOnUI::GetRulesStoredKey( | 233 RulesCacheDelegate::GetRulesStoredKey( |
233 event_name, profile.IsOffTheRecord())); | 234 event_name, profile.IsOffTheRecord())); |
234 scoped_ptr<RulesRegistryWithCache::RuleStorageOnUI> ui_part; | 235 scoped_ptr<RulesCacheDelegate> ui_part; |
235 scoped_refptr<RulesRegistryWithCache> registry(new TestRulesRegistry( | 236 scoped_refptr<RulesRegistry> 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)); |
244 EXPECT_FALSE(ui_part->GetDeclarativeRulesStored(kExtensionId)); | 245 EXPECT_FALSE(ui_part->GetDeclarativeRulesStored(kExtensionId)); |
245 | 246 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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"); |
303 const std::string rules_stored_key1( | 304 const std::string rules_stored_key1( |
304 RulesRegistryWithCache::RuleStorageOnUI::GetRulesStoredKey( | 305 RulesCacheDelegate::GetRulesStoredKey( |
305 event_name1, profile.IsOffTheRecord())); | 306 event_name1, profile.IsOffTheRecord())); |
306 const std::string rules_stored_key2( | 307 const std::string rules_stored_key2( |
307 RulesRegistryWithCache::RuleStorageOnUI::GetRulesStoredKey( | 308 RulesCacheDelegate::GetRulesStoredKey( |
308 event_name2, profile.IsOffTheRecord())); | 309 event_name2, profile.IsOffTheRecord())); |
309 scoped_ptr<RulesRegistryWithCache::RuleStorageOnUI> ui_part1; | 310 scoped_ptr<RulesCacheDelegate> ui_part1; |
310 scoped_refptr<RulesRegistryWithCache> registry1(new TestRulesRegistry( | 311 scoped_refptr<RulesRegistry> registry1(new TestRulesRegistry( |
311 &profile, event_name1, content::BrowserThread::UI, &ui_part1)); | 312 &profile, event_name1, content::BrowserThread::UI, &ui_part1)); |
312 scoped_ptr<RulesRegistryWithCache::RuleStorageOnUI> ui_part2; | 313 scoped_ptr<RulesCacheDelegate> ui_part2; |
313 scoped_refptr<RulesRegistryWithCache> registry2(new TestRulesRegistry( | 314 scoped_refptr<RulesRegistry> registry2(new TestRulesRegistry( |
314 &profile, event_name2, content::BrowserThread::UI, &ui_part2)); | 315 &profile, event_name2, content::BrowserThread::UI, &ui_part2)); |
315 | 316 |
316 // Checkt the correct default values. | 317 // Checkt the correct default values. |
317 EXPECT_TRUE(ui_part1->GetDeclarativeRulesStored(kExtensionId)); | 318 EXPECT_TRUE(ui_part1->GetDeclarativeRulesStored(kExtensionId)); |
318 EXPECT_TRUE(ui_part2->GetDeclarativeRulesStored(kExtensionId)); | 319 EXPECT_TRUE(ui_part2->GetDeclarativeRulesStored(kExtensionId)); |
319 | 320 |
320 // Update the flag for the first registry. | 321 // Update the flag for the first registry. |
321 extension_prefs->UpdateExtensionPref( | 322 extension_prefs->UpdateExtensionPref( |
322 kExtensionId, rules_stored_key1, new base::FundamentalValue(false)); | 323 kExtensionId, rules_stored_key1, new base::FundamentalValue(false)); |
323 EXPECT_FALSE(ui_part1->GetDeclarativeRulesStored(kExtensionId)); | 324 EXPECT_FALSE(ui_part1->GetDeclarativeRulesStored(kExtensionId)); |
(...skipping 18 matching lines...) Expand all Loading... | |
342 "web_request_all_host_permissions.json", | 343 "web_request_all_host_permissions.json", |
343 Manifest::INVALID_LOCATION, | 344 Manifest::INVALID_LOCATION, |
344 Extension::NO_FLAGS, | 345 Extension::NO_FLAGS, |
345 kExtensionId, | 346 kExtensionId, |
346 &error)); | 347 &error)); |
347 ASSERT_TRUE(error.empty()); | 348 ASSERT_TRUE(error.empty()); |
348 extension_service->AddExtension(extension.get()); | 349 extension_service->AddExtension(extension.get()); |
349 system->SetReady(); | 350 system->SetReady(); |
350 | 351 |
351 // 2. First run, adding a rule for the extension. | 352 // 2. First run, adding a rule for the extension. |
352 scoped_ptr<RulesRegistryWithCache::RuleStorageOnUI> ui_part; | 353 scoped_ptr<RulesCacheDelegate> ui_part; |
353 scoped_refptr<TestRulesRegistry> registry(new TestRulesRegistry( | 354 scoped_refptr<TestRulesRegistry> registry(new TestRulesRegistry( |
354 &profile, "testEvent", content::BrowserThread::UI, &ui_part)); | 355 &profile, "testEvent", content::BrowserThread::UI, &ui_part)); |
355 AddRule(kExtensionId, kRuleId, registry.get()); | 356 AddRule(kExtensionId, kRuleId, registry.get()); |
356 message_loop_.RunUntilIdle(); // Posted tasks store the added rule. | 357 message_loop_.RunUntilIdle(); // Posted tasks store the added rule. |
357 EXPECT_EQ(1, GetNumberOfRules(kExtensionId, registry.get())); | 358 EXPECT_EQ(1, GetNumberOfRules(kExtensionId, registry.get())); |
358 | 359 |
359 // 3. Restart the TestRulesRegistry and see the rule still there. | 360 // 3. Restart the TestRulesRegistry and see the rule still there. |
360 registry = new TestRulesRegistry( | 361 registry = new TestRulesRegistry( |
361 &profile, "testEvent", content::BrowserThread::UI, &ui_part); | 362 &profile, "testEvent", content::BrowserThread::UI, &ui_part); |
362 message_loop_.RunUntilIdle(); // Posted tasks retrieve the stored rule. | 363 message_loop_.RunUntilIdle(); // Posted tasks retrieve the stored rule. |
363 EXPECT_EQ(1, GetNumberOfRules(kExtensionId, registry.get())); | 364 EXPECT_EQ(1, GetNumberOfRules(kExtensionId, registry.get())); |
364 } | 365 } |
365 | 366 |
366 } // namespace extensions | 367 } // namespace extensions |
OLD | NEW |