1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/editor/libeditor/html/tests/test_bug478725.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,131 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html><head> 1.6 +<title>Test for bug 478725</title> 1.7 +<style src="/tests/SimpleTest/test.css" type="text/css"></style> 1.8 +<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.9 +<script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script> 1.10 + 1.11 +<script class="testbody" type="application/javascript"> 1.12 + 1.13 +function runTest() { 1.14 + function verifyContent(s) { 1.15 + var e = document.getElementById('i1'); 1.16 + var doc = e.contentDocument; 1.17 + is(doc.body.innerHTML, s, ""); 1.18 + } 1.19 + 1.20 + function pasteInto(html,target_id) { 1.21 + var e = document.getElementById('i1'); 1.22 + var doc = e.contentDocument; 1.23 + doc.designMode = "on"; 1.24 + doc.body.innerHTML = html; 1.25 + e = doc.getElementById(target_id); 1.26 + doc.defaultView.focus(); 1.27 + var selection = doc.defaultView.getSelection(); 1.28 + selection.removeAllRanges(); 1.29 + selection.selectAllChildren(e); 1.30 + selection.collapseToEnd(); 1.31 + SpecialPowers.wrap(doc).execCommand("paste", false, null); 1.32 + return e; 1.33 + } 1.34 + 1.35 + function copyToClipBoard(s,asHTML,target_id) { 1.36 + var e = document.getElementById('i2'); 1.37 + var doc = e.contentDocument; 1.38 + if (asHTML) { 1.39 + doc.body.innerHTML = s; 1.40 + } else { 1.41 + var text = doc.createTextNode(s); 1.42 + doc.body.appendChild(text); 1.43 + } 1.44 + doc.designMode = "on"; 1.45 + doc.defaultView.focus(); 1.46 + var selection = doc.defaultView.getSelection(); 1.47 + selection.removeAllRanges(); 1.48 + if (!target_id) { 1.49 + selection.selectAllChildren(doc.body); 1.50 + } else { 1.51 + var range = document.createRange(); 1.52 + range.selectNode(doc.getElementById(target_id)); 1.53 + selection.addRange(range); 1.54 + } 1.55 + SpecialPowers.wrap(doc).execCommand("copy", false, null); 1.56 + return e; 1.57 + } 1.58 + 1.59 + copyToClipBoard("<dl><dd>Hello Kitty</dd></dl>", true); 1.60 + pasteInto('<ol><li id="paste_here">X</li></ol>',"paste_here"); 1.61 + verifyContent('<ol><li id="paste_here">X<dl><dd>Hello Kitty</dd></dl></li></ol>'); 1.62 + 1.63 + copyToClipBoard("<li>Hello Kitty</li>", true); 1.64 + pasteInto('<ol><li id="paste_here">X</li></ol>',"paste_here"); 1.65 + verifyContent('<ol><li id="paste_here">X</li><li>Hello Kitty</li></ol>'); 1.66 + 1.67 + copyToClipBoard("<ol><li>Hello Kitty</li></ol>", true); 1.68 + pasteInto('<ol><li id="paste_here">X</li></ol>',"paste_here"); 1.69 + verifyContent('<ol><li id="paste_here">X</li><li>Hello Kitty</li></ol>'); 1.70 + 1.71 + copyToClipBoard("<ul><li>Hello Kitty</li></ul>", true); 1.72 + pasteInto('<ol><li id="paste_here">X</li></ol>',"paste_here"); 1.73 + verifyContent('<ol><li id="paste_here">X</li><li>Hello Kitty</li></ol>'); 1.74 + 1.75 + copyToClipBoard("<ul><li>Hello</li><ul><li>Kitty</li></ul></ul>", true); 1.76 + pasteInto('<ol><li id="paste_here">X</li></ol>',"paste_here"); 1.77 + verifyContent('<ol><li id="paste_here">X</li><li>Hello</li><ul><li>Kitty</li></ul></ol>'); 1.78 + 1.79 + copyToClipBoard("<dl><dd>Hello</dd><dd>Kitty</dd></dl>", true); 1.80 + pasteInto('<dl><dd id="paste_here">X</dd></dl>',"paste_here"); 1.81 + verifyContent('<dl><dd id="paste_here">X</dd><dd>Hello</dd><dd>Kitty</dd></dl>'); 1.82 + 1.83 + copyToClipBoard("<dl><dd>Hello</dd><dd>Kitty</dd></dl>", true); 1.84 + pasteInto('<dl><dt id="paste_here">X</dt></dl>',"paste_here"); 1.85 + verifyContent('<dl><dt id="paste_here">X</dt><dd>Hello</dd><dd>Kitty</dd></dl>'); 1.86 + 1.87 + copyToClipBoard("<dl><dt>Hello</dt><dd>Kitty</dd></dl>", true); 1.88 + pasteInto('<dl><dd id="paste_here">X</dd></dl>',"paste_here"); 1.89 + verifyContent('<dl><dd id="paste_here">X</dd><dt>Hello</dt><dd>Kitty</dd></dl>'); 1.90 + 1.91 + copyToClipBoard("<pre>Kitty</pre>", true); 1.92 + pasteInto('<pre id="paste_here">Hello </pre>',"paste_here"); 1.93 + verifyContent('<pre id="paste_here">Hello Kitty</pre>'); 1.94 + 1.95 +// I was expecting these to trigger the special TABLE/TR rules in nsHTMLEditor::InsertHTMLWithContext 1.96 +// but they don't for some reason... 1.97 +// copyToClipBoard('<table><tr id="copy_here"><td>Kitty</td></tr></table>', true, "copy_here"); 1.98 +// pasteInto('<table><tr id="paste_here"><td>Hello</td></tr></table>',"paste_here"); 1.99 +// verifyContent(''); 1.100 +// 1.101 +// copyToClipBoard('<table id="copy_here"><tr><td>Kitty</td></tr></table>', true, "copy_here"); 1.102 +// pasteInto('<table><tr id="paste_here"><td>Hello</td></tr></table>',"paste_here"); 1.103 +// verifyContent(''); 1.104 +// 1.105 +// copyToClipBoard('<table id="copy_here"><tr><td>Kitty</td></tr></table>', true, "copy_here"); 1.106 +// pasteInto('<table id="paste_here"><tr><td>Hello</td></tr></table>',"paste_here"); 1.107 +// verifyContent(''); 1.108 +// 1.109 +// copyToClipBoard('<table><tr id="copy_here"><td>Kitty</td></tr></table>', true, "copy_here"); 1.110 +// pasteInto('<table id="paste_here"><tr><td>Hello</td></tr></table>',"paste_here"); 1.111 +// verifyContent(''); 1.112 + 1.113 + 1.114 + SimpleTest.finish(); 1.115 +} 1.116 + 1.117 +SimpleTest.waitForExplicitFinish(); 1.118 +addLoadEvent(runTest); 1.119 +</script> 1.120 +</head> 1.121 +<body> 1.122 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=478725">Mozilla Bug 478725</a> 1.123 +<p id="display"></p> 1.124 + 1.125 +<pre id="test"> 1.126 +</pre> 1.127 + 1.128 + 1.129 +<iframe id="i1" width="200" height="100" src="about:blank"></iframe><br> 1.130 +<iframe id="i2" width="200" height="100" src="about:blank"></iframe><br> 1.131 + 1.132 +</body> 1.133 +</html> 1.134 +