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

add_setup(async function () {
  await BrowserTestUtils.openNewForegroundTab({
    gBrowser,
    url: "about:logins",
  });
  registerCleanupFunction(() => {
    BrowserTestUtils.removeTab(gBrowser.selectedTab);
  });
});

add_task(async function test_open_feedback() {
  const menuArray = [
    {
      urlFinal:
        "https://example.com/password-manager-remember-delete-edit-logins",
      urlBase: "https://example.com/",
      pref: "app.support.baseURL",
      selector: ".menuitem-help",
    },
  ];

  for (const { urlFinal, urlBase, pref, selector } of menuArray) {
    info("Test on " + urlFinal);

    await SpecialPowers.pushPrefEnv({
      set: [[pref, urlBase]],
    });

    let promiseNewTab = BrowserTestUtils.waitForNewTab(gBrowser, urlFinal);

    let browser = gBrowser.selectedBrowser;
    await BrowserTestUtils.synthesizeMouseAtCenter("menu-button", {}, browser);
    await SpecialPowers.spawn(browser, [], async () => {
      return ContentTaskUtils.waitForCondition(() => {
        let menuButton = content.document.querySelector("menu-button");
        return !menuButton.shadowRoot.querySelector(".menu").hidden;
      }, "waiting for menu to open");
    });

    // Not using synthesizeMouseAtCenter here because the element we want clicked on
    // is in the shadow DOM and therefore requires using a function 1st argument
    // to BrowserTestUtils.synthesizeMouseAtCenter but we need to pass an
    // arbitrary selector. See bug 1557489 for more info. As a workaround, this
    // manually calculates the position to click.
    let { x, y } = await SpecialPowers.spawn(
      browser,
      [selector],
      async menuItemSelector => {
        let menuButton = content.document.querySelector("menu-button");
        let prefsItem = menuButton.shadowRoot.querySelector(menuItemSelector);
        return prefsItem.getBoundingClientRect();
      }
    );
    await BrowserTestUtils.synthesizeMouseAtPoint(x + 5, y + 5, {}, browser);

    info("waiting for new tab to get opened");
    let newTab = await promiseNewTab;
    Assert.ok(true, "New tab opened to" + urlFinal);

    BrowserTestUtils.removeTab(newTab);
  }
});