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 |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
13 #include "chrome/browser/extensions/extension_service.h" | 13 #include "chrome/browser/extensions/extension_service.h" |
14 #include "chrome/browser/extensions/test_extension_environment.h" | 14 #include "chrome/browser/extensions/test_extension_environment.h" |
15 #include "chrome/browser/extensions/test_extension_system.h" | 15 #include "chrome/browser/extensions/test_extension_system.h" |
16 #include "chrome/common/extensions/extension_test_util.h" | 16 #include "chrome/common/extensions/extension_test_util.h" |
17 #include "chrome/common/extensions/features/feature_channel.h" | 17 #include "chrome/common/extensions/features/feature_channel.h" |
18 #include "chrome/test/base/testing_profile.h" | 18 #include "chrome/test/base/testing_profile.h" |
19 #include "content/public/test/test_browser_thread_bundle.h" | 19 #include "content/public/test/test_browser_thread_bundle.h" |
20 #include "extensions/browser/api/declarative/rules_cache_delegate.h" | 20 #include "extensions/browser/api/declarative/rules_cache_delegate.h" |
21 #include "extensions/browser/api/declarative/test_rules_registry.h" | 21 #include "extensions/browser/api/declarative/test_rules_registry.h" |
22 #include "extensions/browser/extension_prefs.h" | 22 #include "extensions/browser/extension_prefs.h" |
| 23 #include "extensions/browser/extension_registry.h" |
23 #include "extensions/browser/value_store/testing_value_store.h" | 24 #include "extensions/browser/value_store/testing_value_store.h" |
24 #include "extensions/common/extension.h" | 25 #include "extensions/common/extension.h" |
25 #include "extensions/common/manifest_constants.h" | 26 #include "extensions/common/manifest_constants.h" |
26 #include "extensions/common/permissions/permissions_data.h" | 27 #include "extensions/common/permissions/permissions_data.h" |
27 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
28 | 29 |
29 using extension_test_util::LoadManifestUnchecked; | 30 using extension_test_util::LoadManifestUnchecked; |
30 | 31 |
31 namespace { | 32 namespace { |
32 const char kRuleId[] = "rule"; | 33 const char kRuleId[] = "rule"; |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 std::string error; | 339 std::string error; |
339 scoped_refptr<Extension> extension( | 340 scoped_refptr<Extension> extension( |
340 LoadManifestUnchecked("permissions", | 341 LoadManifestUnchecked("permissions", |
341 "web_request_all_host_permissions.json", | 342 "web_request_all_host_permissions.json", |
342 Manifest::INVALID_LOCATION, | 343 Manifest::INVALID_LOCATION, |
343 Extension::NO_FLAGS, | 344 Extension::NO_FLAGS, |
344 extension1_->id(), | 345 extension1_->id(), |
345 &error)); | 346 &error)); |
346 ASSERT_TRUE(error.empty()); | 347 ASSERT_TRUE(error.empty()); |
347 extension_service->AddExtension(extension.get()); | 348 extension_service->AddExtension(extension.get()); |
348 EXPECT_TRUE(extension_service->extensions()->Contains(extension->id())); | 349 EXPECT_TRUE(extensions::ExtensionRegistry::Get(env_.profile()) |
| 350 ->enabled_extensions() |
| 351 .Contains(extension->id())); |
349 EXPECT_TRUE(extension->permissions_data()->HasAPIPermission( | 352 EXPECT_TRUE(extension->permissions_data()->HasAPIPermission( |
350 APIPermission::kDeclarativeWebRequest)); | 353 APIPermission::kDeclarativeWebRequest)); |
351 env_.GetExtensionSystem()->SetReady(); | 354 env_.GetExtensionSystem()->SetReady(); |
352 | 355 |
353 // 2. First run, adding a rule for the extension. | 356 // 2. First run, adding a rule for the extension. |
354 scoped_ptr<RulesCacheDelegate> cache_delegate(new RulesCacheDelegate(false)); | 357 scoped_ptr<RulesCacheDelegate> cache_delegate(new RulesCacheDelegate(false)); |
355 scoped_refptr<TestRulesRegistry> registry(new TestRulesRegistry( | 358 scoped_refptr<TestRulesRegistry> registry(new TestRulesRegistry( |
356 profile(), | 359 profile(), |
357 "testEvent", | 360 "testEvent", |
358 content::BrowserThread::UI, | 361 content::BrowserThread::UI, |
(...skipping 28 matching lines...) Expand all Loading... |
387 | 390 |
388 int write_count = store->write_count(); | 391 int write_count = store->write_count(); |
389 EXPECT_EQ("", AddRule(extension1_->id(), kRuleId)); | 392 EXPECT_EQ("", AddRule(extension1_->id(), kRuleId)); |
390 EXPECT_EQ("", AddRule(extension2_->id(), kRule2Id)); | 393 EXPECT_EQ("", AddRule(extension2_->id(), kRule2Id)); |
391 env_.GetExtensionSystem()->SetReady(); | 394 env_.GetExtensionSystem()->SetReady(); |
392 base::RunLoop().RunUntilIdle(); | 395 base::RunLoop().RunUntilIdle(); |
393 EXPECT_EQ(write_count + 2, store->write_count()); | 396 EXPECT_EQ(write_count + 2, store->write_count()); |
394 } | 397 } |
395 | 398 |
396 } // namespace extensions | 399 } // namespace extensions |
OLD | NEW |