summaryrefslogtreecommitdiffstats
path: root/editor/libeditor/tests/test_bug1094000.html
blob: cc27cc67533f4936a9369a3e1b551bf9399b21b6 (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
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1094000
-->
<head>
  <title>Test for Bug 1094000</title>
  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <script type="text/javascript" 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>
<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");

  ok(editor1.getBoundingClientRect().height - editor0.getBoundingClientRect().height > 1,
        "an editor having a <br> element and an empty editor shouldn't 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("VK_RIGHT", {});
  synthesizeKey("VK_BACK_SPACE", {});
  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("VK_LEFT", {});
  synthesizeKey("VK_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("VK_BACK_SPACE", {});
  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("VK_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");

  editor0.focus();
  synthesizeKey("VK_BACK_SPACE", {});
  is(editor0.innerHTML, "",
     "an empty editor should keep being empty even if Backspace key is pressed");
  synthesizeKey("VK_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>