-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[headless] Add clipboard operations test using simulated keystrokes
This ensures that copy paste operations work as expected in new headless after appropriate permissions are granted. Change-Id: Iee256961286ef33085b2e1e1ab4e212007639ef2 Cq-Include-Trybots: luci.chromium.try:mac12-tests Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4228279 Reviewed-by: Andrey Kosyakov <caseq@chromium.org> Commit-Queue: Peter Kvitek <kvitekp@chromium.org> Cr-Commit-Position: refs/heads/main@{#1104152}
- Loading branch information
Peter Kvitek
authored and
Chromium LUCI CQ
committed
Feb 11, 2023
1 parent
85d5ba6
commit c3e8e3c
Showing
3 changed files
with
64 additions
and
0 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
4 changes: 4 additions & 0 deletions
4
chrome/browser/headless/test/data/protocol/input/input-clipboard-ops-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,4 @@ | ||
Tests input field clipboard operations. | ||
input: input_value | ||
input: 123 | ||
input: 123input_value |
59 changes: 59 additions & 0 deletions
59
chrome/browser/headless/test/data/protocol/input/input-clipboard-ops.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,59 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
(async function(testRunner) { | ||
const html = `<!doctype html> | ||
<html><body> | ||
<input type="text" id="input" value="input_value" autofocus> | ||
</body></html> | ||
`; | ||
|
||
const {page, session, dp} = await testRunner.startHTML( | ||
html, `Tests input field clipboard operations.`); | ||
|
||
async function logElementValue(id) { | ||
const value = await session.evaluate(` | ||
document.getElementById("${id}").value; | ||
`); | ||
testRunner.log(`${id}: ${value}`); | ||
} | ||
|
||
async function sendKey( | ||
text, modifiers = 0, commands = []) { | ||
const keyCode = text.charCodeAt(0); | ||
await dp.Input.dispatchKeyEvent({ | ||
type: 'keyDown', | ||
modifiers: modifiers, | ||
text: text, | ||
nativeVirtualKeyCode: keyCode, | ||
commands: commands | ||
}); | ||
await dp.Input.dispatchKeyEvent({ | ||
type: 'keyUp', | ||
modifiers: modifiers, | ||
nativeVirtualKeyCode: keyCode | ||
}); | ||
} | ||
|
||
await dp.Browser.grantPermissions({permissions: ['clipboardReadWrite']}); | ||
|
||
const kControl = 2; | ||
const kCommand = 4; | ||
const mod = navigator.platform.includes('Mac') ? kCommand : kControl; | ||
|
||
await logElementValue('input'); | ||
await sendKey('a', mod, ['selectAll']); | ||
await sendKey('c', mod, ['copy']); | ||
|
||
await sendKey('1'); | ||
await sendKey('2'); | ||
await sendKey('3'); | ||
await logElementValue('input'); | ||
|
||
// Don't send Ctrl+A here because this would cause clipboard copy on | ||
// systems that support selection clipboard, e.g. Linux. | ||
await sendKey('v', mod, ['paste']); | ||
await logElementValue('input'); | ||
|
||
testRunner.completeTest(); | ||
}) |