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

Unified Diff: ui/events/test/keyboard_layout_mac.cc

Issue 2197113002: Force U.S. English keyboard layout for TextfieldTest.KeysWithModifiersTest (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix review issues Created 4 years, 4 months 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: ui/events/test/keyboard_layout_mac.cc
diff --git a/ui/events/test/keyboard_layout_mac.cc b/ui/events/test/keyboard_layout_mac.cc
new file mode 100644
index 0000000000000000000000000000000000000000..2e120b0337122703ad34dece82cdb11a2503d05b
--- /dev/null
+++ b/ui/events/test/keyboard_layout_mac.cc
@@ -0,0 +1,50 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ui/events/test/keyboard_layout.h"
+
+#include "base/logging.h"
+
+namespace ui {
+
+PlatformKeyboardLayout GetPlatformKeyboardLayout(KeyboardLayout layout) {
+ const char* input_source_id;
+ switch (layout) {
+ case KEYBOARD_LAYOUT_ENGLISH_US:
+ input_source_id = "com.apple.keylayout.US";
+ break;
+ case KEYBOARD_LAYOUT_GERMAN:
+ input_source_id = "com.apple.keylayout.German";
+ break;
+ default:
+ NOTREACHED();
+ return PlatformKeyboardLayout();
Peter Kasting 2016/08/26 18:54:33 Nit: I still probably would have tried to avoid ha
Tomasz Moniuszko 2016/08/31 15:29:42 Actually, it seems that tests which need German ke
+ }
+
+ base::ScopedCFTypeRef<CFMutableDictionaryRef> filter_dict(
+ CFDictionaryCreateMutable(kCFAllocatorDefault, 1,
+ &kCFTypeDictionaryKeyCallBacks,
+ &kCFTypeDictionaryValueCallBacks));
+ base::ScopedCFTypeRef<CFStringRef> id_ref(CFStringCreateWithCString(
+ kCFAllocatorDefault, input_source_id, kCFStringEncodingUTF8));
+ CFDictionaryAddValue(filter_dict, kTISPropertyInputSourceID, id_ref);
+ base::ScopedCFTypeRef<CFArrayRef> sources(
+ TISCreateInputSourceList(filter_dict, true));
+ if (CFArrayGetCount(sources) != 1)
+ return PlatformKeyboardLayout();
+
+ return PlatformKeyboardLayout(
+ (TISInputSourceRef)CFArrayGetValueAtIndex(sources, 0));
+}
+
+PlatformKeyboardLayout ScopedKeyboardLayout::GetActiveLayout() {
+ return PlatformKeyboardLayout(TISCopyCurrentKeyboardInputSource());
+}
+
+bool ScopedKeyboardLayout::ActivateLayout(PlatformKeyboardLayout layout) {
+ DCHECK(layout);
+ return TISSelectInputSource(layout) == noErr;
+}
+
+} // namespace ui

Powered by Google App Engine
This is Rietveld 408576698