summaryrefslogtreecommitdiffstats
path: root/toolkit/content/tests/browser/browser_starting_autoscroll_in_about_content.js
blob: f0daa480d4a1324ebb29c9b4a903bcdb98213042 (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
68
69
70
71
72
73
74
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

add_task(async function testStartingAutoScrollInAboutContent() {
  await SpecialPowers.pushPrefEnv({
    set: [
      ["general.autoScroll", true],
      ["middlemouse.contentLoadURL", false],
      ["test.events.async.enabled", true],
    ],
  });

  await BrowserTestUtils.withNewTab("about:support", async function (browser) {
    let autoScroller;
    let promiseStartAutoScroll = new Promise(resolve => {
      let onPopupShown = event => {
        if (event.originalTarget.id != "autoscroller") {
          return;
        }
        autoScroller = event.originalTarget;
        info('"popupshown" event is fired');
        autoScroller.getBoundingClientRect(); // Flush layout of the autoscroller
        resolve();
      };
      window.addEventListener("popupshown", onPopupShown, { capture: true });
      registerCleanupFunction(() => {
        window.removeEventListener("popupshown", onPopupShown, {
          capture: true,
        });
      });
    });

    ok(!browser.isRemoteBrowser, "Browser should not be remote.");
    await ContentTask.spawn(browser, null, async function () {
      await ContentTaskUtils.waitForCondition(
        () =>
          content.document.documentElement.scrollHeight >
          content.document.documentElement.clientHeight,
        "The document should become scrollable"
      );
    });

    await EventUtils.promiseNativeMouseEvent({
      type: "mousemove",
      target: browser,
      offsetX: 10,
      offsetY: 10, // XXX Assuming that there is no interactive content here.
    });
    await EventUtils.promiseNativeMouseEvent({
      type: "mousedown",
      button: 1, // middle click
      target: browser,
      offsetX: 10,
      offsetY: 10,
    });
    info("Waiting to start autoscrolling");
    await promiseStartAutoScroll;
    ok(autoScroller != null, "Autoscrolling should be started");
    await EventUtils.promiseNativeMouseEvent({
      type: "mouseup",
      button: 1, // middle click
      target: browser,
      offsetX: 10,
      offsetY: 10,
    }); // release implicit capture
    EventUtils.synthesizeKey("KEY_Escape"); // Close autoscroller
    await TestUtils.waitForCondition(
      () => autoScroller.state == "closed",
      "autoscroll should be canceled"
    );
  });
});