accessible/tests/mochitest/selectable/test_select.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/accessible/tests/mochitest/selectable/test_select.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,243 @@
     1.4 +<html>
     1.5 +
     1.6 +<head>
     1.7 +  <title>nsIAccessibleSelectable HTML select testing</title>
     1.8 +
     1.9 +  <link rel="stylesheet" type="text/css"
    1.10 +        href="chrome://mochikit/content/tests/SimpleTest/test.css" />
    1.11 +
    1.12 +  </style>
    1.13 +
    1.14 +  <script type="application/javascript"
    1.15 +          src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
    1.16 +
    1.17 +  <script type="application/javascript"
    1.18 +          src="../common.js"></script>
    1.19 +  <script type="application/javascript"
    1.20 +          src="../role.js"></script>
    1.21 +  <script type="application/javascript"
    1.22 +          src="../states.js"></script>
    1.23 +  <script type="application/javascript"
    1.24 +          src="../selectable.js"></script>
    1.25 +
    1.26 +  <script type="application/javascript">
    1.27 +
    1.28 +    function doTest()
    1.29 +    {
    1.30 +      //////////////////////////////////////////////////////////////////////////
    1.31 +      // select@size="1" aka combobox
    1.32 +
    1.33 +      var id = "combobox";
    1.34 +      var combobox = getAccessible(id);
    1.35 +      var comboboxList = combobox.firstChild;
    1.36 +      ok(isAccessible(comboboxList, [nsIAccessibleSelectable]),
    1.37 +         "No selectable accessible for list of " + id);
    1.38 +
    1.39 +      var select = getAccessible(comboboxList, [nsIAccessibleSelectable]);
    1.40 +      testSelectableSelection(select, [ "cb1_item1" ]);
    1.41 +
    1.42 +      // select 2nd item
    1.43 +      select.addItemToSelection(1);
    1.44 +      testSelectableSelection(select, [ "cb1_item2" ], "addItemToSelection(1): ");
    1.45 +
    1.46 +      // unselect 2nd item, 1st item gets selected automatically
    1.47 +      select.removeItemFromSelection(1);
    1.48 +      testSelectableSelection(select, [ "cb1_item1" ],
    1.49 +                              "removeItemFromSelection(1): ");
    1.50 +
    1.51 +      // doesn't change selection
    1.52 +      is(select.selectAll(), false,
    1.53 +         "No way to select all items in combobox '" + id + "'");
    1.54 +      testSelectableSelection(select, [ "cb1_item1" ], "selectAll: ");
    1.55 +
    1.56 +      // doesn't change selection
    1.57 +      select.unselectAll();
    1.58 +      testSelectableSelection(select, [ "cb1_item1" ], "unselectAll: ");
    1.59 +
    1.60 +      //////////////////////////////////////////////////////////////////////////
    1.61 +      // select@size="1" with optgroups
    1.62 +
    1.63 +      id = "combobox2";
    1.64 +      combobox = getAccessible(id);
    1.65 +      comboboxList = combobox.firstChild;
    1.66 +      ok(isAccessible(comboboxList, [nsIAccessibleSelectable]),
    1.67 +         "No selectable accessible for list of " + id);
    1.68 +
    1.69 +      select = getAccessible(comboboxList, [nsIAccessibleSelectable]);
    1.70 +      testSelectableSelection(select, [ "cb2_item1" ]);
    1.71 +
    1.72 +      select.addItemToSelection(1);
    1.73 +      testSelectableSelection(select, [ "cb2_item2" ]);
    1.74 +
    1.75 +      select.removeItemFromSelection(1);
    1.76 +      testSelectableSelection(select, [ "cb2_item1" ]);
    1.77 +
    1.78 +      is(select.selectAll(), false,
    1.79 +         "No way to select all items in combobox " + id + "'");
    1.80 +      testSelectableSelection(select, [ "cb2_item1" ]);
    1.81 +
    1.82 +      select.unselectAll();
    1.83 +      testSelectableSelection(select, [ "cb2_item1" ]);
    1.84 +
    1.85 +      //////////////////////////////////////////////////////////////////////////
    1.86 +      // select@size="4" aka single selectable listbox
    1.87 +
    1.88 +      var id = "listbox";
    1.89 +      ok(isAccessible(id, [nsIAccessibleSelectable]),
    1.90 +         "No selectable accessible for " + id);
    1.91 +
    1.92 +      select = getAccessible(id, [nsIAccessibleSelectable]);
    1.93 +      testSelectableSelection(select, [ ]);
    1.94 +
    1.95 +      // select 2nd item
    1.96 +      select.addItemToSelection(1);
    1.97 +      testSelectableSelection(select, [ "lb1_item2" ], "addItemToSelection(1): ");
    1.98 +
    1.99 +      // unselect 2nd item, 1st item gets selected automatically
   1.100 +      select.removeItemFromSelection(1);
   1.101 +      testSelectableSelection(select, [ ],
   1.102 +                              "removeItemFromSelection(1): ");
   1.103 +
   1.104 +      // doesn't change selection
   1.105 +      is(select.selectAll(), false,
   1.106 +         "No way to select all items in single selectable listbox '" + id + "'");
   1.107 +      testSelectableSelection(select, [ ], "selectAll: ");
   1.108 +
   1.109 +      // doesn't change selection
   1.110 +      select.unselectAll();
   1.111 +      testSelectableSelection(select, [ ], "unselectAll: ");
   1.112 +
   1.113 +      //////////////////////////////////////////////////////////////////////////
   1.114 +      // select@size="4" with optgroups, single selectable
   1.115 +
   1.116 +      id = "listbox2";
   1.117 +      ok(isAccessible(id, [nsIAccessibleSelectable]),
   1.118 +         "No selectable accessible for " + id);
   1.119 +
   1.120 +      select = getAccessible(id, [nsIAccessibleSelectable]);
   1.121 +      testSelectableSelection(select, [ ]);
   1.122 +
   1.123 +      select.addItemToSelection(1);
   1.124 +      testSelectableSelection(select, [ "lb2_item2" ]);
   1.125 +
   1.126 +      select.removeItemFromSelection(1);
   1.127 +      testSelectableSelection(select, [ ]);
   1.128 +
   1.129 +      is(select.selectAll(), false,
   1.130 +         "No way to select all items in single selectable listbox " + id + "'");
   1.131 +      testSelectableSelection(select, [ ]);
   1.132 +
   1.133 +      select.unselectAll();
   1.134 +      testSelectableSelection(select, [ ]);
   1.135 +
   1.136 +      //////////////////////////////////////////////////////////////////////////
   1.137 +      // select@size="4" multiselect aka listbox
   1.138 +
   1.139 +      id = "listbox3";
   1.140 +      ok(isAccessible(id, [nsIAccessibleSelectable]),
   1.141 +         "No selectable accessible for " + id);
   1.142 +
   1.143 +      select = getAccessible(id, [nsIAccessibleSelectable]);
   1.144 +      testSelectableSelection(select, [ ]);
   1.145 +
   1.146 +      select.addItemToSelection(0);
   1.147 +      testSelectableSelection(select, [ "lb3_item1" ], "addItemToSelection: ");
   1.148 +
   1.149 +      select.removeItemFromSelection(0);
   1.150 +      testSelectableSelection(select, [ ], "removeItemFromSelection: ");
   1.151 +
   1.152 +      is(select.selectAll(), true,
   1.153 +         "All items in listbox '" + id + "' should be selected");
   1.154 +      testSelectableSelection(select, [ "lb3_item1", "lb3_item2"],
   1.155 +                              "selectAll: ");
   1.156 +
   1.157 +      select.unselectAll();
   1.158 +      testSelectableSelection(select, [ ], "unselectAll: ");
   1.159 +
   1.160 +      //////////////////////////////////////////////////////////////////////////
   1.161 +      // select@size="4" multiselect with optgroups
   1.162 +
   1.163 +      var id = "listbox4";
   1.164 +      ok(isAccessible(id, [nsIAccessibleSelectable]),
   1.165 +         "No selectable accessible for " + id);
   1.166 +
   1.167 +      select = getAccessible(id, [nsIAccessibleSelectable]);
   1.168 +      testSelectableSelection(select, [ ]);
   1.169 +
   1.170 +      select.addItemToSelection(0);
   1.171 +      testSelectableSelection(select, [ "lb4_item1" ]);
   1.172 +
   1.173 +      select.removeItemFromSelection(0);
   1.174 +      testSelectableSelection(select, [ ]);
   1.175 +
   1.176 +      is(select.selectAll(), true,
   1.177 +         "All items in listbox '" + id + "' should be selected");
   1.178 +      testSelectableSelection(select, [ "lb4_item1", "lb4_item2"]);
   1.179 +
   1.180 +      select.unselectAll();
   1.181 +      testSelectableSelection(select, [ ]);
   1.182 +
   1.183 +      SimpleTest.finish();
   1.184 +    }
   1.185 +
   1.186 +    SimpleTest.waitForExplicitFinish();
   1.187 +    addA11yLoadEvent(doTest);
   1.188 +  </script>
   1.189 +
   1.190 +</head>
   1.191 +
   1.192 +<body>
   1.193 +
   1.194 +  <a target="_blank"
   1.195 +     href="https://bugzilla.mozilla.org/show_bug.cgi?id=530014"
   1.196 +     title="ARIA single selectable widget should implement nsIAccessibleSelectable">
   1.197 +    Mozilla Bug 530014
   1.198 +  </a><br>
   1.199 +  <a target="_blank"
   1.200 +     href="https://bugzilla.mozilla.org/show_bug.cgi?id=590176"
   1.201 +     title="add pseudo SelectAccessible interface">
   1.202 +    Mozilla Bug 590176
   1.203 +  </a><br>
   1.204 +  <p id="display"></p>
   1.205 +  <div id="content" style="display: none"></div>
   1.206 +  <pre id="test">
   1.207 +  </pre>
   1.208 +
   1.209 +  <select id="combobox">
   1.210 +    <option id="cb1_item1">option1</option>
   1.211 +    <option id="cb1_item2">option2</option>
   1.212 +  </select>
   1.213 +
   1.214 +  <select id="combobox2">
   1.215 +    <option id="cb2_item1">option1</option>
   1.216 +    <optgroup>optgroup
   1.217 +      <option id="cb2_item2">option2</option>
   1.218 +    </optgroup>
   1.219 +  </select>
   1.220 +
   1.221 +  <select id="listbox" size="4">
   1.222 +    <option id="lb1_item1">option1</option>
   1.223 +    <option id="lb1_item2">option2</option>
   1.224 +  </select>
   1.225 +
   1.226 +  <select id="listbox2" size="4">
   1.227 +    <option id="lb2_item1">option1</option>
   1.228 +    <optgroup>optgroup>
   1.229 +      <option id="lb2_item2">option2</option>
   1.230 +    </optgroup>
   1.231 +  </select>
   1.232 +
   1.233 +  <select id="listbox3" size="4" multiple="true">
   1.234 +    <option id="lb3_item1">option1</option>
   1.235 +    <option id="lb3_item2">option2</option>
   1.236 +  </select>
   1.237 +
   1.238 +  <select id="listbox4" size="4" multiple="true">
   1.239 +    <option id="lb4_item1">option1</option>
   1.240 +    <optgroup>optgroup>
   1.241 +      <option id="lb4_item2">option2</option>
   1.242 +    </optgroup>
   1.243 +  </select>
   1.244 +
   1.245 +</body>
   1.246 +</html>

mercurial