File: test_panel_list_accessibility.html

package info (click to toggle)
thunderbird 1%3A115.16.0esr-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 3,476,252 kB
  • sloc: cpp: 6,972,150; javascript: 5,209,211; ansic: 3,507,222; python: 1,137,609; asm: 432,531; xml: 205,149; java: 175,761; sh: 116,485; makefile: 22,152; perl: 13,971; objc: 12,561; yacc: 4,583; pascal: 2,840; lex: 1,720; ruby: 1,075; exp: 762; sql: 666; awk: 580; php: 436; lisp: 430; sed: 70; csh: 10
file content (79 lines) | stat: -rw-r--r-- 2,653 bytes parent folder | download | duplicates (6)
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
<!DOCTYPE HTML>
<!-- Any copyright is dedicated to the Public Domain.
     http://creativecommons.org/publicdomain/zero/1.0/ -->
<html>
<head>
  <title>Test Panel List Accessibility</title>
  <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
  <script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
  <script type="text/javascript" src="head.js"></script>
  <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" />
</head>
<body>
<p id="display"></p>

<div id="content">
  <button id="anchor-button">Open</button>
  <panel-list id="panel-list">
    <panel-item>one</panel-item>
    <panel-item>two</panel-item>
    <panel-item>three</panel-item>
  </panel-list>
</div>

<pre id="test">
<script class="testbody" type="application/javascript">
const {BrowserTestUtils} = ChromeUtils.importESModule("resource://testing-common/BrowserTestUtils.sys.mjs");
let anchorButton, panelList, panelItems;


add_setup(function setup() {
  // Clear out the other elements so only our test content is on the page.
  panelList = document.getElementById("panel-list");
  panelItems = [...panelList.children];
  anchorButton = document.getElementById("anchor-button");
  anchorButton.addEventListener("click", e => panelList.toggle(e));
});

add_task(async function testItemFocusOnOpen() {
  ok(document.activeElement, "There is an active element");
  ok(!document.activeElement.closest("panel-list"), "Focus isn't in the list");

  let shown = BrowserTestUtils.waitForEvent(panelList, "shown");
  synthesizeMouseAtCenter(anchorButton, {});
  await shown;

  let hidden = BrowserTestUtils.waitForEvent(panelList, "hidden");
  synthesizeKey("Escape", {});
  await hidden;

  // Focus shouldn't enter the list on a click.
  ok(!document.activeElement.closest("panel-list"), "Focus isn't in the list");

  shown = BrowserTestUtils.waitForEvent(panelList, "shown");
  anchorButton.focus();
  synthesizeKey(" ", {});
  await shown;

  // Focus enters list with keyboard interaction.
  is(document.activeElement, panelItems[0], "The first item is focused");

  hidden = BrowserTestUtils.waitForEvent(panelList, "hidden");
  synthesizeKey("Escape", {});
  await hidden;

  is(document.activeElement, anchorButton, "The anchor is focused again on close");
});

add_task(async function testAriaAttributes() {
  is(panelList.getAttribute("role"), "menu", "The panel is a menu");

  is(panelItems.length, 3, "There are 3 items");
  for (let item of panelItems) {
    is(item.button.getAttribute("role"), "menuitem", "button is a menuitem");
  }
});
</script>
</pre>
</body>
</html>