Skip to content

Commit

Permalink
[headless] Added input field clipboard tests.
Browse files Browse the repository at this point in the history
Test covers select all, copy and paste operations which seem to
get broken every now and then for headless.

Bug: 1170634
Change-Id: Icb9e93843eafd15a64a5100c30934c62d0d99c1b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2860613
Commit-Queue: Peter Kvitek <kvitekp@chromium.org>
Reviewed-by: Andrey Kosyakov <caseq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#877725}
  • Loading branch information
Peter Kvitek authored and Chromium LUCI CQ committed Apr 30, 2021
1 parent bac6fba commit 185fc1b
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Tests input field clipboard operations.
input: input_value
input: abc
input: input_value
52 changes: 52 additions & 0 deletions headless/test/data/protocol/input/input-clipboard-ops.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright 2021 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

(async function(testRunner) {
const {page, session, dp} = await testRunner.startBlank(
`Tests input field clipboard operations.`);

await dp.Page.enable();
dp.Page.navigate({url: testRunner.url('/resources/input.html')});
await dp.Page.onceLoadEventFired();

async function logElementValue(id) {
const value = await session.evaluate(`
document.getElementById("${id}").value;
`);
testRunner.log(`${id}: ${value}`);
}

async function sendKey(text, nativeVirtualKeyCode,
modifiers = 0, commands = []) {
await dp.Input.dispatchKeyEvent({
type: 'keyDown',
modifiers: modifiers,
text: text,
nativeVirtualKeyCode: nativeVirtualKeyCode,
commands: commands
});

await dp.Input.dispatchKeyEvent({
type: 'keyUp',
modifiers: modifiers,
nativeVirtualKeyCode: nativeVirtualKeyCode
});
}

await logElementValue("input");
await sendKey('a', 65, 2, ["selectAll"]);
await sendKey('c', 67, 2, ["copy"]);

await sendKey('a', 65);
await sendKey('b', 66);
await sendKey('c', 67);
await logElementValue("input");

await sendKey('a', 65, 2, ["selectAll"]);
await sendKey('c', 67, 2, ["paste"]);
await logElementValue("input");

testRunner.completeTest();
})

3 changes: 3 additions & 0 deletions headless/test/data/protocol/input/resources/input.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<html> <body>
<input type="text" id="input" value="input_value" autofocus>
</body></html>
2 changes: 2 additions & 0 deletions headless/test/headless_protocol_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,8 @@ HEADLESS_PROTOCOL_TEST(Geolocation, "emulation/geolocation-crash.js")

HEADLESS_PROTOCOL_TEST(DragStarted, "input/dragIntercepted.js")

HEADLESS_PROTOCOL_TEST(InputClipboardOps, "input/input-clipboard-ops.js")

HEADLESS_PROTOCOL_TEST(HeadlessSessionBasicsTest,
"sessions/headless-session-basics.js")

Expand Down

0 comments on commit 185fc1b

Please sign in to comment.