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 | <!DOCTYPE HTML> |
michael@0 | 2 | <html> |
michael@0 | 3 | <!-- |
michael@0 | 4 | https://bugzilla.mozilla.org/show_bug.cgi?id=574663 |
michael@0 | 5 | --> |
michael@0 | 6 | <head> |
michael@0 | 7 | <title>Test for Bug 574663</title> |
michael@0 | 8 | <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 9 | <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script> |
michael@0 | 10 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> |
michael@0 | 11 | </head> |
michael@0 | 12 | <body> |
michael@0 | 13 | <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=574663">Mozilla Bug 574663</a> |
michael@0 | 14 | <p id="display"></p> |
michael@0 | 15 | <div id="content" style="display: none"> |
michael@0 | 16 | |
michael@0 | 17 | </div> |
michael@0 | 18 | <pre id="test"> |
michael@0 | 19 | <script type="application/javascript;version=1.7"> |
michael@0 | 20 | |
michael@0 | 21 | /** Test for Bug 574663 **/ |
michael@0 | 22 | |
michael@0 | 23 | function sendTouchpadScrollMotion(scrollbox, direction, ctrl, momentum) { |
michael@0 | 24 | var win = scrollbox.ownerDocument.defaultView; |
michael@0 | 25 | let event = { |
michael@0 | 26 | deltaMode: WheelEvent.DOM_DELTA_PIXEL, |
michael@0 | 27 | deltaY: direction * 3, |
michael@0 | 28 | lineOrPageDeltaY: direction, |
michael@0 | 29 | ctrlKey: ctrl, |
michael@0 | 30 | isMomentum: momentum |
michael@0 | 31 | }; |
michael@0 | 32 | synthesizeWheel(scrollbox, 10, 10, event, win); |
michael@0 | 33 | // then 5 additional pixel scrolls |
michael@0 | 34 | event.lineOrPageDeltaY = 0; |
michael@0 | 35 | for (let i = 0; i < 5; ++i) { |
michael@0 | 36 | synthesizeWheel(scrollbox, 10, 10, event, win); |
michael@0 | 37 | } |
michael@0 | 38 | } |
michael@0 | 39 | |
michael@0 | 40 | function runTest() { |
michael@0 | 41 | var win = open('data:text/html,<!DOCTYPE html>\n' + |
michael@0 | 42 | '<div id="scrollbox" style="height: 100px; overflow: auto;">' + |
michael@0 | 43 | ' <div style="height: 1000px;"></div>' + |
michael@0 | 44 | '</div>', '_blank', 'width=300,height=300'); |
michael@0 | 45 | SimpleTest.waitForFocus(function () { |
michael@0 | 46 | var scrollbox = win.document.getElementById("scrollbox"); |
michael@0 | 47 | let winUtils = SpecialPowers.getDOMWindowUtils(win); |
michael@0 | 48 | let outstandingTests = [ |
michael@0 | 49 | [false, false], |
michael@0 | 50 | [false, true], |
michael@0 | 51 | [true, false], |
michael@0 | 52 | [true, true], |
michael@0 | 53 | ]; |
michael@0 | 54 | |
michael@0 | 55 | // grab the refresh driver, since we want to make sure |
michael@0 | 56 | // async scrolls happen in deterministic time |
michael@0 | 57 | winUtils.advanceTimeAndRefresh(1000); |
michael@0 | 58 | |
michael@0 | 59 | function nextTest() { |
michael@0 | 60 | if (!outstandingTests.length) { |
michael@0 | 61 | winUtils.restoreNormalRefresh(); |
michael@0 | 62 | win.close(); |
michael@0 | 63 | clearPrefs(); |
michael@0 | 64 | SimpleTest.finish(); |
michael@0 | 65 | return; |
michael@0 | 66 | } |
michael@0 | 67 | |
michael@0 | 68 | let [ctrlKey, isMomentum] = outstandingTests.shift(); |
michael@0 | 69 | let scrollTopBefore = scrollbox.scrollTop; |
michael@0 | 70 | let zoomFactorBefore = winUtils.fullZoom; |
michael@0 | 71 | |
michael@0 | 72 | sendTouchpadScrollMotion(scrollbox, 1, ctrlKey, isMomentum); |
michael@0 | 73 | winUtils.advanceTimeAndRefresh(1000); // force scrolling to happen |
michael@0 | 74 | |
michael@0 | 75 | setTimeout(function () { |
michael@0 | 76 | if (!ctrlKey) { |
michael@0 | 77 | let postfix = isMomentum ? ", even after releasing the touchpad" : ""; |
michael@0 | 78 | // Normal scroll: scroll |
michael@0 | 79 | is(winUtils.fullZoom, zoomFactorBefore, "Normal scrolling shouldn't change zoom" + postfix); |
michael@0 | 80 | isnot(scrollbox.scrollTop, scrollTopBefore, "Normal scrolling should scroll" + postfix); |
michael@0 | 81 | } else { |
michael@0 | 82 | if (!isMomentum) { |
michael@0 | 83 | isnot(winUtils.fullZoom, zoomFactorBefore, "Ctrl-scrolling should zoom while the user is touching the touchpad"); |
michael@0 | 84 | is(scrollbox.scrollTop, scrollTopBefore, "Ctrl-scrolling shouldn't scroll while the user is touching the touchpad"); |
michael@0 | 85 | } else { |
michael@0 | 86 | is(winUtils.fullZoom, zoomFactorBefore, "Momentum scrolling shouldn't zoom, even when pressing Ctrl"); |
michael@0 | 87 | isnot(scrollbox.scrollTop, scrollTopBefore, "Momentum scrolling should scroll, even when pressing Ctrl"); |
michael@0 | 88 | } |
michael@0 | 89 | } |
michael@0 | 90 | // Revert the effect. |
michael@0 | 91 | sendTouchpadScrollMotion(scrollbox, -1, ctrlKey, isMomentum); |
michael@0 | 92 | winUtils.advanceTimeAndRefresh(1000); // force scrolling to happen |
michael@0 | 93 | |
michael@0 | 94 | setTimeout(nextTest, 20); |
michael@0 | 95 | }, 20); |
michael@0 | 96 | } |
michael@0 | 97 | nextTest(); |
michael@0 | 98 | }, win); |
michael@0 | 99 | } |
michael@0 | 100 | |
michael@0 | 101 | function initPrefs() |
michael@0 | 102 | { |
michael@0 | 103 | SpecialPowers.setBoolPref("general.smoothScroll", false); |
michael@0 | 104 | // Disables the app level scroll acceleration |
michael@0 | 105 | SpecialPowers.setIntPref("mousewheel.acceleration.start", -1); |
michael@0 | 106 | SpecialPowers.setBoolPref("mousewheel.system_scroll_override_on_root_content.enabled", false); |
michael@0 | 107 | // Enable zooming for ctrl-scrolling |
michael@0 | 108 | SpecialPowers.setIntPref("mousewheel.with_control.action", 3); |
michael@0 | 109 | } |
michael@0 | 110 | |
michael@0 | 111 | function clearPrefs() |
michael@0 | 112 | { |
michael@0 | 113 | SpecialPowers.clearUserPref("general.smoothScroll"); |
michael@0 | 114 | SpecialPowers.clearUserPref("mousewheel.acceleration.start"); |
michael@0 | 115 | SpecialPowers.clearUserPref("mousewheel.system_scroll_override_on_root_content.enabled"); |
michael@0 | 116 | SpecialPowers.clearUserPref("mousewheel.with_control.action"); |
michael@0 | 117 | } |
michael@0 | 118 | |
michael@0 | 119 | window.onload = function () { |
michael@0 | 120 | initPrefs(); |
michael@0 | 121 | SimpleTest.executeSoon(runTest); |
michael@0 | 122 | } |
michael@0 | 123 | |
michael@0 | 124 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 125 | |
michael@0 | 126 | </script> |
michael@0 | 127 | </pre> |
michael@0 | 128 | |
michael@0 | 129 | </body> |
michael@0 | 130 | </html> |