summaryrefslogtreecommitdiffstats
path: root/devtools/client/framework/test/browser_devtools_api_destroy.js
blob: 736455df65bd3998a5dceefedf55a5291075ac6c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

// Tests devtools API

function test() {
  addTab("about:blank").then(runTests);
}

async function runTests(aTab) {
  const toolDefinition = {
    id: "testTool",
    visibilityswitch: "devtools.testTool.enabled",
    isToolSupported: () => true,
    url: "about:blank",
    label: "someLabel",
    build(iframeWindow, toolbox) {
      return new Promise(resolve => {
        executeSoon(() => {
          resolve({
            target: toolbox.target,
            toolbox,
            isReady: true,
            destroy() {},
          });
        });
      });
    },
  };

  gDevTools.registerTool(toolDefinition);

  const collectedEvents = [];

  gDevTools
    .showToolboxForTab(aTab, { toolId: toolDefinition.id })
    .then(function (toolbox) {
      const panel = toolbox.getPanel(toolDefinition.id);
      ok(panel, "Tool open");

      gDevTools.once("toolbox-destroy", (toolbox, iframe) => {
        collectedEvents.push("toolbox-destroy");
      });

      gDevTools.once(toolDefinition.id + "-destroy", (toolbox, iframe) => {
        collectedEvents.push("gDevTools-" + toolDefinition.id + "-destroy");
      });

      toolbox.once("destroy", () => {
        collectedEvents.push("destroy");
      });

      toolbox.once(toolDefinition.id + "-destroy", () => {
        collectedEvents.push("toolbox-" + toolDefinition.id + "-destroy");
      });

      toolbox.destroy().then(function () {
        is(
          collectedEvents.join(":"),
          "toolbox-destroy:destroy:gDevTools-testTool-destroy:toolbox-testTool-destroy",
          "Found the right amount of collected events."
        );

        gDevTools.unregisterTool(toolDefinition.id);
        gBrowser.removeCurrentTab();

        executeSoon(function () {
          finish();
        });
      });
    });
}