| 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 5d45810f781266fd1a151c9a91411508aac0027f..4ddaef46f5594d37232d5f91de2bd3515c5efe9b 100644
|
| --- a/chrome/browser/extensions/extension_commands_global_registry_apitest.cc
|
| +++ b/chrome/browser/extensions/extension_commands_global_registry_apitest.cc
|
| @@ -20,6 +20,12 @@
|
| #include "ui/gfx/x/x11_types.h"
|
| #endif
|
|
|
| +#if defined(OS_MACOSX)
|
| +#include <Carbon/Carbon.h>
|
| +
|
| +#include "base/mac/scoped_cftyperef.h"
|
| +#endif
|
| +
|
| namespace extensions {
|
|
|
| typedef ExtensionApiTest GlobalCommandsApiTest;
|
| @@ -67,6 +73,44 @@ void SendNativeKeyEventToXDisplay(ui::KeyboardCode key,
|
| }
|
| #endif // OS_LINUX
|
|
|
| +#if defined(OS_MACOSX)
|
| +using base::ScopedCFTypeRef;
|
| +
|
| +void SendNativeCommandShift(int key_code) {
|
| + CGEventSourceRef event_source =
|
| + CGEventSourceCreate(kCGEventSourceStateHIDSystemState);
|
| + CGEventTapLocation event_tap_location = kCGHIDEventTap;
|
| +
|
| + // Create the keyboard press events.
|
| + ScopedCFTypeRef<CGEventRef> command_down(CGEventCreateKeyboardEvent(
|
| + event_source, kVK_Command, true));
|
| + ScopedCFTypeRef<CGEventRef> shift_down(CGEventCreateKeyboardEvent(
|
| + event_source, kVK_Shift, true));
|
| + ScopedCFTypeRef<CGEventRef> key_down(CGEventCreateKeyboardEvent(
|
| + event_source, key_code, true));
|
| + CGEventSetFlags(key_down, kCGEventFlagMaskCommand | kCGEventFlagMaskShift);
|
| +
|
| + // Create the keyboard release events.
|
| + ScopedCFTypeRef<CGEventRef> command_up(CGEventCreateKeyboardEvent(
|
| + event_source, kVK_Command, false));
|
| + ScopedCFTypeRef<CGEventRef> shift_up(CGEventCreateKeyboardEvent(
|
| + event_source, kVK_Shift, false));
|
| + ScopedCFTypeRef<CGEventRef> key_up(CGEventCreateKeyboardEvent(
|
| + event_source, key_code, false));
|
| + CGEventSetFlags(key_up, kCGEventFlagMaskCommand | kCGEventFlagMaskShift);
|
| +
|
| + // Post all of the events.
|
| + CGEventPost(event_tap_location, command_down);
|
| + CGEventPost(event_tap_location, shift_down);
|
| + CGEventPost(event_tap_location, key_down);
|
| + CGEventPost(event_tap_location, key_up);
|
| + CGEventPost(event_tap_location, shift_up);
|
| + CGEventPost(event_tap_location, command_up);
|
| +
|
| + CFRelease(event_source);
|
| +}
|
| +#endif
|
| +
|
| #if defined(OS_WIN) || (defined(OS_LINUX) && !defined(OS_CHROMEOS))
|
| // The feature is only fully implemented on Windows and Linux, other platforms
|
| // coming.
|
| @@ -88,7 +132,7 @@ IN_PROC_BROWSER_TEST_F(GlobalCommandsApiTest, MAYBE_GlobalCommand) {
|
| ASSERT_TRUE(RunExtensionTest("keybinding/global")) << message_;
|
| ASSERT_TRUE(catcher.GetNextResult());
|
|
|
| -#if !defined(OS_LINUX)
|
| +#if defined(OS_WIN)
|
| // Our infrastructure for sending keys expects a browser to send them to, but
|
| // to properly test global shortcuts you need to send them to another target.
|
| // So, create an incognito browser to use as a target to send the shortcuts
|
| @@ -109,7 +153,7 @@ IN_PROC_BROWSER_TEST_F(GlobalCommandsApiTest, MAYBE_GlobalCommand) {
|
| // Activate the shortcut (Ctrl+Shift+9). This should have an effect.
|
| ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
|
| incognito_browser, ui::VKEY_9, true, true, false, false));
|
| -#else
|
| +#elif defined(OS_LINUX)
|
| // Create an incognito browser to capture the focus.
|
| CreateIncognitoBrowser();
|
|
|
| @@ -121,6 +165,14 @@ IN_PROC_BROWSER_TEST_F(GlobalCommandsApiTest, MAYBE_GlobalCommand) {
|
| SendNativeKeyEventToXDisplay(ui::VKEY_1, true, true, false);
|
| SendNativeKeyEventToXDisplay(ui::VKEY_A, true, true, false);
|
| SendNativeKeyEventToXDisplay(ui::VKEY_9, true, true, false);
|
| +#elif defined(OS_MACOSX)
|
| + // Create an incognito browser to capture the focus.
|
| + CreateIncognitoBrowser();
|
| +
|
| + // Send some native mac key events.
|
| + SendNativeCommandShift(kVK_ANSI_1);
|
| + SendNativeCommandShift(kVK_ANSI_A);
|
| + SendNativeCommandShift(kVK_ANSI_9);
|
| #endif
|
|
|
| // If this fails, it might be because the global shortcut failed to work,
|
| @@ -131,6 +183,7 @@ IN_PROC_BROWSER_TEST_F(GlobalCommandsApiTest, MAYBE_GlobalCommand) {
|
|
|
| #if defined(OS_WIN)
|
| // The feature is only fully implemented on Windows, other platforms coming.
|
| +// TODO(smus): On mac, SendKeyPress must first support media keys.
|
| #define MAYBE_GlobalDuplicatedMediaKey GlobalDuplicatedMediaKey
|
| #else
|
| #define MAYBE_GlobalDuplicatedMediaKey DISABLED_GlobalDuplicatedMediaKey
|
|
|