summaryrefslogtreecommitdiffstats
path: root/devtools/client/framework/test/browser_toolbox_toolbar_reorder_by_dnd.js
blob: 9ef82ca6e9a7c6a24c7ce56d6805876593971c22 (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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

// Test for following reordering operation:
// * DragAndDrop the target component to back
// * DragAndDrop the target component to front
// * DragAndDrop the target component over the starting of the tab
// * DragAndDrop the target component over the ending of the tab
// * Mouse was out from the document while dragging
// * Select overflowed item, then DnD that
//
// This test is on the assumption which default toolbar has following tools.
//   * inspector
//   * webconsole
//   * jsdebugger
//   * styleeditor
//   * performance
//   * memory
//   * netmonitor
//   * storage
//   * accessibility
//   * application

const { Toolbox } = require("resource://devtools/client/framework/toolbox.js");

const TEST_STARTING_ORDER = [
  "inspector",
  "webconsole",
  "jsdebugger",
  "styleeditor",
  "performance",
  "memory",
  "netmonitor",
  "storage",
  "accessibility",
  "application",
];
const TEST_DATA = [
  {
    description: "DragAndDrop the target component to back",
    dragTarget: "webconsole",
    dropTarget: "jsdebugger",
    expectedOrder: [
      "inspector",
      "jsdebugger",
      "webconsole",
      "styleeditor",
      "performance",
      "memory",
      "netmonitor",
      "storage",
      "accessibility",
      "application",
    ],
  },
  {
    description: "DragAndDrop the target component to front",
    dragTarget: "webconsole",
    dropTarget: "inspector",
    expectedOrder: [
      "webconsole",
      "inspector",
      "jsdebugger",
      "styleeditor",
      "performance",
      "memory",
      "netmonitor",
      "storage",
      "accessibility",
      "application",
    ],
  },
  {
    description:
      "DragAndDrop the target component over the starting of the tab",
    dragTarget: "netmonitor",
    passedTargets: [
      "memory",
      "performance",
      "styleeditor",
      "jsdebugger",
      "webconsole",
      "inspector",
    ],
    dropTarget: "#toolbox-buttons-start",
    expectedOrder: [
      "netmonitor",
      "inspector",
      "webconsole",
      "jsdebugger",
      "styleeditor",
      "performance",
      "memory",
      "storage",
      "accessibility",
      "application",
    ],
  },
  {
    description: "DragAndDrop the target component over the ending of the tab",
    dragTarget: "webconsole",
    passedTargets: [
      "jsdebugger",
      "styleeditor",
      "performance",
      "memory",
      "netmonitor",
      "storage",
    ],
    dropTarget: "#toolbox-buttons-end",
    expectedOrder: [
      "inspector",
      "jsdebugger",
      "styleeditor",
      "performance",
      "memory",
      "netmonitor",
      "storage",
      "accessibility",
      "application",
      "webconsole",
    ],
  },
];

add_task(async function () {
  // Enable the Application panel (atm it's only available on Nightly)
  await pushPref("devtools.application.enabled", true);

  const tab = await addTab("about:blank");
  const toolbox = await openToolboxForTab(
    tab,
    "inspector",
    Toolbox.HostType.BOTTOM
  );

  const originalPreference = Services.prefs.getCharPref(
    "devtools.toolbox.tabsOrder"
  );
  const win = getWindow(toolbox);
  const { outerWidth: originalWindowWidth, outerHeight: originalWindowHeight } =
    win;
  registerCleanupFunction(() => {
    Services.prefs.setCharPref(
      "devtools.toolbox.tabsOrder",
      originalPreference
    );
    win.resizeTo(originalWindowWidth, originalWindowHeight);
  });

  for (const testData of TEST_DATA) {
    info(`Test for '${testData.description}'`);
    prepareToolTabReorderTest(toolbox, TEST_STARTING_ORDER);
    await dndToolTab(
      toolbox,
      testData.dragTarget,
      testData.dropTarget,
      testData.passedTargets
    );
    assertToolTabOrder(toolbox, testData.expectedOrder);
    assertToolTabSelected(toolbox, testData.dragTarget);
    assertToolTabPreferenceOrder(testData.expectedOrder);
  }

  info("Test with overflowing tabs");
  prepareToolTabReorderTest(toolbox, TEST_STARTING_ORDER);
  await resizeWindow(toolbox, 800);
  await toolbox.selectTool("storage");
  const dragTarget = "storage";
  const dropTarget = "inspector";
  const expectedOrder = [
    "storage",
    "inspector",
    "webconsole",
    "jsdebugger",
    "styleeditor",
    "performance",
    "memory",
    "netmonitor",
    "accessibility",
    "application",
  ];
  await dndToolTab(toolbox, dragTarget, dropTarget);
  assertToolTabSelected(toolbox, dragTarget);
  assertToolTabPreferenceOrder(expectedOrder);
});