1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/editor/libeditor/html/tests/test_bug480972.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,98 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html><head> 1.6 +<title>Test for bug 480972</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 + doc.defaultView.focus(); 1.26 + if (target_id) 1.27 + e = doc.getElementById(target_id); 1.28 + else 1.29 + e = doc.body; 1.30 + var selection = doc.defaultView.getSelection(); 1.31 + selection.removeAllRanges(); 1.32 + selection.selectAllChildren(e); 1.33 + selection.collapseToEnd(); 1.34 + SpecialPowers.wrap(doc).execCommand("paste", false, null); 1.35 + return e; 1.36 + } 1.37 + 1.38 + function copyToClipBoard(s,asHTML,target_id) { 1.39 + var e = document.getElementById('i2'); 1.40 + var doc = e.contentDocument; 1.41 + if (asHTML) { 1.42 + doc.body.innerHTML = s; 1.43 + } else { 1.44 + var text = doc.createTextNode(s); 1.45 + doc.body.appendChild(text); 1.46 + } 1.47 + doc.designMode = "on"; 1.48 + doc.defaultView.focus(); 1.49 + var selection = doc.defaultView.getSelection(); 1.50 + selection.removeAllRanges(); 1.51 + if (!target_id) { 1.52 + selection.selectAllChildren(doc.body); 1.53 + } else { 1.54 + var range = document.createRange(); 1.55 + range.selectNode(doc.getElementById(target_id)); 1.56 + selection.addRange(range); 1.57 + } 1.58 + SpecialPowers.wrap(doc).execCommand("copy", false, null); 1.59 + return e; 1.60 + } 1.61 + 1.62 + copyToClipBoard('<span>Hello</span><span>Kitty</span>', true); 1.63 + pasteInto(''); 1.64 + verifyContent('<span>Hello</span><span>Kitty</span>'); 1.65 + 1.66 + copyToClipBoard("<dl><dd>Hello Kitty</dd></dl><span>Hello</span><span>Kitty</span>", true); 1.67 + pasteInto('<ol><li id="paste_here">X</li></ol>',"paste_here"); 1.68 + verifyContent('<ol><li id="paste_here">X<dl><dd>Hello Kitty</dd></dl><span>Hello</span><span>Kitty</span></li></ol>'); 1.69 + 1.70 +// The following test doesn't do what I expected, because the special handling 1.71 +// of IsList nodes in nsHTMLEditor::InsertHTMLWithContext simply removes 1.72 +// non-list/item children. See bug 481177. 1.73 +// copyToClipBoard("<ol><li>Hello Kitty</li><span>Hello</span></ol>", true); 1.74 +// pasteInto('<ol><li id="paste_here">X</li></ol>',"paste_here"); 1.75 +// verifyContent('<ol><li id="paste_here">X</li><li>Hello Kitty</li><span>Hello</span></ol>'); 1.76 + 1.77 + copyToClipBoard("<pre>Kitty</pre><span>Hello</span>", true); 1.78 + pasteInto('<pre id="paste_here">Hello </pre>',"paste_here"); 1.79 + verifyContent('<pre id="paste_here">Hello Kitty<span>Hello</span></pre>'); 1.80 + 1.81 + SimpleTest.finish(); 1.82 +} 1.83 + 1.84 +SimpleTest.waitForExplicitFinish(); 1.85 +addLoadEvent(runTest); 1.86 +</script> 1.87 +</head> 1.88 +<body> 1.89 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=480972">Mozilla Bug 480972</a> 1.90 +<p id="display"></p> 1.91 + 1.92 +<pre id="test"> 1.93 +</pre> 1.94 + 1.95 + 1.96 +<iframe id="i1" width="200" height="100" src="about:blank"></iframe><br> 1.97 +<iframe id="i2" width="200" height="100" src="about:blank"></iframe><br> 1.98 + 1.99 +</body> 1.100 +</html> 1.101 +