test_execCommandPaste_noTarget.html (1489B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <script src="/tests/SimpleTest/SimpleTest.js"></script> 5 <script src="/tests/SimpleTest/EventUtils.js"></script> 6 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 7 </head> 8 <body> 9 <script> 10 11 add_task(async function() { 12 let seenPaste = false; 13 let seenCopy = false; 14 document.addEventListener("copy", function oncpy(e) { 15 e.clipboardData.setData("text/plain", "my text"); 16 e.preventDefault(); 17 seenCopy = true; 18 }, {once: true}); 19 document.addEventListener("paste", function onpst(e) { 20 is(e.clipboardData.getData("text/plain"), "my text", 21 "The correct text was read from the clipboard"); 22 e.preventDefault(); 23 seenPaste = true; 24 }, {once: true}); 25 26 ok(SpecialPowers.wrap(document).execCommand("copy"), 27 "Call should succeed"); 28 ok(seenCopy, "Successfully copied the text to the clipboard"); 29 ok(SpecialPowers.wrap(document).execCommand("paste"), 30 "Call should succeed"); 31 ok(seenPaste, "Successfully read text from the clipboard"); 32 33 // Check that reading text from the clipboard in non-privileged contexts 34 // still doesn't work. 35 function onpstfail() { 36 ok(false, "Should not see paste event triggered by non-privileged call"); 37 } 38 document.addEventListener("paste", onpstfail); 39 ok(!document.execCommand("paste"), "Call should fail"); 40 document.removeEventListener("paste", onpstfail); 41 }); 42 43 </script> 44 </body> 45 </html>