summaryrefslogtreecommitdiffstats
path: root/devtools/client/inspector/test/browser_inspector_pane-toggle-05.js
blob: d2653639a01d032c6b9a16f50f1a9bc2f712cc72 (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
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

"use strict";

// Tests whether the initial selected tab is displayed when switched from 3 pane to 2 pane
// and back to 3 pane when no other tab is selected explicitly. Rule view is displayed
// immediately on toggling to 2 pane.
add_task(async function () {
  info(
    "Switch to 2 pane inspector and back to 3 pane to test whether the selected tab is used"
  );
  await pushPref("devtools.inspector.three-pane-enabled", true);

  const { inspector } = await openInspectorForURL("about:blank");

  inspector.sidebar.select("changesview");

  is(
    inspector.sidebar.getCurrentTabID(),
    "changesview",
    "Changes view should be the active sidebar"
  );

  info("Click on the toggle button to toggle OFF 3 pane inspector");
  await toggleSidebar(inspector);

  is(
    inspector.sidebar.getCurrentTabID(),
    "ruleview",
    "Rules view should be the active sidebar on toggle to 2 pane"
  );

  info("Click on the toggle button to toggle ON 3 pane inspector");
  await toggleSidebar(inspector);

  is(
    inspector.sidebar.getCurrentTabID(),
    "changesview",
    "Changes view should be the active sidebar again"
  );
});

// Tests whether the selected pane in 2 pane view is also used after toggling to 3 pane view.
add_task(async function () {
  info("Switch to 3 pane to test whether the selected pane is preserved");
  await pushPref("devtools.inspector.three-pane-enabled", false);

  const { inspector } = await openInspectorForURL("about:blank");

  inspector.sidebar.select("changesview");

  is(
    inspector.sidebar.getCurrentTabID(),
    "changesview",
    "Changes view should be the active sidebar"
  );

  info("Click on the toggle button to toggle ON 3 pane inspector");
  await toggleSidebar(inspector);

  is(
    inspector.sidebar.getCurrentTabID(),
    "changesview",
    "Changes view should still be the active sidebar"
  );
});

// Tests whether the selected pane is layout view, if rule view is selected before toggling to 3 pane.
add_task(async function () {
  info("Switch to 3 pane to test whether the selected pane is layout view");
  await pushPref("devtools.inspector.three-pane-enabled", false);

  const { inspector } = await openInspectorForURL("about:blank");

  inspector.sidebar.select("ruleview");

  is(
    inspector.sidebar.getCurrentTabID(),
    "ruleview",
    "Rules view should be the active sidebar in 2 pane"
  );

  info("Click on the toggle button to toggle ON 3 pane inspector");
  await toggleSidebar(inspector);

  is(
    inspector.sidebar.getCurrentTabID(),
    "layoutview",
    "Layout view should be the active sidebar in 3 pane"
  );
});

const toggleSidebar = async inspector => {
  const { panelDoc: doc } = inspector;
  const button = doc.querySelector(".sidebar-toggle");

  const onRuleViewAdded = inspector.once("ruleview-added");
  EventUtils.synthesizeMouseAtCenter(
    button,
    {},
    inspector.panelDoc.defaultView
  );
  await onRuleViewAdded;
};