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

add_task(function*() {
  const kNormalLabel = "Character Encoding";
  CustomizableUI.addWidgetToArea("characterencoding-button", CustomizableUI.AREA_NAVBAR);
  let characterEncoding = document.getElementById("characterencoding-button");
  const kOriginalLabel = characterEncoding.getAttribute("label");
  characterEncoding.setAttribute("label", "\u00ad" + kNormalLabel);
  CustomizableUI.addWidgetToArea("characterencoding-button", CustomizableUI.AREA_PANEL);

  yield PanelUI.show();

  is(characterEncoding.getAttribute("auto-hyphens"), "off",
     "Hyphens should be disabled if the ­ character is present in the label");
  let multilineText = document.getAnonymousElementByAttribute(characterEncoding, "class", "toolbarbutton-multiline-text");
  let multilineTextCS = getComputedStyle(multilineText);
  is(multilineTextCS.MozHyphens, "manual", "-moz-hyphens should be set to manual when the ­ character is present.")

  let hiddenPanelPromise = promisePanelHidden(window);
  PanelUI.toggle();
  yield hiddenPanelPromise;

  characterEncoding.setAttribute("label", kNormalLabel);

  yield PanelUI.show();

  isnot(characterEncoding.getAttribute("auto-hyphens"), "off",
        "Hyphens should not be disabled if the ­ character is not present in the label");
  multilineText = document.getAnonymousElementByAttribute(characterEncoding, "class", "toolbarbutton-multiline-text");
  multilineTextCS = getComputedStyle(multilineText);
  is(multilineTextCS.MozHyphens, "auto", "-moz-hyphens should be set to auto by default.")

  hiddenPanelPromise = promisePanelHidden(window);
  PanelUI.toggle();
  yield hiddenPanelPromise;

  characterEncoding.setAttribute("label", "\u00ad" + kNormalLabel);
  CustomizableUI.removeWidgetFromArea("characterencoding-button");
  yield startCustomizing();

  isnot(characterEncoding.getAttribute("auto-hyphens"), "off",
        "Hyphens should not be disabled when the widget is in the palette");

  gCustomizeMode.addToPanel(characterEncoding);
  is(characterEncoding.getAttribute("auto-hyphens"), "off",
     "Hyphens should be disabled if the ­ character is present in the label in customization mode");
  multilineText = document.getAnonymousElementByAttribute(characterEncoding, "class", "toolbarbutton-multiline-text");
  multilineTextCS = getComputedStyle(multilineText);
  is(multilineTextCS.MozHyphens, "manual", "-moz-hyphens should be set to manual when the ­ character is present in customization mode.")

  yield endCustomizing();

  CustomizableUI.addWidgetToArea("characterencoding-button", CustomizableUI.AREA_NAVBAR);
  ok(!characterEncoding.hasAttribute("auto-hyphens"),
     "Removing the widget from the panel should remove the auto-hyphens attribute");

  characterEncoding.setAttribute("label", kOriginalLabel);
});

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