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=611182 |
michael@0 | 5 | --> |
michael@0 | 6 | <head> |
michael@0 | 7 | <title>Test for Bug 611182</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 | <script type="text/javascript" src="/tests/SimpleTest/WindowSnapshot.js"></script> |
michael@0 | 11 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> |
michael@0 | 12 | </head> |
michael@0 | 13 | <body> |
michael@0 | 14 | <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=611182">Mozilla Bug 611182</a> |
michael@0 | 15 | <p id="display"></p> |
michael@0 | 16 | <div id="content"> |
michael@0 | 17 | <iframe></iframe> |
michael@0 | 18 | <iframe id="ref" src="data:text/html,foo bar"></iframe> |
michael@0 | 19 | </div> |
michael@0 | 20 | <pre id="test"> |
michael@0 | 21 | <script type="application/javascript"> |
michael@0 | 22 | |
michael@0 | 23 | /** Test for Bug 611182 **/ |
michael@0 | 24 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 25 | SimpleTest.waitForFocus(function() { |
michael@0 | 26 | var iframe = document.querySelector("iframe"); |
michael@0 | 27 | var refElem = document.querySelector("#ref"); |
michael@0 | 28 | var ref = snapshotWindow(refElem.contentWindow, false); |
michael@0 | 29 | |
michael@0 | 30 | function findTextNode(doc) { |
michael@0 | 31 | var body = doc.documentElement; |
michael@0 | 32 | var result = findTextNodeWorker(body); |
michael@0 | 33 | ok(result, "Failed to find the text node"); |
michael@0 | 34 | return result; |
michael@0 | 35 | } |
michael@0 | 36 | |
michael@0 | 37 | function findTextNodeWorker(root) { |
michael@0 | 38 | if (root.isContentEditable) { |
michael@0 | 39 | root.focus(); |
michael@0 | 40 | } |
michael@0 | 41 | for (var i = 0; i < root.childNodes.length; ++i) { |
michael@0 | 42 | var node = root.childNodes[i]; |
michael@0 | 43 | if (node.nodeType == node.TEXT_NODE && |
michael@0 | 44 | node.nodeValue == "fooz bar") { |
michael@0 | 45 | return node; |
michael@0 | 46 | } |
michael@0 | 47 | if (node.nodeType == node.ELEMENT_NODE) { |
michael@0 | 48 | node = findTextNodeWorker(node); |
michael@0 | 49 | if (node) { |
michael@0 | 50 | return node; |
michael@0 | 51 | } |
michael@0 | 52 | } |
michael@0 | 53 | } |
michael@0 | 54 | return null; |
michael@0 | 55 | } |
michael@0 | 56 | |
michael@0 | 57 | function testBackspace(src, callback) { |
michael@0 | 58 | ok(true, "Testing " + src); |
michael@0 | 59 | iframe.addEventListener("load", function() { |
michael@0 | 60 | iframe.removeEventListener("load", arguments.callee, false); |
michael@0 | 61 | |
michael@0 | 62 | var doc = iframe.contentDocument; |
michael@0 | 63 | var win = iframe.contentWindow; |
michael@0 | 64 | doc.body.setAttribute("spellcheck", "false"); |
michael@0 | 65 | |
michael@0 | 66 | iframe.focus(); |
michael@0 | 67 | var textNode = findTextNode(doc); |
michael@0 | 68 | var sel = win.getSelection(); |
michael@0 | 69 | sel.collapse(textNode, 4); |
michael@0 | 70 | synthesizeKey("VK_BACK_SPACE", {}); |
michael@0 | 71 | is(textNode.textContent, "foo bar", "Backspace should work correctly"); |
michael@0 | 72 | |
michael@0 | 73 | var snapshot = snapshotWindow(win, false); |
michael@0 | 74 | ok(compareSnapshots(snapshot, ref, true)[0], "No bogus node should exist in the document"); |
michael@0 | 75 | |
michael@0 | 76 | callback(); |
michael@0 | 77 | }, false); |
michael@0 | 78 | iframe.src = src; |
michael@0 | 79 | } |
michael@0 | 80 | |
michael@0 | 81 | const TEST_URIS = [ |
michael@0 | 82 | "data:text/html,<html contenteditable>fooz bar</html>", |
michael@0 | 83 | "data:text/html,<html contenteditable><body>fooz bar</body></html>", |
michael@0 | 84 | "data:text/html,<body contenteditable>fooz bar</body>", |
michael@0 | 85 | "data:text/html,<body contenteditable><p>fooz bar</p></body>", |
michael@0 | 86 | "data:text/html,<body contenteditable><div>fooz bar</div></body>", |
michael@0 | 87 | "data:text/html,<body contenteditable><span>fooz bar</span></body>", |
michael@0 | 88 | "data:text/html,<p contenteditable style='outline:none'>fooz bar</p>", |
michael@0 | 89 | "data:text/html,<!DOCTYPE html><html><body contenteditable>fooz bar</body></html>", |
michael@0 | 90 | "data:text/html,<!DOCTYPE html><html contenteditable><body>fooz bar</body></html>", |
michael@0 | 91 | 'data:application/xhtml+xml,<html xmlns="http://www.w3.org/1999/xhtml"><body contenteditable="true">fooz bar</body></html>', |
michael@0 | 92 | 'data:application/xhtml+xml,<html xmlns="http://www.w3.org/1999/xhtml" contenteditable="true"><body>fooz bar</body></html>', |
michael@0 | 93 | "data:text/html,<body onload=\"document.designMode='on'\">fooz bar</body>", |
michael@0 | 94 | 'data:text/html,<html><script>' + |
michael@0 | 95 | 'onload = function() {' + |
michael@0 | 96 | 'var old = document.body;' + |
michael@0 | 97 | 'old.parentNode.removeChild(old);' + |
michael@0 | 98 | 'var r = document.documentElement;' + |
michael@0 | 99 | 'var b = document.createElement("body");' + |
michael@0 | 100 | 'r.appendChild(b);' + |
michael@0 | 101 | 'b.appendChild(document.createTextNode("fooz bar"));' + |
michael@0 | 102 | 'b.contentEditable = "true";' + |
michael@0 | 103 | '};' + |
michael@0 | 104 | '<\/script><body></body></html>', |
michael@0 | 105 | 'data:text/html,<html><script>' + |
michael@0 | 106 | 'onload = function() {' + |
michael@0 | 107 | 'var old = document.body;' + |
michael@0 | 108 | 'old.parentNode.removeChild(old);' + |
michael@0 | 109 | 'var r = document.documentElement;' + |
michael@0 | 110 | 'var b = document.createElement("body");' + |
michael@0 | 111 | 'b.appendChild(document.createTextNode("fooz bar"));' + |
michael@0 | 112 | 'b.contentEditable = "true";' + |
michael@0 | 113 | 'r.appendChild(b);' + |
michael@0 | 114 | '};' + |
michael@0 | 115 | '<\/script><body></body></html>', |
michael@0 | 116 | 'data:text/html,<html><script>' + |
michael@0 | 117 | 'onload = function() {' + |
michael@0 | 118 | 'var old = document.body;' + |
michael@0 | 119 | 'old.parentNode.removeChild(old);' + |
michael@0 | 120 | 'var r = document.documentElement;' + |
michael@0 | 121 | 'var b = document.createElement("body");' + |
michael@0 | 122 | 'r.appendChild(b);' + |
michael@0 | 123 | 'b.appendChild(document.createTextNode("fooz bar"));' + |
michael@0 | 124 | 'b.setAttribute("contenteditable", "true");' + |
michael@0 | 125 | '};' + |
michael@0 | 126 | '<\/script><body></body></html>', |
michael@0 | 127 | 'data:text/html,<html><script>' + |
michael@0 | 128 | 'onload = function() {' + |
michael@0 | 129 | 'var old = document.body;' + |
michael@0 | 130 | 'old.parentNode.removeChild(old);' + |
michael@0 | 131 | 'var r = document.documentElement;' + |
michael@0 | 132 | 'var b = document.createElement("body");' + |
michael@0 | 133 | 'b.appendChild(document.createTextNode("fooz bar"));' + |
michael@0 | 134 | 'b.setAttribute("contenteditable", "true");' + |
michael@0 | 135 | 'r.appendChild(b);' + |
michael@0 | 136 | '};' + |
michael@0 | 137 | '<\/script><body></body></html>', |
michael@0 | 138 | 'data:text/html,<html><script>' + |
michael@0 | 139 | 'onload = function() {' + |
michael@0 | 140 | 'var old = document.body;' + |
michael@0 | 141 | 'old.parentNode.removeChild(old);' + |
michael@0 | 142 | 'var r = document.documentElement;' + |
michael@0 | 143 | 'var b = document.createElement("body");' + |
michael@0 | 144 | 'r.appendChild(b);' + |
michael@0 | 145 | 'b.contentEditable = "true";' + |
michael@0 | 146 | 'b.appendChild(document.createTextNode("fooz bar"));' + |
michael@0 | 147 | '};' + |
michael@0 | 148 | '<\/script><body></body></html>', |
michael@0 | 149 | 'data:text/html,<html><script>' + |
michael@0 | 150 | 'onload = function() {' + |
michael@0 | 151 | 'var old = document.body;' + |
michael@0 | 152 | 'old.parentNode.removeChild(old);' + |
michael@0 | 153 | 'var r = document.documentElement;' + |
michael@0 | 154 | 'var b = document.createElement("body");' + |
michael@0 | 155 | 'b.contentEditable = "true";' + |
michael@0 | 156 | 'r.appendChild(b);' + |
michael@0 | 157 | 'b.appendChild(document.createTextNode("fooz bar"));' + |
michael@0 | 158 | '};' + |
michael@0 | 159 | '<\/script><body></body></html>', |
michael@0 | 160 | 'data:text/html,<html><script>' + |
michael@0 | 161 | 'onload = function() {' + |
michael@0 | 162 | 'var old = document.body;' + |
michael@0 | 163 | 'old.parentNode.removeChild(old);' + |
michael@0 | 164 | 'var r = document.documentElement;' + |
michael@0 | 165 | 'var b = document.createElement("body");' + |
michael@0 | 166 | 'r.appendChild(b);' + |
michael@0 | 167 | 'b.setAttribute("contenteditable", "true");' + |
michael@0 | 168 | 'b.appendChild(document.createTextNode("fooz bar"));' + |
michael@0 | 169 | '};' + |
michael@0 | 170 | '<\/script><body></body></html>', |
michael@0 | 171 | 'data:text/html,<html><script>' + |
michael@0 | 172 | 'onload = function() {' + |
michael@0 | 173 | 'var old = document.body;' + |
michael@0 | 174 | 'old.parentNode.removeChild(old);' + |
michael@0 | 175 | 'var r = document.documentElement;' + |
michael@0 | 176 | 'var b = document.createElement("body");' + |
michael@0 | 177 | 'b.setAttribute("contenteditable", "true");' + |
michael@0 | 178 | 'r.appendChild(b);' + |
michael@0 | 179 | 'b.appendChild(document.createTextNode("fooz bar"));' + |
michael@0 | 180 | '};' + |
michael@0 | 181 | '<\/script><body></body></html>', |
michael@0 | 182 | 'data:text/html,<html><script>' + |
michael@0 | 183 | 'onload = function() {' + |
michael@0 | 184 | 'document.open();' + |
michael@0 | 185 | 'document.write("<body contenteditable>fooz bar</body>");' + |
michael@0 | 186 | 'document.close();' + |
michael@0 | 187 | '};' + |
michael@0 | 188 | '<\/script><body></body></html>', |
michael@0 | 189 | 'data:text/html,<html><script>' + |
michael@0 | 190 | 'onload = function() {' + |
michael@0 | 191 | 'document.open();' + |
michael@0 | 192 | 'document.write("<body contenteditable><div>fooz bar</div></body>");' + |
michael@0 | 193 | 'document.close();' + |
michael@0 | 194 | '};' + |
michael@0 | 195 | '<\/script><body></body></html>', |
michael@0 | 196 | 'data:text/html,<html><script>' + |
michael@0 | 197 | 'onload = function() {' + |
michael@0 | 198 | 'document.open();' + |
michael@0 | 199 | 'document.write("<body contenteditable><span>fooz bar</span></body>");' + |
michael@0 | 200 | 'document.close();' + |
michael@0 | 201 | '};' + |
michael@0 | 202 | '<\/script><body></body></html>', |
michael@0 | 203 | 'data:text/html,<html><script>' + |
michael@0 | 204 | 'onload = function() {' + |
michael@0 | 205 | 'document.open();' + |
michael@0 | 206 | 'document.write("<p contenteditable style=\\"outline: none\\">fooz bar</p>");' + |
michael@0 | 207 | 'document.close();' + |
michael@0 | 208 | '};' + |
michael@0 | 209 | '<\/script><body></body></html>', |
michael@0 | 210 | 'data:text/html,<html><script>' + |
michael@0 | 211 | 'onload = function() {' + |
michael@0 | 212 | 'document.open();' + |
michael@0 | 213 | 'document.write("<html contenteditable>fooz bar</html>");' + |
michael@0 | 214 | 'document.close();' + |
michael@0 | 215 | '};' + |
michael@0 | 216 | '<\/script><body></body></html>', |
michael@0 | 217 | 'data:text/html,<html><script>' + |
michael@0 | 218 | 'onload = function() {' + |
michael@0 | 219 | 'document.open();' + |
michael@0 | 220 | 'document.write("<html contenteditable><body>fooz bar</body></html>");' + |
michael@0 | 221 | 'document.close();' + |
michael@0 | 222 | '};' + |
michael@0 | 223 | '<\/script><body></body></html>', |
michael@0 | 224 | ]; |
michael@0 | 225 | var currentTest = 0; |
michael@0 | 226 | function runAllTests() { |
michael@0 | 227 | if (currentTest == TEST_URIS.length) { |
michael@0 | 228 | SimpleTest.finish(); |
michael@0 | 229 | return; |
michael@0 | 230 | } |
michael@0 | 231 | testBackspace(TEST_URIS[currentTest++], runAllTests); |
michael@0 | 232 | } |
michael@0 | 233 | runAllTests(); |
michael@0 | 234 | }); |
michael@0 | 235 | |
michael@0 | 236 | </script> |
michael@0 | 237 | </pre> |
michael@0 | 238 | </body> |
michael@0 | 239 | </html> |