editor/libeditor/html/tests/test_bug478725.html

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial