1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/events/test/test_bug574663.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,130 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=574663 1.8 +--> 1.9 +<head> 1.10 + <title>Test for Bug 574663</title> 1.11 + <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.12 + <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script> 1.13 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 1.14 +</head> 1.15 +<body> 1.16 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=574663">Mozilla Bug 574663</a> 1.17 +<p id="display"></p> 1.18 +<div id="content" style="display: none"> 1.19 + 1.20 +</div> 1.21 +<pre id="test"> 1.22 +<script type="application/javascript;version=1.7"> 1.23 + 1.24 +/** Test for Bug 574663 **/ 1.25 + 1.26 +function sendTouchpadScrollMotion(scrollbox, direction, ctrl, momentum) { 1.27 + var win = scrollbox.ownerDocument.defaultView; 1.28 + let event = { 1.29 + deltaMode: WheelEvent.DOM_DELTA_PIXEL, 1.30 + deltaY: direction * 3, 1.31 + lineOrPageDeltaY: direction, 1.32 + ctrlKey: ctrl, 1.33 + isMomentum: momentum 1.34 + }; 1.35 + synthesizeWheel(scrollbox, 10, 10, event, win); 1.36 + // then 5 additional pixel scrolls 1.37 + event.lineOrPageDeltaY = 0; 1.38 + for (let i = 0; i < 5; ++i) { 1.39 + synthesizeWheel(scrollbox, 10, 10, event, win); 1.40 + } 1.41 +} 1.42 + 1.43 +function runTest() { 1.44 + var win = open('data:text/html,<!DOCTYPE html>\n' + 1.45 + '<div id="scrollbox" style="height: 100px; overflow: auto;">' + 1.46 + ' <div style="height: 1000px;"></div>' + 1.47 + '</div>', '_blank', 'width=300,height=300'); 1.48 + SimpleTest.waitForFocus(function () { 1.49 + var scrollbox = win.document.getElementById("scrollbox"); 1.50 + let winUtils = SpecialPowers.getDOMWindowUtils(win); 1.51 + let outstandingTests = [ 1.52 + [false, false], 1.53 + [false, true], 1.54 + [true, false], 1.55 + [true, true], 1.56 + ]; 1.57 + 1.58 + // grab the refresh driver, since we want to make sure 1.59 + // async scrolls happen in deterministic time 1.60 + winUtils.advanceTimeAndRefresh(1000); 1.61 + 1.62 + function nextTest() { 1.63 + if (!outstandingTests.length) { 1.64 + winUtils.restoreNormalRefresh(); 1.65 + win.close(); 1.66 + clearPrefs(); 1.67 + SimpleTest.finish(); 1.68 + return; 1.69 + } 1.70 + 1.71 + let [ctrlKey, isMomentum] = outstandingTests.shift(); 1.72 + let scrollTopBefore = scrollbox.scrollTop; 1.73 + let zoomFactorBefore = winUtils.fullZoom; 1.74 + 1.75 + sendTouchpadScrollMotion(scrollbox, 1, ctrlKey, isMomentum); 1.76 + winUtils.advanceTimeAndRefresh(1000); // force scrolling to happen 1.77 + 1.78 + setTimeout(function () { 1.79 + if (!ctrlKey) { 1.80 + let postfix = isMomentum ? ", even after releasing the touchpad" : ""; 1.81 + // Normal scroll: scroll 1.82 + is(winUtils.fullZoom, zoomFactorBefore, "Normal scrolling shouldn't change zoom" + postfix); 1.83 + isnot(scrollbox.scrollTop, scrollTopBefore, "Normal scrolling should scroll" + postfix); 1.84 + } else { 1.85 + if (!isMomentum) { 1.86 + isnot(winUtils.fullZoom, zoomFactorBefore, "Ctrl-scrolling should zoom while the user is touching the touchpad"); 1.87 + is(scrollbox.scrollTop, scrollTopBefore, "Ctrl-scrolling shouldn't scroll while the user is touching the touchpad"); 1.88 + } else { 1.89 + is(winUtils.fullZoom, zoomFactorBefore, "Momentum scrolling shouldn't zoom, even when pressing Ctrl"); 1.90 + isnot(scrollbox.scrollTop, scrollTopBefore, "Momentum scrolling should scroll, even when pressing Ctrl"); 1.91 + } 1.92 + } 1.93 + // Revert the effect. 1.94 + sendTouchpadScrollMotion(scrollbox, -1, ctrlKey, isMomentum); 1.95 + winUtils.advanceTimeAndRefresh(1000); // force scrolling to happen 1.96 + 1.97 + setTimeout(nextTest, 20); 1.98 + }, 20); 1.99 + } 1.100 + nextTest(); 1.101 + }, win); 1.102 +} 1.103 + 1.104 +function initPrefs() 1.105 +{ 1.106 + SpecialPowers.setBoolPref("general.smoothScroll", false); 1.107 + // Disables the app level scroll acceleration 1.108 + SpecialPowers.setIntPref("mousewheel.acceleration.start", -1); 1.109 + SpecialPowers.setBoolPref("mousewheel.system_scroll_override_on_root_content.enabled", false); 1.110 + // Enable zooming for ctrl-scrolling 1.111 + SpecialPowers.setIntPref("mousewheel.with_control.action", 3); 1.112 +} 1.113 + 1.114 +function clearPrefs() 1.115 +{ 1.116 + SpecialPowers.clearUserPref("general.smoothScroll"); 1.117 + SpecialPowers.clearUserPref("mousewheel.acceleration.start"); 1.118 + SpecialPowers.clearUserPref("mousewheel.system_scroll_override_on_root_content.enabled"); 1.119 + SpecialPowers.clearUserPref("mousewheel.with_control.action"); 1.120 +} 1.121 + 1.122 +window.onload = function () { 1.123 + initPrefs(); 1.124 + SimpleTest.executeSoon(runTest); 1.125 +} 1.126 + 1.127 +SimpleTest.waitForExplicitFinish(); 1.128 + 1.129 +</script> 1.130 +</pre> 1.131 + 1.132 +</body> 1.133 +</html>