diff options
7 files changed, 112 insertions, 5 deletions
@@ -20,6 +20,7 @@ Aditya Bhargava <heuristicist@gmail.com> Ajay Berwal <ajay.berwal@samsung.com> Ajith Kumar V <ajith.v@samsung.com> Aku Kotkavuo <a.kotkavuo@partner.samsung.com> +Alex Gabriel <minilogo@gmail.com> Alex Gartrell <agartrell@cmu.edu> Alex Henrie <alexhenrie24@gmail.com> Alex Scheele <alexscheele@gmail.com> diff --git a/chrome/browser/extensions/api/commands/command_service.cc b/chrome/browser/extensions/api/commands/command_service.cc index 3fd21e6..33a522e 100644 --- a/chrome/browser/extensions/api/commands/command_service.cc +++ b/chrome/browser/extensions/api/commands/command_service.cc @@ -550,15 +550,15 @@ void CommandService::AssignKeybindings(const Extension* extension) { bool CommandService::CanAutoAssign(const Command &command, const Extension* extension) { - // Media Keys are non-exclusive, so allow auto-assigning them. - if (Command::IsMediaKey(command.accelerator())) - return true; - // Extensions are allowed to auto-assign updated keys if the user has not // changed from the previous value. if (IsCommandShortcutUserModified(extension, command.command_name())) return false; + // Media Keys are non-exclusive, so allow auto-assigning them. + if (Command::IsMediaKey(command.accelerator())) + return true; + if (command.global()) { using namespace extensions; if (command.command_name() == manifest_values::kBrowserActionCommandEvent || diff --git a/chrome/browser/extensions/extension_keybinding_apitest.cc b/chrome/browser/extensions/extension_keybinding_apitest.cc index aba521d..7a1c8e9 100644 --- a/chrome/browser/extensions/extension_keybinding_apitest.cc +++ b/chrome/browser/extensions/extension_keybinding_apitest.cc @@ -37,7 +37,11 @@ const char kId[] = "pgoakhfeplldmjheffidklpoklkppipp"; // Default keybinding to use for emulating user-defined shortcut overrides. The // test extensions use Alt+Shift+F and Alt+Shift+H. const char kAltShiftG[] = "Alt+Shift+G"; -} + +// Named command for media key overwrite test. +const char kMediaKeyTestCommand[] = "test_mediakeys_update"; + +} // namespace class CommandsApiTest : public ExtensionApiTest { public: @@ -674,6 +678,60 @@ IN_PROC_BROWSER_TEST_F(CommandsApiTest, EXPECT_TRUE(accelerator.IsAltDown()); } +// Test that Media keys do not overwrite previous settings. +IN_PROC_BROWSER_TEST_F(CommandsApiTest, + MediaKeyShortcutChangedOnUpdateAfterBeingReassignedByUser) { + base::ScopedTempDir scoped_temp_dir; + EXPECT_TRUE(scoped_temp_dir.CreateUniqueTempDir()); + base::FilePath pem_path = test_data_dir_. + AppendASCII("keybinding").AppendASCII("keybinding.pem"); + base::FilePath path_v1 = PackExtensionWithOptions( + test_data_dir_.AppendASCII("keybinding").AppendASCII("update") + .AppendASCII("mk_v1"), + scoped_temp_dir.path().AppendASCII("mk_v1.crx"), + pem_path, + base::FilePath()); + base::FilePath path_v2_reassigned = PackExtensionWithOptions( + test_data_dir_.AppendASCII("keybinding").AppendASCII("update") + .AppendASCII("mk_v2"), + scoped_temp_dir.path().AppendASCII("mk_v2.crx"), + pem_path, + base::FilePath()); + + ExtensionRegistry* registry = ExtensionRegistry::Get(browser()->profile()); + CommandService* command_service = CommandService::Get(browser()->profile()); + + // Install v1 of the extension. + ASSERT_TRUE(InstallExtension(path_v1, 1)); + EXPECT_TRUE(registry->GetExtensionById(kId, ExtensionRegistry::ENABLED) != + NULL); + + // Verify it has a command of MediaPlayPause. + ui::Accelerator accelerator = command_service->FindCommandByName( + kId, kMediaKeyTestCommand).accelerator(); + EXPECT_EQ(ui::VKEY_MEDIA_PLAY_PAUSE, accelerator.key_code()); + EXPECT_FALSE(accelerator.IsCtrlDown()); + EXPECT_FALSE(accelerator.IsShiftDown()); + EXPECT_FALSE(accelerator.IsAltDown()); + + // Simulate the user setting the keybinding to Alt+Shift+G. + command_service->UpdateKeybindingPrefs( + kId, kMediaKeyTestCommand, kAltShiftG); + + // Update to version 2 with different keybinding assigned. + EXPECT_TRUE(UpdateExtension(kId, path_v2_reassigned, 0)); + EXPECT_TRUE(registry->GetExtensionById(kId, ExtensionRegistry::ENABLED) != + NULL); + + // Verify it has a command of Alt+Shift+G. + accelerator = command_service->FindCommandByName( + kId, kMediaKeyTestCommand).accelerator(); + EXPECT_EQ(ui::VKEY_G, accelerator.key_code()); + EXPECT_FALSE(accelerator.IsCtrlDown()); + EXPECT_TRUE(accelerator.IsShiftDown()); + EXPECT_TRUE(accelerator.IsAltDown()); +} + IN_PROC_BROWSER_TEST_F(CommandsApiTest, ShortcutRemovedOnUpdateAfterBeingReassignedByUser) { base::ScopedTempDir scoped_temp_dir; diff --git a/chrome/test/data/extensions/api_test/keybinding/update/mk_v1/background.js b/chrome/test/data/extensions/api_test/keybinding/update/mk_v1/background.js new file mode 100644 index 0000000..ce736cd --- /dev/null +++ b/chrome/test/data/extensions/api_test/keybinding/update/mk_v1/background.js @@ -0,0 +1,5 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +chrome.test.notifyPass(); diff --git a/chrome/test/data/extensions/api_test/keybinding/update/mk_v1/manifest.json b/chrome/test/data/extensions/api_test/keybinding/update/mk_v1/manifest.json new file mode 100644 index 0000000..53fc39c --- /dev/null +++ b/chrome/test/data/extensions/api_test/keybinding/update/mk_v1/manifest.json @@ -0,0 +1,19 @@ +{ + "name": "A test for making sure media keys that get reassigned don't get + reinstated during update.", + "version": "1.0", + "manifest_version": 2, + "background": { + "scripts": ["background.js"] + }, + "permissions": ["activeTab"], + "commands": { + "test_mediakeys_update": { + "suggested_key": { + "default": "MediaPlayPause" + }, + "description": "Test for mediakeys update overwrite", + "global": true + } + } +} diff --git a/chrome/test/data/extensions/api_test/keybinding/update/mk_v2/background.js b/chrome/test/data/extensions/api_test/keybinding/update/mk_v2/background.js new file mode 100644 index 0000000..ce736cd --- /dev/null +++ b/chrome/test/data/extensions/api_test/keybinding/update/mk_v2/background.js @@ -0,0 +1,5 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +chrome.test.notifyPass(); diff --git a/chrome/test/data/extensions/api_test/keybinding/update/mk_v2/manifest.json b/chrome/test/data/extensions/api_test/keybinding/update/mk_v2/manifest.json new file mode 100644 index 0000000..a59e8f1 --- /dev/null +++ b/chrome/test/data/extensions/api_test/keybinding/update/mk_v2/manifest.json @@ -0,0 +1,19 @@ +{ + "name": "A test for making sure media keys that get reassigned don't get + reinstated during update.", + "version": "2.0", + "manifest_version": 2, + "background": { + "scripts": ["background.js"] + }, + "permissions": ["activeTab"], + "commands": { + "test_mediakeys_update": { + "suggested_key": { + "default": "MediaPlayPause" + }, + "description": "Test for mediakeys update overwrite", + "global": true + } + } +} |