DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Line Code
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
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=574663
-->
<head>
  <title>Test for Bug 574663</title>
  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=574663">Mozilla Bug 574663</a>
<p id="display"></p>
<div id="content" style="display: none">

</div>
<pre id="test">
<script type="application/javascript">

/** Test for Bug 574663 **/

// SimpleTest's paint_listener does not work on other windows, so we inline
// a smaller version here.
function waitForPaint(win, utils, callback) {
  win.document.documentElement.getBoundingClientRect();
  if (!utils.isMozAfterPaintPending) {
    callback();
    return;
  }

  var onpaint = function() {
    if (!utils.isMozAfterPaintPending) {
      win.removeEventListener("MozAfterPaint", onpaint);
      callback();
      return;
    }
    if (utils.isTestControllingRefreshes) {
      utils.advanceTimeAndRefresh(0);
    }
  }
  win.addEventListener("MozAfterPaint", onpaint);
  if (utils.isTestControllingRefreshes) {
    utils.advanceTimeAndRefresh(0);
  }
}

function forceScrollAndWait(scrollbox, callback) {
  let win = scrollbox.ownerDocument.defaultView;
  let utils = SpecialPowers.getDOMWindowUtils(win);

  utils.advanceTimeAndRefresh(1000);

  let postApzFlush = function() {
    SpecialPowers.Services.obs.removeObserver(postApzFlush, "apz-repaints-flushed", false);
    waitForPaint(win, utils, callback);
  }
  SpecialPowers.Services.obs.addObserver(postApzFlush, "apz-repaints-flushed");
  if (!utils.flushApzRepaints()) {
    postApzFlush();
  }
}

var kExtraEvents = 5;
var kDelta = 3;

function sendTouchpadScrollMotion(scrollbox, direction, ctrl, momentum, callback) {
  var win = scrollbox.ownerDocument.defaultView;
  let event = {
    deltaMode: WheelEvent.DOM_DELTA_PIXEL,
    deltaY: direction * kDelta,
    lineOrPageDeltaY: direction,
    ctrlKey: ctrl,
    isMomentum: momentum
  };
  let received = 0;
  let deltaY = 0;
  var onwheel = function(e) {
    deltaY += e.deltaY;
    if (++received == 2) {
      // We have captured all the outstanding wheel events. Wait for the
      // animation to add itself to the refresh driver.
      scrollbox.removeEventListener("wheel", onwheel);
      setTimeout(function() {
        forceScrollAndWait(scrollbox, callback);
      }, 0);
    }
  };
  scrollbox.addEventListener("wheel", onwheel);

  synthesizeWheel(scrollbox, 10, 10, event, win);
  // then 5 additional pixel scrolls
  event.lineOrPageDeltaY = 0;
  for (let i = 1; i <= kExtraEvents; ++i) {
    synthesizeWheel(scrollbox, 10, 10, event, win);
  }
}

function runTest() {
  var win = open('bug574663.html', '_blank', 'width=300,height=300');
  let winUtils = SpecialPowers.getDOMWindowUtils(win);

  let waitUntilPainted = function(callback) {
    // Until the first non-blank paint, the parent will set the opacity of our
    // browser to 0 using the 'blank' attribute.
    // Until the blank attribute is removed, we can't send scroll events.
    SimpleTest.waitForFocus(function() {
      let chromeScript = SpecialPowers.loadChromeScript(_ => {
        ChromeUtils.import("resource://gre/modules/Services.jsm");
        let win = Services.wm.getMostRecentWindow("navigator:browser");
        win.requestAnimationFrame(() => {
          win.gBrowser.selectedBrowser.removeAttribute("blank");
          win.requestAnimationFrame(() => {
            sendAsyncMessage("blank-attribute-removed");
          });
        });
      });
      chromeScript.promiseOneMessage("blank-attribute-removed").then(() => {
        chromeScript.destroy();
        waitForPaint(win, winUtils, callback);
      });
    }, win);
  };

  waitUntilPainted(function () {
    var scrollbox = win.document.getElementById("scrollbox");
    let outstandingTests = [
      [false, false],
      [false, true],
      [true, false],
      [true, true],
    ];

    // grab the refresh driver, since we want to make sure
    // async scrolls happen in deterministic time
    winUtils.advanceTimeAndRefresh(1000);

    function nextTest() {
      let [ctrlKey, isMomentum] = outstandingTests.shift();
      let scrollTopBefore = scrollbox.scrollTop;
      let zoomFactorBefore = winUtils.fullZoom;

      let check = function() {
        if (!ctrlKey) {
          let postfix = isMomentum ? ", even after releasing the touchpad" : "";
          // Normal scroll: scroll
          is(winUtils.fullZoom, zoomFactorBefore, "Normal scrolling shouldn't change zoom" + postfix);
          is(scrollbox.scrollTop, scrollTopBefore + kDelta * (kExtraEvents + 1),
             "Normal scrolling should scroll" + postfix);
        } else {
          if (!isMomentum) {
            isnot(winUtils.fullZoom, zoomFactorBefore, "Ctrl-scrolling should zoom while the user is touching the touchpad");
            is(scrollbox.scrollTop, scrollTopBefore, "Ctrl-scrolling shouldn't scroll while the user is touching the touchpad");
          } else {
            is(winUtils.fullZoom, zoomFactorBefore, "Momentum scrolling shouldn't zoom, even when pressing Ctrl");
            is(scrollbox.scrollTop, scrollTopBefore + kDelta * (kExtraEvents + 1),
               "Momentum scrolling should scroll, even when pressing Ctrl");
          }
        }

        if (!outstandingTests.length) {
          winUtils.restoreNormalRefresh();
          win.close();
          SimpleTest.finish();
          return;
        }

        // Revert the effect for the next test.
        sendTouchpadScrollMotion(scrollbox, -1, ctrlKey, isMomentum, function() {
          setTimeout(nextTest, 0);
        });
      }

      sendTouchpadScrollMotion(scrollbox, 1, ctrlKey, isMomentum, check);
    }
    nextTest();
  });
}

window.onload = function() {
  SpecialPowers.pushPrefEnv({
    "set":[["general.smoothScroll", false],
           ["mousewheel.acceleration.start", -1],
           ["mousewheel.system_scroll_override_on_root_content.enabled", false],
           ["mousewheel.with_control.action", 3]]}, runTest);
}

SimpleTest.waitForExplicitFinish();

</script>
</pre>

</body>
</html>