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

Side by Side Diff: chrome/common/extensions/api/commands/commands_manifest_unittest.cc

Issue 11662013: Move Commands from Extension to CommandsHandler (Closed) Base URL: http://git.chromium.org/chromium/src.git@dc_unref_script_badge
Patch Set: Created 7 years, 11 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
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 "chrome/common/extensions/manifest_tests/extension_manifest_test.h" 5 #include "chrome/common/extensions/manifest_tests/extension_manifest_test.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "chrome/common/chrome_switches.h" 9 #include "chrome/common/chrome_switches.h"
10 #include "chrome/common/extensions/api/commands/commands_handler.h"
10 #include "chrome/common/extensions/extension_manifest_constants.h" 11 #include "chrome/common/extensions/extension_manifest_constants.h"
12 #include "chrome/common/extensions/manifest_handler.h"
11 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
12 14
13 namespace errors = extension_manifest_errors; 15 namespace errors = extension_manifest_errors;
14 16
15 TEST_F(ExtensionManifestTest, CommandManifestSimple) { 17 namespace extensions {
18
19 class CommandsManifestTest : public ExtensionManifestTest {
20 protected:
21 virtual void SetUp() OVERRIDE {
22 ManifestHandler::Register(extension_manifest_keys::kCommands,
23 new CommandsHandler);
24 }
25 };
26
27 TEST_F(CommandsManifestTest, CommandManifestSimple) {
16 CommandLine::ForCurrentProcess()->AppendSwitch( 28 CommandLine::ForCurrentProcess()->AppendSwitch(
17 switches::kEnableExperimentalExtensionApis); 29 switches::kEnableExperimentalExtensionApis);
18 30
19 #if defined(OS_MACOSX) 31 #if defined(OS_MACOSX)
20 int ctrl = ui::EF_COMMAND_DOWN; 32 int ctrl = ui::EF_COMMAND_DOWN;
21 #else 33 #else
22 int ctrl = ui::EF_CONTROL_DOWN; 34 int ctrl = ui::EF_CONTROL_DOWN;
23 #endif 35 #endif
24 36
25 const ui::Accelerator ctrl_f = ui::Accelerator(ui::VKEY_F, ctrl); 37 const ui::Accelerator ctrl_f = ui::Accelerator(ui::VKEY_F, ctrl);
26 const ui::Accelerator ctrl_shift_f = 38 const ui::Accelerator ctrl_shift_f =
27 ui::Accelerator(ui::VKEY_F, ctrl | ui::EF_SHIFT_DOWN); 39 ui::Accelerator(ui::VKEY_F, ctrl | ui::EF_SHIFT_DOWN);
28 const ui::Accelerator alt_shift_f = 40 const ui::Accelerator alt_shift_f =
29 ui::Accelerator(ui::VKEY_F, ui::EF_ALT_DOWN | ui::EF_SHIFT_DOWN); 41 ui::Accelerator(ui::VKEY_F, ui::EF_ALT_DOWN | ui::EF_SHIFT_DOWN);
30 42
31 scoped_refptr<extensions::Extension> extension = 43 scoped_refptr<Extension> extension =
32 LoadAndExpectSuccess("command_simple.json"); 44 LoadAndExpectSuccess("command_simple.json");
33 ASSERT_TRUE(extension); 45 ASSERT_TRUE(extension);
34 46
35 const extensions::CommandMap& commands = extension->named_commands(); 47 const CommandMap* commands = CommandsInfo::GetNamedCommands(extension);
36 ASSERT_EQ(1u, commands.size()); 48 ASSERT_TRUE(commands);
37 extensions::CommandMap::const_iterator iter = commands.begin(); 49 ASSERT_EQ(1u, commands->size());
38 ASSERT_TRUE(commands.end() != iter); 50 CommandMap::const_iterator iter = commands->begin();
39 const extensions::Command* named_command = &(*iter).second; 51 ASSERT_TRUE(commands->end() != iter);
52 const Command* named_command = &(*iter).second;
40 ASSERT_STREQ("feature1", named_command->command_name().c_str()); 53 ASSERT_STREQ("feature1", named_command->command_name().c_str());
41 ASSERT_STREQ("desc", UTF16ToASCII(named_command->description()).c_str()); 54 ASSERT_STREQ("desc", UTF16ToASCII(named_command->description()).c_str());
42 ASSERT_EQ(ctrl_shift_f, named_command->accelerator()); 55 ASSERT_EQ(ctrl_shift_f, named_command->accelerator());
43 56
44 const extensions::Command* browser_action = 57 const Command* browser_action =
45 extension->browser_action_command(); 58 CommandsInfo::GetBrowserActionCommand(extension);
46 ASSERT_TRUE(NULL != browser_action); 59 ASSERT_TRUE(NULL != browser_action);
47 ASSERT_STREQ("_execute_browser_action", 60 ASSERT_STREQ("_execute_browser_action",
48 browser_action->command_name().c_str()); 61 browser_action->command_name().c_str());
49 ASSERT_STREQ("", UTF16ToASCII(browser_action->description()).c_str()); 62 ASSERT_STREQ("", UTF16ToASCII(browser_action->description()).c_str());
50 ASSERT_EQ(alt_shift_f, browser_action->accelerator()); 63 ASSERT_EQ(alt_shift_f, browser_action->accelerator());
51 64
52 const extensions::Command* page_action = 65 const Command* page_action = CommandsInfo::GetPageActionCommand(extension);
53 extension->page_action_command();
54 ASSERT_TRUE(NULL != page_action); 66 ASSERT_TRUE(NULL != page_action);
55 ASSERT_STREQ("_execute_page_action", 67 ASSERT_STREQ("_execute_page_action",
56 page_action->command_name().c_str()); 68 page_action->command_name().c_str());
57 ASSERT_STREQ("", UTF16ToASCII(page_action->description()).c_str()); 69 ASSERT_STREQ("", UTF16ToASCII(page_action->description()).c_str());
58 ASSERT_EQ(ctrl_f, page_action->accelerator()); 70 ASSERT_EQ(ctrl_f, page_action->accelerator());
59 } 71 }
60 72
61 TEST_F(ExtensionManifestTest, CommandManifestTooMany) { 73 TEST_F(CommandsManifestTest, CommandManifestTooMany) {
62 CommandLine::ForCurrentProcess()->AppendSwitch( 74 CommandLine::ForCurrentProcess()->AppendSwitch(
63 switches::kEnableExperimentalExtensionApis); 75 switches::kEnableExperimentalExtensionApis);
64 76
65 LoadAndExpectError("command_too_many.json", 77 LoadAndExpectError("command_too_many.json",
66 errors::kInvalidKeyBindingTooMany); 78 errors::kInvalidKeyBindingTooMany);
67 } 79 }
68 80
69 TEST_F(ExtensionManifestTest, CommandManifestAllowNumbers) { 81 TEST_F(CommandsManifestTest, CommandManifestAllowNumbers) {
70 CommandLine::ForCurrentProcess()->AppendSwitch( 82 CommandLine::ForCurrentProcess()->AppendSwitch(
71 switches::kEnableExperimentalExtensionApis); 83 switches::kEnableExperimentalExtensionApis);
72 84
73 scoped_refptr<extensions::Extension> extension = 85 scoped_refptr<Extension> extension =
74 LoadAndExpectSuccess("command_allow_numbers.json"); 86 LoadAndExpectSuccess("command_allow_numbers.json");
75 } 87 }
76 88
77 TEST_F(ExtensionManifestTest, CommandManifestRejectJustShift) { 89 TEST_F(CommandsManifestTest, CommandManifestRejectJustShift) {
78 CommandLine::ForCurrentProcess()->AppendSwitch( 90 CommandLine::ForCurrentProcess()->AppendSwitch(
79 switches::kEnableExperimentalExtensionApis); 91 switches::kEnableExperimentalExtensionApis);
80 92
81 LoadAndExpectError("command_reject_just_shift.json", 93 LoadAndExpectError("command_reject_just_shift.json",
82 errors::kInvalidKeyBinding); 94 errors::kInvalidKeyBinding);
83 } 95 }
96
97 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/common/extensions/api/commands/commands_handler.cc ('k') | chrome/common/extensions/api/omnibox/omnibox_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698