summaryrefslogtreecommitdiffstats
path: root/browser/components/customizableui/test/browser_888817_currentset_updating.js
blob: 6e7c4e95a4a27214802f741b26939c8b7979aa0c (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
/* 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";

// Adding, moving and removing items should update the relevant currentset attributes
add_task(function*() {
  ok(CustomizableUI.inDefaultState, "Should be in the default state when we start");
  let personalbar = document.getElementById(CustomizableUI.AREA_BOOKMARKS);
  setToolbarVisibility(personalbar, true);
  ok(!CustomizableUI.inDefaultState, "Making the bookmarks toolbar visible takes it out of the default state");

  let navbar = document.getElementById(CustomizableUI.AREA_NAVBAR);
  personalbar = document.getElementById(CustomizableUI.AREA_BOOKMARKS);
  let navbarCurrentset = navbar.getAttribute("currentset") || navbar.currentSet;
  let personalbarCurrentset = personalbar.getAttribute("currentset") || personalbar.currentSet;

  let otherWin = yield openAndLoadWindow();
  let otherNavbar = otherWin.document.getElementById(CustomizableUI.AREA_NAVBAR);
  let otherPersonalbar = otherWin.document.getElementById(CustomizableUI.AREA_BOOKMARKS);

  CustomizableUI.moveWidgetWithinArea("home-button", 0);
  navbarCurrentset = "home-button," + navbarCurrentset.replace(",home-button", "");
  is(navbar.getAttribute("currentset"), navbarCurrentset,
     "Should have updated currentSet after move.");
  is(otherNavbar.getAttribute("currentset"), navbarCurrentset,
     "Should have updated other window's currentSet after move.");

  CustomizableUI.addWidgetToArea("home-button", CustomizableUI.AREA_BOOKMARKS);
  navbarCurrentset = navbarCurrentset.replace("home-button,", "");
  personalbarCurrentset = personalbarCurrentset + ",home-button";
  is(navbar.getAttribute("currentset"), navbarCurrentset,
     "Should have updated navbar currentSet after implied remove.");
  is(otherNavbar.getAttribute("currentset"), navbarCurrentset,
     "Should have updated other window's navbar currentSet after implied remove.");
  is(personalbar.getAttribute("currentset"), personalbarCurrentset,
     "Should have updated personalbar currentSet after add.");
  is(otherPersonalbar.getAttribute("currentset"), personalbarCurrentset,
     "Should have updated other window's personalbar currentSet after add.");

  CustomizableUI.removeWidgetFromArea("home-button");
  personalbarCurrentset = personalbarCurrentset.replace(",home-button", "");
  is(personalbar.getAttribute("currentset"), personalbarCurrentset,
     "Should have updated currentSet after remove.");
  is(otherPersonalbar.getAttribute("currentset"), personalbarCurrentset,
     "Should have updated other window's currentSet after remove.");

  yield promiseWindowClosed(otherWin);
  // Reset in asyncCleanup will put our button back for us.
});

add_task(function* asyncCleanup() {
  let personalbar = document.getElementById(CustomizableUI.AREA_BOOKMARKS);
  setToolbarVisibility(personalbar, false);
  yield resetCustomization();
});