Bug 1776444 [wpt PR 34582] - Revert "Add TimedHTMLParserBudget to fieldtrial_testing_...
[gecko.git] / widget / tests / window_bug478536.xhtml
blob7318eb0bff2a845de6eb515ad2271289f5b6994c
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 = SpecialPowers.Services.prefs;
81 const kPrefSmoothScroll = "general.smoothScroll";
82 const kPrefNameTimeout = "mousewheel.transaction.timeout";
83 const kDefaultTimeout = gPrefSvc.getIntPref(kPrefNameTimeout);
85 gPrefSvc.setBoolPref(kPrefSmoothScroll, false);
87 var gTimeout = kDefaultTimeout;
89 gBody.addEventListener("MozMouseScrollFailed", onMouseScrollFailed);
90 gBody.addEventListener("MozMouseScrollTransactionTimeout",
91 onTransactionTimeout);
93 function setTimeoutPrefs(aTimeout)
95 gPrefSvc.setIntPref(kPrefNameTimeout, aTimeout);
96 gTimeout = aTimeout;
99 function resetTimeoutPrefs()
101 if (gTimeout == kDefaultTimeout)
102 return;
103 setTimeoutPrefs(kDefaultTimeout);
106 function growUpTimeoutPrefs()
108 if (gTimeout != kDefaultTimeout)
109 return;
110 setTimeoutPrefs(5000);
113 function onload()
115 disableNonTestMouseEvents(true);
116 setTimeout(runNextTest, 0);
119 function onunload()
121 resetTimeoutPrefs();
122 disableNonTestMouseEvents(false);
123 gPrefSvc.clearUserPref(kPrefSmoothScroll);
124 SpecialPowers.DOMWindowUtils.restoreNormalRefresh();
125 window.arguments[0].SimpleTest.finish();
128 function finish()
130 window.close();
133 // testing code
135 var gTimer;
136 function clearTimer()
138 clearTimeout(gTimer);
139 gTimer = 0;
142 function runNextTest()
144 clearTimer();
145 if (++gCurrentTestIndex >= gTests.length) {
146 ok(true, "didn't crash, succeeded");
147 finish();
148 return;
150 fireWheelScrollEvent(gTests[gCurrentTestIndex].scrollToForward);
153 var gRetryCount = 5;
154 function retryAllTests()
156 clearTimer();
157 if (--gRetryCount >= 0) {
158 gView.scrollTop = 0;
159 gView.scrollLeft = 0;
160 gCurrentTestIndex = -1;
161 growUpTimeoutPrefs();
162 ok(true, "WARNING: retry current test-list...");
163 gTimer = setTimeout(runNextTest, 0);
164 } else {
165 ok(false, "Failed by unexpected timeout");
166 finish();
170 function fireWheelScrollEvent(aForward)
172 gIgnoreScrollEvent = false;
173 var event = { deltaY: aForward ? 4.0 : -4.0,
174 deltaMode: WheelEvent.DOM_DELTA_LINE };
175 sendWheelAndPaint(gView, 5, 5, event, function() {
176 // No callback - we're just forcing the refresh driver to tick.
177 }, window);
180 function onScrollView(aEvent)
182 if (gIgnoreScrollEvent)
183 return;
184 gIgnoreScrollEvent = true;
185 clearTimer();
186 ok(gTests[gCurrentTestIndex].shouldScroll, "The view is scrolled");
187 gTimer = setTimeout(runNextTest, 0);
190 function onMouseScrollFailed(aEvent)
192 clearTimer();
193 gIgnoreScrollEvent = true;
194 ok(!gTests[gCurrentTestIndex].shouldScroll, "The view is not scrolled");
195 if (!gTests[gCurrentTestIndex].shouldScroll)
196 gBody.removeChild(gView);
197 runNextTest();
200 function onTransactionTimeout(aEvent)
202 if (!gTimer)
203 return;
204 gIgnoreScrollEvent = true;
205 retryAllTests();
209 </script>
211 </window>