Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(418)

Side by Side Diff: chrome/browser/extensions/api/declarative/declarative_apitest.cc

Issue 9315010: RulesRegistry for declarative APIs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698