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