tor-browser

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

browser_dbg-features-tabs.js (3085B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
      4 
      5 /**
      6 * This test focuses on the Tabs component, where we display all opened sources.
      7 */
      8 
      9 "use strict";
     10 
     11 const testServer = createVersionizedHttpTestServer(
     12  "../examples/sourcemaps-reload-uncompressed"
     13 );
     14 const TEST_URL = testServer.urlFor("index.html");
     15 
     16 add_task(async function () {
     17  // We open against a blank page and only then navigate to the test page
     18  // so that sources aren't GC-ed before opening the debugger.
     19  // When we (re)load a page while the debugger is opened, the debugger
     20  // will force all sources to be held in memory.
     21  const dbg = await initDebuggerWithAbsoluteURL("about:blank");
     22 
     23  await navigateToAbsoluteURL(dbg, TEST_URL, ...INTEGRATION_TEST_PAGE_SOURCES);
     24 
     25  info("Wait for all sources to be displayed in the source tree");
     26  let displayedSources;
     27  await waitFor(() => {
     28    displayedSources = dbg.selectors.getDisplayedSourcesList();
     29    return displayedSources.length == INTEGRATION_TEST_PAGE_SOURCES.length;
     30  }, "Got the expected number of sources from the selectors");
     31 
     32  // Open each visible source in tabs
     33  const uniqueUrls = new Set();
     34  for (const source of displayedSources) {
     35    info(`Opening '${source.url}'`);
     36    await selectSource(dbg, source);
     37    uniqueUrls.add(source.url);
     38  }
     39 
     40  // Some sources are loaded from the same URL and only one tab will be opened for them
     41  is(countTabs(dbg), uniqueUrls.size, "Got a tab for each distinct source URL");
     42 
     43  invokeInTab("breakInEval");
     44  await waitFor(
     45    () => countTabs(dbg) == uniqueUrls.size + 1,
     46    "Wait for the tab for the new evaled source"
     47  );
     48  await resume(dbg);
     49 
     50  invokeInTab("breakInEval");
     51  await waitFor(
     52    () => countTabs(dbg) == uniqueUrls.size + 2,
     53    "Wait for yet another tab for the second evaled source"
     54  );
     55  await resume(dbg);
     56 
     57  await reload(dbg, ...INTEGRATION_TEST_PAGE_SOURCES);
     58 
     59  await waitFor(
     60    () => countTabs(dbg) == uniqueUrls.size,
     61    "Wait for tab count to be fully restored"
     62  );
     63 
     64  is(
     65    countTabs(dbg),
     66    uniqueUrls.size,
     67    "Still get the same number of tabs after reload"
     68  );
     69 
     70  await selectSource(dbg, "query.js?x=1");
     71  // Ensure focusing the window, otherwise copyToTheClipboard doesn't emit "copy" event.
     72  dbg.panel.panelWin.focus();
     73 
     74  info("Open the current active tab context menu");
     75  const waitForOpen = waitForContextMenu(dbg);
     76  rightClickElement(dbg, "activeTab");
     77  await waitForOpen;
     78  info("Trigger copy to source context menu");
     79  await waitForClipboardPromise(
     80    () => selectContextMenuItem(dbg, `#node-menu-copy-source`),
     81    `function query() {console.log("query x=1");}\n`
     82  );
     83 
     84  // Update displayed sources, so that we pass the right source objects to closeTab
     85  displayedSources = dbg.selectors.getDisplayedSourcesList();
     86  for (const source of displayedSources) {
     87    info(`Closing '${source.url}'`);
     88    await closeTab(dbg, source);
     89  }
     90 
     91  is(countTabs(dbg), 0, "All tabs are closed");
     92 });