tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

browser_aboutdebugging_thisfirefox.js (3841B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 const EXPECTED_TARGET_PANES = [
      7  "Tabs",
      8  "Temporary Extensions",
      9  "Extensions",
     10  "Service Workers",
     11  "Shared Workers",
     12  "Other Workers",
     13 ];
     14 
     15 /**
     16 * Check that the This Firefox runtime page contains the expected categories if
     17 * the preference to enable local tab debugging is true.
     18 */
     19 add_task(async function testThisFirefoxWithLocalTab() {
     20  const { document, tab, window } = await openAboutDebugging({
     21    enableLocalTabs: true,
     22  });
     23  await selectThisFirefoxPage(document, window.AboutDebugging.store);
     24 
     25  // Expect all target panes to be displayed including tabs.
     26  await checkThisFirefoxTargetPanes(document, EXPECTED_TARGET_PANES);
     27 
     28  await removeTab(tab);
     29 });
     30 
     31 /**
     32 * Check that the This Firefox runtime page contains the expected categories if
     33 * the preference to enable local tab debugging is false.
     34 */
     35 add_task(async function testThisFirefoxWithoutLocalTab() {
     36  const { document, tab, window } = await openAboutDebugging({
     37    enableLocalTabs: false,
     38  });
     39  await selectThisFirefoxPage(document, window.AboutDebugging.store);
     40 
     41  // Expect all target panes but tabs to be displayed.
     42  const expectedTargetPanesWithoutTabs = EXPECTED_TARGET_PANES.filter(
     43    p => p !== "Tabs"
     44  );
     45  await checkThisFirefoxTargetPanes(document, expectedTargetPanesWithoutTabs);
     46 
     47  await removeTab(tab);
     48 });
     49 
     50 /**
     51 * Check that the tab which is discarded keeps the state after open the aboutdebugging.
     52 */
     53 add_task(async function testThisFirefoxKeepDiscardedTab() {
     54  const targetTab = await addTab("https://example.com/");
     55  const blankTab = await addTab("about:blank");
     56  targetTab.ownerGlobal.gBrowser.discardBrowser(targetTab);
     57 
     58  const { document, tab, window } = await openAboutDebugging({
     59    enableLocalTabs: false,
     60  });
     61  await selectThisFirefoxPage(document, window.AboutDebugging.store);
     62 
     63  ok(!targetTab.linkedPanel, "The target tab is still discarded");
     64 
     65  await removeTab(blankTab);
     66  await removeTab(targetTab);
     67  await removeTab(tab);
     68 });
     69 
     70 /**
     71 * Check that the Temporary Extensions is hidden if "xpinstall.enabled" is set to false.
     72 */
     73 add_task(async function testThisFirefoxWithXpinstallDisabled() {
     74  await pushPref("xpinstall.enabled", false);
     75 
     76  const { document, tab, window } = await openAboutDebugging();
     77  await selectThisFirefoxPage(document, window.AboutDebugging.store);
     78 
     79  // Expect all target panes but temporary extensions to be displayed.
     80  const expectedTargetPanesWithXpinstallDisabled = EXPECTED_TARGET_PANES.filter(
     81    p => p !== "Temporary Extensions"
     82  );
     83  await checkThisFirefoxTargetPanes(
     84    document,
     85    expectedTargetPanesWithXpinstallDisabled
     86  );
     87 
     88  await removeTab(tab);
     89 });
     90 
     91 async function checkThisFirefoxTargetPanes(doc, expectedTargetPanes) {
     92  const win = doc.ownerGlobal;
     93  // Check that the selected sidebar item is "This Firefox"/"This Nightly"/...
     94  const selectedSidebarItem = doc.querySelector(".qa-sidebar-item-selected");
     95  ok(selectedSidebarItem, "An item is selected in the sidebar");
     96 
     97  const thisFirefoxString = getThisFirefoxString(win);
     98  is(
     99    selectedSidebarItem.textContent,
    100    thisFirefoxString,
    101    "The selected sidebar item is " + thisFirefoxString
    102  );
    103 
    104  const paneTitlesEls = doc.querySelectorAll(".qa-debug-target-pane-title");
    105  is(
    106    paneTitlesEls.length,
    107    expectedTargetPanes.length,
    108    "This Firefox has the expected number of debug target categories"
    109  );
    110 
    111  const paneTitles = [...paneTitlesEls].map(el => el.textContent);
    112 
    113  for (let i = 0; i < expectedTargetPanes.length; i++) {
    114    const expectedPaneTitle = expectedTargetPanes[i];
    115    const actualPaneTitle = paneTitles[i];
    116    ok(
    117      actualPaneTitle.startsWith(expectedPaneTitle),
    118      `Expected debug target category found: ${expectedPaneTitle}`
    119    );
    120  }
    121 }