summaryrefslogtreecommitdiff
path: root/browser/devtools/webconsole/test/browser_webconsole_split_persist.js
blob: d9116f2b1ceb1040ac931b911a732c9b0e9eb5e0 (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
/*
 * Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/
 */

function test() {
  info("Test that the split console state is persisted");

  let toolbox;
  let TEST_URI = "data:text/html;charset=utf-8,<p>Web Console test for splitting</p>";

  Task.spawn(runner).then(finish);

  function* runner() {
    info("Opening a tab while there is no user setting on split console pref");
    let {tab} = yield loadTab(TEST_URI);
    let target = TargetFactory.forTab(tab);
    toolbox = yield gDevTools.showToolbox(target, "inspector");

    ok(!toolbox.splitConsole, "Split console is hidden by default.");
    ok(!isCommandButtonChecked(), "Split console button is unchecked by default.");
    yield toggleSplitConsoleWithEscape();
    ok(toolbox.splitConsole, "Split console is now visible.");
    ok(isCommandButtonChecked(), "Split console button is now checked.");
    ok(getVisiblePrefValue(), "Visibility pref is true");

    is(getHeightPrefValue(), toolbox.webconsolePanel.height, "Panel height matches the pref");
    toolbox.webconsolePanel.height = 200;

    yield toolbox.destroy();

    info("Opening a tab while there is a true user setting on split console pref");
    ({tab} = yield loadTab(TEST_URI));
    target = TargetFactory.forTab(tab);
    toolbox = yield gDevTools.showToolbox(target, "inspector");

    ok(toolbox.splitConsole, "Split console is visible by default.");
    ok(isCommandButtonChecked(), "Split console button is checked by default.");
    is(getHeightPrefValue(), 200, "Height is set based on panel height after closing");

    // Use the binding element since jsterm.inputNode is a XUL textarea element.
    let activeElement = getActiveElement(toolbox.doc);
    activeElement = activeElement.ownerDocument.getBindingParent(activeElement);
    let inputNode = toolbox.getPanel("webconsole").hud.jsterm.inputNode;
    is(activeElement, inputNode, "Split console input is focused by default");

    toolbox.webconsolePanel.height = 1;
    ok (toolbox.webconsolePanel.clientHeight > 1,
        "The actual height of the console is bound with a min height");

    toolbox.webconsolePanel.height = 10000;
    ok (toolbox.webconsolePanel.clientHeight < 10000,
        "The actual height of the console is bound with a max height");

    yield toggleSplitConsoleWithEscape();
    ok(!toolbox.splitConsole, "Split console is now hidden.");
    ok(!isCommandButtonChecked(), "Split console button is now unchecked.");
    ok(!getVisiblePrefValue(), "Visibility pref is false");

    yield toolbox.destroy();

    is(getHeightPrefValue(), 10000, "Height is set based on panel height after closing");


    info("Opening a tab while there is a false user setting on split console pref");
    ({tab} = yield loadTab(TEST_URI));
    target = TargetFactory.forTab(tab);
    toolbox = yield gDevTools.showToolbox(target, "inspector");

    ok(!toolbox.splitConsole, "Split console is hidden by default.");
    ok(!getVisiblePrefValue(), "Visibility pref is false");

    yield toolbox.destroy();
  }

  function getActiveElement(doc) {
    let activeElement = doc.activeElement;
    while (activeElement && activeElement.contentDocument) {
      activeElement = activeElement.contentDocument.activeElement;
    }
    return activeElement;
  }

  function getVisiblePrefValue() {
    return Services.prefs.getBoolPref("devtools.toolbox.splitconsoleEnabled");
  }

  function getHeightPrefValue() {
    return Services.prefs.getIntPref("devtools.toolbox.splitconsoleHeight");
  }

  function isCommandButtonChecked() {
    return toolbox.doc.querySelector("#command-button-splitconsole").
      hasAttribute("checked");
  }

  function toggleSplitConsoleWithEscape() {
    let onceSplitConsole = toolbox.once("split-console");
    let contentWindow = toolbox.frame.contentWindow;
    contentWindow.focus();
    EventUtils.sendKey("ESCAPE", contentWindow);
    return onceSplitConsole;
  }

  function finish() {
    toolbox = TEST_URI = null;
    Services.prefs.clearUserPref("devtools.toolbox.splitconsoleEnabled");
    Services.prefs.clearUserPref("devtools.toolbox.splitconsoleHeight");
    finishTest();
  }
}