diff options
author | zhchbin@gmail.com <zhchbin@gmail.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-04 05:44:38 +0000 |
---|---|---|
committer | zhchbin@gmail.com <zhchbin@gmail.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-04 05:44:38 +0000 |
commit | 639dec9a36f2f9db7de9952133e6c7fe557b4168 (patch) | |
tree | 723f8d508185e44ff1aeb69c3fcb5a5a0ad63fb9 /chrome/browser/extensions/extension_keybinding_apitest.cc | |
parent | 08ac6f9ebc29f5d86df4f5ce9bc5e076ccfe370a (diff) | |
download | chromium_src-639dec9a36f2f9db7de9952133e6c7fe557b4168.zip chromium_src-639dec9a36f2f9db7de9952133e6c7fe557b4168.tar.gz chromium_src-639dec9a36f2f9db7de9952133e6c7fe557b4168.tar.bz2 |
Fix issue: when overriding keybinding preferences, should remove the one taken.
Also including the following things:
1. Fix a problem that introduced by my previous CL[0].
In the ExtensionKeybindingRegistry::RemoveExtensionKeybinding, we should break
only when we really find the specified command.
2. Test case for removal of keybinding preference should be platform-specific.
[0]: https://codereview.chromium.org/64273008/
BUG=302437
TEST=interactive_ui_tests --gtest_filter=CommandsApiTest.UpdateKeybindingPrefsTest
TEST=browser_test --gtest_filter=CommandServiceTest.RemoveKeybindingPrefsShouldBePlatformSpecific
TBR=finnur@chromium.org
Review URL: https://codereview.chromium.org/94723008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@238587 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/extension_keybinding_apitest.cc')
-rw-r--r-- | chrome/browser/extensions/extension_keybinding_apitest.cc | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/chrome/browser/extensions/extension_keybinding_apitest.cc b/chrome/browser/extensions/extension_keybinding_apitest.cc index 22e56be..7886afa 100644 --- a/chrome/browser/extensions/extension_keybinding_apitest.cc +++ b/chrome/browser/extensions/extension_keybinding_apitest.cc @@ -3,6 +3,7 @@ // found in the LICENSE file. #include "chrome/browser/extensions/active_tab_permission_granter.h" +#include "chrome/browser/extensions/api/commands/command_service.h" #include "chrome/browser/extensions/browser_action_test_util.h" #include "chrome/browser/extensions/extension_action.h" #include "chrome/browser/extensions/extension_action_manager.h" @@ -287,4 +288,55 @@ IN_PROC_BROWSER_TEST_F(CommandsApiTest, MAYBE_AllowDuplicatedMediaKeys) { ASSERT_TRUE(catcher.GetNextResult()); } +// This test validates that update (including removal) of keybinding preferences +// works correctly. +IN_PROC_BROWSER_TEST_F(CommandsApiTest, UpdateKeybindingPrefsTest) { +#if defined(OS_MACOSX) + // Send "Tab" on OS X to move the focus, otherwise the omnibox will intercept + // the key presses we send below. + ASSERT_TRUE(ui_test_utils::SendKeyPressSync( + browser(), ui::VKEY_TAB, false, false, false, false)); +#endif + ResultCatcher catcher; + ASSERT_TRUE(RunExtensionTest("keybinding/command_update")); + ASSERT_TRUE(catcher.GetNextResult()); + const Extension* extension = GetSingleLoadedExtension(); + + CommandService* command_service = CommandService::Get(browser()->profile()); + extensions::CommandMap named_commands; + command_service->GetNamedCommands(extension->id(), + extensions::CommandService::ACTIVE_ONLY, + extensions::CommandService::ANY_SCOPE, + &named_commands); + EXPECT_EQ(3u, named_commands.size()); + + const char kCommandNameC[] = "command_C"; + command_service->RemoveKeybindingPrefs(extension->id(), kCommandNameC); + command_service->GetNamedCommands(extension->id(), + extensions::CommandService::ACTIVE_ONLY, + extensions::CommandService::ANY_SCOPE, + &named_commands); + EXPECT_EQ(2u, named_commands.size()); + + // Send "Alt+C", it shouldn't work because it has been removed. + ASSERT_TRUE(ui_test_utils::SendKeyPressSync( + browser(), ui::VKEY_C, false, false, true, false)); + + const char kCommandNameB[] = "command_B"; + const char kKeyStroke[] = "Alt+A"; + command_service->UpdateKeybindingPrefs(extension->id(), + kCommandNameB, + kKeyStroke); + command_service->GetNamedCommands(extension->id(), + extensions::CommandService::ACTIVE_ONLY, + extensions::CommandService::ANY_SCOPE, + &named_commands); + EXPECT_EQ(1u, named_commands.size()); + + // Activate the shortcut (Alt+A). + ASSERT_TRUE(ui_test_utils::SendKeyPressSync( + browser(), ui::VKEY_A, false, false, true, false)); + ASSERT_TRUE(catcher.GetNextResult()) << message_; +} + } // namespace extensions |