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