Chromium Code Reviews| Index: chrome/browser/extensions/extension_commands_global_registry_apitest.cc |
| diff --git a/chrome/browser/extensions/extension_commands_global_registry_apitest.cc b/chrome/browser/extensions/extension_commands_global_registry_apitest.cc |
| index b9b5f6d7c77b83a684ffc192f8a59295f93ba3b4..c18e8482fdaf0e50ed3b336cb883c1ea6740fb73 100644 |
| --- a/chrome/browser/extensions/extension_commands_global_registry_apitest.cc |
| +++ b/chrome/browser/extensions/extension_commands_global_registry_apitest.cc |
| @@ -17,6 +17,8 @@ |
| #include "ui/events/keycodes/keyboard_code_conversion_x.h" |
| #include "ui/gfx/x/x11_types.h" |
| +#elif defined(OS_WIN) |
| +#include "ui/events/keycodes/keyboard_code_conversion_win.h" |
| #endif |
| namespace extensions { |
| @@ -66,6 +68,91 @@ void SendNativeKeyEventToXDisplay(ui::KeyboardCode key, |
| } |
| #endif // OS_LINUX |
| +#if defined(OS_WIN) |
| +bool FillKeyboardInput(ui::KeyboardCode key, INPUT* input, bool key_up) { |
| + memset(input, 0, sizeof(INPUT)); |
| + input->type = INPUT_KEYBOARD; |
| + input->ki.wVk = ui::WindowsKeyCodeForKeyboardCode(key); |
| + input->ki.dwFlags = key_up ? KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP : |
| + KEYEVENTF_EXTENDEDKEY; |
| + |
| + return true; |
| +} |
|
Finnur
2013/11/12 16:27:54
Why do we need to copy this function?
|
| + |
| +// This function is modified from |SendKeyPressImpl| of |
| +// ui_controls_internal_win.cc. Use ui_test_utils::SendKeyPressSync when testing |
| +// global media keys will fail, this is because we have register the single key |
| +// using RegisterHotKey, so the keyboard hook of current thread will never be |
| +// called when we only send the single key (For example: "MediaNextTrack" down |
| +// -> "MediaNextTrack" up). The difference when testing global key combinations: |
| +// the key event are sent one by one. For example, sending "Ctrl+Shift+1", we |
| +// will send "Ctrl" down -> "Shift" down -> "1" down, (here the hot key is |
| +// activated.), then 1 "up" (here InputDispatcher will receive an key up event, |
| +// then the message loop in |SendKeyPressToWindowSync| could stop running |
| +// normally) -> "Shift" up -> "Ctrl" up. |
| +// |
| +// Note: The above comment is only when I have digged out when investigate why |
| +// using ui_test_utils::SendKeyPressSync to test global media keys will fail. |
| +// I need some help about whether we can use this custom function? |
| +// TODO(zhchbin): Clear up the comment. |
|
Finnur
2013/11/12 16:27:54
I think this is not the right approach.
1) I'm not
zhchbin
2013/11/13 05:01:57
You can do an experiment:
1. Change the SendNativ
zhchbin
2013/11/13 16:05:10
Maybe you ignore this comment?
Finnur
2013/11/18 11:16:14
I didn't have a good advice for you because I don'
zhchbin
2013/11/18 13:10:13
The message loop is: https://code.google.com/p/chr
Finnur
2013/11/18 14:14:53
I think this is the one remaining issue before you
zhchbin
2013/11/18 14:54:44
Em... first of all, sorry for my poor English that
|
| +bool SendNativeKeyEvent(ui::KeyboardCode key, |
| + bool control, |
| + bool shift, |
| + bool alt) { |
| + INPUT input[8] = { 0 }; // 8, assuming all the modifiers are activated. |
| + |
| + UINT i = 0; |
| + if (control) { |
| + if (!FillKeyboardInput(ui::VKEY_CONTROL, &input[i], false)) |
| + return false; |
| + i++; |
| + } |
| + |
| + if (shift) { |
| + if (!FillKeyboardInput(ui::VKEY_SHIFT, &input[i], false)) |
| + return false; |
| + i++; |
| + } |
| + |
| + if (alt) { |
| + if (!FillKeyboardInput(ui::VKEY_MENU, &input[i], false)) |
| + return false; |
| + i++; |
| + } |
| + |
| + if (!FillKeyboardInput(key, &input[i], false)) |
| + return false; |
| + i++; |
| + |
| + if (!FillKeyboardInput(key, &input[i], true)) |
| + return false; |
| + i++; |
| + |
| + if (alt) { |
| + if (!FillKeyboardInput(ui::VKEY_MENU, &input[i], true)) |
| + return false; |
| + i++; |
| + } |
| + |
| + if (shift) { |
| + if (!FillKeyboardInput(ui::VKEY_SHIFT, &input[i], true)) |
| + return false; |
| + i++; |
| + } |
| + |
| + if (control) { |
| + if (!FillKeyboardInput(ui::VKEY_CONTROL, &input[i], true)) |
| + return false; |
| + i++; |
| + } |
| + |
| + if (::SendInput(i, input, sizeof(INPUT)) != i) |
| + return false; |
| + |
| + return true; |
| +} |
| +#endif // OS_WIN |
| + |
| #if defined(OS_WIN) || (defined(OS_LINUX) && !defined(OS_CHROMEOS)) |
| // The feature is only fully implemented on Windows and Linux, other platforms |
| // coming. |
| @@ -128,4 +215,31 @@ IN_PROC_BROWSER_TEST_F(GlobalCommandsApiTest, MAYBE_GlobalCommand) { |
| ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| } |
| +#if defined(OS_WIN) |
| +// The feature is only fully implemented on Windows, other platforms coming. |
| +#define MAYBE_GlobalDuplicatedMediaKey GlobalDuplicatedMediaKey |
| +#else |
| +#define MAYBE_GlobalDuplicatedMediaKey DISABLED_GlobalDuplicatedMediaKey |
| +#endif |
| + |
| +IN_PROC_BROWSER_TEST_F(GlobalCommandsApiTest, MAYBE_GlobalDuplicatedMediaKey) { |
| + FeatureSwitch::ScopedOverride enable_global_commands( |
| + FeatureSwitch::global_commands(), true); |
| + |
| + ResultCatcher catcher; |
| + ASSERT_TRUE(RunExtensionTest("keybinding/global_media_keys_0")) << message_; |
| + ASSERT_TRUE(catcher.GetNextResult()); |
| + ASSERT_TRUE(RunExtensionTest("keybinding/global_media_keys_1")) << message_; |
| + ASSERT_TRUE(catcher.GetNextResult()); |
| + |
| + WindowController* controller = browser()->extension_window_controller(); |
| + controller->window()->Minimize(); |
| + |
| + SendNativeKeyEvent(ui::VKEY_MEDIA_NEXT_TRACK, false, false, false); |
| + |
| + // We should get two success result. |
| + ASSERT_TRUE(catcher.GetNextResult()); |
| + ASSERT_TRUE(catcher.GetNextResult()); |
| +} |
| + |
| } // namespace extensions |