summaryrefslogtreecommitdiffstats
path: root/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_thisfirefox.js
blob: 3f673df7585d493ae7282d71938caef798632e15 (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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

const EXPECTED_TARGET_PANES = [
  "Tabs",
  "Temporary Extensions",
  "Extensions",
  "Service Workers",
  "Shared Workers",
  "Other Workers",
];

/**
 * Check that the This Firefox runtime page contains the expected categories if
 * the preference to enable local tab debugging is true.
 */
add_task(async function testThisFirefoxWithLocalTab() {
  const { document, tab, window } = await openAboutDebugging({
    enableLocalTabs: true,
  });
  await selectThisFirefoxPage(document, window.AboutDebugging.store);

  // Expect all target panes to be displayed including tabs.
  await checkThisFirefoxTargetPanes(document, EXPECTED_TARGET_PANES);

  await removeTab(tab);
});

/**
 * Check that the This Firefox runtime page contains the expected categories if
 * the preference to enable local tab debugging is false.
 */
add_task(async function testThisFirefoxWithoutLocalTab() {
  const { document, tab, window } = await openAboutDebugging({
    enableLocalTabs: false,
  });
  await selectThisFirefoxPage(document, window.AboutDebugging.store);

  // Expect all target panes but tabs to be displayed.
  const expectedTargetPanesWithoutTabs = EXPECTED_TARGET_PANES.filter(
    p => p !== "Tabs"
  );
  await checkThisFirefoxTargetPanes(document, expectedTargetPanesWithoutTabs);

  await removeTab(tab);
});

/**
 * Check that the tab which is discarded keeps the state after open the aboutdebugging.
 */
add_task(async function testThisFirefoxKeepDiscardedTab() {
  const targetTab = await addTab("https://example.com/");
  const blankTab = await addTab("about:blank");
  targetTab.ownerGlobal.gBrowser.discardBrowser(targetTab);

  const { document, tab, window } = await openAboutDebugging({
    enableLocalTabs: false,
  });
  await selectThisFirefoxPage(document, window.AboutDebugging.store);

  ok(!targetTab.linkedPanel, "The target tab is still discarded");

  await removeTab(blankTab);
  await removeTab(targetTab);
  await removeTab(tab);
});

/**
 * Check that the Temporary Extensions is hidden if "xpinstall.enabled" is set to false.
 */
add_task(async function testThisFirefoxWithXpinstallDisabled() {
  await pushPref("xpinstall.enabled", false);

  const { document, tab, window } = await openAboutDebugging();
  await selectThisFirefoxPage(document, window.AboutDebugging.store);

  // Expect all target panes but temporary extensions to be displayed.
  const expectedTargetPanesWithXpinstallDisabled = EXPECTED_TARGET_PANES.filter(
    p => p !== "Temporary Extensions"
  );
  await checkThisFirefoxTargetPanes(
    document,
    expectedTargetPanesWithXpinstallDisabled
  );

  await removeTab(tab);
});

async function checkThisFirefoxTargetPanes(doc, expectedTargetPanes) {
  const win = doc.ownerGlobal;
  // Check that the selected sidebar item is "This Firefox"/"This Nightly"/...
  const selectedSidebarItem = doc.querySelector(".qa-sidebar-item-selected");
  ok(selectedSidebarItem, "An item is selected in the sidebar");

  const thisFirefoxString = getThisFirefoxString(win);
  is(
    selectedSidebarItem.textContent,
    thisFirefoxString,
    "The selected sidebar item is " + thisFirefoxString
  );

  const paneTitlesEls = doc.querySelectorAll(".qa-debug-target-pane-title");
  is(
    paneTitlesEls.length,
    expectedTargetPanes.length,
    "This Firefox has the expected number of debug target categories"
  );

  const paneTitles = [...paneTitlesEls].map(el => el.textContent);

  for (let i = 0; i < expectedTargetPanes.length; i++) {
    const expectedPaneTitle = expectedTargetPanes[i];
    const actualPaneTitle = paneTitles[i];
    ok(
      actualPaneTitle.startsWith(expectedPaneTitle),
      `Expected debug target category found: ${expectedPaneTitle}`
    );
  }
}