Index: chrome/browser/extensions/extension_commands_global_registry_apitest.cc |
=================================================================== |
--- chrome/browser/extensions/extension_commands_global_registry_apitest.cc (revision 239014) |
+++ chrome/browser/extensions/extension_commands_global_registry_apitest.cc (working copy) |
@@ -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,7 +73,43 @@ |
} |
#endif // OS_LINUX |
-#if defined(OS_WIN) || (defined(OS_LINUX) && !defined(OS_CHROMEOS)) |
+#if defined(OS_MACOSX) |
+using base::ScopedCFTypeRef; |
+ |
+void SendNativeCommandShift(int key_code) { |
+ CGEventSourceRef event_source = |
+ CGEventSourceCreate(kCGEventSourceStateHIDSystemState); |
Robert Sesek
2013/12/12 20:33:10
nit: indent 2 more spaces
smus
2013/12/12 21:13:52
Done.
|
+ 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); |
+} |
+#endif |
+ |
+#if defined(OS_WIN) || (defined(OS_LINUX) && !defined(OS_CHROMEOS)) || defined(OS_MACOSX) |
Robert Sesek
2013/12/12 20:33:10
nit: 80 columns
smus
2013/12/12 21:13:52
Done.
|
// The feature is only fully implemented on Windows and Linux, other platforms |
// coming. |
#define MAYBE_GlobalCommand GlobalCommand |
@@ -88,7 +130,7 @@ |
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 +151,7 @@ |
// 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 +163,14 @@ |
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 +181,7 @@ |
#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 |