Chromium Code Reviews| Index: chrome/browser/extensions/api/declarative/declarative_apitest.cc |
| diff --git a/chrome/browser/extensions/api/declarative/declarative_apitest.cc b/chrome/browser/extensions/api/declarative/declarative_apitest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..cc3658f30382ca83dc41fe4228c333229d0ff58e |
| --- /dev/null |
| +++ b/chrome/browser/extensions/api/declarative/declarative_apitest.cc |
| @@ -0,0 +1,60 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "base/command_line.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "chrome/browser/extensions/api/declarative/rules_registry_service.h" |
| +#include "chrome/browser/extensions/api/declarative/test_rules_registry.h" |
| +#include "chrome/browser/extensions/extension_apitest.h" |
| +#include "chrome/browser/extensions/extension_service.h" |
| +#include "chrome/browser/profiles/profile.h" |
| +#include "chrome/browser/ui/browser.h" |
| +#include "chrome/common/chrome_switches.h" |
| +#include "chrome/common/extensions/extension.h" |
| + |
| +namespace { |
| +const char kTestEvent[] = "webRequest.onRequest"; |
| +} // namespace |
| + |
| +class DeclarativeApiTest : public ExtensionApiTest { |
| + public: |
| + DeclarativeApiTest() : test_rules_registry_(NULL) {} |
| + virtual ~DeclarativeApiTest() {} |
| + |
| + virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| + ExtensionApiTest::SetUpCommandLine(command_line); |
| + 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
|
| + } |
| + |
| + void RegisterTestRuleRegistry() { |
| + 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
|
| + Profile* profile = browser()->profile(); |
| + RulesRegistryService* rules_registry = |
| + profile->GetExtensionService()->GetRulesRegistryService(); |
| + scoped_ptr<RulesRegistry> test_rules_registry(new TestRulesRegistry()); |
| + test_rules_registry_ = test_rules_registry.get(); |
| + 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
|
| + rules_registry->RegisterRulesRegistry(kTestEvent, |
| + test_rules_registry.Pass()); |
| + } |
| + |
| + // Weak pointer that is deleted when the profile is destroyed. |
| + extensions::RulesRegistry* test_rules_registry_; |
| +}; |
| + |
| +IN_PROC_BROWSER_TEST_F(DeclarativeApiTest, DeclarativeApi) { |
| + RegisterTestRuleRegistry(); |
| + ASSERT_TRUE(RunExtensionTest("declarative/api")) << message_; |
| + |
| + // Check that unloading the page has removed all rules. |
| + std::string extension_id = GetSingleLoadedExtension()->id(); |
| + UnloadExtension(extension_id); |
| + |
| + std::vector<std::string> rule_identifiers; // Empty to get all rules. |
| + std::vector<DictionaryValue*> known_rules; |
| + test_rules_registry_->GetRules(extension_id, |
| + rule_identifiers, |
| + &known_rules); |
| + EXPECT_TRUE(known_rules.empty()); |
| +} |