summaryrefslogtreecommitdiffstats
path: root/toolkit/mozapps/extensions/test/browser/browser_sidebar_preferences_button.js
blob: 91a631bca24805fc2cf779e19c9d07664afa0766 (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
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

add_task(async function testNoOtherTabsPresent() {
  let addonsWin = await loadInitialView("extension");
  let preferencesButton =
    addonsWin.document.querySelector("#preferencesButton");

  let preferencesPromise = BrowserTestUtils.waitForNewTab(
    gBrowser,
    "about:preferences"
  );

  preferencesButton.click();

  let preferencesTab = await preferencesPromise;

  is(
    gBrowser.currentURI.spec,
    "about:preferences",
    "about:preferences should open if neither it nor about:settings are present"
  );

  gBrowser.removeTab(preferencesTab);

  await closeView(addonsWin);
});

async function ensurePreferencesButtonFocusesTab(expectedUri) {
  let addonsWin = await loadInitialView("extension");
  let preferencesButton =
    addonsWin.document.querySelector("#preferencesButton");

  let tabCountBeforeClick = gBrowser.tabCount;
  preferencesButton.click();
  let tabCountAfterClick = gBrowser.tabCount;

  is(
    tabCountAfterClick,
    tabCountBeforeClick,
    "preferences button should not open new tabs"
  );
  is(
    gBrowser.currentURI.spec,
    expectedUri,
    "the correct tab should be focused"
  );

  addonsWin.focus();
  await closeView(addonsWin);
}

add_task(async function testAboutPreferencesPresent() {
  await BrowserTestUtils.withNewTab("about:preferences", async () => {
    await ensurePreferencesButtonFocusesTab("about:preferences");
  });
});

add_task(async function testAboutSettingsPresent() {
  await BrowserTestUtils.withNewTab("about:settings", async () => {
    await ensurePreferencesButtonFocusesTab("about:settings");
  });
});

add_task(async function testAboutSettingsAndPreferencesPresent() {
  await BrowserTestUtils.withNewTab("about:settings", async () => {
    await BrowserTestUtils.withNewTab("about:preferences", async () => {
      await ensurePreferencesButtonFocusesTab("about:settings");
    });
  });
});