Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1947)

Unified Diff: chrome/browser/extensions/extension_commands_global_registry_apitest.cc

Issue 60353008: Mac global keybindings (Closed) Base URL: https://src.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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,44 @@
}
#endif // OS_LINUX
-#if defined(OS_WIN) || (defined(OS_LINUX) && !defined(OS_CHROMEOS))
+#if defined(OS_MACOSX)
+// From http://goo.gl/N5AwAJ:
+const int kKeyCodeCommand = 55;
+const int kKeyCodeShift = 56;
+
+void SendNativeKeyEventMac(ui::KeyboardCode key) {
+ CGEventSourceRef src =
+ CGEventSourceCreate(kCGEventSourceStateHIDSystemState);
+
+ CGEventRef cmd_d = CGEventCreateKeyboardEvent(src, kKeyCodeCommand, true);
+ CGEventRef cmd_u = CGEventCreateKeyboardEvent(src, kKeyCodeCommand, false);
+ CGEventRef shift_d = CGEventCreateKeyboardEvent(src, kKeyCodeShift, true);
+ CGEventRef shift_u = CGEventCreateKeyboardEvent(src, kKeyCodeShift, false);
+ CGEventRef key_d = CGEventCreateKeyboardEvent(src, key, true);
+ CGEventRef key_u = CGEventCreateKeyboardEvent(src, key, false);
+
+ CGEventSetFlags(key_d, kCGEventFlagMaskCommand | kCGEventFlagMaskShift);
+ CGEventSetFlags(key_u, kCGEventFlagMaskCommand | kCGEventFlagMaskShift);
+
+ CGEventTapLocation loc = kCGHIDEventTap; // kCGSessionEventTap also works
+ 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);
+ 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 +129,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 +150,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 +162,13 @@
SendNativeKeyEventToXDisplay(ui::VKEY_1, true, true, false);
SendNativeKeyEventToXDisplay(ui::VKEY_A, true, true, false);
SendNativeKeyEventToXDisplay(ui::VKEY_9, true, true, false);
+ SendNativeKeyEventToXDisplay((ui::KeyboardCode)0x39, true, true, false);
Finnur 2013/12/09 17:29:08 wait... what is this for?
smus 2013/12/09 18:11:01 Done.
+#elif defined(OS_MACOSX)
+ // Create an incognito browser to capture the focus.
+ CreateIncognitoBrowser();
+
+ // Expect Command N.
+ SendNativeKeyEventMac((ui::KeyboardCode)25);
Finnur 2013/12/09 17:29:08 I'm confused... The other platforms send Ctrl+Shi
smus 2013/12/09 18:11:01 I uploaded some stale version of the CL. Here's an
#endif
// If this fails, it might be because the global shortcut failed to work,
@@ -131,6 +179,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
« no previous file with comments | « chrome/browser/extensions/api/commands/command_service.cc ('k') | chrome/browser/extensions/global_shortcut_listener_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698