summaryrefslogtreecommitdiffstats
path: root/devtools/client/framework/test/browser_new_activation_workflow.js
blob: 4092bf1a742173e92704113f063c3786c4dc1052 (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
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

// Tests devtools API

var toolbox, target;

var tempScope = {};

function test() {
  addTab("about:blank").then(function (aTab) {
    target = TargetFactory.forTab(gBrowser.selectedTab);
    loadWebConsole(aTab).then(function () {
      console.log("loaded");
    });
  });
}

function loadWebConsole(aTab) {
  ok(gDevTools, "gDevTools exists");

  return gDevTools.showToolbox(target, "webconsole").then(function (aToolbox) {
    toolbox = aToolbox;
    checkToolLoading();
  });
}

function checkToolLoading() {
  is(toolbox.currentToolId, "webconsole", "The web console is selected");
  ok(toolbox.isReady, "toolbox is ready");

  selectAndCheckById("jsdebugger").then(function () {
    selectAndCheckById("styleeditor").then(function () {
      testToggle();
    });
  });
}

function selectAndCheckById(id) {
  return toolbox.selectTool(id).then(function () {
    let tab = toolbox.doc.getElementById("toolbox-tab-" + id);
    is(tab.hasAttribute("selected"), true, "The " + id + " tab is selected");
  });
}

function testToggle() {
  toolbox.once("destroyed", () => {
    // Cannot reuse a target after it's destroyed.
    target = TargetFactory.forTab(gBrowser.selectedTab);
    gDevTools.showToolbox(target, "styleeditor").then(function (aToolbox) {
      toolbox = aToolbox;
      is(toolbox.currentToolId, "styleeditor", "The style editor is selected");
      finishUp();
    });
  });

  toolbox.destroy();
}

function finishUp() {
  toolbox.destroy().then(function () {
    toolbox = null;
    target = null;
    gBrowser.removeCurrentTab();
    finish();
  });
}