widget/tests/window_bug478536.xul

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/widget/tests/window_bug478536.xul	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,208 @@
     1.4 +<?xml version="1.0"?>
     1.5 +<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
     1.6 +<window title="Mozilla Bug 478536"
     1.7 +  width="600" height="600"
     1.8 +  onload="onload();"
     1.9 +  onunload="onunload();"
    1.10 +  xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
    1.11 +
    1.12 +  <script type="application/javascript"
    1.13 +          src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js" />
    1.14 +
    1.15 +<body xmlns="http://www.w3.org/1999/xhtml" id="body">
    1.16 +<style type="text/css">
    1.17 +  #view {
    1.18 +    overflow: auto;
    1.19 +    width: 100px;
    1.20 +    height: 100px;
    1.21 +    border: 1px solid;
    1.22 +    margin: 0;
    1.23 +  }
    1.24 +</style>
    1.25 +<pre id="view" onscroll="onScrollView(event);">
    1.26 +Text. Text. Text. Text. Text. Text. Text. Text. Text. Text. Text.
    1.27 +Text. Text. Text. Text. Text. Text. Text. Text. Text. Text. Text.
    1.28 +Text. Text. Text. Text. Text. Text. Text. Text. Text. Text. Text.
    1.29 +Text. Text. Text. Text. Text. Text. Text. Text. Text. Text. Text.
    1.30 +Text. Text. Text. Text. Text. Text. Text. Text. Text. Text. Text.
    1.31 +Text. Text. Text. Text. Text. Text. Text. Text. Text. Text. Text.
    1.32 +Text. Text. Text. Text. Text. Text. Text. Text. Text. Text. Text.
    1.33 +Text. Text. Text. Text. Text. Text. Text. Text. Text. Text. Text.
    1.34 +Text. Text. Text. Text. Text. Text. Text. Text. Text. Text. Text.
    1.35 +Text. Text. Text. Text. Text. Text. Text. Text. Text. Text. Text.
    1.36 +</pre>
    1.37 +</body>
    1.38 +
    1.39 +<script class="testbody" type="application/javascript">
    1.40 +<![CDATA[
    1.41 +
    1.42 +function ok(aCondition, aMessage)
    1.43 +{
    1.44 +  window.opener.wrappedJSObject.SimpleTest.ok(aCondition, aMessage);
    1.45 +}
    1.46 +
    1.47 +function is(aLeft, aRight, aMessage)
    1.48 +{
    1.49 +  window.opener.wrappedJSObject.SimpleTest.is(aLeft, aRight, aMessage);
    1.50 +}
    1.51 +
    1.52 +function isnot(aLeft, aRight, aMessage)
    1.53 +{
    1.54 +  window.opener.wrappedJSObject.SimpleTest.isnot(aLeft, aRight, aMessage);
    1.55 +}
    1.56 +
    1.57 +var gBody = document.getElementById("body");
    1.58 +var gView = document.getElementById("view");
    1.59 +
    1.60 +/**
    1.61 + * Description:
    1.62 + *
    1.63 + *   First, lock the wheel scrolling target to "view" at first step.
    1.64 + *   Next, scroll back to top most of the "view" at second step.
    1.65 + *   Finally, scroll back again at third step.  This fails to scroll the "view",
    1.66 + *   then, |onMouseScrollFailed| event should be fired.  And at that time, we
    1.67 + *   can remove the "view".  So, in post processing of the event firere, the
    1.68 + *   "view" should not be referred.
    1.69 + *
    1.70 + *   For suppressing random test failure, all tests will be retried if we handle
    1.71 + *   unexpected timeout event.
    1.72 + */
    1.73 +
    1.74 +var gTests = [
    1.75 + { scrollToForward: true,  shouldScroll: true },
    1.76 + { scrollToForward: false, shouldScroll: true },
    1.77 + { scrollToForward: false, shouldScroll: false }
    1.78 +];
    1.79 +var gCurrentTestIndex = -1;
    1.80 +var gIgnoreScrollEvent = true;
    1.81 +
    1.82 +var gPrefSvc = Components.classes["@mozilla.org/preferences-service;1"].
    1.83 +               getService(Components.interfaces.nsIPrefBranch);
    1.84 +const kPrefSmoothScroll = "general.smoothScroll";
    1.85 +const kPrefNameTimeout = "mousewheel.transaction.timeout";
    1.86 +const kDefaultTimeout = gPrefSvc.getIntPref(kPrefNameTimeout);
    1.87 +
    1.88 +gPrefSvc.setBoolPref(kPrefSmoothScroll, false);
    1.89 +
    1.90 +var gTimeout = kDefaultTimeout;
    1.91 +
    1.92 +gBody.addEventListener("MozMouseScrollFailed", onMouseScrollFailed, false);
    1.93 +gBody.addEventListener("MozMouseScrollTransactionTimeout",
    1.94 +                       onTransactionTimeout, false);
    1.95 +
    1.96 +function setTimeoutPrefs(aTimeout)
    1.97 +{
    1.98 +  gPrefSvc.setIntPref(kPrefNameTimeout, aTimeout);
    1.99 +  gTimeout = aTimeout;
   1.100 +}
   1.101 +
   1.102 +function resetTimeoutPrefs()
   1.103 +{
   1.104 +  if (gTimeout == kDefaultTimeout)
   1.105 +    return;
   1.106 +  setTimeoutPrefs(kDefaultTimeout);
   1.107 +}
   1.108 +
   1.109 +function growUpTimeoutPrefs()
   1.110 +{
   1.111 +  if (gTimeout != kDefaultTimeout)
   1.112 +    return;
   1.113 +  setTimeoutPrefs(5000);
   1.114 +}
   1.115 +
   1.116 +function onload()
   1.117 +{
   1.118 +  disableNonTestMouseEvents(true);
   1.119 +  setTimeout(runNextTest, 0);
   1.120 +}
   1.121 +
   1.122 +function onunload()
   1.123 +{
   1.124 +  resetTimeoutPrefs();
   1.125 +  disableNonTestMouseEvents(false);
   1.126 +  gPrefSvc.clearUserPref(kPrefSmoothScroll);
   1.127 +  window.opener.wrappedJSObject.SimpleTest.finish();
   1.128 +}
   1.129 +
   1.130 +function finish()
   1.131 +{
   1.132 +  window.close();
   1.133 +}
   1.134 +
   1.135 +// testing code
   1.136 +
   1.137 +var gTimer;
   1.138 +function clearTimer()
   1.139 +{
   1.140 +  clearTimeout(gTimer);
   1.141 +  gTimer = 0;
   1.142 +}
   1.143 +
   1.144 +function runNextTest()
   1.145 +{
   1.146 +  clearTimer();
   1.147 +  if (++gCurrentTestIndex >= gTests.length) {
   1.148 +    ok(true, "didn't crash, succeeded");
   1.149 +    finish();
   1.150 +    return;
   1.151 +  }
   1.152 +  fireWheelScrollEvent(gTests[gCurrentTestIndex].scrollToForward);
   1.153 +}
   1.154 +
   1.155 +var gRetryCount = 5;
   1.156 +function retryAllTests()
   1.157 +{
   1.158 +  clearTimer();
   1.159 +  if (--gRetryCount >= 0) {
   1.160 +    gView.scrollTop = 0;
   1.161 +    gView.scrollLeft = 0;
   1.162 +    gCurrentTestIndex = -1;
   1.163 +    growUpTimeoutPrefs();
   1.164 +    ok(true, "WARNING: retry current test-list...");
   1.165 +    gTimer = setTimeout(runNextTest, 0);
   1.166 +  } else {
   1.167 +    ok(false, "Failed by unexpected timeout");
   1.168 +    finish();
   1.169 +  }
   1.170 +}
   1.171 +
   1.172 +function fireWheelScrollEvent(aForward)
   1.173 +{
   1.174 +  gIgnoreScrollEvent = false;
   1.175 +  var event = { deltaY: aForward ? 4.0 : -4.0,
   1.176 +                deltaMode: WheelEvent.DOM_DELTA_LINE };
   1.177 +  synthesizeWheel(gView, 5, 5, event, window);
   1.178 +}
   1.179 +
   1.180 +function onScrollView(aEvent)
   1.181 +{
   1.182 +  if (gIgnoreScrollEvent)
   1.183 +    return;
   1.184 +  gIgnoreScrollEvent = true;
   1.185 +  clearTimer();
   1.186 +  ok(gTests[gCurrentTestIndex].shouldScroll, "The view is scrolled");
   1.187 +  gTimer = setTimeout(runNextTest, 0);
   1.188 +}
   1.189 +
   1.190 +function onMouseScrollFailed(aEvent)
   1.191 +{
   1.192 +  clearTimer();
   1.193 +  gIgnoreScrollEvent = true;
   1.194 +  ok(!gTests[gCurrentTestIndex].shouldScroll, "The view is not scrolled");
   1.195 +  if (!gTests[gCurrentTestIndex].shouldScroll)
   1.196 +    gBody.removeChild(gView);
   1.197 +  runNextTest();
   1.198 +}
   1.199 +
   1.200 +function onTransactionTimeout(aEvent)
   1.201 +{
   1.202 +  if (!gTimer)
   1.203 +    return;
   1.204 +  gIgnoreScrollEvent = true;
   1.205 +  retryAllTests();
   1.206 +}
   1.207 +
   1.208 +]]>
   1.209 +</script>
   1.210 +
   1.211 +</window>

mercurial