summaryrefslogtreecommitdiffstats
path: root/devtools/client/inspector/test/browser_inspector_pane-toggle-02.js
blob: 132f0feb7f7d6e67682c971f742afd756663549f (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
/* Any copyright is dedicated to the Public Domain.
 http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

// Tests that the 3 pane toggle button can toggle on and off the inspector's 3 pane mode,
// and the 3 panes rendered are all of equal widths in the BOTTOM host.

add_task(async function () {
  info("Switch to 2 pane inspector to test the 3 pane toggle button behavior");
  await pushPref("devtools.inspector.three-pane-enabled", false);

  const { inspector } = await openInspectorForURL("about:blank");
  const { panelDoc: doc } = inspector;
  const button = doc.querySelector(".sidebar-toggle");
  const ruleViewSidebar =
    inspector.sidebarSplitBoxRef.current.startPanelContainer;
  const toolboxWidth = doc.getElementById("inspector-splitter-box").clientWidth;

  ok(
    button.classList.contains("pane-collapsed"),
    "The button is in collapsed state"
  );

  info("Click on the toggle button to toggle ON 3 pane inspector");
  let onRuleViewAdded = inspector.once("ruleview-added");
  EventUtils.synthesizeMouseAtCenter(
    button,
    {},
    inspector.panelDoc.defaultView
  );
  await onRuleViewAdded;

  info("Checking the state of the 3 pane inspector");
  let sidebarWidth = inspector.splitBox.state.width;
  const sidebarSplitBoxWidth = inspector.sidebarSplitBoxRef.current.state.width;
  ok(
    !button.classList.contains("pane-collapsed"),
    "The button is in expanded state"
  );
  ok(doc.getElementById("ruleview-panel"), "The rule view panel exist");
  is(
    inspector.sidebar.getCurrentTabID(),
    "layoutview",
    "Layout view is shown in the sidebar"
  );
  is(
    ruleViewSidebar.style.display,
    "block",
    "The split rule view sidebar is displayed"
  );
  is(sidebarWidth, (toolboxWidth * 2) / 3, "Got correct main split box width");
  is(
    sidebarSplitBoxWidth,
    toolboxWidth / 3,
    "Got correct sidebar split box width"
  );

  info("Click on the toggle button to toggle OFF the 3 pane inspector");
  onRuleViewAdded = inspector.once("ruleview-added");
  EventUtils.synthesizeMouseAtCenter(
    button,
    {},
    inspector.panelDoc.defaultView
  );
  await onRuleViewAdded;

  info("Checking the state of the 2 pane inspector");
  sidebarWidth = inspector.splitBox.state.width;
  ok(
    button.classList.contains("pane-collapsed"),
    "The button is in collapsed state"
  );
  is(
    inspector.sidebar.getCurrentTabID(),
    "ruleview",
    "Rule view is shown in the sidebar"
  );
  is(
    ruleViewSidebar.style.display,
    "none",
    "The split rule view sidebar is hidden"
  );
  is(sidebarWidth, sidebarSplitBoxWidth, "Got correct sidebar width");
});