Bug 1613552 [wpt PR 21618] - Fix timeout vs. task-queue race conditions in promise...
[gecko.git] / widget / tests / window_bug478536.xhtml
blob53be97754d05722b4cd40c2d2aeae84f04afa3b8
1 <?xml version="1.0"?>
2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
3 <window title="Mozilla Bug 478536"
4 width="600" height="600"
5 onload="onload();"
6 onunload="onunload();"
7 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
9 <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" />
10 <script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js" />
11 <script src="chrome://mochikit/content/tests/SimpleTest/paint_listener.js" />
13 <body xmlns="http://www.w3.org/1999/xhtml" id="body">
14 <style type="text/css">
15 #view {
16 overflow: auto;
17 width: 100px;
18 height: 100px;
19 border: 1px solid;
20 margin: 0;
22 </style>
23 <pre id="view" onscroll="onScrollView(event);">
24 Text. Text. Text. Text. Text. Text. Text. Text. Text. Text. Text.
25 Text. Text. Text. Text. Text. Text. Text. Text. Text. Text. Text.
26 Text. Text. Text. Text. Text. Text. Text. Text. Text. Text. Text.
27 Text. Text. Text. Text. Text. Text. Text. Text. Text. Text. Text.
28 Text. Text. Text. Text. Text. Text. Text. Text. Text. Text. Text.
29 Text. Text. Text. Text. Text. Text. Text. Text. Text. Text. Text.
30 Text. Text. Text. Text. Text. Text. Text. Text. Text. Text. Text.
31 Text. Text. Text. Text. Text. Text. Text. Text. Text. Text. Text.
32 Text. Text. Text. Text. Text. Text. Text. Text. Text. Text. Text.
33 Text. Text. Text. Text. Text. Text. Text. Text. Text. Text. Text.
34 </pre>
35 </body>
37 <script class="testbody" type="application/javascript">
38 <![CDATA[
40 function ok(aCondition, aMessage)
42 window.arguments[0].SimpleTest.ok(aCondition, aMessage);
45 function is(aLeft, aRight, aMessage)
47 window.arguments[0].SimpleTest.is(aLeft, aRight, aMessage);
50 function isnot(aLeft, aRight, aMessage)
52 window.arguments[0].SimpleTest.isnot(aLeft, aRight, aMessage);
55 var gBody = document.getElementById("body");
56 var gView = document.getElementById("view");
58 /**
59 * Description:
61 * First, lock the wheel scrolling target to "view" at first step.
62 * Next, scroll back to top most of the "view" at second step.
63 * Finally, scroll back again at third step. This fails to scroll the "view",
64 * then, |onMouseScrollFailed| event should be fired. And at that time, we
65 * can remove the "view". So, in post processing of the event firere, the
66 * "view" should not be referred.
68 * For suppressing random test failure, all tests will be retried if we handle
69 * unexpected timeout event.
72 var gTests = [
73 { scrollToForward: true, shouldScroll: true },
74 { scrollToForward: false, shouldScroll: true },
75 { scrollToForward: false, shouldScroll: false }
77 var gCurrentTestIndex = -1;
78 var gIgnoreScrollEvent = true;
80 var gPrefSvc = Cc["@mozilla.org/preferences-service;1"].
81 getService(Ci.nsIPrefBranch);
82 const kPrefSmoothScroll = "general.smoothScroll";
83 const kPrefNameTimeout = "mousewheel.transaction.timeout";
84 const kDefaultTimeout = gPrefSvc.getIntPref(kPrefNameTimeout);
86 gPrefSvc.setBoolPref(kPrefSmoothScroll, false);
88 var gTimeout = kDefaultTimeout;
90 gBody.addEventListener("MozMouseScrollFailed", onMouseScrollFailed, false);
91 gBody.addEventListener("MozMouseScrollTransactionTimeout",
92 onTransactionTimeout, false);
94 function setTimeoutPrefs(aTimeout)
96 gPrefSvc.setIntPref(kPrefNameTimeout, aTimeout);
97 gTimeout = aTimeout;
100 function resetTimeoutPrefs()
102 if (gTimeout == kDefaultTimeout)
103 return;
104 setTimeoutPrefs(kDefaultTimeout);
107 function growUpTimeoutPrefs()
109 if (gTimeout != kDefaultTimeout)
110 return;
111 setTimeoutPrefs(5000);
114 function onload()
116 disableNonTestMouseEvents(true);
117 setTimeout(runNextTest, 0);
120 function onunload()
122 resetTimeoutPrefs();
123 disableNonTestMouseEvents(false);
124 gPrefSvc.clearUserPref(kPrefSmoothScroll);
125 SpecialPowers.DOMWindowUtils.restoreNormalRefresh();
126 window.arguments[0].SimpleTest.finish();
129 function finish()
131 window.close();
134 // testing code
136 var gTimer;
137 function clearTimer()
139 clearTimeout(gTimer);
140 gTimer = 0;
143 function runNextTest()
145 clearTimer();
146 if (++gCurrentTestIndex >= gTests.length) {
147 ok(true, "didn't crash, succeeded");
148 finish();
149 return;
151 fireWheelScrollEvent(gTests[gCurrentTestIndex].scrollToForward);
154 var gRetryCount = 5;
155 function retryAllTests()
157 clearTimer();
158 if (--gRetryCount >= 0) {
159 gView.scrollTop = 0;
160 gView.scrollLeft = 0;
161 gCurrentTestIndex = -1;
162 growUpTimeoutPrefs();
163 ok(true, "WARNING: retry current test-list...");
164 gTimer = setTimeout(runNextTest, 0);
165 } else {
166 ok(false, "Failed by unexpected timeout");
167 finish();
171 function fireWheelScrollEvent(aForward)
173 gIgnoreScrollEvent = false;
174 var event = { deltaY: aForward ? 4.0 : -4.0,
175 deltaMode: WheelEvent.DOM_DELTA_LINE };
176 sendWheelAndPaint(gView, 5, 5, event, function() {
177 // No callback - we're just forcing the refresh driver to tick.
178 }, window);
181 function onScrollView(aEvent)
183 if (gIgnoreScrollEvent)
184 return;
185 gIgnoreScrollEvent = true;
186 clearTimer();
187 ok(gTests[gCurrentTestIndex].shouldScroll, "The view is scrolled");
188 gTimer = setTimeout(runNextTest, 0);
191 function onMouseScrollFailed(aEvent)
193 clearTimer();
194 gIgnoreScrollEvent = true;
195 ok(!gTests[gCurrentTestIndex].shouldScroll, "The view is not scrolled");
196 if (!gTests[gCurrentTestIndex].shouldScroll)
197 gBody.removeChild(gView);
198 runNextTest();
201 function onTransactionTimeout(aEvent)
203 if (!gTimer)
204 return;
205 gIgnoreScrollEvent = true;
206 retryAllTests();
210 </script>
212 </window>