summaryrefslogtreecommitdiffstats
path: root/browser/components/preferences/tests/browser_searchScroll.js
blob: e0755231c38c055bb09060a37cbee00297d8aacb (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
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

/* import-globals-from ../../../../gfx/layers/apz/test/mochitest/apz_test_native_event_utils.js */
Services.scriptloader.loadSubScript(
  "chrome://mochitests/content/browser/gfx/layers/apz/test/mochitest/apz_test_native_event_utils.js",
  this
);

const { AddonTestUtils } = ChromeUtils.import(
  "resource://testing-common/AddonTestUtils.jsm"
);
const { SearchTestUtils } = ChromeUtils.importESModule(
  "resource://testing-common/SearchTestUtils.sys.mjs"
);
const { SearchUtils } = ChromeUtils.importESModule(
  "resource://gre/modules/SearchUtils.sys.mjs"
);

AddonTestUtils.initMochitest(this);
SearchTestUtils.init(this);

add_setup(async function() {
  await SpecialPowers.pushPrefEnv({
    set: [["dom.w3c_touch_events.enabled", 0]],
  });
});

add_task(async function test_scroll() {
  info("Open preferences page for search");
  await openPreferencesViaOpenPreferencesAPI("search", { leaveOpen: true });

  const doc = gBrowser.selectedBrowser.contentDocument;
  const tree = doc.querySelector("#engineList");

  info("Add engines to make the tree scrollable");
  for (let i = 0, n = parseInt(tree.getAttribute("rows")); i < n; i++) {
    let extension = await SearchTestUtils.installSearchExtension({
      id: `${i}@tests.mozilla.org`,
      name: `example${i}`,
      version: "1.0",
      keyword: `example${i}`,
    });
    await AddonTestUtils.waitForSearchProviderStartup(extension);
  }

  info("Make tree element move into viewport");
  const mainContent = doc.querySelector(".main-content");
  const readyForScrollIntoView = new Promise(r => {
    mainContent.addEventListener("scroll", r, { once: true });
  });
  tree.scrollIntoView();
  await readyForScrollIntoView;

  const previousScroll = mainContent.scrollTop;

  await promiseMoveMouseAndScrollWheelOver(tree, 1, 1, false);

  Assert.equal(
    previousScroll,
    mainContent.scrollTop,
    "Container element does not scroll"
  );

  info("Clean up");
  gBrowser.removeCurrentTab();
});