Bug 1772588 [wpt PR 34302] - [wpt] Add test for block-in-inline offsetParent., a...
[gecko.git] / editor / libeditor / tests / test_bug795785.html
blob485a6a20f6b76b71ff6a521a8c1cb8c5de5d8cd8
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 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
11 </head>
12 <body>
13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=795785">Mozilla Bug 795785</a>
14 <div id="display">
15 <textarea id="textarea" style="overflow: hidden; height: 3em; width: 5em; word-wrap: normal;"></textarea>
16 <div id="div" contenteditable style="overflow: hidden; height: 3em; width: 5em;"></div>
17 </div>
18 <div id="content" style="display: none">
20 </div>
21 <pre id="test">
22 </pre>
24 <script class="testbody" type="application/javascript">
27 SimpleTest.waitForExplicitFinish();
28 SimpleTest.requestFlakyTimeout("This test uses setTimeouts in order to fix an intermittent failure.");
30 // Turn off spatial navigation because it hijacks arrow key events and VK_RETURN
31 // events.
32 SimpleTest.waitForFocus(function() {
33 SpecialPowers.pushPrefEnv({"set": [["snav.enabled", false]]}, runTests);
34 });
35 var textarea = document.getElementById("textarea");
36 var div = document.getElementById("div");
38 function hitEventLoop(aFunc, aTimes) {
39 if (--aTimes) {
40 setTimeout(hitEventLoop, 0, aFunc, aTimes);
41 } else {
42 setTimeout(aFunc, 100);
46 function doKeyEventTest(aElement, aElementDescription, aCallback) {
47 aElement.focus();
48 aElement.scrollTop = 0;
49 hitEventLoop(function() {
50 is(aElement.scrollTop, 0,
51 aElementDescription + "'s scrollTop isn't 0");
52 synthesizeKey("KEY_Enter", {shiftKey: true, repeat: 6});
53 hitEventLoop(function() {
54 isnot(aElement.scrollTop, 0,
55 aElementDescription + " was not scrolled by inserting line breaks");
56 var scrollTop = aElement.scrollTop;
57 synthesizeKey("KEY_ArrowUp", {repeat: 5});
58 hitEventLoop(function() {
59 isnot(aElement.scrollTop, scrollTop,
60 aElementDescription + " was not scrolled by up key events");
61 synthesizeKey("KEY_ArrowDown", {repeat: 5});
62 hitEventLoop(function() {
63 is(aElement.scrollTop, scrollTop,
64 aElementDescription + " was not scrolled by down key events");
65 var longWord = "aaaaaaaaaaaaaaaaaaaa";
66 sendString(longWord);
67 hitEventLoop(function() {
68 isnot(aElement.scrollLeft, 0,
69 aElementDescription + " was not scrolled by typing long word");
70 var scrollLeft = aElement.scrollLeft;
71 synthesizeKey("KEY_ArrowLeft", {repeat: longWord.length});
72 hitEventLoop(function() {
73 isnot(aElement.scrollLeft, scrollLeft,
74 aElementDescription + " was not scrolled by left key events");
75 synthesizeKey("KEY_ArrowRight", {repeat: longWord.length});
76 hitEventLoop(function() {
77 is(aElement.scrollLeft, scrollLeft,
78 aElementDescription + " was not scrolled by right key events");
79 aCallback();
80 }, 20);
81 }, 20);
82 }, 20);
83 }, 20);
84 }, 20);
85 }, 20);
86 }, 20);
89 function doCompositionTest(aElement, aElementDescription, aCallback) {
90 aElement.focus();
91 aElement.scrollTop = 0;
92 hitEventLoop(function() {
93 is(aElement.scrollTop, 0,
94 aElementDescription + "'s scrollTop isn't 0");
95 var str = "Web \u958b\u767a\u8005\u306e\u7686\u3055\u3093\u306f\u3001" +
96 "Firefox \u306b\u5b9f\u88c5\u3055\u308c\u3066\u3044\u308b HTML5" +
97 " \u3084 CSS \u306e\u65b0\u6a5f\u80fd\u3092\u6d3b\u7528\u3059" +
98 "\u308b\u3053\u3068\u3067\u3001\u9b45\u529b\u3042\u308b Web " +
99 "\u30b5\u30a4\u30c8\u3084\u9769\u65b0\u7684\u306a Web \u30a2" +
100 "\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u3088\u308a" +
101 "\u77ed\u6642\u9593\u3067\u7c21\u5358\u306b\u4f5c\u6210\u3067" +
102 "\u304d\u307e\u3059\u3002";
103 synthesizeCompositionChange({
104 composition: {
105 string: str,
106 clauses: [
107 { length: str.length, attr: COMPOSITION_ATTR_RAW_CLAUSE },
110 caret: { start: str.length, length: 0 },
112 hitEventLoop(function() {
113 isnot(aElement.scrollTop, 0,
114 aElementDescription + " was not scrolled by composition");
115 synthesizeComposition({ type: "compositioncommit", data: "" });
116 hitEventLoop(function() {
117 is(aElement.scrollTop, 0,
118 aElementDescription + " was not scrolled back to the top by canceling composition");
119 aCallback();
120 }, 20);
121 }, 20);
122 }, 20);
125 function runTests() {
126 doKeyEventTest(textarea, "textarea",
127 function() {
128 textarea.value = "";
129 doKeyEventTest(div, "div (contenteditable)",
130 function() {
131 div.innerHTML = "";
132 doCompositionTest(textarea, "textarea",
133 function() {
134 doCompositionTest(div, "div (contenteditable)",
135 function() {
136 SimpleTest.finish();
143 </script>
144 </body>
146 </html>