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

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

Issue 9422003: Migrate Declarative API bindings to new JSON objects generated by JSON compiler (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix memory leaks Created 8 years, 9 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/memory/scoped_ptr.h" 6 #include "base/memory/scoped_ptr.h"
7 #include "chrome/browser/extensions/api/declarative/rules_registry_service.h" 7 #include "chrome/browser/extensions/api/declarative/rules_registry_service.h"
8 #include "chrome/browser/extensions/api/declarative/test_rules_registry.h" 8 #include "chrome/browser/extensions/api/declarative/test_rules_registry.h"
9 #include "chrome/browser/extensions/extension_apitest.h" 9 #include "chrome/browser/extensions/extension_apitest.h"
10 #include "chrome/browser/extensions/extension_service.h" 10 #include "chrome/browser/extensions/extension_service.h"
11 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/ui/browser.h" 12 #include "chrome/browser/ui/browser.h"
13 #include "chrome/common/chrome_switches.h" 13 #include "chrome/common/chrome_switches.h"
14 #include "chrome/common/extensions/extension.h" 14 #include "chrome/common/extensions/extension.h"
15 #include "chrome/test/base/ui_test_utils.h"
15 16
16 using namespace extensions; 17 using namespace extensions;
17 18
18 namespace { 19 namespace {
19 const char kTestEvent[] = "webRequest.onRequest"; 20 const char kTestEvent[] = "webRequest.onRequest";
20 } // namespace 21 } // namespace
21 22
22 class DeclarativeApiTest : public ExtensionApiTest { 23 class DeclarativeApiTest : public ExtensionApiTest {
23 public: 24 public:
24 DeclarativeApiTest() : test_rules_registry_(NULL) {} 25 DeclarativeApiTest() : test_rules_registry_(NULL) {}
25 virtual ~DeclarativeApiTest() {} 26 virtual ~DeclarativeApiTest() {}
26 27
27 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 28 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
28 ExtensionApiTest::SetUpCommandLine(command_line); 29 ExtensionApiTest::SetUpCommandLine(command_line);
29 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis); 30 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis);
30 } 31 }
31 32
32 void RegisterTestRuleRegistry() { 33 void RegisterTestRuleRegistry() {
33 Profile* profile = browser()->profile(); 34 Profile* profile = browser()->profile();
34 RulesRegistryService* rules_registry = 35 RulesRegistryService* rules_registry_service =
35 profile->GetExtensionService()->GetRulesRegistryService(); 36 profile->GetExtensionService()->GetRulesRegistryService();
36 scoped_ptr<RulesRegistry> test_rules_registry(new TestRulesRegistry()); 37 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 38 // TODO(battre): Remove this, once we have a real implementation for a
39 // RulesRegistry. 39 // RulesRegistry.
40 rules_registry->RegisterRulesRegistry(kTestEvent, 40 rules_registry_service->RegisterRulesRegistry(kTestEvent,
41 test_rules_registry.Pass()); 41 test_rules_registry_);
42 } 42 }
43 43
44 // Weak pointer that is deleted when the profile is destroyed. 44 scoped_refptr<RulesRegistry> test_rules_registry_;
45 RulesRegistry* test_rules_registry_;
46 }; 45 };
47 46
48 IN_PROC_BROWSER_TEST_F(DeclarativeApiTest, DeclarativeApi) { 47 IN_PROC_BROWSER_TEST_F(DeclarativeApiTest, DeclarativeApi) {
49 RegisterTestRuleRegistry(); 48 RegisterTestRuleRegistry();
50 ASSERT_TRUE(RunExtensionTest("declarative/api")) << message_; 49 ASSERT_TRUE(RunExtensionTest("declarative/api")) << message_;
51 50
52 // Check that unloading the page has removed all rules. 51 // Check that unloading the page has removed all rules.
53 std::string extension_id = GetSingleLoadedExtension()->id(); 52 std::string extension_id = GetSingleLoadedExtension()->id();
54 UnloadExtension(extension_id); 53 UnloadExtension(extension_id);
55 54
56 std::vector<std::string> rule_identifiers; // Empty to get all rules. 55 // Make sure that RulesRegistry had a chance to process unloading the
57 std::vector<DictionaryValue*> known_rules; 56 // extension.
58 test_rules_registry_->GetRules(extension_id, 57 ui_test_utils::RunAllPendingInMessageLoop(
59 rule_identifiers, 58 test_rules_registry_->GetOwnerThread());
60 &known_rules); 59
60 std::vector<linked_ptr<RulesRegistry::Rule> > known_rules;
61
62 test_rules_registry_->GetAllRules(extension_id, &known_rules);
61 EXPECT_TRUE(known_rules.empty()); 63 EXPECT_TRUE(known_rules.empty());
62 } 64 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698