Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | <?xml version="1.0"?> |
michael@0 | 2 | <?xml-stylesheet href="chrome://global/skin" type="text/css"?> |
michael@0 | 3 | <window title="Mozilla Bug 478536" |
michael@0 | 4 | width="600" height="600" |
michael@0 | 5 | onload="onload();" |
michael@0 | 6 | onunload="onunload();" |
michael@0 | 7 | xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> |
michael@0 | 8 | |
michael@0 | 9 | <script type="application/javascript" |
michael@0 | 10 | src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js" /> |
michael@0 | 11 | |
michael@0 | 12 | <body xmlns="http://www.w3.org/1999/xhtml" id="body"> |
michael@0 | 13 | <style type="text/css"> |
michael@0 | 14 | #view { |
michael@0 | 15 | overflow: auto; |
michael@0 | 16 | width: 100px; |
michael@0 | 17 | height: 100px; |
michael@0 | 18 | border: 1px solid; |
michael@0 | 19 | margin: 0; |
michael@0 | 20 | } |
michael@0 | 21 | </style> |
michael@0 | 22 | <pre id="view" onscroll="onScrollView(event);"> |
michael@0 | 23 | Text. Text. Text. Text. Text. Text. Text. Text. Text. Text. Text. |
michael@0 | 24 | Text. Text. Text. Text. Text. Text. Text. Text. Text. Text. Text. |
michael@0 | 25 | Text. Text. Text. Text. Text. Text. Text. Text. Text. Text. Text. |
michael@0 | 26 | Text. Text. Text. Text. Text. Text. Text. Text. Text. Text. Text. |
michael@0 | 27 | Text. Text. Text. Text. Text. Text. Text. Text. Text. Text. Text. |
michael@0 | 28 | Text. Text. Text. Text. Text. Text. Text. Text. Text. Text. Text. |
michael@0 | 29 | Text. Text. Text. Text. Text. Text. Text. Text. Text. Text. Text. |
michael@0 | 30 | Text. Text. Text. Text. Text. Text. Text. Text. Text. Text. Text. |
michael@0 | 31 | Text. Text. Text. Text. Text. Text. Text. Text. Text. Text. Text. |
michael@0 | 32 | Text. Text. Text. Text. Text. Text. Text. Text. Text. Text. Text. |
michael@0 | 33 | </pre> |
michael@0 | 34 | </body> |
michael@0 | 35 | |
michael@0 | 36 | <script class="testbody" type="application/javascript"> |
michael@0 | 37 | <![CDATA[ |
michael@0 | 38 | |
michael@0 | 39 | function ok(aCondition, aMessage) |
michael@0 | 40 | { |
michael@0 | 41 | window.opener.wrappedJSObject.SimpleTest.ok(aCondition, aMessage); |
michael@0 | 42 | } |
michael@0 | 43 | |
michael@0 | 44 | function is(aLeft, aRight, aMessage) |
michael@0 | 45 | { |
michael@0 | 46 | window.opener.wrappedJSObject.SimpleTest.is(aLeft, aRight, aMessage); |
michael@0 | 47 | } |
michael@0 | 48 | |
michael@0 | 49 | function isnot(aLeft, aRight, aMessage) |
michael@0 | 50 | { |
michael@0 | 51 | window.opener.wrappedJSObject.SimpleTest.isnot(aLeft, aRight, aMessage); |
michael@0 | 52 | } |
michael@0 | 53 | |
michael@0 | 54 | var gBody = document.getElementById("body"); |
michael@0 | 55 | var gView = document.getElementById("view"); |
michael@0 | 56 | |
michael@0 | 57 | /** |
michael@0 | 58 | * Description: |
michael@0 | 59 | * |
michael@0 | 60 | * First, lock the wheel scrolling target to "view" at first step. |
michael@0 | 61 | * Next, scroll back to top most of the "view" at second step. |
michael@0 | 62 | * Finally, scroll back again at third step. This fails to scroll the "view", |
michael@0 | 63 | * then, |onMouseScrollFailed| event should be fired. And at that time, we |
michael@0 | 64 | * can remove the "view". So, in post processing of the event firere, the |
michael@0 | 65 | * "view" should not be referred. |
michael@0 | 66 | * |
michael@0 | 67 | * For suppressing random test failure, all tests will be retried if we handle |
michael@0 | 68 | * unexpected timeout event. |
michael@0 | 69 | */ |
michael@0 | 70 | |
michael@0 | 71 | var gTests = [ |
michael@0 | 72 | { scrollToForward: true, shouldScroll: true }, |
michael@0 | 73 | { scrollToForward: false, shouldScroll: true }, |
michael@0 | 74 | { scrollToForward: false, shouldScroll: false } |
michael@0 | 75 | ]; |
michael@0 | 76 | var gCurrentTestIndex = -1; |
michael@0 | 77 | var gIgnoreScrollEvent = true; |
michael@0 | 78 | |
michael@0 | 79 | var gPrefSvc = Components.classes["@mozilla.org/preferences-service;1"]. |
michael@0 | 80 | getService(Components.interfaces.nsIPrefBranch); |
michael@0 | 81 | const kPrefSmoothScroll = "general.smoothScroll"; |
michael@0 | 82 | const kPrefNameTimeout = "mousewheel.transaction.timeout"; |
michael@0 | 83 | const kDefaultTimeout = gPrefSvc.getIntPref(kPrefNameTimeout); |
michael@0 | 84 | |
michael@0 | 85 | gPrefSvc.setBoolPref(kPrefSmoothScroll, false); |
michael@0 | 86 | |
michael@0 | 87 | var gTimeout = kDefaultTimeout; |
michael@0 | 88 | |
michael@0 | 89 | gBody.addEventListener("MozMouseScrollFailed", onMouseScrollFailed, false); |
michael@0 | 90 | gBody.addEventListener("MozMouseScrollTransactionTimeout", |
michael@0 | 91 | onTransactionTimeout, false); |
michael@0 | 92 | |
michael@0 | 93 | function setTimeoutPrefs(aTimeout) |
michael@0 | 94 | { |
michael@0 | 95 | gPrefSvc.setIntPref(kPrefNameTimeout, aTimeout); |
michael@0 | 96 | gTimeout = aTimeout; |
michael@0 | 97 | } |
michael@0 | 98 | |
michael@0 | 99 | function resetTimeoutPrefs() |
michael@0 | 100 | { |
michael@0 | 101 | if (gTimeout == kDefaultTimeout) |
michael@0 | 102 | return; |
michael@0 | 103 | setTimeoutPrefs(kDefaultTimeout); |
michael@0 | 104 | } |
michael@0 | 105 | |
michael@0 | 106 | function growUpTimeoutPrefs() |
michael@0 | 107 | { |
michael@0 | 108 | if (gTimeout != kDefaultTimeout) |
michael@0 | 109 | return; |
michael@0 | 110 | setTimeoutPrefs(5000); |
michael@0 | 111 | } |
michael@0 | 112 | |
michael@0 | 113 | function onload() |
michael@0 | 114 | { |
michael@0 | 115 | disableNonTestMouseEvents(true); |
michael@0 | 116 | setTimeout(runNextTest, 0); |
michael@0 | 117 | } |
michael@0 | 118 | |
michael@0 | 119 | function onunload() |
michael@0 | 120 | { |
michael@0 | 121 | resetTimeoutPrefs(); |
michael@0 | 122 | disableNonTestMouseEvents(false); |
michael@0 | 123 | gPrefSvc.clearUserPref(kPrefSmoothScroll); |
michael@0 | 124 | window.opener.wrappedJSObject.SimpleTest.finish(); |
michael@0 | 125 | } |
michael@0 | 126 | |
michael@0 | 127 | function finish() |
michael@0 | 128 | { |
michael@0 | 129 | window.close(); |
michael@0 | 130 | } |
michael@0 | 131 | |
michael@0 | 132 | // testing code |
michael@0 | 133 | |
michael@0 | 134 | var gTimer; |
michael@0 | 135 | function clearTimer() |
michael@0 | 136 | { |
michael@0 | 137 | clearTimeout(gTimer); |
michael@0 | 138 | gTimer = 0; |
michael@0 | 139 | } |
michael@0 | 140 | |
michael@0 | 141 | function runNextTest() |
michael@0 | 142 | { |
michael@0 | 143 | clearTimer(); |
michael@0 | 144 | if (++gCurrentTestIndex >= gTests.length) { |
michael@0 | 145 | ok(true, "didn't crash, succeeded"); |
michael@0 | 146 | finish(); |
michael@0 | 147 | return; |
michael@0 | 148 | } |
michael@0 | 149 | fireWheelScrollEvent(gTests[gCurrentTestIndex].scrollToForward); |
michael@0 | 150 | } |
michael@0 | 151 | |
michael@0 | 152 | var gRetryCount = 5; |
michael@0 | 153 | function retryAllTests() |
michael@0 | 154 | { |
michael@0 | 155 | clearTimer(); |
michael@0 | 156 | if (--gRetryCount >= 0) { |
michael@0 | 157 | gView.scrollTop = 0; |
michael@0 | 158 | gView.scrollLeft = 0; |
michael@0 | 159 | gCurrentTestIndex = -1; |
michael@0 | 160 | growUpTimeoutPrefs(); |
michael@0 | 161 | ok(true, "WARNING: retry current test-list..."); |
michael@0 | 162 | gTimer = setTimeout(runNextTest, 0); |
michael@0 | 163 | } else { |
michael@0 | 164 | ok(false, "Failed by unexpected timeout"); |
michael@0 | 165 | finish(); |
michael@0 | 166 | } |
michael@0 | 167 | } |
michael@0 | 168 | |
michael@0 | 169 | function fireWheelScrollEvent(aForward) |
michael@0 | 170 | { |
michael@0 | 171 | gIgnoreScrollEvent = false; |
michael@0 | 172 | var event = { deltaY: aForward ? 4.0 : -4.0, |
michael@0 | 173 | deltaMode: WheelEvent.DOM_DELTA_LINE }; |
michael@0 | 174 | synthesizeWheel(gView, 5, 5, event, window); |
michael@0 | 175 | } |
michael@0 | 176 | |
michael@0 | 177 | function onScrollView(aEvent) |
michael@0 | 178 | { |
michael@0 | 179 | if (gIgnoreScrollEvent) |
michael@0 | 180 | return; |
michael@0 | 181 | gIgnoreScrollEvent = true; |
michael@0 | 182 | clearTimer(); |
michael@0 | 183 | ok(gTests[gCurrentTestIndex].shouldScroll, "The view is scrolled"); |
michael@0 | 184 | gTimer = setTimeout(runNextTest, 0); |
michael@0 | 185 | } |
michael@0 | 186 | |
michael@0 | 187 | function onMouseScrollFailed(aEvent) |
michael@0 | 188 | { |
michael@0 | 189 | clearTimer(); |
michael@0 | 190 | gIgnoreScrollEvent = true; |
michael@0 | 191 | ok(!gTests[gCurrentTestIndex].shouldScroll, "The view is not scrolled"); |
michael@0 | 192 | if (!gTests[gCurrentTestIndex].shouldScroll) |
michael@0 | 193 | gBody.removeChild(gView); |
michael@0 | 194 | runNextTest(); |
michael@0 | 195 | } |
michael@0 | 196 | |
michael@0 | 197 | function onTransactionTimeout(aEvent) |
michael@0 | 198 | { |
michael@0 | 199 | if (!gTimer) |
michael@0 | 200 | return; |
michael@0 | 201 | gIgnoreScrollEvent = true; |
michael@0 | 202 | retryAllTests(); |
michael@0 | 203 | } |
michael@0 | 204 | |
michael@0 | 205 | ]]> |
michael@0 | 206 | </script> |
michael@0 | 207 | |
michael@0 | 208 | </window> |