summaryrefslogtreecommitdiffstats
path: root/devtools/client/webconsole/test/browser_console_hide_jsterm_when_devtools_chrome_enabled_false.js
blob: d3fdb08be81d92ef535e9b19c61451bd96985f7f (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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/* -*- 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/ */

/*
 * Bug 922161 - Hide Browser Console JS input field if devtools.chrome.enabled
 * is false.
 * when devtools.chrome.enabled then
 *   -browser console jsterm should be enabled
 *   -browser console object inspector properties should be set.
 *   -webconsole jsterm should be enabled
 *   -webconsole object inspector properties should be set.
 *
 * when devtools.chrome.enabled == false then
 *   -browser console jsterm should be disabled
 *   -browser console object inspector properties should not be set.
 *   -webconsole jsterm should be enabled
 *   -webconsole object inspector properties should be set.
 */

"use strict";

function testObjectInspectorPropertiesAreNotSet(variablesView) {
  is(variablesView.eval, null, "vview.eval is null");
  is(variablesView.switch, null, "vview.switch is null");
  is(variablesView.delete, null, "vview.delete is null");
}

function* getVariablesView(hud) {
  function openVariablesView(event, vview) {
    deferred.resolve(vview._variablesView);
  }

  let deferred = promise.defer();

  // Filter out other messages to ensure ours stays visible.
  hud.ui.filterBox.value = "browser_console_hide_jsterm_test";

  hud.jsterm.clearOutput();
  hud.jsterm.execute("new Object({ browser_console_hide_jsterm_test: true })");

  let [message] = yield waitForMessages({
    webconsole: hud,
    messages: [{
      text: "Object { browser_console_hide_jsterm_test: true }",
      category: CATEGORY_OUTPUT,
    }],
  });

  hud.jsterm.once("variablesview-fetched", openVariablesView);

  let anchor = [...message.matched][0].querySelector("a");

  executeSoon(() =>
    EventUtils.synthesizeMouse(anchor, 2, 2, {}, hud.iframeWindow)
  );

  return deferred.promise;
}

function testJSTermIsVisible(hud) {
  let inputContainer = hud.ui.window.document
                                    .querySelector(".jsterm-input-container");
  isnot(inputContainer.style.display, "none", "input is visible");
}

function testObjectInspectorPropertiesAreSet(variablesView) {
  isnot(variablesView.eval, null, "vview.eval is set");
  isnot(variablesView.switch, null, "vview.switch is set");
  isnot(variablesView.delete, null, "vview.delete is set");
}

function testJSTermIsNotVisible(hud) {
  let inputContainer = hud.ui.window.document
                                    .querySelector(".jsterm-input-container");
  is(inputContainer.style.display, "none", "input is not visible");
}

function* testRunner() {
  let browserConsole, webConsole, variablesView;

  Services.prefs.setBoolPref("devtools.chrome.enabled", true);

  browserConsole = yield HUDService.toggleBrowserConsole();
  variablesView = yield getVariablesView(browserConsole);
  testJSTermIsVisible(browserConsole);
  testObjectInspectorPropertiesAreSet(variablesView);

  let {tab: browserTab} = yield loadTab("data:text/html;charset=utf8,hello world");
  webConsole = yield openConsole(browserTab);
  variablesView = yield getVariablesView(webConsole);
  testJSTermIsVisible(webConsole);
  testObjectInspectorPropertiesAreSet(variablesView);
  yield closeConsole(browserTab);

  yield HUDService.toggleBrowserConsole();
  Services.prefs.setBoolPref("devtools.chrome.enabled", false);

  browserConsole = yield HUDService.toggleBrowserConsole();
  variablesView = yield getVariablesView(browserConsole);
  testJSTermIsNotVisible(browserConsole);
  testObjectInspectorPropertiesAreNotSet(variablesView);

  webConsole = yield openConsole(browserTab);
  variablesView = yield getVariablesView(webConsole);
  testJSTermIsVisible(webConsole);
  testObjectInspectorPropertiesAreSet(variablesView);
  yield closeConsole(browserTab);
}

function test() {
  Task.spawn(testRunner).then(finishTest);
}