summaryrefslogtreecommitdiffstats
path: root/editor/libeditor/tests/test_bug1257363.html
blob: c0596334833a729420bab4a46ac421d81edd7b8d (plain)
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<!DOCTYPE>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1257363
-->
<head>
  <title>Test for Bug 1257363</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" href="/tests/SimpleTest/test.css">
  <script src="/tests/SimpleTest/EventUtils.js"></script>
</head>
<body>
<div id="display">
</div>

<div id="backspaceCSS" contenteditable><p style="color:red;">12345</p>67</div>
<div id="backspace" contenteditable><p><font color="red">12345</font></p>67</div>
<div id="deleteCSS" contenteditable><p style="color:red;">x</p></div>
<div id="delete" contenteditable><p><font color="red">y</font></p></div>

<pre id="test">
</pre>

<script class="testbody" type="application/javascript">

/** Test for Bug 1257363 **/
SimpleTest.waitForExplicitFinish();
SimpleTest.waitForFocus(function() {
  // ***** Backspace test *****
  var div = document.getElementById("backspaceCSS");
  div.focus();
  synthesizeMouse(div, 100, 2, {}); /* click behind and down */

  var sel = window.getSelection();
  var selRange = sel.getRangeAt(0);
  is(selRange.endContainer.nodeName, "#text", "selection should be at the end of text node");
  is(selRange.endOffset, 5, "offset should be 5");

  // Return and backspace should take us to where we started.
  synthesizeKey("KEY_Enter");
  synthesizeKey("KEY_Backspace");

  selRange = sel.getRangeAt(0);
  is(selRange.endContainer.nodeName, "#text", "selection should be at the end of text node");
  is(selRange.endOffset, 5, "offset should be 5");

  // Add an "a" to the end of the paragraph.
  sendString("a");

  // Return and forward delete should take us to the following line.
  synthesizeKey("KEY_Enter");
  synthesizeKey("KEY_Delete");

  // Add a "b" to the start.
  sendString("b");

  is(div.innerHTML, "<p style=\"color:red;\">12345a</p>b67",
                    "unexpected HTML");

  // Let's repeat the whole thing, but a font tag instead of CSS.
  // The behaviour is different since the font is carried over.
  div = document.getElementById("backspace");
  div.focus();
  synthesizeMouse(div, 100, 2, {}); /* click behind and down */

  sel = window.getSelection();
  selRange = sel.getRangeAt(0);
  is(selRange.endContainer.nodeName, "#text", "selection should be at the end of text node");
  is(selRange.endOffset, 5, "offset should be 5");

  // Return and backspace should take us to where we started.
  synthesizeKey("KEY_Enter");
  synthesizeKey("KEY_Backspace");

  selRange = sel.getRangeAt(0);
  is(selRange.endContainer.nodeName, "#text", "selection should be at the end of text node");
  is(selRange.endOffset, 5, "offset should be 5");

  // Add an "a" to the end of the paragraph.
  sendString("a");

  // Return and forward delete should take us to the following line.
  synthesizeKey("KEY_Enter");
  synthesizeKey("KEY_Delete");

  // Add a "b" to the start.
  sendString("b");

  // Here we get a somewhat ugly result since the red sticks.
  is(div.innerHTML, "<p><font color=\"red\">12345a</font></p><font color=\"#ff0000\">b</font>67",
                    "unexpected HTML");

  // ***** Delete test *****
  div = document.getElementById("deleteCSS");
  div.focus();
  synthesizeMouse(div, 100, 2, {}); /* click behind and down */

  sel = window.getSelection();
  selRange = sel.getRangeAt(0);
  is(selRange.endContainer.nodeName, "#text", "selection should be at the end of text node");
  is(selRange.endOffset, 1, "offset should be 1");

  // left, enter should create a new empty paragraph before
  // but leave the selection at the start of the existing paragraph.
  synthesizeKey("KEY_ArrowLeft");
  synthesizeKey("KEY_Enter");

  selRange = sel.getRangeAt(0);
  is(selRange.endContainer.nodeName, "#text", "selection should be at the start of text node");
  is(selRange.endOffset, 0, "offset should be 0");
  is(selRange.endContainer.nodeValue, "x", "we should be in the text node with the x");

  // Now moving up into the new empty paragraph.
  synthesizeKey("KEY_ArrowUp");

  selRange = sel.getRangeAt(0);
  is(selRange.endContainer.nodeName, "P", "selection should be the new empty paragraph");
  is(selRange.endOffset, 0, "offset should be 0");

  // Forward delete should now take us to where we started.
  synthesizeKey("KEY_Delete");

  selRange = sel.getRangeAt(0);
  is(selRange.endContainer.nodeName, "#text", "selection should be at the start of text node");
  is(selRange.endOffset, 0, "offset should be 0");

  // Add an "a" to the start of the paragraph.
  sendString("a");

  is(div.innerHTML, "<p style=\"color:red;\">ax</p>",
                    "unexpected HTML");

  // Let's repeat the whole thing, but a font tag instead of CSS.
  div = document.getElementById("delete");
  div.focus();
  synthesizeMouse(div, 100, 2, {}); /* click behind and down */

  sel = window.getSelection();
  selRange = sel.getRangeAt(0);
  is(selRange.endContainer.nodeName, "#text", "selection should be at the end of text node");
  is(selRange.endOffset, 1, "offset should be 1");

  // left, enter should create a new empty paragraph before
  // but leave the selection at the start of the existing paragraph.
  synthesizeKey("KEY_ArrowLeft");
  synthesizeKey("KEY_Enter");

  selRange = sel.getRangeAt(0);
  is(selRange.endContainer.nodeName, "#text", "selection should be at the start of text node");
  is(selRange.endOffset, 0, "offset should be 0");
  is(selRange.endContainer.nodeValue, "y", "we should be in the text node with the y");

  // Now moving up into the new empty paragraph.
  synthesizeKey("KEY_ArrowUp");

  selRange = sel.getRangeAt(0);
  is(selRange.endContainer.nodeName, "FONT", "selection should be the font tag");
  is(selRange.endOffset, 0, "offset should be 0");
  is(selRange.endContainer.parentNode.nodeName, "P", "the parent of the font should be a paragraph");

  // Forward delete should now take us to where we started.
  synthesizeKey("KEY_Delete");

  selRange = sel.getRangeAt(0);
  is(selRange.endContainer.nodeName, "#text", "selection should be at the start of text node");
  is(selRange.endOffset, 0, "offset should be 0");

  // Add an "a" to the start of the paragraph.
  sendString("a");

  is(div.innerHTML, "<p><font color=\"red\">ay</font></p>",
                    "unexpected HTML");

  SimpleTest.finish();
});

</script>
</body>

</html>