test_bug795418-3.html (2420B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=795418 5 --> 6 <head> 7 <meta charset="utf-8"> 8 <title>Test #3 for Bug 772796</title> 9 <script src="/tests/SimpleTest/SimpleTest.js"></script> 10 <script src="/tests/SimpleTest/EventUtils.js"></script> 11 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 12 </head> 13 <body> 14 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=772796">Mozilla Bug 795418</a> 15 <p id="display"></p> 16 <div id="content" style="display: none"> 17 </div> 18 19 <div id="copySource">Copy this</div> 20 <iframe srcdoc="<html><body><span>AB</span>"></iframe> 21 22 <pre id="test"> 23 24 <script type="application/javascript"> 25 26 /** Test for Bug 795418 */ 27 SimpleTest.waitForExplicitFinish(); 28 SimpleTest.waitForFocus(function() { 29 var div = document.getElementById("copySource"); 30 var sel = window.getSelection(); 31 sel.removeAllRanges(); 32 33 // Select the text from the text node in div. 34 var r = document.createRange(); 35 r.setStart(div.firstChild, 0); 36 r.setEnd(div.firstChild, 9); 37 sel.addRange(r); 38 39 function checkResult() { 40 var iframe = document.querySelector("iframe"); 41 var theEdit = iframe.contentDocument.body; 42 theEdit.offsetHeight; 43 is(theEdit.innerHTML, 44 "<span>AB<blockquote type=\"cite\">Copy this</blockquote></span>", 45 "unexpected HTML for test"); 46 SimpleTest.finish(); 47 } 48 49 function pasteQuote() { 50 var iframe = document.querySelector("iframe"); 51 var iframeWindow = iframe.contentWindow; 52 var theEdit = iframe.contentDocument.body; 53 iframe.contentDocument.designMode = "on"; 54 iframe.contentDocument.body.offsetHeight; 55 iframeWindow.focus(); 56 SimpleTest.waitForFocus(function() { 57 var iframeSel = iframeWindow.getSelection(); 58 iframeSel.removeAllRanges(); 59 iframeSel.collapse(theEdit.firstChild, 1); 60 61 SpecialPowers.doCommand(iframeWindow, "cmd_pasteQuote"); 62 setTimeout(checkResult, 0); 63 }, iframeWindow); 64 } 65 66 SimpleTest.waitForClipboard( 67 aData => { 68 // XXX Oddly, specifying `r.toString()` causes timeout in headless mode. 69 info(`copied text: "${aData}"`); 70 return true; 71 }, 72 function setup() { 73 synthesizeKey("C", {accelKey: true}); 74 }, 75 function onSuccess() { 76 setTimeout(pasteQuote, 0); 77 }, 78 function onFailure() { 79 SimpleTest.finish(); 80 }, 81 "text/html" 82 ); 83 }); 84 85 </script> 86 87 </pre> 88 </body> 89 </html>