summaryrefslogtreecommitdiffstats
path: root/widget/tests/window_bug478536.xhtml
blob: 7318eb0bff2a845de6eb515ad2271289f5b6994c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<window title="Mozilla Bug 478536"
  width="600" height="600"
  onload="onload();"
  onunload="onunload();"
  xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">

  <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" />
  <script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js" />
  <script src="chrome://mochikit/content/tests/SimpleTest/paint_listener.js" />

<body xmlns="http://www.w3.org/1999/xhtml" id="body">
<style type="text/css">
  #view {
    overflow: auto;
    width: 100px;
    height: 100px;
    border: 1px solid;
    margin: 0;
  }
</style>
<pre id="view" onscroll="onScrollView(event);">
Text. Text. Text. Text. Text. Text. Text. Text. Text. Text. Text.
Text. Text. Text. Text. Text. Text. Text. Text. Text. Text. Text.
Text. Text. Text. Text. Text. Text. Text. Text. Text. Text. Text.
Text. Text. Text. Text. Text. Text. Text. Text. Text. Text. Text.
Text. Text. Text. Text. Text. Text. Text. Text. Text. Text. Text.
Text. Text. Text. Text. Text. Text. Text. Text. Text. Text. Text.
Text. Text. Text. Text. Text. Text. Text. Text. Text. Text. Text.
Text. Text. Text. Text. Text. Text. Text. Text. Text. Text. Text.
Text. Text. Text. Text. Text. Text. Text. Text. Text. Text. Text.
Text. Text. Text. Text. Text. Text. Text. Text. Text. Text. Text.
</pre>
</body>

<script class="testbody" type="application/javascript">
<![CDATA[

function ok(aCondition, aMessage)
{
  window.arguments[0].SimpleTest.ok(aCondition, aMessage);
}

function is(aLeft, aRight, aMessage)
{
  window.arguments[0].SimpleTest.is(aLeft, aRight, aMessage);
}

function isnot(aLeft, aRight, aMessage)
{
  window.arguments[0].SimpleTest.isnot(aLeft, aRight, aMessage);
}

var gBody = document.getElementById("body");
var gView = document.getElementById("view");

/**
 * Description:
 *
 *   First, lock the wheel scrolling target to "view" at first step.
 *   Next, scroll back to top most of the "view" at second step.
 *   Finally, scroll back again at third step.  This fails to scroll the "view",
 *   then, |onMouseScrollFailed| event should be fired.  And at that time, we
 *   can remove the "view".  So, in post processing of the event firere, the
 *   "view" should not be referred.
 *
 *   For suppressing random test failure, all tests will be retried if we handle
 *   unexpected timeout event.
 */

var gTests = [
 { scrollToForward: true,  shouldScroll: true },
 { scrollToForward: false, shouldScroll: true },
 { scrollToForward: false, shouldScroll: false }
];
var gCurrentTestIndex = -1;
var gIgnoreScrollEvent = true;

var gPrefSvc = SpecialPowers.Services.prefs;
const kPrefSmoothScroll = "general.smoothScroll";
const kPrefNameTimeout = "mousewheel.transaction.timeout";
const kDefaultTimeout = gPrefSvc.getIntPref(kPrefNameTimeout);

gPrefSvc.setBoolPref(kPrefSmoothScroll, false);

var gTimeout = kDefaultTimeout;

gBody.addEventListener("MozMouseScrollFailed", onMouseScrollFailed);
gBody.addEventListener("MozMouseScrollTransactionTimeout",
                       onTransactionTimeout);

function setTimeoutPrefs(aTimeout)
{
  gPrefSvc.setIntPref(kPrefNameTimeout, aTimeout);
  gTimeout = aTimeout;
}

function resetTimeoutPrefs()
{
  if (gTimeout == kDefaultTimeout)
    return;
  setTimeoutPrefs(kDefaultTimeout);
}

function growUpTimeoutPrefs()
{
  if (gTimeout != kDefaultTimeout)
    return;
  setTimeoutPrefs(5000);
}

function onload()
{
  disableNonTestMouseEvents(true);
  setTimeout(runNextTest, 0);
}

function onunload()
{
  resetTimeoutPrefs();
  disableNonTestMouseEvents(false);
  gPrefSvc.clearUserPref(kPrefSmoothScroll);
  SpecialPowers.DOMWindowUtils.restoreNormalRefresh();
  window.arguments[0].SimpleTest.finish();
}

function finish()
{
  window.close();
}

// testing code

var gTimer;
function clearTimer()
{
  clearTimeout(gTimer);
  gTimer = 0;
}

function runNextTest()
{
  clearTimer();
  if (++gCurrentTestIndex >= gTests.length) {
    ok(true, "didn't crash, succeeded");
    finish();
    return;
  }
  fireWheelScrollEvent(gTests[gCurrentTestIndex].scrollToForward);
}

var gRetryCount = 5;
function retryAllTests()
{
  clearTimer();
  if (--gRetryCount >= 0) {
    gView.scrollTop = 0;
    gView.scrollLeft = 0;
    gCurrentTestIndex = -1;
    growUpTimeoutPrefs();
    ok(true, "WARNING: retry current test-list...");
    gTimer = setTimeout(runNextTest, 0);
  } else {
    ok(false, "Failed by unexpected timeout");
    finish();
  }
}

function fireWheelScrollEvent(aForward)
{
  gIgnoreScrollEvent = false;
  var event = { deltaY: aForward ? 4.0 : -4.0,
                deltaMode: WheelEvent.DOM_DELTA_LINE };
  sendWheelAndPaint(gView, 5, 5, event, function() {
    // No callback - we're just forcing the refresh driver to tick.
  }, window);
}

function onScrollView(aEvent)
{
  if (gIgnoreScrollEvent)
    return;
  gIgnoreScrollEvent = true;
  clearTimer();
  ok(gTests[gCurrentTestIndex].shouldScroll, "The view is scrolled");
  gTimer = setTimeout(runNextTest, 0);
}

function onMouseScrollFailed(aEvent)
{
  clearTimer();
  gIgnoreScrollEvent = true;
  ok(!gTests[gCurrentTestIndex].shouldScroll, "The view is not scrolled");
  if (!gTests[gCurrentTestIndex].shouldScroll)
    gBody.removeChild(gView);
  runNextTest();
}

function onTransactionTimeout(aEvent)
{
  if (!gTimer)
    return;
  gIgnoreScrollEvent = true;
  retryAllTests();
}

]]>
</script>

</window>