1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1094000
-->
<head>
<title>Test for Bug 1094000</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script src="/tests/SimpleTest/EventUtils.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1094000">Mozilla Bug 1094000</a>
<p id="display"></p>
<div id="content">
<div id="editor0" contenteditable></div>
<div id="editor1" contenteditable><br></div>
<div id="editor2" contenteditable>a</div>
<div id="editor3" contenteditable>b</div>
<div id="editor4" contenteditable>c</div>
<div id="editor5" contenteditable>d</div>
<div id="editor6" contenteditable>e</div>
<div id="editor7" contenteditable><span>f</span></div>
<div id="editor8" contenteditable><span>g</span></div>
<div id="editor9" contenteditable><span>h</span></div>
</div>
<pre id="test">
<script type="application/javascript">
/** Test for Bug 1094000 **/
SimpleTest.waitForExplicitFinish();
const kIsLinux = navigator.platform.indexOf("Linux") == 0;
function runTests() {
var editor0 = document.getElementById("editor0");
var editor1 = document.getElementById("editor1");
var editor2 = document.getElementById("editor2");
var editor3 = document.getElementById("editor3");
var editor4 = document.getElementById("editor4");
var editor5 = document.getElementById("editor5");
var editor6 = document.getElementById("editor6");
var editor7 = document.getElementById("editor7");
var editor8 = document.getElementById("editor8");
var editor9 = document.getElementById("editor9");
ok(Math.abs(editor1.getBoundingClientRect().height - editor0.getBoundingClientRect().height) <= 1,
"an editor having a <br> element and an empty editor should be same height");
ok(Math.abs(editor1.getBoundingClientRect().height - editor2.getBoundingClientRect().height) <= 1,
"an editor having only a <br> element and an editor having \"a\" should be same height");
editor2.focus();
synthesizeKey("KEY_ArrowRight");
synthesizeKey("KEY_Backspace");
is(editor2.innerHTML, "<br>",
"an editor which had \"a\" should have only <br> element after Backspace keypress");
ok(Math.abs(editor2.getBoundingClientRect().height - editor1.getBoundingClientRect().height) <= 1,
"an editor whose content was removed by Backspace key should have a place to put a caret");
editor3.focus();
synthesizeKey("KEY_ArrowLeft");
synthesizeKey("KEY_Delete");
is(editor3.innerHTML, "<br>",
"an editor which had \"b\" should have only <br> element after Delete keypress");
ok(Math.abs(editor3.getBoundingClientRect().height - editor1.getBoundingClientRect().height) <= 1,
"an editor whose content was removed by Delete key should have a place to put a caret");
editor4.focus();
window.getSelection().selectAllChildren(editor4);
synthesizeKey("KEY_Backspace");
is(editor4.innerHTML, "<br>",
"an editor which had \"c\" should have only <br> element after removing selected text with Backspace key");
ok(Math.abs(editor4.getBoundingClientRect().height - editor1.getBoundingClientRect().height) <= 1,
"an editor whose content was selected and removed by Backspace key should have a place to put a caret");
editor5.focus();
window.getSelection().selectAllChildren(editor5);
synthesizeKey("KEY_Delete");
is(editor5.innerHTML, "<br>",
"an editor which had \"d\" should have only <br> element after removing selected text with Delete key");
ok(Math.abs(editor5.getBoundingClientRect().height - editor1.getBoundingClientRect().height) <= 1,
"an editor whose content was selected and removed by Delete key should have a place to put a caret");
editor6.focus();
window.getSelection().selectAllChildren(editor6);
synthesizeKey("x", {accelKey: true});
is(editor6.innerHTML, "<br>",
"an editor which had \"e\" should have only <br> element after removing selected text by \"Cut\"");
ok(Math.abs(editor6.getBoundingClientRect().height - editor1.getBoundingClientRect().height) <= 1,
"an editor whose content was selected and removed by \"Cut\" should have a place to put a caret");
editor7.focus();
synthesizeKey("KEY_ArrowRight");
synthesizeKey("KEY_Backspace");
is(
editor7.innerHTML,
SpecialPowers.getBoolPref("editor.white_space_normalization.blink_compatible")
? "<br>"
: "<span><br></span>",
"an editor which had \"f\" in a <span> element should have only <br> element after Backspace keypress"
);
ok(Math.abs(editor7.getBoundingClientRect().height - editor1.getBoundingClientRect().height) <= 1,
"an editor whose content was removed by Backspace key should have a place to put a caret");
editor8.focus();
synthesizeKey("KEY_ArrowLeft");
synthesizeKey("KEY_Delete");
todo_is(editor8.innerHTML, "<br>",
"an editor which had \"g\" in a <span> element should have only <br> element after Delete keypress");
todo_isnot(
editor8.innerHTML,
SpecialPowers.getBoolPref("editor.white_space_normalization.blink_compatible")
? "<br><span></span>"
: "<span><br></span>",
"an editor which had \"g\" in a <span> element should have only <br> element after Delete keypress"
);
ok(Math.abs(editor8.getBoundingClientRect().height - editor1.getBoundingClientRect().height) <= 1,
"an editor whose content was removed by Backspace key should have a place to put a caret");
editor9.focus();
window.getSelection().selectAllChildren(editor9.querySelector("span"));
synthesizeKey("KEY_Backspace");
todo_is(editor9.innerHTML, "<br>",
"an editor which had \"h\" in a <span> element should have only <br> element after removing selected text with Backspace key");
todo_isnot(editor9.innerHTML, "<span><br></span>",
"an editor which had \"h\" in a <span> element should have only <br> element after removing selected text with Backspace key");
ok(Math.abs(editor9.getBoundingClientRect().height - editor1.getBoundingClientRect().height) <= 1,
"an editor whose content was removed by Backspace key should have a place to put a caret");
editor0.focus();
synthesizeKey("KEY_Backspace");
is(editor0.innerHTML, "",
"an empty editor should keep being empty even if Backspace key is pressed");
synthesizeKey("KEY_Delete");
is(editor0.innerHTML, "",
"an empty editor should keep being empty even if Delete key is pressed");
SimpleTest.finish();
}
SimpleTest.waitForFocus(runTests);
</script>
</pre>
</body>
</html>
|