Commit ff45c14f authored by chongz's avatar chongz Committed by Commit Bot

[WPT] Add automated manual test for InputEvent typing

Passed on Chrome and Safari.

BUG=652439

Review-Url: https://codereview.chromium.org/2919603002
Cr-Commit-Position: refs/heads/master@{#476377}
parent d2f0dd39
<!DOCTYPE html>
<meta charset="utf-8">
<title>InputEvent have data when typing on textarea and contenteditable</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<p>To manually run this test, please follow the steps below:<br/>
1. Focus the first box and press key 'a' and then 'b'.<br/>
2. Focus the second box and press key 'c' and then 'd'.<br/>
<br/>
If a "PASS" result appears the test passes, otherwise it fails</p>
<textarea id='plain'></textarea>
<div id='rich' style='border-style: solid;' contenteditable></div>
<script>
async_test(t => {
const expectedResult = [
'plain-beforeinput-a',
'plain-input-a',
'plain-beforeinput-b',
'plain-input-b',
'rich-beforeinput-c',
'rich-input-c',
'rich-beforeinput-d',
'rich-input-d',
];
let eventCounter = 0;
for (const targetId of ['plain', 'rich']) {
for (const eventType of ['beforeinput', 'input']) {
document.getElementById(targetId).addEventListener(eventType, t.step_func(e => {
assert_equals(`${targetId}-${eventType}-${e.data}`, expectedResult[eventCounter]);
++eventCounter;
if (eventCounter === expectedResult.length)
t.done();
}));
}
}
})
</script>
importAutomationScript('/input-events/inputevent_common_input.js');
function inject_input() {
return focusAndKeyDown('#plain', 'a').then(() => {
return keyDown('b');
}).then(() => {
return focusAndKeyDown('#rich', 'c');
}).then(() => {
return keyDown('d');
});
}
// Returns a Promise for future conversion into WebDriver-backed API.
function keyDown(key, modifiers) {
return new Promise(function(resolve, reject) {
if (window.eventSender) {
eventSender.keyDown(key, modifiers);
resolve();
} else {
reject();
}
});
}
function focusAndKeyDown(selector, key, modifiers) {
document.querySelector(selector).focus();
return keyDown(key, modifiers);
}
{
const inputevent_automation = async_test("InputEvent Automation");
// Defined in every test and should return a promise that gets resolved when input is finished.
inject_input().then(inputevent_automation.step_func_done());
}
...@@ -119,7 +119,8 @@ ...@@ -119,7 +119,8 @@
} else if (pathAndBase.startsWith('/pointerevents/') } else if (pathAndBase.startsWith('/pointerevents/')
|| pathAndBase.startsWith('/uievents/') || pathAndBase.startsWith('/uievents/')
|| pathAndBase.startsWith('/pointerlock/') || pathAndBase.startsWith('/pointerlock/')
|| pathAndBase.startsWith('/html/')) { || pathAndBase.startsWith('/html/')
|| pathAndBase.startsWith('/input-events/')) {
// Per-test automation scripts. // Per-test automation scripts.
src = automationPath + pathAndBase + '-automation.js'; src = automationPath + pathAndBase + '-automation.js';
} else { } else {
......
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