summaryrefslogtreecommitdiffstats
path: root/accessible/tests/mochitest/events/test_attrchange.html
blob: edd9195ddd94599868c93403a0c6e4ace0bd5e9e (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
103
104
105
106
107
<html>

<head>
  <title>Accessible attr change event testing</title>

  <link rel="stylesheet" type="text/css"
        href="chrome://mochikit/content/tests/SimpleTest/test.css" />

  <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>

  <script type="application/javascript"
          src="../common.js"></script>
  <script type="application/javascript"
          src="../promisified-events.js"></script>
  <script type="application/javascript"
          src="../role.js"></script>
  <script type="application/javascript"
          src="../states.js"></script>

  <script type="application/javascript">
    async function testGotAttrChange(elem, name, value) {
      const waitFor = waitForEvent(EVENT_OBJECT_ATTRIBUTE_CHANGED, elem);
      if (value) {
        document.getElementById(elem).setAttribute(name, value);
      } else {
        document.getElementById(elem).removeAttribute(name);
      }
      await waitFor;
    }

    async function doTests() {
      info("Removing summary attr");
      // after summary is removed, we should have a layout table
      await testGotAttrChange(
        "sampleTable",
        "summary",
        null
        );

      info("Setting abbr attr");
      // after abbr is set we should have a data table again
      await testGotAttrChange(
        "cellOne",
        "abbr",
        "hello world"
        );

      info("Removing abbr attr");
      // after abbr is removed we should have a layout table again
      await testGotAttrChange(
        "cellOne",
        "abbr",
        null
        );

      info("Setting scope attr");
      // after scope is set we should have a data table again
      await testGotAttrChange(
        "cellOne",
        "scope",
        "col"
        );

      info("Removing scope attr");
      // remove scope should give layout
      await testGotAttrChange(
        "cellOne",
        "scope",
        null
        );

      info("Setting headers attr");
      // add headers attr should give data
      await testGotAttrChange(
        "cellThree",
        "headers",
        "cellOne"
        );

      info("Removing headers attr");
      // remove headers attr should give layout
      await testGotAttrChange(
        "cellThree",
        "headers",
        null
        );

      SimpleTest.finish();
    }

    SimpleTest.waitForExplicitFinish();
    addA11yLoadEvent(doTests);
  </script>
</head>
<body>
  <table id="sampleTable" summary="example summary">
      <tr>
        <td id="cellOne">cell1</td>
        <td>cell2</td>
      </tr>
      <tr>
        <td id="cellThree">cell3</td>
        <td>cell4</td>
      </tr>
    </table>
</body>
</html>