forked from chromium/chromium
-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DevTools: Add commands option to Input.dispatchKeyEvent
Key events emulated with DevTools can now use the commands option to send editing commands that will be executed if the event is not canceled. This is important for shortcuts like Meta+A = SelectAll to work on a Mac. See puppeteer/puppeteer#1313 and microsoft/playwright#1067 Change-Id: Id258668bfc71ef9f7f47477ef9de3422ada1d4b5 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2211929 Commit-Queue: Joel Einbinder <einbinder@chromium.org> Reviewed-by: Andrey Kosyakov <caseq@chromium.org> Reviewed-by: Dmitry Gozman <dgozman@chromium.org> Reviewed-by: Yang Guo <yangguo@chromium.org> Cr-Commit-Position: refs/heads/master@{#780848}
- Loading branch information
1 parent
47de01c
commit 3d3ee67
Showing
5 changed files
with
122 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
third_party/blink/web_tests/inspector-protocol/input/dispatchKeyEvent-commands-expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
Tests Input.dispatchKeyEvent commands option. | ||
|
||
Sending "b" | ||
with commands ["selectAll"] | ||
hello world | ||
~~~~~~~~~~~^ | ||
|
||
Sending "Backspace" | ||
|
||
^ | ||
|
||
Sending "c" | ||
c | ||
^ | ||
|
||
Canceling the next keydown | ||
|
||
Sending "d" | ||
with commands ["selectAll"] | ||
c | ||
^ | ||
|
||
Sending "e" | ||
ce | ||
^ | ||
|
78 changes: 78 additions & 0 deletions
78
third_party/blink/web_tests/inspector-protocol/input/dispatchKeyEvent-commands.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
(async function(testRunner) { | ||
const {session, dp} = await testRunner.startBlank(`Tests Input.dispatchKeyEvent commands option.`); | ||
|
||
await session.evaluate(` | ||
const textarea = document.createElement('textarea'); | ||
document.body.appendChild(textarea); | ||
textarea.value = 'hello world'; | ||
textarea.focus(); | ||
function selectedText() { | ||
const textarea = document.querySelector('textarea'); | ||
return textarea.value + '\\n' + ' '.repeat(textarea.selectionStart) + '~'.repeat(textarea.selectionEnd-textarea.selectionStart) + '^' | ||
} | ||
`); | ||
|
||
async function dumpErrorAndLogs(options) { | ||
testRunner.log(''); | ||
testRunner.log(`Sending "${options.key}"`); | ||
if (options.commands && options.commands.length) | ||
testRunner.log(`with commands ${JSON.stringify(options.commands)}`) | ||
const message = await dp.Input.dispatchKeyEvent(options); | ||
if (message.error) | ||
testRunner.log('Error: ' + message.error.message); | ||
|
||
testRunner.log(await session.evaluate(`selectedText()`)); | ||
} | ||
|
||
await dumpErrorAndLogs({ | ||
type: 'keyDown', | ||
key: 'b', | ||
modifiers: 2, | ||
commands: ['selectAll'], | ||
windowsVirtualKeyCode: 66, | ||
code: 'KeyB' | ||
}); | ||
await dumpErrorAndLogs({ | ||
type: 'keyDown', | ||
windowsVirtualKeyCode: 8, | ||
key: 'Backspace', | ||
code: 'Backspace' | ||
}); | ||
|
||
await dumpErrorAndLogs({ | ||
type: 'keyDown', | ||
key: 'c', | ||
text: 'c', | ||
unmodifiedText: 'c', | ||
commands: [], | ||
windowsVirtualKeyCode: 67, | ||
code: 'KeyC' | ||
}); | ||
|
||
testRunner.log(''); | ||
testRunner.log('Canceling the next keydown'); | ||
|
||
await session.evaluate(` | ||
window.addEventListener('keydown', event => event.preventDefault(), {once: true}); | ||
`); | ||
await dumpErrorAndLogs({ | ||
type: 'keyDown', | ||
key: 'd', | ||
modifiers: 2, | ||
commands: ['selectAll'], | ||
windowsVirtualKeyCode: 67, | ||
code: 'KeyC' | ||
}); | ||
await dumpErrorAndLogs({ | ||
type: 'keyDown', | ||
key: 'e', | ||
text: 'e', | ||
unmodifiedText: 'e', | ||
commands: [], | ||
windowsVirtualKeyCode: 68, | ||
code: 'KeyE' | ||
}); | ||
|
||
testRunner.completeTest(); | ||
}); |