1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/editor/libeditor/html/tests/test_bug611182.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,239 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=611182 1.8 +--> 1.9 +<head> 1.10 + <title>Test for Bug 611182</title> 1.11 + <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.12 + <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script> 1.13 + <script type="text/javascript" src="/tests/SimpleTest/WindowSnapshot.js"></script> 1.14 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 1.15 +</head> 1.16 +<body> 1.17 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=611182">Mozilla Bug 611182</a> 1.18 +<p id="display"></p> 1.19 +<div id="content"> 1.20 + <iframe></iframe> 1.21 + <iframe id="ref" src="data:text/html,foo bar"></iframe> 1.22 +</div> 1.23 +<pre id="test"> 1.24 +<script type="application/javascript"> 1.25 + 1.26 +/** Test for Bug 611182 **/ 1.27 +SimpleTest.waitForExplicitFinish(); 1.28 +SimpleTest.waitForFocus(function() { 1.29 + var iframe = document.querySelector("iframe"); 1.30 + var refElem = document.querySelector("#ref"); 1.31 + var ref = snapshotWindow(refElem.contentWindow, false); 1.32 + 1.33 + function findTextNode(doc) { 1.34 + var body = doc.documentElement; 1.35 + var result = findTextNodeWorker(body); 1.36 + ok(result, "Failed to find the text node"); 1.37 + return result; 1.38 + } 1.39 + 1.40 + function findTextNodeWorker(root) { 1.41 + if (root.isContentEditable) { 1.42 + root.focus(); 1.43 + } 1.44 + for (var i = 0; i < root.childNodes.length; ++i) { 1.45 + var node = root.childNodes[i]; 1.46 + if (node.nodeType == node.TEXT_NODE && 1.47 + node.nodeValue == "fooz bar") { 1.48 + return node; 1.49 + } 1.50 + if (node.nodeType == node.ELEMENT_NODE) { 1.51 + node = findTextNodeWorker(node); 1.52 + if (node) { 1.53 + return node; 1.54 + } 1.55 + } 1.56 + } 1.57 + return null; 1.58 + } 1.59 + 1.60 + function testBackspace(src, callback) { 1.61 + ok(true, "Testing " + src); 1.62 + iframe.addEventListener("load", function() { 1.63 + iframe.removeEventListener("load", arguments.callee, false); 1.64 + 1.65 + var doc = iframe.contentDocument; 1.66 + var win = iframe.contentWindow; 1.67 + doc.body.setAttribute("spellcheck", "false"); 1.68 + 1.69 + iframe.focus(); 1.70 + var textNode = findTextNode(doc); 1.71 + var sel = win.getSelection(); 1.72 + sel.collapse(textNode, 4); 1.73 + synthesizeKey("VK_BACK_SPACE", {}); 1.74 + is(textNode.textContent, "foo bar", "Backspace should work correctly"); 1.75 + 1.76 + var snapshot = snapshotWindow(win, false); 1.77 + ok(compareSnapshots(snapshot, ref, true)[0], "No bogus node should exist in the document"); 1.78 + 1.79 + callback(); 1.80 + }, false); 1.81 + iframe.src = src; 1.82 + } 1.83 + 1.84 + const TEST_URIS = [ 1.85 + "data:text/html,<html contenteditable>fooz bar</html>", 1.86 + "data:text/html,<html contenteditable><body>fooz bar</body></html>", 1.87 + "data:text/html,<body contenteditable>fooz bar</body>", 1.88 + "data:text/html,<body contenteditable><p>fooz bar</p></body>", 1.89 + "data:text/html,<body contenteditable><div>fooz bar</div></body>", 1.90 + "data:text/html,<body contenteditable><span>fooz bar</span></body>", 1.91 + "data:text/html,<p contenteditable style='outline:none'>fooz bar</p>", 1.92 + "data:text/html,<!DOCTYPE html><html><body contenteditable>fooz bar</body></html>", 1.93 + "data:text/html,<!DOCTYPE html><html contenteditable><body>fooz bar</body></html>", 1.94 + 'data:application/xhtml+xml,<html xmlns="http://www.w3.org/1999/xhtml"><body contenteditable="true">fooz bar</body></html>', 1.95 + 'data:application/xhtml+xml,<html xmlns="http://www.w3.org/1999/xhtml" contenteditable="true"><body>fooz bar</body></html>', 1.96 + "data:text/html,<body onload=\"document.designMode='on'\">fooz bar</body>", 1.97 + 'data:text/html,<html><script>' + 1.98 + 'onload = function() {' + 1.99 + 'var old = document.body;' + 1.100 + 'old.parentNode.removeChild(old);' + 1.101 + 'var r = document.documentElement;' + 1.102 + 'var b = document.createElement("body");' + 1.103 + 'r.appendChild(b);' + 1.104 + 'b.appendChild(document.createTextNode("fooz bar"));' + 1.105 + 'b.contentEditable = "true";' + 1.106 + '};' + 1.107 + '<\/script><body></body></html>', 1.108 + 'data:text/html,<html><script>' + 1.109 + 'onload = function() {' + 1.110 + 'var old = document.body;' + 1.111 + 'old.parentNode.removeChild(old);' + 1.112 + 'var r = document.documentElement;' + 1.113 + 'var b = document.createElement("body");' + 1.114 + 'b.appendChild(document.createTextNode("fooz bar"));' + 1.115 + 'b.contentEditable = "true";' + 1.116 + 'r.appendChild(b);' + 1.117 + '};' + 1.118 + '<\/script><body></body></html>', 1.119 + 'data:text/html,<html><script>' + 1.120 + 'onload = function() {' + 1.121 + 'var old = document.body;' + 1.122 + 'old.parentNode.removeChild(old);' + 1.123 + 'var r = document.documentElement;' + 1.124 + 'var b = document.createElement("body");' + 1.125 + 'r.appendChild(b);' + 1.126 + 'b.appendChild(document.createTextNode("fooz bar"));' + 1.127 + 'b.setAttribute("contenteditable", "true");' + 1.128 + '};' + 1.129 + '<\/script><body></body></html>', 1.130 + 'data:text/html,<html><script>' + 1.131 + 'onload = function() {' + 1.132 + 'var old = document.body;' + 1.133 + 'old.parentNode.removeChild(old);' + 1.134 + 'var r = document.documentElement;' + 1.135 + 'var b = document.createElement("body");' + 1.136 + 'b.appendChild(document.createTextNode("fooz bar"));' + 1.137 + 'b.setAttribute("contenteditable", "true");' + 1.138 + 'r.appendChild(b);' + 1.139 + '};' + 1.140 + '<\/script><body></body></html>', 1.141 + 'data:text/html,<html><script>' + 1.142 + 'onload = function() {' + 1.143 + 'var old = document.body;' + 1.144 + 'old.parentNode.removeChild(old);' + 1.145 + 'var r = document.documentElement;' + 1.146 + 'var b = document.createElement("body");' + 1.147 + 'r.appendChild(b);' + 1.148 + 'b.contentEditable = "true";' + 1.149 + 'b.appendChild(document.createTextNode("fooz bar"));' + 1.150 + '};' + 1.151 + '<\/script><body></body></html>', 1.152 + 'data:text/html,<html><script>' + 1.153 + 'onload = function() {' + 1.154 + 'var old = document.body;' + 1.155 + 'old.parentNode.removeChild(old);' + 1.156 + 'var r = document.documentElement;' + 1.157 + 'var b = document.createElement("body");' + 1.158 + 'b.contentEditable = "true";' + 1.159 + 'r.appendChild(b);' + 1.160 + 'b.appendChild(document.createTextNode("fooz bar"));' + 1.161 + '};' + 1.162 + '<\/script><body></body></html>', 1.163 + 'data:text/html,<html><script>' + 1.164 + 'onload = function() {' + 1.165 + 'var old = document.body;' + 1.166 + 'old.parentNode.removeChild(old);' + 1.167 + 'var r = document.documentElement;' + 1.168 + 'var b = document.createElement("body");' + 1.169 + 'r.appendChild(b);' + 1.170 + 'b.setAttribute("contenteditable", "true");' + 1.171 + 'b.appendChild(document.createTextNode("fooz bar"));' + 1.172 + '};' + 1.173 + '<\/script><body></body></html>', 1.174 + 'data:text/html,<html><script>' + 1.175 + 'onload = function() {' + 1.176 + 'var old = document.body;' + 1.177 + 'old.parentNode.removeChild(old);' + 1.178 + 'var r = document.documentElement;' + 1.179 + 'var b = document.createElement("body");' + 1.180 + 'b.setAttribute("contenteditable", "true");' + 1.181 + 'r.appendChild(b);' + 1.182 + 'b.appendChild(document.createTextNode("fooz bar"));' + 1.183 + '};' + 1.184 + '<\/script><body></body></html>', 1.185 + 'data:text/html,<html><script>' + 1.186 + 'onload = function() {' + 1.187 + 'document.open();' + 1.188 + 'document.write("<body contenteditable>fooz bar</body>");' + 1.189 + 'document.close();' + 1.190 + '};' + 1.191 + '<\/script><body></body></html>', 1.192 + 'data:text/html,<html><script>' + 1.193 + 'onload = function() {' + 1.194 + 'document.open();' + 1.195 + 'document.write("<body contenteditable><div>fooz bar</div></body>");' + 1.196 + 'document.close();' + 1.197 + '};' + 1.198 + '<\/script><body></body></html>', 1.199 + 'data:text/html,<html><script>' + 1.200 + 'onload = function() {' + 1.201 + 'document.open();' + 1.202 + 'document.write("<body contenteditable><span>fooz bar</span></body>");' + 1.203 + 'document.close();' + 1.204 + '};' + 1.205 + '<\/script><body></body></html>', 1.206 + 'data:text/html,<html><script>' + 1.207 + 'onload = function() {' + 1.208 + 'document.open();' + 1.209 + 'document.write("<p contenteditable style=\\"outline: none\\">fooz bar</p>");' + 1.210 + 'document.close();' + 1.211 + '};' + 1.212 + '<\/script><body></body></html>', 1.213 + 'data:text/html,<html><script>' + 1.214 + 'onload = function() {' + 1.215 + 'document.open();' + 1.216 + 'document.write("<html contenteditable>fooz bar</html>");' + 1.217 + 'document.close();' + 1.218 + '};' + 1.219 + '<\/script><body></body></html>', 1.220 + 'data:text/html,<html><script>' + 1.221 + 'onload = function() {' + 1.222 + 'document.open();' + 1.223 + 'document.write("<html contenteditable><body>fooz bar</body></html>");' + 1.224 + 'document.close();' + 1.225 + '};' + 1.226 + '<\/script><body></body></html>', 1.227 + ]; 1.228 + var currentTest = 0; 1.229 + function runAllTests() { 1.230 + if (currentTest == TEST_URIS.length) { 1.231 + SimpleTest.finish(); 1.232 + return; 1.233 + } 1.234 + testBackspace(TEST_URIS[currentTest++], runAllTests); 1.235 + } 1.236 + runAllTests(); 1.237 +}); 1.238 + 1.239 +</script> 1.240 +</pre> 1.241 +</body> 1.242 +</html>