Skip to content

Commit

Permalink
Add tests for clipboard content changes during paste action
Browse files Browse the repository at this point in the history
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
EdgarChen authored and moz-wptsync-bot committed Jan 6, 2025
1 parent a738440 commit 15089aa
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions editing/other/paste-clipboard-change.tentative.html
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>

0 comments on commit 15089aa

Please sign in to comment.