Bug 1874684 - Part 17: Fix uninitialised variable warnings from clang-tidy. r=allstarschh
[gecko.git] / editor / libeditor / tests / test_bug795785.html
blob3e56207b637b053e9938349c79f4b281e6da3fbf
1 <html>
2 <!--
3 https://bugzilla.mozilla.org/show_bug.cgi?id=795785
4 -->
5 <head>
6 <title>Test for Bug 795785</title>
7 <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
8 <script src="/tests/SimpleTest/SimpleTest.js"></script>
9 <script src="/tests/SimpleTest/EventUtils.js"></script>
10 <script src="/tests/gfx/layers/apz/test/mochitest/apz_test_utils.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=795785">Mozilla Bug 795785</a>
15 <div id="display">
16 <textarea style="overflow: hidden; height: 3em; width: 5em; word-wrap: normal;"></textarea>
17 <div contenteditable style="overflow: hidden; height: 3em; width: 5em;"></div>
18 </div>
19 <div id="content" style="display: none">
21 </div>
22 <pre id="test">
23 </pre>
25 <script>
26 "use strict";
28 function waitForScroll() {
29 return waitToClearOutAnyPotentialScrolls(window);
32 async function synthesizeKeyInEachEventLoop(aKey, aEvent, aCount) {
33 for (let i = 0; i < aCount; i++) {
34 synthesizeKey(aKey, aEvent);
35 await new Promise(resolve => SimpleTest.executeSoon(resolve));
39 async function sendStringOneByOne(aString) {
40 for (const ch of aString) {
41 sendString(ch);
42 await new Promise(resolve => SimpleTest.executeSoon(resolve));
46 async function doKeyEventTest(aSelector) {
47 const element = document.querySelector(aSelector);
48 if (element.value !== undefined) {
49 element.value = "";
50 } else {
51 element.innerHTML = "";
53 element.focus();
54 element.scrollTop = 0;
55 await waitForScroll();
56 is(element.scrollTop, 0, `${aSelector}.scrollTop should be 0`);
57 await synthesizeKeyInEachEventLoop("KEY_Enter", {shiftKey: true}, 6);
58 await waitForScroll();
59 isnot(element.scrollTop, 0, `${aSelector} should be scrolled by inserting line breaks`);
60 const oldScrollTop = element.scrollTop;
61 await synthesizeKeyInEachEventLoop("KEY_ArrowUp", {}, 5);
62 await waitForScroll();
63 isnot(element.scrollTop, oldScrollTop, `${aSelector} should be scrolled by up key events`);
64 await synthesizeKeyInEachEventLoop("KEY_ArrowDown", {}, 5);
65 await waitForScroll();
66 is(element.scrollTop, oldScrollTop, `${aSelector} should be scrolled by down key events`);
67 const longWord = "aaaaaaaaaaaaaaaaaaaa";
68 await sendStringOneByOne(longWord);
69 await waitForScroll();
70 isnot(element.scrollLeft, 0, `${aSelector} should be scrolled by typing long word`);
71 const oldScrollLeft = element.scrollLeft;
72 await synthesizeKeyInEachEventLoop("KEY_ArrowLeft", {}, longWord.length);
73 await waitForScroll();
74 isnot(element.scrollLeft, oldScrollLeft, `${aSelector} should be scrolled by left key events`);
75 await synthesizeKeyInEachEventLoop("KEY_ArrowRight", {}, longWord.length);
76 await waitForScroll();
77 is(element.scrollLeft, oldScrollLeft, `${aSelector} should be scrolled by right key events`);
80 async function doCompositionTest(aSelector) {
81 const element = document.querySelector(aSelector);
82 if (element.value !== undefined) {
83 element.value = "";
84 } else {
85 element.innerHTML = "";
87 element.focus();
88 element.scrollTop = 0;
89 await waitForScroll();
90 is(element.scrollTop, 0, `${aSelector}.scrollTop should be 0`);
91 const longCompositionString =
92 "Web \u958b\u767a\u8005\u306e\u7686\u3055\u3093\u306f\u3001" +
93 "Firefox \u306b\u5b9f\u88c5\u3055\u308c\u3066\u3044\u308b HTML5" +
94 " \u3084 CSS \u306e\u65b0\u6a5f\u80fd\u3092\u6d3b\u7528\u3059" +
95 "\u308b\u3053\u3068\u3067\u3001\u9b45\u529b\u3042\u308b Web " +
96 "\u30b5\u30a4\u30c8\u3084\u9769\u65b0\u7684\u306a Web \u30a2" +
97 "\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u3088\u308a" +
98 "\u77ed\u6642\u9593\u3067\u7c21\u5358\u306b\u4f5c\u6210\u3067" +
99 "\u304d\u307e\u3059\u3002";
100 synthesizeCompositionChange(
102 composition: {
103 string: longCompositionString,
104 clauses: [
106 length: longCompositionString.length,
107 attr: COMPOSITION_ATTR_RAW_CLAUSE,
111 caret: {
112 start: longCompositionString.length,
113 length: 0,
117 await waitForScroll();
118 isnot(element.scrollTop, 0, `${aSelector} should be scrolled by composition`);
119 synthesizeComposition({ type: "compositioncommit", data: "" });
120 await waitForScroll();
122 element.scrollTop,
124 `${aSelector} should be scrolled back to the top by canceling composition`
128 SimpleTest.waitForExplicitFinish();
129 SimpleTest.waitForFocus(async () => {
130 await doKeyEventTest("textarea");
131 await doKeyEventTest("div[contenteditable]");
132 await doCompositionTest("textarea");
133 await doCompositionTest("div[contenteditable]");
134 SimpleTest.finish();
136 </script>
137 </body>
139 </html>