summaryrefslogtreecommitdiffstats
path: root/accessible/tests/mochitest/treeupdate/test_textleaf.html
blob: f0181dd754363ad3a0fe756c53d96719023df95e (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
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
<!DOCTYPE html>
<html>

<head>
  <title>Test accessible recreation</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="../role.js"></script>
  <script type="application/javascript"
          src="../events.js"></script>

  <script type="application/javascript">

    // //////////////////////////////////////////////////////////////////////////
    // Invokers

    function textLeafUpdate(aID, aIsTextLeafLinkable) {
      this.node = getNode(aID);

      this.eventSeq = [
        new invokerChecker(EVENT_REORDER, this.node.parentNode),
      ];

      this.finalCheck = function textLeafUpdate_finalCheck() {
        var textLeaf = getAccessible(this.node).firstChild;
        is(textLeaf.actionCount, (aIsTextLeafLinkable ? 1 : 0),
           "Wrong action numbers!");
      };
    }

    function setOnClickAttr(aID) {
      var node = getNode(aID);
      node.setAttribute("onclick", "alert(3);");
      var textLeaf = getAccessible(node).firstChild;
      is(textLeaf.actionCount, 1, "setOnClickAttr: wrong action numbers!");
    }

    function removeOnClickAttr(aID) {
      var node = getNode(aID);
      node.removeAttribute("onclick");
      var textLeaf = getAccessible(node).firstChild;
      is(textLeaf.actionCount, 0,
         "removeOnClickAttr: wrong action numbers!");
    }

    function setOnClickNRoleAttrs(aID) {
      this.__proto__ = new textLeafUpdate(aID, true);

      this.invoke = function setOnClickAttr_invoke() {
        this.node.setAttribute("role", "link");
        this.node.setAttribute("onclick", "alert(3);");
      };

      this.getID = function setOnClickAttr_getID() {
        return "make " + prettyName(aID) + " linkable";
      };
    }

    function removeTextData(aID, aRole) {
      this.containerNode = getNode(aID);
      this.textNode = this.containerNode.firstChild;

      this.eventSeq = [
        new invokerChecker(EVENT_REORDER, this.containerNode),
      ];

      this.invoke = function removeTextData_invoke() {
        var tree = {
          role: aRole,
          children: [
            {
              role: ROLE_TEXT_LEAF,
              name: "text",
            },
          ],
        };
        testAccessibleTree(this.containerNode, tree);

        this.textNode.data = "";
      };

      this.finalCheck = function removeTextData_finalCheck() {
        var tree = {
          role: aRole,
          children: [],
        };
        testAccessibleTree(this.containerNode, tree);
      };

      this.getID = function removeTextData_finalCheck() {
        return "remove text data of text node inside '" + aID + "'.";
      };
    }

    // //////////////////////////////////////////////////////////////////////////
    // Test

    // gA11yEventDumpID = "eventdump"; // debug stuff
    // gA11yEventDumpToConsole = true;

    var gQueue = null;

    function doTest() {
      // adds onclick on element, text leaf should inherit its action
      setOnClickAttr("div");
      // remove onclick attribute, text leaf shouldn't have any action
      removeOnClickAttr("div");

      // Call rest of event tests.
      gQueue = new eventQueue();

      // set onclick attribute making span accessible, it's inserted into tree
      // and adopts text leaf accessible, text leaf should have an action
      gQueue.push(new setOnClickNRoleAttrs("span"));

      // text data removal of text node should remove its text accessible
      gQueue.push(new removeTextData("p", ROLE_PARAGRAPH));
      gQueue.push(new removeTextData("pre", ROLE_TEXT_CONTAINER));

      gQueue.invoke(); // SimpleTest.finish() will be called in the end
    }

    SimpleTest.waitForExplicitFinish();
    addA11yLoadEvent(doTest);
  </script>
</head>
<body>

  <a target="_blank"
     title="Clean up the code of accessible initialization and binding to the tree"
     href="https://bugzilla.mozilla.org/show_bug.cgi?id=545465">
    Mozilla Bug 545465
  </a>
  <a target="_blank"
     title="Make sure accessible tree is correct when rendered text is changed"
     href="https://bugzilla.mozilla.org/show_bug.cgi?id=625652">
    Mozilla Bug 625652
  </a>
  <a target="_blank"
     title="Remove text accesible getting no text inside a preformatted area"
     href="https://bugzilla.mozilla.org/show_bug.cgi?id=706335">
    Mozilla Bug 706335
  </a>

  <p id="display"></p>
  <div id="content" style="display: none"></div>
  <pre id="test">
  </pre>

  <div id="container">
    <div id="div">div</div>
    <span id="span">span</span>
  </div>

  <p id="p">text</p>
  <pre id="pre">text</pre>

  <div id="eventdump"></div>
</body>
</html>