summaryrefslogtreecommitdiffstats
path: root/toolkit/content/tests/browser/browser_autoscroll_disabled.js
blob: 07c6174abd9f1d3f82b8d08443ae229022e15e39 (plain)
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
add_task(function* ()
{
  const kPrefName_AutoScroll = "general.autoScroll";
  Services.prefs.setBoolPref(kPrefName_AutoScroll, false);

  let dataUri = 'data:text/html,<html><body id="i" style="overflow-y: scroll"><div style="height: 2000px"></div>\
      <iframe id="iframe" style="display: none;"></iframe>\
</body></html>';

  let loadedPromise = BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser);
  gBrowser.loadURI(dataUri);
  yield loadedPromise;

  yield BrowserTestUtils.synthesizeMouse("#i", 50, 50, { button: 1 },
                                         gBrowser.selectedBrowser);

  yield ContentTask.spawn(gBrowser.selectedBrowser, { }, function* () {
    var iframe = content.document.getElementById("iframe");

    if (iframe) {
      var e = new iframe.contentWindow.PageTransitionEvent("pagehide",
                                                           { bubbles: true,
                                                             cancelable: true,
                                                             persisted: false });
      iframe.contentDocument.dispatchEvent(e);
      iframe.contentDocument.documentElement.dispatchEvent(e);
    }
  });

  yield BrowserTestUtils.synthesizeMouse("#i", 100, 100,
                                         { type: "mousemove", clickCount: "0" },
                                         gBrowser.selectedBrowser);

  // If scrolling didn't work, we wouldn't do any redraws and thus time out, so
  // request and force redraws to get the chance to check for scrolling at all.
  yield new Promise(resolve => window.requestAnimationFrame(resolve));

  let msg = yield ContentTask.spawn(gBrowser.selectedBrowser, { }, function* () {
    // Skip the first animation frame callback as it's the same callback that
    // the browser uses to kick off the scrolling.
    return new Promise(resolve => {
      function checkScroll() {
        let msg = "";
        let elem = content.document.getElementById('i');
        if (elem.scrollTop != 0) {
          msg += "element should not have scrolled vertically";
        }
        if (elem.scrollLeft != 0) {
          msg += "element should not have scrolled horizontally";
        }

        resolve(msg);
      }

      content.requestAnimationFrame(checkScroll);
    });
  });

  ok(!msg, "element scroll " + msg);

  // restore the changed prefs
  if (Services.prefs.prefHasUserValue(kPrefName_AutoScroll))
    Services.prefs.clearUserPref(kPrefName_AutoScroll);

  // wait for focus to fix a failure in the next test if the latter runs too soon.
  yield SimpleTest.promiseFocus();
});