tor-browser

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

browser_toolbox_show_toolbox_tool_ready.js (1921B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 const URL =
      7  "data:text/html;charset=utf8,test for showToolbox called while tool is opened";
      8 const lazyToolId = "testtool1";
      9 
     10 registerCleanupFunction(() => {
     11  gDevTools.unregisterTool(lazyToolId);
     12 });
     13 
     14 // Delay to wait before the lazy tool should finish
     15 const TOOL_OPEN_DELAY = 3000;
     16 
     17 class LazyDevToolsPanel extends DevToolPanel {
     18  constructor(iframeWindow, toolbox) {
     19    super(iframeWindow, toolbox);
     20  }
     21 
     22  async open() {
     23    await wait(TOOL_OPEN_DELAY);
     24    return this;
     25  }
     26 }
     27 
     28 function isPanelReady(toolbox, toolId) {
     29  return !!toolbox.getPanel(toolId);
     30 }
     31 
     32 /**
     33 * Test that showToolbox will wait until the specified tool is completely read before
     34 * returning. See Bug 1543907.
     35 */
     36 add_task(async function automaticallyBindTexbox() {
     37  info(
     38    "Registering a tool with an input field and making sure the context menu works"
     39  );
     40 
     41  gDevTools.registerTool({
     42    id: lazyToolId,
     43    isToolSupported: () => true,
     44    url: CHROME_URL_ROOT + "doc_lazy_tool.html",
     45    label: "Lazy",
     46    build(iframeWindow, toolbox) {
     47      this.panel = new LazyDevToolsPanel(iframeWindow, toolbox);
     48      return this.panel.open();
     49    },
     50  });
     51 
     52  const tab = await addTab(URL);
     53  const toolbox = await openToolboxForTab(tab, "inspector");
     54  const onLazyToolReady = toolbox.once(lazyToolId + "-ready");
     55  toolbox.selectTool(lazyToolId);
     56 
     57  info("Wait until toolbox considers the current tool is the lazy tool");
     58  await waitUntil(() => toolbox.currentToolId == lazyToolId);
     59 
     60  ok(!isPanelReady(toolbox, lazyToolId), "lazyTool should not be ready yet");
     61  await gDevTools.showToolboxForTab(tab, { toolId: lazyToolId });
     62  ok(
     63    isPanelReady(toolbox, lazyToolId),
     64    "lazyTool should not ready after showToolbox"
     65  );
     66 
     67  // Make sure lazyTool is ready before leaving the test.
     68  await onLazyToolReady;
     69 });