tor-browser

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

browser_devtools_api_destroy.js (1865B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 // Tests devtools API
      5 
      6 function test() {
      7  addTab("about:blank").then(runTests);
      8 }
      9 
     10 async function runTests(tab) {
     11  const toolDefinition = {
     12    id: "testTool",
     13    visibilityswitch: "devtools.testTool.enabled",
     14    isToolSupported: () => true,
     15    url: "about:blank",
     16    label: "someLabel",
     17    build(iframeWindow, toolbox) {
     18      return new Promise(resolve => {
     19        executeSoon(() => {
     20          resolve({
     21            target: toolbox.target,
     22            toolbox,
     23            isReady: true,
     24            destroy() {},
     25          });
     26        });
     27      });
     28    },
     29  };
     30 
     31  gDevTools.registerTool(toolDefinition);
     32 
     33  const collectedEvents = [];
     34 
     35  gDevTools
     36    .showToolboxForTab(tab, { toolId: toolDefinition.id })
     37    .then(function (toolbox) {
     38      const panel = toolbox.getPanel(toolDefinition.id);
     39      ok(panel, "Tool open");
     40 
     41      gDevTools.once("toolbox-destroy", () => {
     42        collectedEvents.push("toolbox-destroy");
     43      });
     44 
     45      gDevTools.once(toolDefinition.id + "-destroy", () => {
     46        collectedEvents.push("gDevTools-" + toolDefinition.id + "-destroy");
     47      });
     48 
     49      toolbox.once("destroy", () => {
     50        collectedEvents.push("destroy");
     51      });
     52 
     53      toolbox.once(toolDefinition.id + "-destroy", () => {
     54        collectedEvents.push("toolbox-" + toolDefinition.id + "-destroy");
     55      });
     56 
     57      toolbox.destroy().then(function () {
     58        is(
     59          collectedEvents.join(":"),
     60          "toolbox-destroy:destroy:gDevTools-testTool-destroy:toolbox-testTool-destroy",
     61          "Found the right amount of collected events."
     62        );
     63 
     64        gDevTools.unregisterTool(toolDefinition.id);
     65        gBrowser.removeCurrentTab();
     66 
     67        executeSoon(function () {
     68          finish();
     69        });
     70      });
     71    });
     72 }