3 https://bugzilla.mozilla.org/show_bug.cgi?id=795785
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" />
14 <a target=
"_blank" href=
"https://bugzilla.mozilla.org/show_bug.cgi?id=795785">Mozilla Bug
795785</a>
16 <textarea style=
"overflow: hidden; height: 3em; width: 5em; word-wrap: normal;"></textarea>
17 <div contenteditable
style=
"overflow: hidden; height: 3em; width: 5em;"></div>
19 <div id=
"content" style=
"display: none">
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
) {
42 await
new Promise(resolve
=> SimpleTest
.executeSoon(resolve
));
46 async
function doKeyEventTest(aSelector
) {
47 const element
= document
.querySelector(aSelector
);
48 if (element
.value
!== undefined) {
51 element
.innerHTML
= "";
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) {
85 element
.innerHTML
= "";
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(
103 string
: longCompositionString
,
106 length
: longCompositionString
.length
,
107 attr
: COMPOSITION_ATTR_RAW_CLAUSE
,
112 start
: longCompositionString
.length
,
117 await
waitForScroll();
118 isnot(element
.scrollTop
, 0, `${aSelector} should be scrolled by composition`);
119 synthesizeComposition({ type
: "compositioncommit", data
: "" });
120 await
waitForScroll();
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]");