summaryrefslogtreecommitdiffstats
path: root/browser/components/customizableui/test/browser_1008559_anchor_undo_restore.js
blob: a7da97cc959fb0c4c5b6c0040c84b4da307eeb5b (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
/* 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
 * and into the palette.
 */
add_task(async function () {
  CustomizableUI.addWidgetToArea(
    "history-panelmenu",
    CustomizableUI.AREA_FIXED_OVERFLOW_PANEL
  );
  await startCustomizing();
  let button = document.getElementById("history-panelmenu");
  is(
    button.getAttribute(kAnchorAttribute),
    "nav-bar-overflow-button",
    "Button (" + button.id + ") starts out with correct anchor"
  );

  let navbar = CustomizableUI.getCustomizationTarget(
    document.getElementById("nav-bar")
  );
  let onMouseUp = BrowserTestUtils.waitForEvent(navbar, "mouseup");
  simulateItemDrag(button, navbar);
  await onMouseUp;
  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"
  );

  CustomizableUI.addWidgetToArea(
    "history-panelmenu",
    CustomizableUI.AREA_FIXED_OVERFLOW_PANEL
  );

  is(
    button.getAttribute(kAnchorAttribute),
    "nav-bar-overflow-button",
    "Button (" + button.id + ") has anchor again"
  );

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

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

  await endCustomizing();
});

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

  let panel = document.getElementById(CustomizableUI.AREA_FIXED_OVERFLOW_PANEL);
  let onMouseUp = BrowserTestUtils.waitForEvent(panel, "mouseup");
  simulateItemDrag(button, panel);
  await onMouseUp;
  is(
    CustomizableUI.getPlacementOfWidget(button.id).area,
    CustomizableUI.AREA_FIXED_OVERFLOW_PANEL,
    "Button (" + button.id + ") ends up in panel"
  );
  is(
    button.getAttribute(kAnchorAttribute),
    "nav-bar-overflow-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.");
  await gCustomizeMode.reset();

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

  await endCustomizing();
});