OLD | NEW |
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 "extensions/browser/api/declarative/rules_registry.h" | 5 #include "extensions/browser/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 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 new RulesCacheDelegate(false)); | 235 new RulesCacheDelegate(false)); |
236 scoped_refptr<RulesRegistry> registry( | 236 scoped_refptr<RulesRegistry> registry( |
237 new TestRulesRegistry(profile(), event_name, content::BrowserThread::UI, | 237 new TestRulesRegistry(profile(), event_name, content::BrowserThread::UI, |
238 cache_delegate.get(), kRulesRegistryID)); | 238 cache_delegate.get(), kRulesRegistryID)); |
239 | 239 |
240 // 1. Test the handling of preferences. | 240 // 1. Test the handling of preferences. |
241 // Default value is always true. | 241 // Default value is always true. |
242 EXPECT_TRUE(cache_delegate->GetDeclarativeRulesStored(extension1_->id())); | 242 EXPECT_TRUE(cache_delegate->GetDeclarativeRulesStored(extension1_->id())); |
243 | 243 |
244 extension_prefs->UpdateExtensionPref( | 244 extension_prefs->UpdateExtensionPref( |
245 extension1_->id(), rules_stored_key, new base::FundamentalValue(false)); | 245 extension1_->id(), rules_stored_key, new base::Value(false)); |
246 EXPECT_FALSE(cache_delegate->GetDeclarativeRulesStored(extension1_->id())); | 246 EXPECT_FALSE(cache_delegate->GetDeclarativeRulesStored(extension1_->id())); |
247 | 247 |
248 extension_prefs->UpdateExtensionPref( | 248 extension_prefs->UpdateExtensionPref( |
249 extension1_->id(), rules_stored_key, new base::FundamentalValue(true)); | 249 extension1_->id(), rules_stored_key, new base::Value(true)); |
250 EXPECT_TRUE(cache_delegate->GetDeclarativeRulesStored(extension1_->id())); | 250 EXPECT_TRUE(cache_delegate->GetDeclarativeRulesStored(extension1_->id())); |
251 | 251 |
252 // 2. Test writing behavior. | 252 // 2. Test writing behavior. |
253 // The ValueStore is lazily created when reading/writing. None done yet so | 253 // The ValueStore is lazily created when reading/writing. None done yet so |
254 // verify that not yet created. | 254 // verify that not yet created. |
255 TestingValueStore* store = env_.GetExtensionSystem()->value_store(); | 255 TestingValueStore* store = env_.GetExtensionSystem()->value_store(); |
256 // No write yet so no store should have been created. | 256 // No write yet so no store should have been created. |
257 ASSERT_FALSE(store); | 257 ASSERT_FALSE(store); |
258 | 258 |
259 std::unique_ptr<base::ListValue> value(new base::ListValue); | 259 std::unique_ptr<base::ListValue> value(new base::ListValue); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 scoped_refptr<RulesRegistry> registry2( | 318 scoped_refptr<RulesRegistry> registry2( |
319 new TestRulesRegistry(profile(), event_name2, content::BrowserThread::UI, | 319 new TestRulesRegistry(profile(), event_name2, content::BrowserThread::UI, |
320 cache_delegate2.get(), kRulesRegistryID)); | 320 cache_delegate2.get(), kRulesRegistryID)); |
321 | 321 |
322 // Checkt the correct default values. | 322 // Checkt the correct default values. |
323 EXPECT_TRUE(cache_delegate1->GetDeclarativeRulesStored(extension1_->id())); | 323 EXPECT_TRUE(cache_delegate1->GetDeclarativeRulesStored(extension1_->id())); |
324 EXPECT_TRUE(cache_delegate2->GetDeclarativeRulesStored(extension1_->id())); | 324 EXPECT_TRUE(cache_delegate2->GetDeclarativeRulesStored(extension1_->id())); |
325 | 325 |
326 // Update the flag for the first registry. | 326 // Update the flag for the first registry. |
327 extension_prefs->UpdateExtensionPref( | 327 extension_prefs->UpdateExtensionPref( |
328 extension1_->id(), rules_stored_key1, new base::FundamentalValue(false)); | 328 extension1_->id(), rules_stored_key1, new base::Value(false)); |
329 EXPECT_FALSE(cache_delegate1->GetDeclarativeRulesStored(extension1_->id())); | 329 EXPECT_FALSE(cache_delegate1->GetDeclarativeRulesStored(extension1_->id())); |
330 EXPECT_TRUE(cache_delegate2->GetDeclarativeRulesStored(extension1_->id())); | 330 EXPECT_TRUE(cache_delegate2->GetDeclarativeRulesStored(extension1_->id())); |
331 } | 331 } |
332 | 332 |
333 TEST_F(RulesRegistryWithCacheTest, RulesPreservedAcrossRestart) { | 333 TEST_F(RulesRegistryWithCacheTest, RulesPreservedAcrossRestart) { |
334 // This test makes sure that rules are restored from the rule store | 334 // This test makes sure that rules are restored from the rule store |
335 // on registry (in particular, browser) restart. | 335 // on registry (in particular, browser) restart. |
336 | 336 |
337 // TODO(vabr): Once some API using declarative rules enters the stable | 337 // TODO(vabr): Once some API using declarative rules enters the stable |
338 // channel, make sure to use that API here, and remove |channel|. | 338 // channel, make sure to use that API here, and remove |channel|. |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 | 391 |
392 int write_count = 0; | 392 int write_count = 0; |
393 EXPECT_EQ("", AddRule(extension1_->id(), kRuleId)); | 393 EXPECT_EQ("", AddRule(extension1_->id(), kRuleId)); |
394 EXPECT_EQ("", AddRule(extension2_->id(), kRule2Id)); | 394 EXPECT_EQ("", AddRule(extension2_->id(), kRule2Id)); |
395 env_.GetExtensionSystem()->SetReady(); | 395 env_.GetExtensionSystem()->SetReady(); |
396 base::RunLoop().RunUntilIdle(); | 396 base::RunLoop().RunUntilIdle(); |
397 EXPECT_EQ(write_count + 2, system->value_store()->write_count()); | 397 EXPECT_EQ(write_count + 2, system->value_store()->write_count()); |
398 } | 398 } |
399 | 399 |
400 } // namespace extensions | 400 } // namespace extensions |
OLD | NEW |