summaryrefslogtreecommitdiffstats
path: root/accessible/tests/mochitest/events/test_focus_general.xul
blob: f72834f399fc61b1d1b1b477c4844482b902e528 (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
<?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="Accessible focus event testing">

  <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="../role.js" />
  <script type="application/javascript"
          src="../states.js" />
  <script type="application/javascript"
          src="../events.js" />

  <script type="application/javascript">
    function getColorBtn(aBtnObj)
    {
      var colorpicker = aBtnObj.colorpicker;
      var container = colorpicker.firstChild;
      var btn = container.getChildAt(aBtnObj.btnIndex);
      return btn;
    }

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

    var gQueue = null;
    function doTests()
    {
      // Test focus events.
      gQueue = new eventQueue();

      gQueue.push(new synthFocus("textbox",
                                 new focusChecker(getNode("textbox").inputField)));
      gQueue.push(new synthFocus("textbox_multiline",
                                 new focusChecker(getNode("textbox_multiline").inputField)));
      gQueue.push(new synthFocus("scale"));
      gQueue.push(new synthFocusOnFrame("editabledoc"));
      gQueue.push(new synthFocus("radioclothes",
                                 new focusChecker("radiosweater")));
      gQueue.push(new synthDownKey("radiosweater",
                                   new focusChecker("radiojacket")));
      gQueue.push(new synthFocus("checkbox"));
      gQueue.push(new synthFocus("button"));
      gQueue.push(new synthFocus("checkbutton"));
      gQueue.push(new synthFocus("radiobutton"));

      // focus menubutton
      gQueue.push(new synthFocus("menubutton"));
      // click menubutton, open popup, focus stays on menu button
      gQueue.push(new synthClick("menubutton", new nofocusChecker()));
      // select first menu item ("item 1"), focus on menu item
      gQueue.push(new synthDownKey("menubutton", new focusChecker("mb_item1")));
      // choose select menu item, focus gets back to menubutton
      gQueue.push(new synthEnterKey("mb_item1", new focusChecker("menubutton")));
      // press enter to open popup, focus stays on menubutton
      gQueue.push(new synthEnterKey("menubutton", new nofocusChecker()));
      // select second menu item ("item 2"), focus on menu item
      gQueue.push(new synthUpKey("menubutton", new focusChecker("mb_item2")));

      // clicking on button having associated popup doesn't change a focus
      gQueue.push(new synthClick("popupbutton", new nofocusChecker()));
      // select first menu item ("item 1"), focus on menu item
      gQueue.push(new synthDownKey("popupbutton", new focusChecker("bp_item1")));
      // choose select menu item, focus gets back to menubutton
      gQueue.push(new synthEnterKey("bp_item1", new focusChecker("menubutton")));
      // show popup again for the next test
      gQueue.push(new synthClick("popupbutton", new nofocusChecker()));

if (!MAC) {
      // click menubutton of the 'menubutton' button while popup of button open.
      gQueue.push(new synthClick("mbb", new focusChecker("mbb"), { where: "right" }));
      // close popup, focus stays on menubutton, fire focus event
      gQueue.push(new synthEscapeKey("mbb", new focusChecker("mbb")));
      // click menubutton, open popup, focus stays on menubutton
      gQueue.push(new synthClick("mbb", new nofocusChecker(), { where: "right" }));
      // select first menu item ("item 1"), focus on menu item
      gQueue.push(new synthDownKey("mbb", new focusChecker("mbb_item1")));
      // choose select menu item, focus gets back to menubutton
      gQueue.push(new synthEnterKey("mbb_item1", new focusChecker("mbb")));
      // open popup, focus stays on menubutton
      gQueue.push(new synthOpenComboboxKey("mbb", new nofocusChecker()));
      // select second menu item ("item 2"), focus on menu item
      gQueue.push(new synthUpKey("menubutton", new focusChecker("mbb_item2")));
      // click on menu item of menubutton menu, focus menubutton
      gQueue.push(new synthClick("mbb_item2", new focusChecker("mbb")));
} else {
      todo(false, "mbb tests time out on OS X, fix bug 746970 and reenable!");
}

      // focus colorpicker button
      gQueue.push(new synthFocus("colorpicker"));
      // click on button, open popup, focus goes to current color button
      var btnObj = { colorpicker: getAccessible("colorpicker"), btnIndex: 0 };
      var checker = new focusChecker(getColorBtn, btnObj);
      gQueue.push(new synthClick("colorpicker", checker));
      // select sibling color button, focus on it
      btnObj = { colorpicker: getAccessible("colorpicker"), btnIndex: 1 };
      var checker = new focusChecker(getColorBtn, btnObj);
      gQueue.push(new synthRightKey("colorpicker", checker));
      // choose selected color button, close popup, focus on colorpicker button
      gQueue.push(new synthEnterKey("colorpicker", new focusChecker("colorpicker")));

      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=492518"
         title="xul:slider accessible of xul:scale is accessible illegally">
        Mozilla Bug 492518
      </a>
      <a target="_blank"
         href="https://bugzilla.mozilla.org/show_bug.cgi?id=552368"
         title=" fire focus event on document accessible whenever the root or body element is focused">
        Mozilla Bug 552368
      </a>
      <p id="display"></p>
      <div id="content" style="display: none"></div>
      <pre id="test">
      </pre>
    </body>

    <vbox flex="1">
      <textbox id="textbox" value="hello"/>
      <textbox id="textbox_multiline" multiline="true" value="hello"/>
      <scale id="scale" min="0" max="9" value="5"/>
      <iframe id="editabledoc" src="focus.html"/>
      <radiogroup id="radioclothes">
        <radio id="radiosweater" label="radiosweater"/>
        <radio id="radiocap" label="radiocap" disabled="true"/>
        <radio id="radiojacket" label="radiojacket"/>
      </radiogroup>
      <checkbox id="checkbox" label="checkbox"/>
      <button id="button" label="button"/>
      <button id="checkbutton" type="checkbox" label="checkbutton"/>
      <button id="radiobutton" type="radio" group="rbgroup" label="radio1"/>

      <button id="menubutton" type="menu" label="menubutton">
        <menupopup>
          <menuitem id="mb_item1" label="item1"/>
          <menuitem id="mb_item2" label="item2"/>
        </menupopup>
      </button>
      <button id="mbb" type="menu-button" label="menubutton button">
        <menupopup>
          <menuitem id="mbb_item1" label="item1"/>
          <menuitem id="mbb_item2" label="item2"/>
        </menupopup>
      </button>

      <colorpicker id="colorpicker" type="button" label="color picker"
                   color="#FFFFFF"/>

      <popupset>
        <menupopup id="backpopup" position="after_start">
          <menuitem id="bp_item1" label="Page 1"/>
          <menuitem id="bp_item2" label="Page 2"/>
        </menupopup>
      </popupset>
      <button id="popupbutton" label="Pop Me Up" popup="backpopup"/>

      <vbox id="eventdump"/>
    </vbox>
  </hbox>
</window>