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,10 @@ |
#include "ui/gfx/x/x11_types.h" |
#endif |
+#if defined(OS_MACOSX) |
+#include <Carbon/Carbon.h> |
+#endif |
+ |
namespace extensions { |
typedef ExtensionApiTest GlobalCommandsApiTest; |
@@ -67,7 +71,40 @@ |
} |
#endif // OS_LINUX |
-#if defined(OS_WIN) || (defined(OS_LINUX) && !defined(OS_CHROMEOS)) |
+#if defined(OS_MACOSX) |
+void SendNativeCommandShift(int key_code) { |
+ CGEventSourceRef src = |
+ CGEventSourceCreate(kCGEventSourceStateHIDSystemState); |
+ |
+ CGEventRef cmd_d = CGEventCreateKeyboardEvent(src, kVK_Command, true); |
Robert Sesek
2013/12/09 19:17:42
You should place these in a ScopedCFTypeRef so tha
Mark Mentovai
2013/12/09 19:31:54
This sounds like the key event is for command-D, c
smus
2013/12/09 23:37:06
Done.
|
+ CGEventRef cmd_u = CGEventCreateKeyboardEvent(src, kVK_Command, false); |
Mark Mentovai
2013/12/09 19:31:54
Why don’t you create these in the order that they
smus
2013/12/09 23:37:06
Done.
|
+ CGEventRef shift_d = CGEventCreateKeyboardEvent(src, kVK_Shift, true); |
+ CGEventRef shift_u = CGEventCreateKeyboardEvent(src, kVK_Shift, false); |
+ CGEventRef key_d = CGEventCreateKeyboardEvent(src, key_code, true); |
+ CGEventRef key_u = CGEventCreateKeyboardEvent(src, key_code, false); |
+ |
+ CGEventSetFlags(key_d, kCGEventFlagMaskCommand | kCGEventFlagMaskShift); |
Mark Mentovai
2013/12/09 19:31:54
This should immediately follow the creation of key
smus
2013/12/09 23:37:06
Done.
|
+ CGEventSetFlags(key_u, kCGEventFlagMaskCommand | kCGEventFlagMaskShift); |
Mark Mentovai
2013/12/09 19:31:54
Ditto, key_u.
smus
2013/12/09 23:37:06
Done.
|
+ |
+ CGEventTapLocation loc = kCGHIDEventTap; // kCGSessionEventTap also works |
Mark Mentovai
2013/12/09 19:31:54
http://google-styleguide.googlecode.com/svn/trunk/
smus
2013/12/09 23:37:06
Done.
|
+ CGEventPost(loc, cmd_d); |
+ CGEventPost(loc, shift_d); |
+ CGEventPost(loc, key_d); |
+ CGEventPost(loc, key_u); |
+ CGEventPost(loc, shift_u); |
+ CGEventPost(loc, cmd_u); |
+ |
+ CFRelease(cmd_d); |
Mark Mentovai
2013/12/09 19:31:54
Use a base::ScopedCFTypeRef (base/mac/scoped_cftyp
smus
2013/12/09 23:37:06
Done.
|
+ CFRelease(cmd_u); |
+ CFRelease(shift_d); |
+ CFRelease(shift_u); |
+ CFRelease(key_d); |
+ CFRelease(key_u); |
+ CFRelease(src); |
+} |
+#endif |
+ |
+#if defined(OS_WIN) || (defined(OS_LINUX) && !defined(OS_CHROMEOS)) || defined(OS_MACOSX) |
// The feature is only fully implemented on Windows and Linux, other platforms |
// coming. |
#define MAYBE_GlobalCommand GlobalCommand |
@@ -88,7 +125,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 +146,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 +158,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 +176,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 |