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> |
michael@0 | 3 | <!-- |
michael@0 | 4 | https://bugzilla.mozilla.org/show_bug.cgi?id=551704 |
michael@0 | 5 | --> |
michael@0 | 6 | <head> |
michael@0 | 7 | <title>Test for Bug 551704</title> |
michael@0 | 8 | <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 9 | <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script> |
michael@0 | 10 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> |
michael@0 | 11 | </head> |
michael@0 | 12 | <body> |
michael@0 | 13 | <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=551704">Mozilla Bug 551704</a> |
michael@0 | 14 | <p id="display"></p> |
michael@0 | 15 | <div id="content"> |
michael@0 | 16 | <div id="preformatted" style="white-space: pre" contenteditable>a b</div> |
michael@0 | 17 | <div id="test1" contenteditable><br></div> |
michael@0 | 18 | <div id="test2" contenteditable>a<br></div> |
michael@0 | 19 | <div id="test3" contenteditable style="white-space: pre"><br></div> |
michael@0 | 20 | <div id="test4" contenteditable style="white-space: pre">a<br></div> |
michael@0 | 21 | <div id="test5" contenteditable></div> |
michael@0 | 22 | <div id="test6" contenteditable>a</div> |
michael@0 | 23 | <div id="test7" contenteditable style="white-space: pre"></div> |
michael@0 | 24 | <div id="test8" contenteditable style="white-space: pre">a</div> |
michael@0 | 25 | </div> |
michael@0 | 26 | <pre id="test"> |
michael@0 | 27 | <script type="application/javascript"> |
michael@0 | 28 | |
michael@0 | 29 | function testLineBreak(div, type, expectedText, expectedHTML, callback) |
michael@0 | 30 | { |
michael@0 | 31 | div.focus(); |
michael@0 | 32 | getSelection().collapse(div, 0); |
michael@0 | 33 | type(); |
michael@0 | 34 | is(div.innerHTML, expectedHTML, "The expected HTML after editing should be correct"); |
michael@0 | 35 | SimpleTest.waitForClipboard(expectedText, |
michael@0 | 36 | function() { |
michael@0 | 37 | getSelection().selectAllChildren(div); |
michael@0 | 38 | synthesizeKey("C", {accelKey: true}); |
michael@0 | 39 | }, |
michael@0 | 40 | function() { |
michael@0 | 41 | var t = document.createElement("textarea"); |
michael@0 | 42 | document.body.appendChild(t); |
michael@0 | 43 | t.focus(); |
michael@0 | 44 | synthesizeKey("V", {accelKey: true}); |
michael@0 | 45 | is(t.value, expectedText, "The expected text should be copied to the clipboard"); |
michael@0 | 46 | callback(); |
michael@0 | 47 | }, |
michael@0 | 48 | function() { |
michael@0 | 49 | SimpleTest.finish(); |
michael@0 | 50 | } |
michael@0 | 51 | ); |
michael@0 | 52 | } |
michael@0 | 53 | |
michael@0 | 54 | function typeABCDEF() { |
michael@0 | 55 | synthesizeKey("a", {}); |
michael@0 | 56 | typeBCDEF_chars(); |
michael@0 | 57 | } |
michael@0 | 58 | |
michael@0 | 59 | function typeBCDEF() { |
michael@0 | 60 | synthesizeKey("VK_RIGHT", {}); |
michael@0 | 61 | typeBCDEF_chars(); |
michael@0 | 62 | } |
michael@0 | 63 | |
michael@0 | 64 | function typeBCDEF_chars() { |
michael@0 | 65 | synthesizeKey("b", {}); |
michael@0 | 66 | synthesizeKey("c", {}); |
michael@0 | 67 | synthesizeKey("VK_RETURN", {}); |
michael@0 | 68 | synthesizeKey("d", {}); |
michael@0 | 69 | synthesizeKey("e", {}); |
michael@0 | 70 | synthesizeKey("f", {}); |
michael@0 | 71 | } |
michael@0 | 72 | |
michael@0 | 73 | /** Test for Bug 551704 **/ |
michael@0 | 74 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 75 | SimpleTest.waitForFocus(function() { |
michael@0 | 76 | var preformatted = document.getElementById("preformatted"); |
michael@0 | 77 | is(preformatted.innerHTML, "a\nb", "No BR node should be injected for preformatted editable fields"); |
michael@0 | 78 | |
michael@0 | 79 | var iframe = document.createElement("iframe"); |
michael@0 | 80 | iframe.addEventListener("load", function() { |
michael@0 | 81 | var sel = iframe.contentWindow.getSelection(); |
michael@0 | 82 | is(sel.rangeCount, 0, "There should be no range in the selection initially"); |
michael@0 | 83 | iframe.contentDocument.designMode = "on"; |
michael@0 | 84 | sel = iframe.contentWindow.getSelection(); |
michael@0 | 85 | is(sel.rangeCount, 1, "There should be a single range in the selection after setting designMode"); |
michael@0 | 86 | var range = sel.getRangeAt(0); |
michael@0 | 87 | ok(range.collapsed, "The range should be collapsed"); |
michael@0 | 88 | is(range.startContainer, iframe.contentDocument.body.firstChild, "The range should start on the text"); |
michael@0 | 89 | is(range.startOffset, 0, "The start offset should be zero"); |
michael@0 | 90 | |
michael@0 | 91 | continueTest(); |
michael@0 | 92 | }, false); |
michael@0 | 93 | iframe.src = "data:text/html,foo"; |
michael@0 | 94 | document.getElementById("content").appendChild(iframe); |
michael@0 | 95 | }); |
michael@0 | 96 | |
michael@0 | 97 | function continueTest() { |
michael@0 | 98 | var divs = []; |
michael@0 | 99 | for (var i = 0; i < 8; ++i) { |
michael@0 | 100 | divs[i] = document.getElementById("test" + (i+1)); |
michael@0 | 101 | } |
michael@0 | 102 | var current = 0; |
michael@0 | 103 | function doNextTest() { |
michael@0 | 104 | if (current == divs.length) { |
michael@0 | 105 | SimpleTest.finish(); |
michael@0 | 106 | return; |
michael@0 | 107 | } |
michael@0 | 108 | var div = divs[current++]; |
michael@0 | 109 | if (div.textContent == "a") { |
michael@0 | 110 | var type = typeBCDEF; |
michael@0 | 111 | } else { |
michael@0 | 112 | var type = typeABCDEF; |
michael@0 | 113 | } |
michael@0 | 114 | var expectedHTML = "abc<br>def<br>"; |
michael@0 | 115 | var expectedText = "abc\ndef"; |
michael@0 | 116 | testLineBreak(div, type, expectedText, expectedHTML, doNextTest); |
michael@0 | 117 | } |
michael@0 | 118 | |
michael@0 | 119 | doNextTest(); |
michael@0 | 120 | } |
michael@0 | 121 | |
michael@0 | 122 | </script> |
michael@0 | 123 | </pre> |
michael@0 | 124 | </body> |
michael@0 | 125 | </html> |