| 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 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 EXPECT_EQ("", AddRule(extension1_->id(), kRuleId)); | 199 EXPECT_EQ("", AddRule(extension1_->id(), kRuleId)); |
| 200 EXPECT_EQ("", AddRule(extension1_->id(), kRule2Id)); | 200 EXPECT_EQ("", AddRule(extension1_->id(), kRule2Id)); |
| 201 EXPECT_EQ("", AddRule(extension2_->id(), kRuleId)); | 201 EXPECT_EQ("", AddRule(extension2_->id(), kRuleId)); |
| 202 | 202 |
| 203 // Check that we get the correct rules. | 203 // Check that we get the correct rules. |
| 204 std::vector<linked_ptr<api::events::Rule>> gotten_rules; | 204 std::vector<linked_ptr<api::events::Rule>> gotten_rules; |
| 205 registry_->GetAllRules(extension1_->id(), &gotten_rules); | 205 registry_->GetAllRules(extension1_->id(), &gotten_rules); |
| 206 EXPECT_EQ(2u, gotten_rules.size()); | 206 EXPECT_EQ(2u, gotten_rules.size()); |
| 207 ASSERT_TRUE(gotten_rules[0]->id.get()); | 207 ASSERT_TRUE(gotten_rules[0]->id.get()); |
| 208 ASSERT_TRUE(gotten_rules[1]->id.get()); | 208 ASSERT_TRUE(gotten_rules[1]->id.get()); |
| 209 EXPECT_TRUE( (kRuleId == *(gotten_rules[0]->id) && | 209 EXPECT_TRUE((kRuleId == *(gotten_rules[0]->id) && |
| 210 kRule2Id == *(gotten_rules[1]->id)) || | 210 kRule2Id == *(gotten_rules[1]->id)) || |
| 211 (kRuleId == *(gotten_rules[1]->id) && | 211 (kRuleId == *(gotten_rules[1]->id) && |
| 212 kRule2Id == *(gotten_rules[0]->id)) ); | 212 kRule2Id == *(gotten_rules[0]->id)) ); |
| 213 } | 213 } |
| 214 | 214 |
| 215 TEST_F(RulesRegistryWithCacheTest, OnExtensionUninstalled) { | 215 TEST_F(RulesRegistryWithCacheTest, OnExtensionUninstalled) { |
| 216 // Prime registry. | 216 // Prime registry. |
| 217 EXPECT_EQ("", AddRule(extension1_->id(), kRuleId)); | 217 EXPECT_EQ("", AddRule(extension1_->id(), kRuleId)); |
| 218 EXPECT_EQ("", AddRule(extension2_->id(), kRuleId)); | 218 EXPECT_EQ("", AddRule(extension2_->id(), kRuleId)); |
| 219 | 219 |
| 220 // Check that the correct rules are removed. | 220 // Check that the correct rules are removed. |
| 221 registry_->OnExtensionUninstalled(extension1_.get()); | 221 registry_->OnExtensionUninstalled(extension1_.get()); |
| 222 EXPECT_EQ(0, GetNumberOfRules(extension1_->id())); | 222 EXPECT_EQ(0, GetNumberOfRules(extension1_->id())); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 EXPECT_FALSE(cache_delegate1->GetDeclarativeRulesStored(extension1_->id())); | 321 EXPECT_FALSE(cache_delegate1->GetDeclarativeRulesStored(extension1_->id())); |
| 322 EXPECT_TRUE(cache_delegate2->GetDeclarativeRulesStored(extension1_->id())); | 322 EXPECT_TRUE(cache_delegate2->GetDeclarativeRulesStored(extension1_->id())); |
| 323 } | 323 } |
| 324 | 324 |
| 325 TEST_F(RulesRegistryWithCacheTest, RulesPreservedAcrossRestart) { | 325 TEST_F(RulesRegistryWithCacheTest, RulesPreservedAcrossRestart) { |
| 326 // This test makes sure that rules are restored from the rule store | 326 // This test makes sure that rules are restored from the rule store |
| 327 // on registry (in particular, browser) restart. | 327 // on registry (in particular, browser) restart. |
| 328 | 328 |
| 329 // TODO(vabr): Once some API using declarative rules enters the stable | 329 // TODO(vabr): Once some API using declarative rules enters the stable |
| 330 // channel, make sure to use that API here, and remove |channel|. | 330 // channel, make sure to use that API here, and remove |channel|. |
| 331 ScopedCurrentChannel channel(chrome::VersionInfo::CHANNEL_UNKNOWN); | 331 ScopedCurrentChannel channel(version_info::Channel::UNKNOWN); |
| 332 | 332 |
| 333 ExtensionService* extension_service = env_.GetExtensionService(); | 333 ExtensionService* extension_service = env_.GetExtensionService(); |
| 334 | 334 |
| 335 // 1. Add an extension, before rules registry gets created. | 335 // 1. Add an extension, before rules registry gets created. |
| 336 std::string error; | 336 std::string error; |
| 337 scoped_refptr<Extension> extension( | 337 scoped_refptr<Extension> extension( |
| 338 LoadManifestUnchecked("permissions", | 338 LoadManifestUnchecked("permissions", |
| 339 "web_request_all_host_permissions.json", | 339 "web_request_all_host_permissions.json", |
| 340 Manifest::INVALID_LOCATION, | 340 Manifest::INVALID_LOCATION, |
| 341 Extension::NO_FLAGS, | 341 Extension::NO_FLAGS, |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 | 381 |
| 382 int write_count = store->write_count(); | 382 int write_count = store->write_count(); |
| 383 EXPECT_EQ("", AddRule(extension1_->id(), kRuleId)); | 383 EXPECT_EQ("", AddRule(extension1_->id(), kRuleId)); |
| 384 EXPECT_EQ("", AddRule(extension2_->id(), kRule2Id)); | 384 EXPECT_EQ("", AddRule(extension2_->id(), kRule2Id)); |
| 385 env_.GetExtensionSystem()->SetReady(); | 385 env_.GetExtensionSystem()->SetReady(); |
| 386 base::RunLoop().RunUntilIdle(); | 386 base::RunLoop().RunUntilIdle(); |
| 387 EXPECT_EQ(write_count + 2, store->write_count()); | 387 EXPECT_EQ(write_count + 2, store->write_count()); |
| 388 } | 388 } |
| 389 | 389 |
| 390 } // namespace extensions | 390 } // namespace extensions |
| OLD | NEW |