test_bug478725.html (4901B)
1 <!DOCTYPE HTML> 2 <html><head> 3 <title>Test for bug 478725</title> 4 <style src="/tests/SimpleTest/test.css" type="text/css"></style> 5 <script src="/tests/SimpleTest/SimpleTest.js"></script> 6 <script src="/tests/SimpleTest/EventUtils.js"></script> 7 8 <script class="testbody" type="application/javascript"> 9 10 function runTest() { 11 function verifyContent(s) { 12 var e = document.getElementById("i1"); 13 var doc = e.contentDocument; 14 is(doc.body.innerHTML, s, ""); 15 } 16 17 function pasteInto(html, target_id) { 18 var e = document.getElementById("i1"); 19 var doc = e.contentDocument; 20 doc.designMode = "on"; 21 doc.body.innerHTML = html; 22 e = doc.getElementById(target_id); 23 doc.defaultView.focus(); 24 var selection = doc.defaultView.getSelection(); 25 selection.removeAllRanges(); 26 selection.selectAllChildren(e); 27 selection.collapseToEnd(); 28 SpecialPowers.wrap(doc).execCommand("paste", false, null); 29 return e; 30 } 31 32 function copyToClipBoard(s, asHTML, target_id) { 33 var e = document.getElementById("i2"); 34 var doc = e.contentDocument; 35 if (asHTML) { 36 doc.body.innerHTML = s; 37 } else { 38 var text = doc.createTextNode(s); 39 doc.body.appendChild(text); 40 } 41 doc.designMode = "on"; 42 doc.defaultView.focus(); 43 var selection = doc.defaultView.getSelection(); 44 selection.removeAllRanges(); 45 if (!target_id) { 46 selection.selectAllChildren(doc.body); 47 } else { 48 var range = document.createRange(); 49 range.selectNode(doc.getElementById(target_id)); 50 selection.addRange(range); 51 } 52 SpecialPowers.wrap(doc).execCommand("copy", false, null); 53 return e; 54 } 55 56 copyToClipBoard("<dl><dd>Hello Kitty</dd></dl>", true); 57 pasteInto('<ol><li id="paste_here">X</li></ol>', "paste_here"); 58 verifyContent('<ol><li id="paste_here">X<dl><dd>Hello Kitty</dd></dl></li></ol>'); 59 60 copyToClipBoard("<li>Hello Kitty</li>", true); 61 pasteInto('<ol><li id="paste_here">X</li></ol>', "paste_here"); 62 verifyContent('<ol><li id="paste_here">X</li><li>Hello Kitty</li></ol>'); 63 64 copyToClipBoard("<ol><li>Hello Kitty</li></ol>", true); 65 pasteInto('<ol><li id="paste_here">X</li></ol>', "paste_here"); 66 verifyContent('<ol><li id="paste_here">X</li><li>Hello Kitty</li></ol>'); 67 68 copyToClipBoard("<ul><li>Hello Kitty</li></ul>", true); 69 pasteInto('<ol><li id="paste_here">X</li></ol>', "paste_here"); 70 verifyContent('<ol><li id="paste_here">X</li><li>Hello Kitty</li></ol>'); 71 72 copyToClipBoard("<ul><li>Hello</li><ul><li>Kitty</li></ul></ul>", true); 73 pasteInto('<ol><li id="paste_here">X</li></ol>', "paste_here"); 74 verifyContent('<ol><li id="paste_here">X</li><li>Hello</li><ul><li>Kitty</li></ul></ol>'); 75 76 copyToClipBoard("<dl><dd>Hello</dd><dd>Kitty</dd></dl>", true); 77 pasteInto('<dl><dd id="paste_here">X</dd></dl>', "paste_here"); 78 verifyContent('<dl><dd id="paste_here">X</dd><dd>Hello</dd><dd>Kitty</dd></dl>'); 79 80 copyToClipBoard("<dl><dd>Hello</dd><dd>Kitty</dd></dl>", true); 81 pasteInto('<dl><dt id="paste_here">X</dt></dl>', "paste_here"); 82 verifyContent('<dl><dt id="paste_here">X</dt><dd>Hello</dd><dd>Kitty</dd></dl>'); 83 84 copyToClipBoard("<dl><dt>Hello</dt><dd>Kitty</dd></dl>", true); 85 pasteInto('<dl><dd id="paste_here">X</dd></dl>', "paste_here"); 86 verifyContent('<dl><dd id="paste_here">X</dd><dt>Hello</dt><dd>Kitty</dd></dl>'); 87 88 copyToClipBoard("<pre>Kitty</pre>", true); 89 pasteInto('<pre id="paste_here">Hello </pre>', "paste_here"); 90 verifyContent('<pre id="paste_here">Hello Kitty</pre>'); 91 92 // I was expecting these to trigger the special TABLE/TR rules in nsHTMLEditor::InsertHTMLWithContext 93 // but they don't for some reason... 94 // copyToClipBoard('<table><tr id="copy_here"><td>Kitty</td></tr></table>', true, "copy_here"); 95 // pasteInto('<table><tr id="paste_here"><td>Hello</td></tr></table>',"paste_here"); 96 // verifyContent(''); 97 // 98 // copyToClipBoard('<table id="copy_here"><tr><td>Kitty</td></tr></table>', true, "copy_here"); 99 // pasteInto('<table><tr id="paste_here"><td>Hello</td></tr></table>',"paste_here"); 100 // verifyContent(''); 101 // 102 // copyToClipBoard('<table id="copy_here"><tr><td>Kitty</td></tr></table>', true, "copy_here"); 103 // pasteInto('<table id="paste_here"><tr><td>Hello</td></tr></table>',"paste_here"); 104 // verifyContent(''); 105 // 106 // copyToClipBoard('<table><tr id="copy_here"><td>Kitty</td></tr></table>', true, "copy_here"); 107 // pasteInto('<table id="paste_here"><tr><td>Hello</td></tr></table>',"paste_here"); 108 // verifyContent(''); 109 110 111 SimpleTest.finish(); 112 } 113 114 SimpleTest.waitForExplicitFinish(); 115 addLoadEvent(runTest); 116 </script> 117 </head> 118 <body> 119 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=478725">Mozilla Bug 478725</a> 120 <p id="display"></p> 121 122 <pre id="test"> 123 </pre> 124 125 126 <iframe id="i1" width="200" height="100" src="about:blank"></iframe><br> 127 <iframe id="i2" width="200" height="100" src="about:blank"></iframe><br> 128 129 </body> 130 </html>