Chromium Code Reviews| 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 namespace { | |
| 17 const char kTestEvent[] = "webRequest.onRequest"; | |
| 18 } // namespace | |
| 19 | |
| 20 class DeclarativeApiTest : public ExtensionApiTest { | |
| 21 public: | |
| 22 DeclarativeApiTest() : test_rules_registry_(NULL) {} | |
| 23 virtual ~DeclarativeApiTest() {} | |
| 24 | |
| 25 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | |
| 26 ExtensionApiTest::SetUpCommandLine(command_line); | |
| 27 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis); | |
|
not at google - send to devlin
2012/02/07 03:25:10
other tests seem to do
CommandLine::ForCurrentPro
battre
2012/02/07 18:45:33
There are several examples of using it this way: d
| |
| 28 } | |
| 29 | |
| 30 void RegisterTestRuleRegistry() { | |
| 31 using namespace extensions; | |
|
not at google - send to devlin
2012/02/07 03:25:10
put at top of file
battre
2012/02/07 18:45:33
There was some discussion on chrome-team that kind
not at google - send to devlin
2012/02/07 23:54:57
oh really?
Well like many things it's a judgement
| |
| 32 Profile* profile = browser()->profile(); | |
| 33 RulesRegistryService* rules_registry = | |
| 34 profile->GetExtensionService()->GetRulesRegistryService(); | |
| 35 scoped_ptr<RulesRegistry> test_rules_registry(new TestRulesRegistry()); | |
| 36 test_rules_registry_ = test_rules_registry.get(); | |
| 37 rules_registry->UnregisterAllRulesRegistries(); | |
|
not at google - send to devlin
2012/02/07 03:25:10
Why this? Is it so that the previous test's regist
battre
2012/02/07 18:45:33
The idea here is,that the webRequest implementatio
| |
| 38 rules_registry->RegisterRulesRegistry(kTestEvent, | |
| 39 test_rules_registry.Pass()); | |
| 40 } | |
| 41 | |
| 42 // Weak pointer that is deleted when the profile is destroyed. | |
| 43 extensions::RulesRegistry* test_rules_registry_; | |
| 44 }; | |
| 45 | |
| 46 IN_PROC_BROWSER_TEST_F(DeclarativeApiTest, DeclarativeApi) { | |
| 47 RegisterTestRuleRegistry(); | |
| 48 ASSERT_TRUE(RunExtensionTest("declarative/api")) << message_; | |
| 49 | |
| 50 // Check that unloading the page has removed all rules. | |
| 51 std::string extension_id = GetSingleLoadedExtension()->id(); | |
| 52 UnloadExtension(extension_id); | |
| 53 | |
| 54 std::vector<std::string> rule_identifiers; // Empty to get all rules. | |
| 55 std::vector<DictionaryValue*> known_rules; | |
| 56 test_rules_registry_->GetRules(extension_id, | |
| 57 rule_identifiers, | |
| 58 &known_rules); | |
| 59 EXPECT_TRUE(known_rules.empty()); | |
| 60 } | |
| OLD | NEW |