summaryrefslogtreecommitdiff
path: root/accessible/tests/mochitest/treeupdate/test_contextmenu.xul
blob: 5b31e013635968aa4cc654ee06fc33e0e29fd4f3 (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
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
                 type="text/css"?>

<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
        title="menu tree and events">

  <script type="application/javascript"
          src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" />
  <script type="application/javascript"
          src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>

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

  <script type="application/javascript">
  <![CDATA[

    function openMenu(aID, aTree)
    {
      this.eventSeq = [
        new invokerChecker(EVENT_MENUPOPUP_START, getNode(aID))
      ];

      this.invoke = function openMenu_invoke()
      {
        var button = getNode("button");
        getNode(aID).openPopup(button, "after_start", 0, 0, true, false);
      }

      this.finalCheck = function openMenu_finalCheck(aEvent)
      {
        testAccessibleTree(aID, aTree);
      }

      this.getID = function openMenu_getID()
      {
        return "open menu " + prettyName(aID);
      }
    }

    function selectNextMenuItem(aID)
    {
      this.eventSeq = [
        new invokerChecker(EVENT_FOCUS, getNode(aID))
      ];

      this.invoke = function selectMenuItem_invoke()
      {
        synthesizeKey("VK_DOWN", { });
      }

      this.getID = function selectMenuItem_getID()
      {
        return "select menuitem " + prettyName(aID);
      }
    }
    
    function openSubMenu(aSubMenuID, aItemID, aMenuID, aTree)
    {
      this.eventSeq = [
        new invokerChecker(EVENT_FOCUS, getNode(aItemID)),
      ];

      this.invoke = function openSubMenu_invoke()
      {
        synthesizeKey("VK_RETURN", { });
      }

      this.finalCheck = function openSubMenu_finalCheck(aEvent)
      {
        testAccessibleTree(aMenuID, aTree);
      }

      this.getID = function openSubMenu_getID()
      {
        return "open submenu " + prettyName(aSubMenuID) + " focusing item " + prettyName(aItemID);
      }
    }

    function closeSubMenu(aSubMenuID, aItemID)
    {
      this.eventSeq = [
        new invokerChecker(EVENT_FOCUS, getNode(aItemID)),
      ];

      this.invoke = function closeSubMenu_invoke()
      {
        synthesizeKey("VK_ESCAPE", { });
      }

      this.getID = function closeSubMenu_getID()
      {
        return "close submenu " + prettyName(aSubMenuID) + " focusing item " + prettyName(aItemID);
      }
    }

    function closeMenu(aID)
    {
      this.eventSeq = [
        new invokerChecker(EVENT_MENUPOPUP_END, getNode(aID))
      ];

      this.invoke = function closeMenu_invoke()
      {
        synthesizeKey("VK_ESCAPE", { });
      }

      this.getID = function closeMenu_getID()
      {
        return "close menu " + prettyName(aID);
      }
    }

    //gA11yEventDumpToConsole = true;
    //enableLogging("tree,verbose");

    var gQueue = null;
    var gContextTree = {};

    // Linux and Windows menu trees discrepancy: bug 527646.

    /**
     * Return the context menu tree before submenus were open.
     */
    function getMenuTree1()
    {
      if (LINUX || SOLARIS) {
        var tree = {
          role: ROLE_MENUPOPUP,
          children: [
            {
              name: "item0",
              role: ROLE_MENUITEM,
              children: []
            },
            {
              name: "item1",
              role: ROLE_MENUITEM,
              children: []
            },
            {
              name: "item2",
              role: ROLE_PARENT_MENUITEM,
              children: [ ]
            }
          ]
        };
        return tree;
      }

      // Windows
      var tree = {
        role: ROLE_MENUPOPUP,
        children: [
          {
            name: "item0",
            role: ROLE_MENUITEM,
            children: []
          },
          {
            name: "item1",
            role: ROLE_MENUITEM,
            children: []
          },
          {
            name: "item2",
            role: ROLE_PARENT_MENUITEM,
            children: [
              {
                name: "item2",
                role: ROLE_MENUPOPUP,
                children: [ ]
              }
            ]
          }
        ]
      };
      return tree;
    }

    /**
     * Return context menu tree when submenu was open.
     */
    function getMenuTree2()
    {
      var tree = getMenuTree1();
      if (LINUX || SOLARIS) {
        var submenuTree =
        {
          name: "item2.0",
          role: ROLE_PARENT_MENUITEM,
          children: [ ]
        };
        tree.children[2].children.push(submenuTree);
        return tree;
      }

      // Windows
      var submenuTree =
      {
        name: "item2.0",
        role: ROLE_PARENT_MENUITEM,
        children: [
          {
            name: "item2.0",
            role: ROLE_MENUPOPUP,
            children: [ ]
          }
        ]
      };

      tree.children[2].children[0].children.push(submenuTree);
      return tree;
    }

    /**
     * Return context menu tree when subsub menu was open.
     */
    function getMenuTree3()
    {
      var tree = getMenuTree2();
      var subsubmenuTree =
      {
        name: "item2.0.0",
        role: ROLE_MENUITEM,
        children: []
      };

      if (LINUX || SOLARIS)
        tree.children[2].children[0].children.push(subsubmenuTree);
      else
        tree.children[2].children[0].children[0].children[0].children.push(subsubmenuTree);

      return tree;
    }


    function doTests()
    {
      gQueue = new eventQueue();

      // Check initial empty tree
      testAccessibleTree("context", { MENUPOPUP: [] });

      // Open context menu and check that menu item accesibles are created.
      gQueue.push(new openMenu("context", getMenuTree1()));

      // Select items and check focus event on them.
      gQueue.push(new selectNextMenuItem("item0"));
      gQueue.push(new selectNextMenuItem("item1"));
      gQueue.push(new selectNextMenuItem("item2"));

      // Open sub menu and check menu accessible tree and focus event.
      gQueue.push(new openSubMenu("submenu2", "item2.0",
                                  "context", getMenuTree2()));
      gQueue.push(new openSubMenu("submenu2.0", "item2.0.0",
                                  "context", getMenuTree3()));

      // Close submenus and check that focus goes to parent.
      gQueue.push(new closeSubMenu("submenu2.0", "item2.0"));
      gQueue.push(new closeSubMenu("submenu2", "item2"));

      gQueue.push(new closeMenu("context"));

      gQueue.invoke(); // Will call SimpleTest.finish();
    }

    SimpleTest.waitForExplicitFinish();
    addA11yLoadEvent(doTests);
  ]]>
  </script>

  <hbox flex="1" style="overflow: auto;">
  <body xmlns="http://www.w3.org/1999/xhtml">
    <a target="_blank"
       href="https://bugzilla.mozilla.org/show_bug.cgi?id=630194"
       title="Update accessible tree when opening the menu popup">
      Mozilla Bug 630194
    </a>
    <a target="_blank"
       href="https://bugzilla.mozilla.org/show_bug.cgi?id=630486"
       title="Don't force accessible creation for popup children.">
      Mozilla Bug 630486
    </a>
  <p id="display"></p>
    <div id="content" style="display: none">
    </div>
    <pre id="test">
    </pre>
  </body>

    <vbox flex="1">

      <menupopup id="context">
        <menuitem id="item0" label="item0"/>
        <menuitem id="item1" label="item1"/>
        <menu id="item2" label="item2">
          <menupopup id="submenu2">
            <menu id="item2.0" label="item2.0">
              <menupopup id="submenu2.0">
                <menuitem id="item2.0.0" label="item2.0.0"/>
              </menupopup>
            </menu>
          </menupopup>
        </menu>
      </menupopup>

      <button context="context" id="button">btn</button>
    </vbox>
  </hbox>
</window>