test_paste_clipboard_change.html (1057B)
1 <!doctype html> 2 <html> 3 <head> 4 <title>Test for clipboard content changes during the paste event handler</title> 5 <script src="/tests/SimpleTest/SimpleTest.js"></script> 6 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 7 </head> 8 <body> 9 <input type="text"> 10 <div contenteditable="true"></div> 11 <script> 12 document.querySelectorAll("input, div[contenteditable]").forEach((element) => { 13 add_task(async () => { 14 info("test for " + element); 15 info("Waiting for initializing clipboard..."); 16 await SimpleTest.promiseClipboardChange( 17 "Original text", 18 () => SpecialPowers.clipboardCopyString("Original text") 19 ); 20 21 element.focus(); 22 element.addEventListener("paste", () => { 23 // Overwrite the clipboard content. 24 SpecialPowers.clipboardCopyString("New text"); 25 }, { once: true }); 26 SpecialPowers.doCommand(window, "cmd_paste"); 27 28 // Check content. 29 is(element.isContentEditable ? element.textContent : element.value, "New text", "Check paste content"); 30 }); 31 }) 32 </script> 33 </body> 34 </html>