Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | <!DOCTYPE HTML> |
michael@0 | 2 | <html><head> |
michael@0 | 3 | <title>Test for bug 480972</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 | doc.defaultView.focus(); |
michael@0 | 23 | if (target_id) |
michael@0 | 24 | e = doc.getElementById(target_id); |
michael@0 | 25 | else |
michael@0 | 26 | e = doc.body; |
michael@0 | 27 | var selection = doc.defaultView.getSelection(); |
michael@0 | 28 | selection.removeAllRanges(); |
michael@0 | 29 | selection.selectAllChildren(e); |
michael@0 | 30 | selection.collapseToEnd(); |
michael@0 | 31 | SpecialPowers.wrap(doc).execCommand("paste", false, null); |
michael@0 | 32 | return e; |
michael@0 | 33 | } |
michael@0 | 34 | |
michael@0 | 35 | function copyToClipBoard(s,asHTML,target_id) { |
michael@0 | 36 | var e = document.getElementById('i2'); |
michael@0 | 37 | var doc = e.contentDocument; |
michael@0 | 38 | if (asHTML) { |
michael@0 | 39 | doc.body.innerHTML = s; |
michael@0 | 40 | } else { |
michael@0 | 41 | var text = doc.createTextNode(s); |
michael@0 | 42 | doc.body.appendChild(text); |
michael@0 | 43 | } |
michael@0 | 44 | doc.designMode = "on"; |
michael@0 | 45 | doc.defaultView.focus(); |
michael@0 | 46 | var selection = doc.defaultView.getSelection(); |
michael@0 | 47 | selection.removeAllRanges(); |
michael@0 | 48 | if (!target_id) { |
michael@0 | 49 | selection.selectAllChildren(doc.body); |
michael@0 | 50 | } else { |
michael@0 | 51 | var range = document.createRange(); |
michael@0 | 52 | range.selectNode(doc.getElementById(target_id)); |
michael@0 | 53 | selection.addRange(range); |
michael@0 | 54 | } |
michael@0 | 55 | SpecialPowers.wrap(doc).execCommand("copy", false, null); |
michael@0 | 56 | return e; |
michael@0 | 57 | } |
michael@0 | 58 | |
michael@0 | 59 | copyToClipBoard('<span>Hello</span><span>Kitty</span>', true); |
michael@0 | 60 | pasteInto(''); |
michael@0 | 61 | verifyContent('<span>Hello</span><span>Kitty</span>'); |
michael@0 | 62 | |
michael@0 | 63 | copyToClipBoard("<dl><dd>Hello Kitty</dd></dl><span>Hello</span><span>Kitty</span>", true); |
michael@0 | 64 | pasteInto('<ol><li id="paste_here">X</li></ol>',"paste_here"); |
michael@0 | 65 | verifyContent('<ol><li id="paste_here">X<dl><dd>Hello Kitty</dd></dl><span>Hello</span><span>Kitty</span></li></ol>'); |
michael@0 | 66 | |
michael@0 | 67 | // The following test doesn't do what I expected, because the special handling |
michael@0 | 68 | // of IsList nodes in nsHTMLEditor::InsertHTMLWithContext simply removes |
michael@0 | 69 | // non-list/item children. See bug 481177. |
michael@0 | 70 | // copyToClipBoard("<ol><li>Hello Kitty</li><span>Hello</span></ol>", true); |
michael@0 | 71 | // pasteInto('<ol><li id="paste_here">X</li></ol>',"paste_here"); |
michael@0 | 72 | // verifyContent('<ol><li id="paste_here">X</li><li>Hello Kitty</li><span>Hello</span></ol>'); |
michael@0 | 73 | |
michael@0 | 74 | copyToClipBoard("<pre>Kitty</pre><span>Hello</span>", true); |
michael@0 | 75 | pasteInto('<pre id="paste_here">Hello </pre>',"paste_here"); |
michael@0 | 76 | verifyContent('<pre id="paste_here">Hello Kitty<span>Hello</span></pre>'); |
michael@0 | 77 | |
michael@0 | 78 | SimpleTest.finish(); |
michael@0 | 79 | } |
michael@0 | 80 | |
michael@0 | 81 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 82 | addLoadEvent(runTest); |
michael@0 | 83 | </script> |
michael@0 | 84 | </head> |
michael@0 | 85 | <body> |
michael@0 | 86 | <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=480972">Mozilla Bug 480972</a> |
michael@0 | 87 | <p id="display"></p> |
michael@0 | 88 | |
michael@0 | 89 | <pre id="test"> |
michael@0 | 90 | </pre> |
michael@0 | 91 | |
michael@0 | 92 | |
michael@0 | 93 | <iframe id="i1" width="200" height="100" src="about:blank"></iframe><br> |
michael@0 | 94 | <iframe id="i2" width="200" height="100" src="about:blank"></iframe><br> |
michael@0 | 95 | |
michael@0 | 96 | </body> |
michael@0 | 97 | </html> |
michael@0 | 98 |