| OLD | NEW |
| (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 "chrome/common/extensions/manifest_tests/extension_manifest_test.h" | |
| 6 | |
| 7 #include "base/command_line.h" | |
| 8 #include "base/string_util.h" | |
| 9 #include "chrome/common/chrome_switches.h" | |
| 10 #include "chrome/common/extensions/extension_manifest_constants.h" | |
| 11 #include "testing/gtest/include/gtest/gtest.h" | |
| 12 | |
| 13 namespace errors = extension_manifest_errors; | |
| 14 | |
| 15 TEST_F(ExtensionManifestTest, CommandManifestSimple) { | |
| 16 CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 17 switches::kEnableExperimentalExtensionApis); | |
| 18 | |
| 19 #if defined(OS_MACOSX) | |
| 20 int ctrl = ui::EF_COMMAND_DOWN; | |
| 21 #else | |
| 22 int ctrl = ui::EF_CONTROL_DOWN; | |
| 23 #endif | |
| 24 | |
| 25 const ui::Accelerator ctrl_f = ui::Accelerator(ui::VKEY_F, ctrl); | |
| 26 const ui::Accelerator ctrl_shift_f = | |
| 27 ui::Accelerator(ui::VKEY_F, ctrl | ui::EF_SHIFT_DOWN); | |
| 28 const ui::Accelerator alt_shift_f = | |
| 29 ui::Accelerator(ui::VKEY_F, ui::EF_ALT_DOWN | ui::EF_SHIFT_DOWN); | |
| 30 | |
| 31 scoped_refptr<extensions::Extension> extension = | |
| 32 LoadAndExpectSuccess("command_simple.json"); | |
| 33 ASSERT_TRUE(extension); | |
| 34 | |
| 35 const extensions::CommandMap& commands = extension->named_commands(); | |
| 36 ASSERT_EQ(1u, commands.size()); | |
| 37 extensions::CommandMap::const_iterator iter = commands.begin(); | |
| 38 ASSERT_TRUE(commands.end() != iter); | |
| 39 const extensions::Command* named_command = &(*iter).second; | |
| 40 ASSERT_STREQ("feature1", named_command->command_name().c_str()); | |
| 41 ASSERT_STREQ("desc", UTF16ToASCII(named_command->description()).c_str()); | |
| 42 ASSERT_EQ(ctrl_shift_f, named_command->accelerator()); | |
| 43 | |
| 44 const extensions::Command* browser_action = | |
| 45 extension->browser_action_command(); | |
| 46 ASSERT_TRUE(NULL != browser_action); | |
| 47 ASSERT_STREQ("_execute_browser_action", | |
| 48 browser_action->command_name().c_str()); | |
| 49 ASSERT_STREQ("", UTF16ToASCII(browser_action->description()).c_str()); | |
| 50 ASSERT_EQ(alt_shift_f, browser_action->accelerator()); | |
| 51 | |
| 52 const extensions::Command* page_action = | |
| 53 extension->page_action_command(); | |
| 54 ASSERT_TRUE(NULL != page_action); | |
| 55 ASSERT_STREQ("_execute_page_action", | |
| 56 page_action->command_name().c_str()); | |
| 57 ASSERT_STREQ("", UTF16ToASCII(page_action->description()).c_str()); | |
| 58 ASSERT_EQ(ctrl_f, page_action->accelerator()); | |
| 59 } | |
| 60 | |
| 61 TEST_F(ExtensionManifestTest, CommandManifestTooMany) { | |
| 62 CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 63 switches::kEnableExperimentalExtensionApis); | |
| 64 | |
| 65 LoadAndExpectError("command_too_many.json", | |
| 66 errors::kInvalidKeyBindingTooMany); | |
| 67 } | |
| 68 | |
| 69 TEST_F(ExtensionManifestTest, CommandManifestAllowNumbers) { | |
| 70 CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 71 switches::kEnableExperimentalExtensionApis); | |
| 72 | |
| 73 scoped_refptr<extensions::Extension> extension = | |
| 74 LoadAndExpectSuccess("command_allow_numbers.json"); | |
| 75 } | |
| 76 | |
| 77 TEST_F(ExtensionManifestTest, CommandManifestRejectJustShift) { | |
| 78 CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 79 switches::kEnableExperimentalExtensionApis); | |
| 80 | |
| 81 LoadAndExpectError("command_reject_just_shift.json", | |
| 82 errors::kInvalidKeyBinding); | |
| 83 } | |
| OLD | NEW |