Make hitting "Enter" submit the add/change profile dialog.
[chromium-blink-merge.git] / chrome / test / webdriver / webdriver_test_util.cc
blobce464b11b97618f2180b9f6530c9698591bf2b65
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/test/webdriver/webdriver_test_util.h"
7 #include "base/logging.h"
8 #include "base/utf_string_conversions.h"
10 namespace webdriver {
12 RestoreKeyboardLayoutOnDestruct::RestoreKeyboardLayoutOnDestruct() {
13 #if defined(OS_WIN)
14 layout_ = GetKeyboardLayout(NULL);
15 #elif defined(OS_MACOSX)
16 layout_.reset(TISCopyCurrentKeyboardInputSource());
17 #elif defined(OS_LINUX)
18 NOTIMPLEMENTED();
19 #endif
22 RestoreKeyboardLayoutOnDestruct::~RestoreKeyboardLayoutOnDestruct() {
23 #if defined(OS_WIN)
24 ActivateKeyboardLayout(layout_, 0);
25 #elif defined(OS_MACOSX)
26 TISSelectInputSource(layout_);
27 #elif defined(OS_LINUX)
28 NOTIMPLEMENTED();
29 #endif
32 #if defined(OS_WIN)
33 bool SwitchKeyboardLayout(const std::string& input_locale_identifier) {
34 HKL layout = LoadKeyboardLayout(
35 UTF8ToWide(input_locale_identifier).c_str(), 0);
36 if (!layout)
37 return false;
38 return !!ActivateKeyboardLayout(layout, 0);
40 #endif // defined(OS_WIN)
42 #if defined(OS_MACOSX)
43 bool SwitchKeyboardLayout(const std::string& input_source_id) {
44 base::mac::ScopedCFTypeRef<CFMutableDictionaryRef> filter_dict(
45 CFDictionaryCreateMutable(kCFAllocatorDefault,
47 &kCFTypeDictionaryKeyCallBacks,
48 &kCFTypeDictionaryValueCallBacks));
49 base::mac::ScopedCFTypeRef<CFStringRef> id_ref(CFStringCreateWithCString(
50 kCFAllocatorDefault, input_source_id.c_str(), kCFStringEncodingUTF8));
51 CFDictionaryAddValue(filter_dict, kTISPropertyInputSourceID, id_ref);
52 base::mac::ScopedCFTypeRef<CFArrayRef> sources(
53 TISCreateInputSourceList(filter_dict, true));
54 if (CFArrayGetCount(sources) != 1)
55 return false;
56 TISInputSourceRef source = (TISInputSourceRef)CFArrayGetValueAtIndex(
57 sources, 0);
58 return TISSelectInputSource(source) == noErr;
60 #endif // defined(OS_WIN)
62 } // namespace webdriver