Commit 38d32753 authored by thakis@chromium.org's avatar thakis@chromium.org

Revert 222168 "Add a CodeToNativeKeycode helper that converts UI..."

UsbKeycodeMap.Basic consistently fails on the Win7 dbg main waterfall bot:
http://build.chromium.org/p/chromium.win/builders/Win7%20Tests%20(dbg)(1)
base\keycodes\usb_keycode_map_unittest.cc(36): error: Value of: "Unidentified"
Actual: 00890D98
Expected: InvalidKeyboardEventCode()
Which is: 007F90D4

> Add a CodeToNativeKeycode helper that converts UIEvent code to native code.
> Also add a SimulateKeyPress helper for browser_tests that takes both a UIEvent |code| and a ui::KeyboardCode.
> 
> issue=284754
> 
> Review URL: https://chromiumcodereview.appspot.com/23542008

TBR=weitaosu@chromium.org

Review URL: https://codereview.chromium.org/23451030

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@222199 0039d316-1c4b-4281-b951-d872f2087c98
parent 99f803a5
......@@ -31,19 +31,6 @@
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_getter.h"
#include "testing/gtest/include/gtest/gtest.h"
#if defined(OS_WIN)
#define USB_KEYMAP(usb, xkb, win, mac, code) {usb, win, code}
#elif defined(OS_LINUX)
#define USB_KEYMAP(usb, xkb, win, mac, code) {usb, xkb, code}
#elif defined(OS_MACOSX)
#define USB_KEYMAP(usb, xkb, win, mac, code) {usb, mac, code}
#else
#define USB_KEYMAP(usb, xkb, win, mac, code) {usb, 0, code}
#endif
#include "ui/base/keycodes/usb_keycode_map.h"
#undef USB_KEYMAP
#include "ui/base/resource/resource_bundle.h"
static const int kDefaultWsPort = 8880;
......@@ -133,15 +120,14 @@ bool ExecuteScriptHelper(RenderViewHost* render_view_host,
}
void BuildSimpleWebKeyEvent(WebKit::WebInputEvent::Type type,
ui::KeyboardCode key_code,
int native_key_code,
ui::KeyboardCode key,
bool control,
bool shift,
bool alt,
bool command,
NativeWebKeyboardEvent* event) {
event->nativeKeyCode = native_key_code;
event->windowsKeyCode = key_code;
event->nativeKeyCode = 0;
event->windowsKeyCode = key;
event->setKeyIdentifierFromWindowsKeyCode();
event->type = type;
event->modifiers = 0;
......@@ -151,8 +137,8 @@ void BuildSimpleWebKeyEvent(WebKit::WebInputEvent::Type type,
if (type == WebKit::WebInputEvent::Char ||
type == WebKit::WebInputEvent::RawKeyDown) {
event->text[0] = key_code;
event->unmodifiedText[0] = key_code;
event->text[0] = key;
event->unmodifiedText[0] = key;
}
if (control)
......@@ -279,57 +265,26 @@ void SimulateMouseEvent(WebContents* web_contents,
}
void SimulateKeyPress(WebContents* web_contents,
ui::KeyboardCode key_code,
ui::KeyboardCode key,
bool control,
bool shift,
bool alt,
bool command) {
SimulateKeyPressWithCode(
web_contents, key_code, NULL, control, shift, alt, command);
}
void SimulateKeyPressWithCode(WebContents* web_contents,
ui::KeyboardCode key_code,
const char* code,
bool control,
bool shift,
bool alt,
bool command) {
int native_key_code = CodeToNativeKeycode(code);
NativeWebKeyboardEvent event_down;
BuildSimpleWebKeyEvent(
WebKit::WebInputEvent::RawKeyDown,
key_code,
native_key_code,
control,
shift,
alt,
command,
WebKit::WebInputEvent::RawKeyDown, key, control, shift, alt, command,
&event_down);
web_contents->GetRenderViewHost()->ForwardKeyboardEvent(event_down);
NativeWebKeyboardEvent char_event;
BuildSimpleWebKeyEvent(
WebKit::WebInputEvent::Char,
key_code,
native_key_code,
control,
shift,
alt,
command,
WebKit::WebInputEvent::Char, key, control, shift, alt, command,
&char_event);
web_contents->GetRenderViewHost()->ForwardKeyboardEvent(char_event);
NativeWebKeyboardEvent event_up;
BuildSimpleWebKeyEvent(
WebKit::WebInputEvent::KeyUp,
key_code,
native_key_code,
control,
shift,
alt,
command,
WebKit::WebInputEvent::KeyUp, key, control, shift, alt, command,
&event_up);
web_contents->GetRenderViewHost()->ForwardKeyboardEvent(event_up);
}
......
......@@ -79,33 +79,8 @@ void SimulateMouseEvent(WebContents* web_contents,
const gfx::Point& point);
// Sends a key press asynchronously.
// The native code of the key event will be set to InvalidNativeKeycode().
// |key_code| alone is good enough for scenarios that only need the char
// value represented by a key event and not the physical key on the keyboard
// or the keyboard layout.
// For scenarios such as chromoting that need the native code,
// SimulateKeyPressWithCode should be used.
void SimulateKeyPress(WebContents* web_contents,
ui::KeyboardCode key_code,
bool control,
bool shift,
bool alt,
bool command);
// Sends a key press asynchronously.
// |code| specifies the UIEvents (aka: DOM4Events) value of the key:
// https://dvcs.w3.org/hg/d4e/raw-file/tip/source_respec.htm
// The native code of the key event will be set based on |code|.
// See ui/base/keycodes/vi usb_keycode_map.h for mappings between |code|
// and the native code.
// Examples of the various codes:
// key_code: VKEY_A
// code: "KeyA"
// native key code: 0x001e (for Windows).
// native key code: 0x0026 (for Linux).
void SimulateKeyPressWithCode(WebContents* web_contents,
ui::KeyboardCode key_code,
const char* code,
ui::KeyboardCode key,
bool control,
bool shift,
bool alt,
......
......@@ -17,6 +17,88 @@ using extensions::Extension;
namespace remoting {
// BuildSimpleWebKeyEvent and SimulateKeyPress below are adapted from
// content/public/test/browser_test_utils.cc.
// TODO: Move this to browser_test_utils.cc after the support is added for
// the UIEvent key |code|.
void BuildSimpleWebKeyEvent(WebKit::WebInputEvent::Type type,
ui::KeyboardCode key,
int nativeKeyCode,
bool control,
bool shift,
bool alt,
bool command,
content::NativeWebKeyboardEvent* event) {
event->nativeKeyCode = nativeKeyCode;
event->windowsKeyCode = key;
event->setKeyIdentifierFromWindowsKeyCode();
event->type = type;
event->modifiers = 0;
event->isSystemKey = false;
event->timeStampSeconds = base::Time::Now().ToDoubleT();
event->skip_in_browser = true;
if (type == WebKit::WebInputEvent::Char ||
type == WebKit::WebInputEvent::RawKeyDown) {
event->text[0] = key;
event->unmodifiedText[0] = key;
}
if (control)
event->modifiers |= WebKit::WebInputEvent::ControlKey;
if (shift)
event->modifiers |= WebKit::WebInputEvent::ShiftKey;
if (alt)
event->modifiers |= WebKit::WebInputEvent::AltKey;
if (command)
event->modifiers |= WebKit::WebInputEvent::MetaKey;
}
void SimulateKeyPress(content::WebContents* web_contents,
ui::KeyboardCode key,
int nativeKeyCode,
bool control,
bool shift,
bool alt,
bool command) {
content::NativeWebKeyboardEvent event_down;
BuildSimpleWebKeyEvent(
WebKit::WebInputEvent::RawKeyDown,
key, nativeKeyCode,
control,
shift,
alt,
command,
&event_down);
web_contents->GetRenderViewHost()->ForwardKeyboardEvent(event_down);
content::NativeWebKeyboardEvent char_event;
BuildSimpleWebKeyEvent(
WebKit::WebInputEvent::Char,
key, nativeKeyCode,
control,
shift,
alt,
command,
&char_event);
web_contents->GetRenderViewHost()->ForwardKeyboardEvent(char_event);
content::NativeWebKeyboardEvent event_up;
BuildSimpleWebKeyEvent(
WebKit::WebInputEvent::KeyUp,
key,
nativeKeyCode,
control,
shift,
alt,
command,
&event_up);
web_contents->GetRenderViewHost()->ForwardKeyboardEvent(event_up);
}
RemoteDesktopBrowserTest::RemoteDesktopBrowserTest() {}
RemoteDesktopBrowserTest::~RemoteDesktopBrowserTest() {}
......@@ -200,23 +282,25 @@ void RemoteDesktopBrowserTest::StartMe2Me() {
EXPECT_FALSE(HtmlElementVisible("me2me-first-run"));
}
void RemoteDesktopBrowserTest::SimulateKeyPressWithCode(
ui::KeyboardCode keyCode,
const char* code) {
SimulateKeyPressWithCode(keyCode, code, false, false, false, false);
void RemoteDesktopBrowserTest::SimulateKeyPress(
ui::KeyboardCode key,
int nativeKeyCode) {
SimulateKeyPress(key, nativeKeyCode, false, false, false, false);
}
void RemoteDesktopBrowserTest::SimulateKeyPressWithCode(
ui::KeyboardCode keyCode,
const char* code,
void RemoteDesktopBrowserTest::SimulateKeyPress(
ui::KeyboardCode key,
int nativeKeyCode,
bool control,
bool shift,
bool alt,
bool command) {
content::SimulateKeyPressWithCode(
// TODO: Switch to content::SimulateKeyPress when an overload of it is
// added to take the UIEvent key |code| string.
remoting::SimulateKeyPress(
browser()->tab_strip_model()->GetActiveWebContents(),
keyCode,
code,
key,
nativeKeyCode,
control,
shift,
alt,
......
......@@ -82,10 +82,10 @@ class RemoteDesktopBrowserTest : public ExtensionBrowserTest {
void StartMe2Me();
// Simulate a key event.
void SimulateKeyPressWithCode(ui::KeyboardCode keyCode, const char* code);
void SimulateKeyPress(ui::KeyboardCode key, int nativeKeyCode);
void SimulateKeyPressWithCode(ui::KeyboardCode keyCode,
const char* code,
void SimulateKeyPress(ui::KeyboardCode key,
int nativeKeyCode,
bool control,
bool shift,
bool alt,
......
......@@ -399,21 +399,6 @@ inline const char* NativeKeycodeToCode(uint16_t native_keycode) {
return InvalidKeyboardEventCode();
}
inline uint16_t CodeToNativeKeycode(const char* code) {
if (!code ||
strcmp(code, InvalidKeyboardEventCode()) == 0) {
return InvalidNativeKeycode();
}
for (size_t i = 0; i < arraysize(usb_keycode_map); ++i) {
if (usb_keycode_map[i].code &&
strcmp(usb_keycode_map[i].code, code) == 0) {
return usb_keycode_map[i].native_keycode;
}
}
return InvalidNativeKeycode();
}
// USB keycodes
// Note that USB keycodes are not part of any web standard.
// Please don't use USB keycodes in new code.
......
......@@ -33,8 +33,6 @@ TEST(UsbKeycodeMap, Basic) {
// Verify that the first element in the table is the "invalid" code.
EXPECT_EQ(InvalidUsbKeycode(), usb_keycode_map[0].usb_keycode);
EXPECT_EQ(InvalidNativeKeycode(), usb_keycode_map[0].native_keycode);
EXPECT_EQ(InvalidKeyboardEventCode(), "Unidentified");
EXPECT_EQ(InvalidNativeKeycode(), CodeToNativeKeycode("Unidentified"));
// Verify that there are no duplicate entries in the mapping.
std::map<uint32_t, uint16_t> usb_to_native;
......@@ -48,18 +46,6 @@ TEST(UsbKeycodeMap, Basic) {
EXPECT_EQ(usb_keycode_map[i].native_keycode,
UsbKeycodeToNativeKeycode(usb_keycode_map[i].usb_keycode));
// Verify CodeToNativeKeycode and NativeKeycodeToCode work correctly.
if (usb_keycode_map[i].code) {
EXPECT_EQ(usb_keycode_map[i].native_keycode,
CodeToNativeKeycode(usb_keycode_map[i].code));
EXPECT_EQ(usb_keycode_map[i].code,
NativeKeycodeToCode(usb_keycode_map[i].native_keycode));
}
else {
EXPECT_EQ(InvalidNativeKeycode(),
CodeToNativeKeycode(usb_keycode_map[i].code));
}
// Verify that the USB or native codes aren't duplicated.
EXPECT_EQ(0U, usb_to_native.count(usb_keycode_map[i].usb_keycode))
<< " duplicate of USB code 0x" << std::hex << std::setfill('0')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment