summaryrefslogtreecommitdiffstats
path: root/browser/components/customizableui/test/browser_890140_orphaned_placeholders.js
blob: 84b126a9b6d97feb1c3663d3dcf523391cc2ff84 (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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
/* 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";

requestLongerTimeout(2);

// One orphaned item should have two placeholders next to it.
add_task(function*() {
  yield startCustomizing();

  if (isInDevEdition()) {
    CustomizableUI.addWidgetToArea("developer-button", CustomizableUI.AREA_PANEL);
    ok(!CustomizableUI.inDefaultState, "Should no longer be in default state.");
  }
  if (!isInDevEdition()) {
    ok(CustomizableUI.inDefaultState, "Should be in default state.");
  } else {
    ok(!CustomizableUI.inDefaultState, "Should not be in default state if on DevEdition.");
  }

  // This test relies on an exact number of widgets being in the panel.
  // Remove the sync-button to satisfy that. (bug 1229236)
  CustomizableUI.removeWidgetFromArea("sync-button");
  let panel = document.getElementById(CustomizableUI.AREA_PANEL);
  let placements = getAreaWidgetIds(CustomizableUI.AREA_PANEL);

  assertAreaPlacements(CustomizableUI.AREA_PANEL, placements);
  is(getVisiblePlaceholderCount(panel), 2, "Should only have 2 visible placeholders before exiting");

  yield endCustomizing();
  yield startCustomizing();
  is(getVisiblePlaceholderCount(panel), 2, "Should only have 2 visible placeholders after re-entering");

  if (isInDevEdition()) {
    CustomizableUI.addWidgetToArea("developer-button", CustomizableUI.AREA_NAVBAR, 2);
  }

  CustomizableUI.addWidgetToArea("sync-button", CustomizableUI.AREA_PANEL);
  ok(CustomizableUI.inDefaultState, "Should be in default state again.");
});

// Two orphaned items should have one placeholder next to them (case 1).
add_task(function*() {
  yield startCustomizing();

  if (isInDevEdition()) {
    CustomizableUI.addWidgetToArea("developer-button", CustomizableUI.AREA_PANEL);
  }

  // This test relies on an exact number of widgets being in the panel.
  // Remove the sync-button to satisfy that. (bug 1229236)
  CustomizableUI.removeWidgetFromArea("sync-button");

  let btn = document.getElementById("open-file-button");
  let panel = document.getElementById(CustomizableUI.AREA_PANEL);
  let placements = getAreaWidgetIds(CustomizableUI.AREA_PANEL);
  let placementsAfterAppend = placements;

  placementsAfterAppend = placements.concat(["open-file-button"]);
  simulateItemDrag(btn, panel);

  assertAreaPlacements(CustomizableUI.AREA_PANEL, placementsAfterAppend);

  ok(!CustomizableUI.inDefaultState, "Should not be in default state.");

  is(getVisiblePlaceholderCount(panel), 1, "Should only have 1 visible placeholder before exiting");

  yield endCustomizing();
  yield startCustomizing();
  is(getVisiblePlaceholderCount(panel), 1, "Should only have 1 visible placeholder after re-entering");

  let palette = document.getElementById("customization-palette");
  simulateItemDrag(btn, palette);

  btn = document.getElementById("open-file-button");
  simulateItemDrag(btn, palette);

  if (isInDevEdition()) {
    CustomizableUI.addWidgetToArea("developer-button", CustomizableUI.AREA_NAVBAR, 2);
  }

  CustomizableUI.addWidgetToArea("sync-button", CustomizableUI.AREA_PANEL);
  ok(CustomizableUI.inDefaultState, "Should be in default state again.");
});

// Two orphaned items should have one placeholder next to them (case 2).
add_task(function*() {
  yield startCustomizing();

  if (isInDevEdition()) {
    CustomizableUI.addWidgetToArea("developer-button", CustomizableUI.AREA_PANEL);
  }
  // This test relies on an exact number of widgets being in the panel.
  // Remove the sync-button to satisfy that. (bug 1229236)
  CustomizableUI.removeWidgetFromArea("sync-button");

  let btn = document.getElementById("add-ons-button");
  let btn2 = document.getElementById("developer-button");
  let panel = document.getElementById(CustomizableUI.AREA_PANEL);
  let palette = document.getElementById("customization-palette");
  let placements = getAreaWidgetIds(CustomizableUI.AREA_PANEL);

  let placementsAfterAppend = placements.filter(p => p != btn.id && p != btn2.id);
  simulateItemDrag(btn, palette);
  simulateItemDrag(btn2, palette);

  assertAreaPlacements(CustomizableUI.AREA_PANEL, placementsAfterAppend);
  ok(!CustomizableUI.inDefaultState, "Should no longer be in default state.");
  is(getVisiblePlaceholderCount(panel), 1, "Should only have 1 visible placeholder before exiting");

  yield endCustomizing();
  yield startCustomizing();
  is(getVisiblePlaceholderCount(panel), 1, "Should only have 1 visible placeholder after re-entering");

  simulateItemDrag(btn, panel);
  simulateItemDrag(btn2, panel);

  assertAreaPlacements(CustomizableUI.AREA_PANEL, placements);

  if (isInDevEdition()) {
    CustomizableUI.addWidgetToArea("developer-button", CustomizableUI.AREA_NAVBAR, 2);
  }

  CustomizableUI.addWidgetToArea("sync-button", CustomizableUI.AREA_PANEL);
  ok(CustomizableUI.inDefaultState, "Should be in default state again.");
});

// A wide widget at the bottom of the panel should have three placeholders after it.
add_task(function*() {
  yield startCustomizing();

  if (isInDevEdition()) {
    CustomizableUI.addWidgetToArea("developer-button", CustomizableUI.AREA_PANEL);
  }

  // This test relies on an exact number of widgets being in the panel.
  // Remove the sync-button to satisfy that. (bug 1229236)
  CustomizableUI.removeWidgetFromArea("sync-button");

  let btn = document.getElementById("edit-controls");
  let btn2 = document.getElementById("developer-button");
  let panel = document.getElementById(CustomizableUI.AREA_PANEL);
  let palette = document.getElementById("customization-palette");
  let placements = getAreaWidgetIds(CustomizableUI.AREA_PANEL);

  placements.pop();
  simulateItemDrag(btn2, palette);

  let placementsAfterAppend = placements.concat([placements.shift()]);
  simulateItemDrag(btn, panel);
  assertAreaPlacements(CustomizableUI.AREA_PANEL, placementsAfterAppend);
  ok(!CustomizableUI.inDefaultState, "Should no longer be in default state.");
  is(getVisiblePlaceholderCount(panel), 3, "Should have 3 visible placeholders before exiting");

  yield endCustomizing();
  yield startCustomizing();
  is(getVisiblePlaceholderCount(panel), 3, "Should have 3 visible placeholders after re-entering");

  simulateItemDrag(btn2, panel);

  let zoomControls = document.getElementById("zoom-controls");
  simulateItemDrag(btn, zoomControls);

  if (isInDevEdition()) {
    CustomizableUI.addWidgetToArea("developer-button", CustomizableUI.AREA_NAVBAR, 2);
  }

  CustomizableUI.addWidgetToArea("sync-button", CustomizableUI.AREA_PANEL);
  ok(CustomizableUI.inDefaultState, "Should be in default state again.");
});

// The default placements should have two placeholders at the bottom (or 1 in win8).
add_task(function*() {
  yield startCustomizing();
  let numPlaceholders = -1;

  if (isInDevEdition()) {
    numPlaceholders = 3;
  } else {
    numPlaceholders = 2;
  }

  let panel = document.getElementById(CustomizableUI.AREA_PANEL);
  ok(CustomizableUI.inDefaultState, "Should be in default state.");

  // This test relies on an exact number of widgets being in the panel.
  // Remove the sync-button to satisfy that. (bug 1229236)
  CustomizableUI.removeWidgetFromArea("sync-button");

  is(getVisiblePlaceholderCount(panel), numPlaceholders, "Should have " + numPlaceholders + " visible placeholders before exiting");

  yield endCustomizing();
  yield startCustomizing();
  is(getVisiblePlaceholderCount(panel), numPlaceholders, "Should have " + numPlaceholders + " visible placeholders after re-entering");

  CustomizableUI.addWidgetToArea("sync-button", CustomizableUI.AREA_PANEL);
  ok(CustomizableUI.inDefaultState, "Should still be in default state.");
});

add_task(function* asyncCleanup() {
  yield endCustomizing();
  yield resetCustomization();
});

function getVisiblePlaceholderCount(aPanel) {
  let visiblePlaceholders = aPanel.querySelectorAll(".panel-customization-placeholder:not([hidden=true])");
  return visiblePlaceholders.length;
}