| 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/api/declarative/rules_registry_service.h" |
| 8 #include "chrome/browser/extensions/api/declarative/test_rules_registry.h" |
| 9 #include "chrome/browser/extensions/extension_apitest.h" |
| 10 #include "chrome/browser/extensions/extension_service.h" |
| 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/ui/browser.h" |
| 13 #include "chrome/common/chrome_switches.h" |
| 14 #include "chrome/common/extensions/extension.h" |
| 15 |
| 16 using namespace extensions; |
| 17 |
| 18 namespace { |
| 19 const char kTestEvent[] = "webRequest.onRequest"; |
| 20 } // namespace |
| 21 |
| 22 class DeclarativeApiTest : public ExtensionApiTest { |
| 23 public: |
| 24 DeclarativeApiTest() : test_rules_registry_(NULL) {} |
| 25 virtual ~DeclarativeApiTest() {} |
| 26 |
| 27 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 28 ExtensionApiTest::SetUpCommandLine(command_line); |
| 29 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis); |
| 30 } |
| 31 |
| 32 void RegisterTestRuleRegistry() { |
| 33 Profile* profile = browser()->profile(); |
| 34 RulesRegistryService* rules_registry = |
| 35 profile->GetExtensionService()->GetRulesRegistryService(); |
| 36 scoped_ptr<RulesRegistry> test_rules_registry(new TestRulesRegistry()); |
| 37 test_rules_registry_ = test_rules_registry.get(); |
| 38 // TODO(battre): Remove this, once we have a real implementation for a |
| 39 // RulesRegistry. |
| 40 rules_registry->RegisterRulesRegistry(kTestEvent, |
| 41 test_rules_registry.Pass()); |
| 42 } |
| 43 |
| 44 // Weak pointer that is deleted when the profile is destroyed. |
| 45 RulesRegistry* test_rules_registry_; |
| 46 }; |
| 47 |
| 48 IN_PROC_BROWSER_TEST_F(DeclarativeApiTest, DeclarativeApi) { |
| 49 RegisterTestRuleRegistry(); |
| 50 ASSERT_TRUE(RunExtensionTest("declarative/api")) << message_; |
| 51 |
| 52 // Check that unloading the page has removed all rules. |
| 53 std::string extension_id = GetSingleLoadedExtension()->id(); |
| 54 UnloadExtension(extension_id); |
| 55 |
| 56 std::vector<std::string> rule_identifiers; // Empty to get all rules. |
| 57 std::vector<DictionaryValue*> known_rules; |
| 58 test_rules_registry_->GetRules(extension_id, |
| 59 rule_identifiers, |
| 60 &known_rules); |
| 61 EXPECT_TRUE(known_rules.empty()); |
| 62 } |
| OLD | NEW |