tor-browser

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

browser_aboutdebugging_tab_zombietab.js (3677B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 let gUniqueCounter = 0;
      7 
      8 const triggeringPrincipal_base64 = E10SUtils.SERIALIZED_SYSTEMPRINCIPAL;
      9 
     10 const BROWSER_STATE_TABS = [
     11  "about:debugging",
     12  "data:text/html,<title>TEST_TAB_1</title>",
     13  "data:text/html,<title>TEST_TAB_2</title>",
     14  "data:text/html,<title>TEST_TAB_3</title>",
     15 ];
     16 const BROWSER_STATE = {
     17  windows: [
     18    {
     19      tabs: BROWSER_STATE_TABS.map(url => {
     20        return {
     21          entries: [{ url, triggeringPrincipal_base64 }],
     22          extData: { uniq: Date.now() + "-" + ++gUniqueCounter },
     23        };
     24      }),
     25      selected: 1,
     26    },
     27  ],
     28 };
     29 
     30 // Check that the inspect action is disabled for lazy/zombie tabs, such as the
     31 // ones created after a session restore.
     32 add_task(async function () {
     33  // This setup is normally handed by the openAboutDebugging helper, but here we
     34  // open about:debugging via session restore.
     35  silenceWorkerUpdates();
     36  await pushPref("devtools.aboutdebugging.local-tab-debugging", true);
     37 
     38  info("Restore 4 tabs including a selected about:debugging tab");
     39  const onBrowserSessionRestored = Promise.all([
     40    TestUtils.topicObserved("sessionstore-browser-state-restored"),
     41    BrowserTestUtils.waitForEvent(gBrowser.tabContainer, "SSTabRestored"),
     42  ]);
     43  SessionStore.setBrowserState(JSON.stringify(BROWSER_STATE));
     44  await onBrowserSessionRestored;
     45 
     46  const tab = gBrowser.selectedTab;
     47  const browser = tab.linkedBrowser;
     48  const doc = browser.contentDocument;
     49  const win = browser.contentWindow;
     50  const store = win.AboutDebugging.store;
     51 
     52  info("Wait until Connect page is displayed");
     53  await waitUntil(() => doc.querySelector(".qa-connect-page"));
     54 
     55  await selectThisFirefoxPage(doc, store);
     56 
     57  // Check that all inspect butttons are disabled.
     58  checkInspectButton("TEST_TAB_1", doc, { expectDisabled: true });
     59  checkInspectButton("TEST_TAB_2", doc, { expectDisabled: true });
     60  checkInspectButton("TEST_TAB_3", doc, { expectDisabled: true });
     61 
     62  info("Select the TEST_TAB_2 tab top restore it completely");
     63  const onTabRestored = BrowserTestUtils.waitForEvent(
     64    gBrowser.tabContainer,
     65    "SSTabRestored"
     66  );
     67  gBrowser.selectedTab = gBrowser.tabs[2];
     68  await onTabRestored;
     69 
     70  const onTabsSuccess = waitForDispatch(store, "REQUEST_TABS_SUCCESS");
     71 
     72  info("Select the about:debugging tab again");
     73  gBrowser.selectedTab = tab;
     74 
     75  info("Wait until the tabs update is finished");
     76  await onTabsSuccess;
     77 
     78  info("Wait until the inspect button for TEST_TAB_2 is enabled");
     79  await waitUntil(() => {
     80    const target = findDebugTargetByText("TEST_TAB_2", doc);
     81    if (!target) {
     82      // TEST_TAB_2 target might be missing while the tab target list updates.
     83      return false;
     84    }
     85 
     86    const button = target.querySelector(".qa-debug-target-inspect-button");
     87    return !button.disabled;
     88  });
     89 
     90  // Check that all inspect butttons are disabled, except for #2.
     91  checkInspectButton("TEST_TAB_1", doc, { expectDisabled: true });
     92  checkInspectButton("TEST_TAB_2", doc, { expectDisabled: false });
     93  checkInspectButton("TEST_TAB_3", doc, { expectDisabled: true });
     94 });
     95 
     96 function checkInspectButton(targetText, doc, { expectDisabled }) {
     97  const inspectButton = getInspectButton(targetText, doc);
     98  if (expectDisabled) {
     99    ok(inspectButton.disabled, `Inspect button is disabled for ${targetText}`);
    100  } else {
    101    ok(!inspectButton.disabled, `Inspect button is enabled for ${targetText}`);
    102  }
    103 }
    104 
    105 function getInspectButton(targetText, doc) {
    106  const targetElement = findDebugTargetByText(targetText, doc);
    107  return targetElement.querySelector(".qa-debug-target-inspect-button");
    108 }