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

const kToolbarName = "test-new-overflowable-toolbar";
const kTestWidgetPrefix = "test-widget-for-overflowable-toolbar-";

add_task(async function addOverflowingToolbar() {
  let originalWindowWidth = window.outerWidth;

  let widgetIds = [];
  registerCleanupFunction(() => {
    try {
      for (let id of widgetIds) {
        CustomizableUI.destroyWidget(id);
      }
    } catch (ex) {
      console.error(ex);
    }
  });

  for (let i = 0; i < 10; i++) {
    let id = kTestWidgetPrefix + i;
    widgetIds.push(id);
    let spec = {
      id,
      type: "button",
      removable: true,
      label: "test",
      tooltiptext: "" + i,
    };
    CustomizableUI.createWidget(spec);
  }

  let toolbarNode = createOverflowableToolbarWithPlacements(
    kToolbarName,
    widgetIds
  );
  assertAreaPlacements(kToolbarName, widgetIds);

  for (let id of widgetIds) {
    document.getElementById(id).style.minWidth = "200px";
  }

  isnot(
    toolbarNode.overflowable,
    null,
    "Toolbar should have overflowable controller"
  );
  isnot(
    CustomizableUI.getCustomizationTarget(toolbarNode),
    null,
    "Toolbar should have customization target"
  );
  isnot(
    CustomizableUI.getCustomizationTarget(toolbarNode),
    toolbarNode,
    "Customization target should not be toolbar node"
  );

  let oldChildCount =
    CustomizableUI.getCustomizationTarget(toolbarNode).childElementCount;
  let overflowableList = document.getElementById(
    kToolbarName + "-overflow-list"
  );
  let oldOverflowCount = overflowableList.childElementCount;

  isnot(oldChildCount, 0, "Toolbar should have non-overflowing widgets");

  window.resizeTo(kForceOverflowWidthPx, window.outerHeight);
  await TestUtils.waitForCondition(() =>
    toolbarNode.hasAttribute("overflowing")
  );
  ok(
    toolbarNode.hasAttribute("overflowing"),
    "Should have an overflowing toolbar."
  );
  ok(
    CustomizableUI.getCustomizationTarget(toolbarNode).childElementCount <
      oldChildCount,
    "Should have fewer children."
  );
  ok(
    overflowableList.childElementCount > oldOverflowCount,
    "Should have more overflowed widgets."
  );

  window.resizeTo(originalWindowWidth, window.outerHeight);
});

add_task(async function asyncCleanup() {
  removeCustomToolbars();
  await resetCustomization();
});