summaryrefslogtreecommitdiffstats
path: root/browser/components/customizableui/test/browser_1008559_anchor_undo_restore.js
blob: 56657914baef1cc1aecaa608d9406c5cbe0684cb (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
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

const kAnchorAttribute = "cui-anchorid";

/**
 * Check that anchor gets set correctly when moving an item from the panel to the toolbar
 * using 'undo'
 */
add_task(function*() {
  yield startCustomizing();
  let button = document.getElementById("history-panelmenu");
  is(button.getAttribute(kAnchorAttribute), "PanelUI-menu-button",
     "Button (" + button.id + ") starts out with correct anchor");

  let navbar = document.getElementById("nav-bar").customizationTarget;
  simulateItemDrag(button, navbar);
  is(CustomizableUI.getPlacementOfWidget(button.id).area, "nav-bar",
     "Button (" + button.id + ") ends up in nav-bar");

  ok(!button.hasAttribute(kAnchorAttribute),
     "Button (" + button.id + ") has no anchor in toolbar");

  let resetButton = document.getElementById("customization-reset-button");
  ok(!resetButton.hasAttribute("disabled"), "Should be able to reset now.");
  yield gCustomizeMode.reset();

  is(button.getAttribute(kAnchorAttribute), "PanelUI-menu-button",
     "Button (" + button.id + ") has anchor again");

  let undoButton = document.getElementById("customization-undo-reset-button");
  ok(!undoButton.hasAttribute("disabled"), "Should be able to undo now.");
  yield gCustomizeMode.undoReset();

  ok(!button.hasAttribute(kAnchorAttribute),
     "Button (" + button.id + ") once again has no anchor in toolbar");

  yield gCustomizeMode.reset();

  yield endCustomizing();
});


/**
 * Check that anchor gets set correctly when moving an item from the panel to the toolbar
 * using 'reset'
 */
add_task(function*() {
  yield startCustomizing();
  let button = document.getElementById("bookmarks-menu-button");
  ok(!button.hasAttribute(kAnchorAttribute),
     "Button (" + button.id + ") has no anchor in toolbar");

  let panel = document.getElementById("PanelUI-contents");
  simulateItemDrag(button, panel);
  is(CustomizableUI.getPlacementOfWidget(button.id).area, "PanelUI-contents",
     "Button (" + button.id + ") ends up in panel");
  is(button.getAttribute(kAnchorAttribute), "PanelUI-menu-button",
     "Button (" + button.id + ") has correct anchor in the panel");

  let resetButton = document.getElementById("customization-reset-button");
  ok(!resetButton.hasAttribute("disabled"), "Should be able to reset now.");
  yield gCustomizeMode.reset();

  ok(!button.hasAttribute(kAnchorAttribute),
     "Button (" + button.id + ") once again has no anchor in toolbar");

  yield endCustomizing();
});