summaryrefslogtreecommitdiffstats
path: root/devtools/client/inspector/compatibility/test/browser/browser_compatibility_event_panel-select.js
blob: 9aa845db0ddacfaac2e73c71a5550278efe31761 (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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

// Test the behavior when the panel is selected.

const TEST_URI = "<body style='background-color: lime;'><div>test</div></body>";
const TEST_ANOTHER_URI = "<body></body>";

const {
  COMPATIBILITY_UPDATE_SELECTED_NODE_START,
  COMPATIBILITY_UPDATE_TOP_LEVEL_TARGET_START,
} = require("resource://devtools/client/inspector/compatibility/actions/index.js");

add_task(async function () {
  info(
    "Check that the panel does not update when no changes occur while hidden"
  );

  await pushPref("devtools.inspector.activeSidebar", "");

  const tab = await addTab(_toDataURL(TEST_URI));
  const { inspector } = await openCompatibilityView();

  info("Select another sidebar panel");
  await _selectSidebarPanel(inspector, "changesview");

  info("Select the compatibility panel again");
  let isSelectedNodeUpdated = false;
  let isTopLevelTargetUpdated = false;
  waitForDispatch(
    inspector.store,
    COMPATIBILITY_UPDATE_SELECTED_NODE_START
  ).then(() => {
    isSelectedNodeUpdated = true;
  });
  waitForDispatch(
    inspector.store,
    COMPATIBILITY_UPDATE_TOP_LEVEL_TARGET_START
  ).then(() => {
    isTopLevelTargetUpdated = true;
  });

  await _selectSidebarPanel(inspector, "compatibilityview");

  // Check above both flags after taking enough time.
  await wait(1000);

  ok(!isSelectedNodeUpdated, "Avoid updating the selected node pane");
  ok(!isTopLevelTargetUpdated, "Avoid updating the top level target pane");

  await removeTab(tab);
});

add_task(async function () {
  info(
    "Check that the panel only updates for the selected node when the node is changed while the panel is hidden"
  );

  await pushPref("devtools.inspector.activeSidebar", "");

  const tab = await addTab(_toDataURL(TEST_URI));
  const { inspector } = await openCompatibilityView();

  info("Select another sidebar panel");
  await _selectSidebarPanel(inspector, "changesview");

  info("Select another node");
  await selectNode("div", inspector);

  info("Select the compatibility panel again");
  const onSelectedNodePaneUpdated = waitForUpdateSelectedNodeAction(
    inspector.store
  );
  let isTopLevelTargetUpdated = false;
  waitForDispatch(
    inspector.store,
    COMPATIBILITY_UPDATE_TOP_LEVEL_TARGET_START
  ).then(() => {
    isTopLevelTargetUpdated = true;
  });

  await _selectSidebarPanel(inspector, "compatibilityview");

  await onSelectedNodePaneUpdated;
  ok(true, "Update the selected node pane");
  ok(!isTopLevelTargetUpdated, "Avoid updating the top level target pane");

  await removeTab(tab);
});

add_task(async function () {
  info(
    "Check that both panes update when the top-level target changed while the panel is hidden"
  );

  await pushPref("devtools.inspector.activeSidebar", "");

  const tab = await addTab(_toDataURL(TEST_URI));
  const { inspector } = await openCompatibilityView();

  info("Select another sidebar panel");
  await _selectSidebarPanel(inspector, "changesview");

  info("Navigate to another page");
  BrowserTestUtils.loadURIString(
    tab.linkedBrowser,
    _toDataURL(TEST_ANOTHER_URI)
  );

  info("Select the compatibility panel again");
  const onSelectedNodePaneUpdated = waitForUpdateSelectedNodeAction(
    inspector.store
  );
  const onTopLevelTargetPaneUpdated = waitForUpdateTopLevelTargetAction(
    inspector.store
  );

  await _selectSidebarPanel(inspector, "compatibilityview");

  await onSelectedNodePaneUpdated;
  await onTopLevelTargetPaneUpdated;
  ok(true, "Update both panes");

  await removeTab(tab);
});

add_task(async function () {
  info(
    "Check that both panes update when a rule is changed changed while the panel is hidden"
  );

  await pushPref("devtools.inspector.activeSidebar", "");

  info("Disable 3 pane mode");
  await pushPref("devtools.inspector.three-pane-enabled", false);

  const tab = await addTab(_toDataURL(TEST_URI));
  const { inspector } = await openCompatibilityView();

  info("Select rule view");
  await _selectSidebarPanel(inspector, "ruleview");

  info("Change a rule");
  await togglePropStatusOnRuleView(inspector, 0, 0);

  info("Select the compatibility panel again");
  const onSelectedNodePaneUpdated = waitForUpdateSelectedNodeAction(
    inspector.store
  );
  const onTopLevelTargetPaneUpdated = waitForUpdateTopLevelTargetAction(
    inspector.store
  );

  await _selectSidebarPanel(inspector, "compatibilityview");

  await onSelectedNodePaneUpdated;
  await onTopLevelTargetPaneUpdated;
  ok(true, "Update both panes");

  await removeTab(tab);
});

async function _selectSidebarPanel(inspector, toolId) {
  const onSelected = inspector.sidebar.once(`${toolId}-selected`);
  inspector.sidebar.select(toolId);
  await onSelected;
}

function _toDataURL(content) {
  return "data:text/html;charset=utf-8," + encodeURIComponent(content);
}