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

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: Running try servers 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
diff --git a/chrome/browser/extensions/extension_commands_global_registry_apitest.cc b/chrome/browser/extensions/extension_commands_global_registry_apitest.cc
index 5d45810f781266fd1a151c9a91411508aac0027f..57bcd84780d47a3b08063c4065090311abd79a16 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,7 +73,46 @@ void SendNativeKeyEventToXDisplay(ui::KeyboardCode key,
}
#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);
+ 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)) \
+ || defined(OS_MACOSX)
// The feature is only fully implemented on Windows and Linux, other platforms
// coming.
#define MAYBE_GlobalCommand GlobalCommand
@@ -88,7 +133,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 +154,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 +166,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 +184,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
« 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