test_copypaste_disabled.html (3618B)
1 <!doctype html> 2 <script src="/tests/SimpleTest/SimpleTest.js"></script> 3 <script src="/tests/SimpleTest/EventUtils.js"></script> 4 <script src="/tests/SimpleTest/paint_listener.js"></script> 5 <script src="/tests/gfx/layers/apz/test/mochitest/apz_test_utils.js"></script> 6 <script src="copypaste.js"></script> 7 <link rel="stylesheet" href="/tests/SimpleTest/test.css"> 8 <div id="content"> 9 <style> 10 @font-face { 11 font-family: Ahem; 12 src: url("/tests/dom/base/test/Ahem.ttf"); 13 } 14 body { font-family: Ahem; font-size: 20px; margin: 0; } 15 input, textarea { 16 font: inherit; 17 -moz-appearance: none; 18 padding: 0; 19 border: 0; 20 scrollbar-width: none; 21 } 22 </style> 23 <input id="disabled-input" disabled value="abcd"> efgh <br> <textarea rows=1 id="disabled-textarea" disabled>ijkl</textarea> mnop <br> 24 </div> 25 26 <script> 27 function dragSelect(e, x1, x2, x3) { 28 let dir = x2 > x1 ? 1 : -1; 29 synthesizeMouse(e, x1, 5, { type: "mousedown" }); 30 synthesizeMouse(e, x1 + dir, 5, { type: "mousemove" }); 31 if (x3) 32 synthesizeMouse(e, x3, 5, { type: "mousemove" }); 33 synthesizeMouse(e, x2 - dir, 5, { type: "mousemove" }); 34 synthesizeMouse(e, x2, 5, { type: "mouseup" }); 35 } 36 37 SimpleTest.waitForExplicitFinish(); 38 waitUntilApzStable().then(async function() { 39 const docShell = SpecialPowers.wrap(window).docShell; 40 41 const clipboard = SpecialPowers.Services.clipboard; 42 43 function copySelectionToClipboard() { 44 return SimpleTest.promiseClipboardChange( 45 () => true, 46 () => { 47 SpecialPowers.doCommand(window, "cmd_copy"); 48 } 49 ); 50 } 51 52 function getLoadContext() { 53 return docShell.QueryInterface(SpecialPowers.Ci.nsILoadContext); 54 } 55 56 function getClipboardData(mime) { 57 var transferable = SpecialPowers.Cc[ 58 "@mozilla.org/widget/transferable;1" 59 ].createInstance(SpecialPowers.Ci.nsITransferable); 60 transferable.init(getLoadContext()); 61 transferable.addDataFlavor(mime); 62 clipboard.getData(transferable, 1, SpecialPowers.wrap(window).browsingContext.currentWindowContext); 63 var data = SpecialPowers.createBlankObject(); 64 transferable.getTransferData(mime, data); 65 return data; 66 } 67 68 function testClipboardValue(mime, expected) { 69 var data = SpecialPowers.wrap(getClipboardData(mime)); 70 is( 71 data.value == null 72 ? data.value 73 : data.value.QueryInterface(SpecialPowers.Ci.nsISupportsString).data, 74 expected, 75 mime + " value in the clipboard" 76 ); 77 return data.value; 78 } 79 80 async function runTestsOn(doc) { 81 for (let id of ["disabled-input", "disabled-textarea"]) { 82 let element = doc.getElementById(id); 83 dragSelect(element, 0, 60); 84 await copySelectionToClipboard(); 85 testClipboardValue("text/plain", element.value.substr(0, 3)); 86 } 87 } 88 89 await runTestsOn(document) 90 91 let iframe = document.createElement("iframe"); 92 iframe.setAttribute("frameborder", "0"); 93 iframe.srcdoc = `<!doctype html>${document.getElementById("content").outerHTML}`; 94 let iframeLoad = new Promise(resolve => { 95 iframe.addEventListener("load", resolve, { once: true }); 96 }); 97 document.body.appendChild(iframe); 98 99 await iframeLoad; 100 iframe.width = window.innerWidth; 101 iframe.height = window.innerHeight; 102 103 await SimpleTest.promiseFocus(iframe.contentWindow); 104 await runTestsOn(iframe.contentDocument); 105 106 // Add a contenteditable element to test the case where there's an HTMLEditor 107 // around the page. 108 let div = document.createElement("div"); 109 div.setAttribute("contenteditable", "true"); 110 document.body.appendChild(div); 111 112 await runTestsOn(document); 113 114 SimpleTest.finish(); 115 }); 116 </script>