| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/command_line.h" |
| 6 #include "base/memory/scoped_ptr.h" |
| 7 #include "chrome/browser/extensions/extension_apitest.h" |
| 8 #include "chrome/browser/extensions/api/declarative/rules_registry_service.h" |
| 9 #include "chrome/browser/extensions/api/declarative/rules_registry_service_facto
ry.h" |
| 10 #include "chrome/browser/extensions/api/declarative/test_rules_registry.h" |
| 11 #include "chrome/browser/ui/browser.h" |
| 12 #include "chrome/common/chrome_switches.h" |
| 13 #include "chrome/common/extensions/extension.h" |
| 14 |
| 15 namespace { |
| 16 const char kTestEvent[] = "experimental.declarative.testEvent"; |
| 17 } // namespace |
| 18 |
| 19 class DeclarativeApiTest : public ExtensionApiTest { |
| 20 public: |
| 21 DeclarativeApiTest() : test_rules_registry_(NULL) {} |
| 22 virtual ~DeclarativeApiTest() {} |
| 23 |
| 24 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 25 ExtensionApiTest::SetUpCommandLine(command_line); |
| 26 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis); |
| 27 } |
| 28 |
| 29 void RegisterTestRuleRegistry() { |
| 30 using namespace extensions; |
| 31 Profile* profile = browser()->profile(); |
| 32 RulesRegistryService* rules_registry = |
| 33 RulesRegistryServiceFactory::GetInstance()->GetForProfile(profile); |
| 34 scoped_ptr<RulesRegistry> test_rules_registry(new TestRulesRegistry()); |
| 35 test_rules_registry_ = test_rules_registry.get(); |
| 36 rules_registry->RegisterRuleRegistry(kTestEvent, |
| 37 test_rules_registry.Pass()); |
| 38 } |
| 39 |
| 40 // Weak pointer that is deleted when the profile is destroyed. |
| 41 extensions::RulesRegistry* test_rules_registry_; |
| 42 }; |
| 43 |
| 44 IN_PROC_BROWSER_TEST_F(DeclarativeApiTest, DeclarativeApi) { |
| 45 RegisterTestRuleRegistry(); |
| 46 ASSERT_TRUE(RunExtensionTest("declarative/api")) << message_; |
| 47 |
| 48 // Check that unloading the page has removed all rules. |
| 49 std::string extension_id = GetSingleLoadedExtension()->id(); |
| 50 UnloadExtension(extension_id); |
| 51 |
| 52 std::vector<std::string> rule_identifiers; // Empty to get all rules. |
| 53 std::vector<DictionaryValue*> known_rules; |
| 54 test_rules_registry_->GetRules(extension_id, |
| 55 rule_identifiers, |
| 56 &known_rules); |
| 57 EXPECT_TRUE(known_rules.empty()); |
| 58 } |
| OLD | NEW |