Skip to content

Commit

Permalink
[Reland #1] ChromeDriver: Handle key events properly on Mac
Browse files Browse the repository at this point in the history
Fixes devtool's emulation of key input events to emulate
os key event for OSX.

Original CL: https://codereview.chromium.org/2656903005
Only major difference between two CLs is we now bypass browser
if native_key_code was not set.

667387, 732053

Change-Id: If99f002491ef55caadbb7c82bcf55a2d1dbff8e6
Reviewed-on: https://chromium-review.googlesource.com/562583
Commit-Queue: Blaise Bruer <[email protected]>
Reviewed-by: Dmitry Gozman <[email protected]>
Reviewed-by: Erik Chen <[email protected]>
Cr-Commit-Position: refs/heads/master@{#489156}
  • Loading branch information
allada authored and Commit Bot committed Jul 25, 2017
1 parent c2960a7 commit 59ae567
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions front_end/Tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,61 @@
step1();
};

TestSuite.prototype.testDispatchKeyEventShowsAutoFill = function() {
var test = this;
var receivedReady = false;

function signalToShowAutofill() {
SDK.targetManager.mainTarget().inputAgent().invoke_dispatchKeyEvent(
{type: 'rawKeyDown', key: 'Down', windowsVirtualKeyCode: 40, nativeVirtualKeyCode: 40});
SDK.targetManager.mainTarget().inputAgent().invoke_dispatchKeyEvent(
{type: 'keyUp', key: 'Down', windowsVirtualKeyCode: 40, nativeVirtualKeyCode: 40});
}

function selectTopAutoFill() {
SDK.targetManager.mainTarget().inputAgent().invoke_dispatchKeyEvent(
{type: 'rawKeyDown', key: 'Down', windowsVirtualKeyCode: 40, nativeVirtualKeyCode: 40});
SDK.targetManager.mainTarget().inputAgent().invoke_dispatchKeyEvent(
{type: 'keyUp', key: 'Down', windowsVirtualKeyCode: 40, nativeVirtualKeyCode: 40});
SDK.targetManager.mainTarget().inputAgent().invoke_dispatchKeyEvent(
{type: 'rawKeyDown', key: 'Enter', windowsVirtualKeyCode: 13, nativeVirtualKeyCode: 13});
SDK.targetManager.mainTarget().inputAgent().invoke_dispatchKeyEvent(
{type: 'keyUp', key: 'Enter', windowsVirtualKeyCode: 13, nativeVirtualKeyCode: 13});

test.evaluateInConsole_('document.getElementById("name").value', onResultOfInput);
}

function onResultOfInput(value) {
// Console adds "" around the response.
test.assertEquals('"Abbf"', value);
test.releaseControl();
}

function onConsoleMessage(event) {
var message = event.data.messageText;
if (message === 'ready' && !receivedReady) {
receivedReady = true;
signalToShowAutofill();
}
// This log comes from the browser unittest code.
if (message === 'didShowSuggestions')
selectTopAutoFill();
}

this.takeControl();

// It is possible for the ready console messagage to be already received but not handled
// or received later. This ensures we can catch both cases.
ConsoleModel.consoleModel.addEventListener(ConsoleModel.ConsoleModel.Events.MessageAdded, onConsoleMessage, this);

var messages = ConsoleModel.consoleModel.messages();
if (messages.length) {
var text = messages[0].messageText;
this.assertEquals('ready', text);
signalToShowAutofill();
}
};

TestSuite.prototype.testDispatchKeyEventDoesNotCrash = function() {
SDK.targetManager.mainTarget().inputAgent().invoke_dispatchKeyEvent(
{type: 'rawKeyDown', windowsVirtualKeyCode: 0x23, key: 'End'});
Expand Down

0 comments on commit 59ae567

Please sign in to comment.