File: test_moz_box_button.html

package info (click to toggle)
thunderbird 1%3A143.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 4,703,968 kB
  • sloc: cpp: 7,770,492; javascript: 5,943,842; ansic: 3,918,754; python: 1,418,263; xml: 653,354; asm: 474,045; java: 183,079; sh: 111,238; makefile: 20,410; perl: 14,359; objc: 13,059; yacc: 4,583; pascal: 3,405; lex: 1,720; ruby: 999; exp: 762; sql: 715; awk: 580; php: 436; lisp: 430; sed: 69; csh: 10
file content (218 lines) | stat: -rw-r--r-- 6,937 bytes parent folder | download | duplicates (11)
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
<!doctype html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>MozBoxButton Tests</title>
    <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
    <script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
    <link rel="stylesheet" href="chrome://global/skin/in-content/common.css" />
    <link
      rel="stylesheet"
      href="chrome://mochikit/content/tests/SimpleTest/test.css"
    />
    <script
      type="module"
      src="chrome://global/content/elements/moz-box-button.mjs"
    ></script>
    <script src="lit-test-helpers.js"></script>
    <script>
      let html;
      let testHelpers = new LitTestHelpers();

      add_setup(async function setup() {
        ({ html } = await testHelpers.setupLit());
        let templateFn = attrs => html`
          <moz-box-button ${attrs}></moz-box-button>
        `;
        testHelpers.setupTests({ templateFn });
      });

      add_task(async function testMozBoxButtonProperties() {
        const TEST_LABEL = "this is a test";
        let labelledTemplate = testHelpers.templateFn({ label: TEST_LABEL });
        let renderTarget = await testHelpers.renderTemplate(labelledTemplate);
        let button = renderTarget.firstElementChild;

        ok(button, "The box button renders.");
        ok(
          button.navIcon,
          "The box button has an icon indicating the type of navigation that happens on click."
        );
        is(
          button.navIcon.src,
          "chrome://global/skin/icons/arrow-right.svg",
          "The button uses the expected icon."
        );

        is(button.label, TEST_LABEL, "The box button has the expected label.");
        is(
          button.labelEl.textContent.trim(),
          TEST_LABEL,
          "The box button label is rendered."
        );

        const TEST_DESCRIPTION = "This is a description";
        button.description = TEST_DESCRIPTION;
        await button.updateComplete;

        is(
          button.descriptionEl.textContent.trim(),
          TEST_DESCRIPTION,
          "The button supports setting a description."
        );

        const ICON_SRC = "chrome://global/skin/icons/edit-copy.svg";
        button.iconSrc = ICON_SRC;
        await button.updateComplete;

        is(
          button.iconEl.getAttribute("src"),
          ICON_SRC,
          "The button supports setting an icon."
        );
      });

      add_task(async function testMozBoxButtonEvents() {
        let seenEvents = [];

        let renderTarget = await testHelpers.renderTemplate();
        let button = renderTarget.firstElementChild;
        button.addEventListener("click", e => seenEvents.push(e));

        synthesizeMouseAtCenter(button, {});
        await TestUtils.waitForTick();

        is(
          seenEvents.length,
          1,
          "MozBoxButton emitted the expected number of events."
        );
        is(seenEvents[0].type, "click", "MozBoxButton emitted a click event.");
      });

      add_task(async function testMozBoxButtonKeyboardFocus() {
        let focusTemplate = html`
          <button id="first">Button before</button>
          <moz-box-button id="box" label="I'm the box button"></moz-box-button>
          <button id="last">Button after</button>
        `;
        let renderTarget = await testHelpers.renderTemplate(focusTemplate);
        let firstButton = renderTarget.firstElementChild;

        firstButton.focus();
        is(document.activeElement, firstButton, "The first button is focused.");
        synthesizeKey("KEY_Tab", {});

        let mozBoxButton = document.getElementById("box");
        is(
          document.activeElement,
          mozBoxButton,
          "The MozBoxButton receives focus."
        );

        synthesizeKey("KEY_Tab", {});
        let lastButton = document.getElementById("last");
        is(
          document.activeElement,
          lastButton,
          "Focus moves from the MozBoxButton."
        );
      });

      add_task(async function testMozBoxButtonDisabled() {
        let {
          children: [button],
        } = await testHelpers.renderTemplate();
        is(button.disabled, false, "MozBoxButton is enabled by default.");
        is(button.buttonEl.disabled, false, "Inner button element is enabled.");

        button.disabled = true;
        await button.updateComplete;

        is(
          button.buttonEl.disabled,
          true,
          "Inner button element gets disabled when MozBoxButton is disabled."
        );
      });

      add_task(async function testMozBoxButtonAccesskey() {
        let accesskey = "t";
        let accesskeyTemplate = html`
          <moz-box-button
            label="I have an accesskey"
            accesskey=${accesskey}
          ></moz-box-button>
          <moz-box-button label="I don't...yet"></moz-box-button>
        `;
        let {
          children: [firstButton, secondButton],
        } = await testHelpers.renderTemplate(accesskeyTemplate);

        let seenEvents = [];

        function trackEvent(event) {
          seenEvents.push(event.type);
        }

        [firstButton, secondButton].forEach(button => {
          button.addEventListener("click", trackEvent);
        });

        isnot(
          document.activeElement,
          firstButton,
          "firstButton button is not focused."
        );
        isnot(
          firstButton.shadowRoot.activeElement,
          firstButton.buttonEl,
          "Inner button element is not focused."
        );

        let accessKeyDetails = navigator.platform.includes("Mac")
          ? { altKey: true, ctrlKey: true }
          : { altKey: true, shiftKey: true };
        synthesizeKey(accesskey, accessKeyDetails);

        is(
          document.activeElement,
          firstButton,
          "First button recieves focus after accesskey is pressed."
        );
        is(
          firstButton.shadowRoot.activeElement,
          firstButton.buttonEl,
          "Inner button input element is focused after accesskey is pressed."
        );
        is(seenEvents.length, 1, "One event was triggered.");
        is(seenEvents[0], "click", "The first button was clicked.");

        secondButton.setAttribute("accesskey", accesskey);
        await secondButton.updateComplete;

        synthesizeKey(accesskey, accessKeyDetails);

        is(
          document.activeElement,
          secondButton,
          "Focus cycles between buttons with the same accesskey."
        );

        synthesizeKey(accesskey, accessKeyDetails);

        is(
          document.activeElement,
          firstButton,
          "Focus cycles between buttons with the same accesskey."
        );
        is(seenEvents.length, 1, "No additional click events were triggered.");
      });
    </script>
  </head>
  <body>
    <p id="display"></p>
    <div id="content" style="display: none"></div>
    <pre id="test"></pre>
  </body>
</html>