| OLD | NEW |
| 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/api/commands/commands_handler.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 | 12 |
| 13 namespace errors = extension_manifest_errors; | 13 namespace errors = extension_manifest_errors; |
| 14 | 14 |
| 15 namespace extensions { | 15 namespace extensions { |
| 16 | 16 |
| 17 class CommandsManifestTest : public ExtensionManifestTest { | 17 class CommandsManifestTest : public ExtensionManifestTest { |
| 18 protected: | 18 protected: |
| 19 virtual void SetUp() OVERRIDE { | 19 virtual void SetUp() OVERRIDE { |
| 20 (new CommandsHandler)->Register(); | 20 (new CommandsHandler)->Register(); |
| 21 } | 21 } |
| 22 }; | 22 }; |
| 23 | 23 |
| 24 TEST_F(CommandsManifestTest, CommandManifestSimple) { | 24 TEST_F(CommandsManifestTest, CommandManifestSimple) { |
| 25 CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 26 switches::kEnableExperimentalExtensionApis); | |
| 27 | |
| 28 #if defined(OS_MACOSX) | 25 #if defined(OS_MACOSX) |
| 29 int ctrl = ui::EF_COMMAND_DOWN; | 26 int ctrl = ui::EF_COMMAND_DOWN; |
| 30 #else | 27 #else |
| 31 int ctrl = ui::EF_CONTROL_DOWN; | 28 int ctrl = ui::EF_CONTROL_DOWN; |
| 32 #endif | 29 #endif |
| 33 | 30 |
| 34 const ui::Accelerator ctrl_f = ui::Accelerator(ui::VKEY_F, ctrl); | 31 const ui::Accelerator ctrl_f = ui::Accelerator(ui::VKEY_F, ctrl); |
| 35 const ui::Accelerator ctrl_shift_f = | 32 const ui::Accelerator ctrl_shift_f = |
| 36 ui::Accelerator(ui::VKEY_F, ctrl | ui::EF_SHIFT_DOWN); | 33 ui::Accelerator(ui::VKEY_F, ctrl | ui::EF_SHIFT_DOWN); |
| 37 const ui::Accelerator alt_shift_f = | 34 const ui::Accelerator alt_shift_f = |
| (...skipping 22 matching lines...) Expand all Loading... |
| 60 ASSERT_EQ(alt_shift_f, browser_action->accelerator()); | 57 ASSERT_EQ(alt_shift_f, browser_action->accelerator()); |
| 61 | 58 |
| 62 const Command* page_action = CommandsInfo::GetPageActionCommand(extension); | 59 const Command* page_action = CommandsInfo::GetPageActionCommand(extension); |
| 63 ASSERT_TRUE(NULL != page_action); | 60 ASSERT_TRUE(NULL != page_action); |
| 64 ASSERT_STREQ("_execute_page_action", | 61 ASSERT_STREQ("_execute_page_action", |
| 65 page_action->command_name().c_str()); | 62 page_action->command_name().c_str()); |
| 66 ASSERT_STREQ("", UTF16ToASCII(page_action->description()).c_str()); | 63 ASSERT_STREQ("", UTF16ToASCII(page_action->description()).c_str()); |
| 67 ASSERT_EQ(ctrl_f, page_action->accelerator()); | 64 ASSERT_EQ(ctrl_f, page_action->accelerator()); |
| 68 } | 65 } |
| 69 | 66 |
| 70 TEST_F(CommandsManifestTest, CommandManifestTooMany) { | 67 TEST_F(CommandsManifestTest, CommandManifestShortcutsTooMany) { |
| 71 CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 72 switches::kEnableExperimentalExtensionApis); | |
| 73 | |
| 74 LoadAndExpectError("command_too_many.json", | 68 LoadAndExpectError("command_too_many.json", |
| 75 errors::kInvalidKeyBindingTooMany); | 69 errors::kInvalidKeyBindingTooMany); |
| 76 } | 70 } |
| 77 | 71 |
| 72 TEST_F(CommandsManifestTest, CommandManifestManyButWithinBounds) { |
| 73 scoped_refptr<Extension> extension = |
| 74 LoadAndExpectSuccess("command_many_but_shortcuts_under_limit.json"); |
| 75 } |
| 76 |
| 78 TEST_F(CommandsManifestTest, CommandManifestAllowNumbers) { | 77 TEST_F(CommandsManifestTest, CommandManifestAllowNumbers) { |
| 79 CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 80 switches::kEnableExperimentalExtensionApis); | |
| 81 | |
| 82 scoped_refptr<Extension> extension = | 78 scoped_refptr<Extension> extension = |
| 83 LoadAndExpectSuccess("command_allow_numbers.json"); | 79 LoadAndExpectSuccess("command_allow_numbers.json"); |
| 84 } | 80 } |
| 85 | 81 |
| 86 TEST_F(CommandsManifestTest, CommandManifestRejectJustShift) { | 82 TEST_F(CommandsManifestTest, CommandManifestRejectJustShift) { |
| 87 CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 88 switches::kEnableExperimentalExtensionApis); | |
| 89 | |
| 90 LoadAndExpectError("command_reject_just_shift.json", | 83 LoadAndExpectError("command_reject_just_shift.json", |
| 91 errors::kInvalidKeyBinding); | 84 errors::kInvalidKeyBinding); |
| 92 } | 85 } |
| 93 | 86 |
| 94 } // namespace extensions | 87 } // namespace extensions |
| OLD | NEW |