forked from web-platform-tests/wpt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for clipboard content changes during paste action
Differential Revision: https://phabricator.services.mozilla.com/D233173 bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1939870 gecko-commit: 4bd6e1bafe1c8c33b4e11b81122c874135c89401 gecko-reviewers: masayuki
- Loading branch information
1 parent
a738440
commit 15089aa
Showing
1 changed file
with
49 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<!doctype html> | ||
<meta charset=utf-8> | ||
<title>This Test is for clipboard content changes during the paste event handler</title> | ||
<meta name="variant" content="?id=text"> | ||
<meta name="variant" content="?id=contenteditable"> | ||
<script src=/resources/testharness.js></script> | ||
<script src=/resources/testharnessreport.js></script> | ||
<script src="/resources/testdriver.js"></script> | ||
<script src="/resources/testdriver-vendor.js"></script> | ||
<script src="/resources/testdriver-actions.js"></script> | ||
<script src="../include/editor-test-utils.js"></script> | ||
<div contenteditable="true" id="contentCopy">Original text</div> | ||
<div id="pasteContainer"> | ||
<input type="text" id="text"> | ||
<div id="contenteditable" contenteditable="true"></div> | ||
</div> | ||
<script> | ||
"use strict"; | ||
|
||
const testingId = new URLSearchParams(document.location.search).get("id"); | ||
const testElement = document.getElementById(testingId); | ||
const utils = new EditorTestUtils(testElement); | ||
|
||
promise_test(async () => { | ||
// Copy the content to the clipboard. | ||
const range = document.createRange(); | ||
const contentToCopy = document.getElementById("contentCopy"); | ||
range.selectNodeContents(contentToCopy); | ||
const selection = window.getSelection(); | ||
selection.removeAllRanges(); | ||
selection.addRange(range); | ||
await utils.sendCopyShortcutKey(); | ||
|
||
// Paste the content to the test element. | ||
testElement.addEventListener("copy", (e) => { | ||
e.preventDefault(); | ||
e.clipboardData.setData("text/plain", "New text"); | ||
}, { once: true }); | ||
testElement.addEventListener("paste", (e) => { | ||
// Overwrite the clipboard content. | ||
document.execCommand("copy"); | ||
}, { once: true }); | ||
await test_driver.click(testElement); | ||
await utils.sendPasteShortcutKey(); | ||
|
||
// Check content. | ||
assert_equals(testElement.isContentEditable ? testElement.textContent : testElement.value, "New text"); | ||
}, "clipboard change during paste event handler"); | ||
</script> |