accessible/tests/mochitest/events/test_tree.xul

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 <?xml version="1.0"?>
michael@0 2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
michael@0 3 <?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
michael@0 4 type="text/css"?>
michael@0 5
michael@0 6 <window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
michael@0 7 title="DOM TreeRowCountChanged and a11y name change events.">
michael@0 8
michael@0 9 <script type="application/javascript"
michael@0 10 src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" />
michael@0 11
michael@0 12 <script type="application/javascript"
michael@0 13 src="../treeview.js" />
michael@0 14
michael@0 15 <script type="application/javascript"
michael@0 16 src="../common.js" />
michael@0 17 <script type="application/javascript"
michael@0 18 src="../events.js" />
michael@0 19
michael@0 20 <script type="application/javascript">
michael@0 21 <![CDATA[
michael@0 22
michael@0 23 ////////////////////////////////////////////////////////////////////////////
michael@0 24 // Invoker's checkers
michael@0 25
michael@0 26 /**
michael@0 27 * Check TreeRowCountChanged event.
michael@0 28 */
michael@0 29 function rowCountChangedChecker(aMsg, aIdx, aCount)
michael@0 30 {
michael@0 31 this.type = "TreeRowCountChanged";
michael@0 32 this.target = gTree;
michael@0 33 this.check = function check(aEvent)
michael@0 34 {
michael@0 35 var propBag = aEvent.detail.QueryInterface(Components.interfaces.nsIPropertyBag2);
michael@0 36 var index = propBag.getPropertyAsInt32("index");
michael@0 37 is(index, aIdx, "Wrong 'index' data of 'treeRowCountChanged' event.");
michael@0 38
michael@0 39 var count = propBag.getPropertyAsInt32("count");
michael@0 40 is(count, aCount, "Wrong 'count' data of 'treeRowCountChanged' event.");
michael@0 41 }
michael@0 42 this.getID = function getID()
michael@0 43 {
michael@0 44 return aMsg + "TreeRowCountChanged";
michael@0 45 }
michael@0 46 }
michael@0 47
michael@0 48 /**
michael@0 49 * Check TreeInvalidated event.
michael@0 50 */
michael@0 51 function treeInvalidatedChecker(aMsg, aStartRow, aEndRow, aStartCol, aEndCol)
michael@0 52 {
michael@0 53 this.type = "TreeInvalidated";
michael@0 54 this.target = gTree;
michael@0 55 this.check = function check(aEvent)
michael@0 56 {
michael@0 57 var propBag = aEvent.detail.QueryInterface(Components.interfaces.nsIPropertyBag2);
michael@0 58 try {
michael@0 59 var startRow = propBag.getPropertyAsInt32("startrow");
michael@0 60 } catch (e if e.name == 'NS_ERROR_NOT_AVAILABLE') {
michael@0 61 startRow = null;
michael@0 62 }
michael@0 63 is(startRow, aStartRow,
michael@0 64 "Wrong 'startrow' of 'treeInvalidated' event on " + aMsg);
michael@0 65
michael@0 66 try {
michael@0 67 var endRow = propBag.getPropertyAsInt32("endrow");
michael@0 68 } catch (e if e.name == 'NS_ERROR_NOT_AVAILABLE') {
michael@0 69 endRow = null;
michael@0 70 }
michael@0 71 is(endRow, aEndRow,
michael@0 72 "Wrong 'endrow' of 'treeInvalidated' event on " + aMsg);
michael@0 73
michael@0 74 try {
michael@0 75 var startCol = propBag.getPropertyAsInt32("startcolumn");
michael@0 76 } catch (e if e.name == 'NS_ERROR_NOT_AVAILABLE') {
michael@0 77 startCol = null;
michael@0 78 }
michael@0 79 is(startCol, aStartCol,
michael@0 80 "Wrong 'startcolumn' of 'treeInvalidated' event on " + aMsg);
michael@0 81
michael@0 82 try {
michael@0 83 var endCol = propBag.getPropertyAsInt32("endcolumn");
michael@0 84 } catch (e if e.name == 'NS_ERROR_NOT_AVAILABLE') {
michael@0 85 startCol = null;
michael@0 86 }
michael@0 87 is(endCol, aEndCol,
michael@0 88 "Wrong 'endcolumn' of 'treeInvalidated' event on " + aMsg);
michael@0 89 }
michael@0 90 this.getID = function getID()
michael@0 91 {
michael@0 92 return "TreeInvalidated on " + aMsg;
michael@0 93 }
michael@0 94 }
michael@0 95
michael@0 96 /**
michael@0 97 * Check name changed a11y event.
michael@0 98 */
michael@0 99 function nameChangeChecker(aMsg, aRow, aCol)
michael@0 100 {
michael@0 101 this.type = EVENT_NAME_CHANGE;
michael@0 102
michael@0 103 function targetGetter()
michael@0 104 {
michael@0 105 var acc = getAccessible(gTree);
michael@0 106
michael@0 107 var tableAcc = getAccessible(acc, [nsIAccessibleTable]);
michael@0 108 return tableAcc.getCellAt(aRow, aCol);
michael@0 109 }
michael@0 110 Object.defineProperty(this, "target", { get: targetGetter });
michael@0 111
michael@0 112 this.getID = function getID()
michael@0 113 {
michael@0 114 return aMsg + "name changed";
michael@0 115 }
michael@0 116 }
michael@0 117
michael@0 118 /**
michael@0 119 * Check name changed a11y event for a row.
michael@0 120 */
michael@0 121 function rowNameChangeChecker(aMsg, aRow)
michael@0 122 {
michael@0 123 this.type = EVENT_NAME_CHANGE;
michael@0 124
michael@0 125 function targetGetter()
michael@0 126 {
michael@0 127 var acc = getAccessible(gTree);
michael@0 128 return acc.getChildAt(aRow + 1);
michael@0 129 }
michael@0 130 Object.defineProperty(this, "target", { get: targetGetter });
michael@0 131
michael@0 132 this.getID = function getID()
michael@0 133 {
michael@0 134 return aMsg + "name changed";
michael@0 135 }
michael@0 136 }
michael@0 137
michael@0 138 ////////////////////////////////////////////////////////////////////////////
michael@0 139 // Invokers
michael@0 140
michael@0 141 /**
michael@0 142 * Set tree view.
michael@0 143 */
michael@0 144 function setTreeView()
michael@0 145 {
michael@0 146 this.invoke = function setTreeView_invoke()
michael@0 147 {
michael@0 148 gTreeBox.view = gView;
michael@0 149 }
michael@0 150
michael@0 151 this.getID = function setTreeView_getID() { return "set tree view"; }
michael@0 152
michael@0 153 this.eventSeq = [
michael@0 154 new invokerChecker(EVENT_REORDER, gTree)
michael@0 155 ];
michael@0 156 };
michael@0 157
michael@0 158 /**
michael@0 159 * Insert row at 0 index and checks TreeRowCountChanged and TreeInvalidated
michael@0 160 * event.
michael@0 161 */
michael@0 162 function insertRow()
michael@0 163 {
michael@0 164 this.invoke = function insertRow_invoke()
michael@0 165 {
michael@0 166 gView.appendItem("last");
michael@0 167 gTreeBox.rowCountChanged(0, 1);
michael@0 168 }
michael@0 169
michael@0 170 this.eventSeq =
michael@0 171 [
michael@0 172 new rowCountChangedChecker("insertRow: ", 0, 1),
michael@0 173 new treeInvalidatedChecker("insertRow", 0, 5, null, null)
michael@0 174 ];
michael@0 175
michael@0 176 this.getID = function insertRow_getID()
michael@0 177 {
michael@0 178 return "insert row";
michael@0 179 }
michael@0 180 }
michael@0 181
michael@0 182 /**
michael@0 183 * Invalidates first column and checks six name changed events for each
michael@0 184 * treeitem plus TreeInvalidated event.
michael@0 185 */
michael@0 186 function invalidateColumn()
michael@0 187 {
michael@0 188 this.invoke = function invalidateColumn_invoke()
michael@0 189 {
michael@0 190 // Make sure accessible subtree of XUL tree is created otherwise no
michael@0 191 // name change events for cell accessibles are emitted.
michael@0 192 var tree = getAccessible(gTree);
michael@0 193 var child = tree.firstChild;
michael@0 194 var walkDown = true;
michael@0 195 while (child != tree) {
michael@0 196 if (walkDown) {
michael@0 197 var grandChild = child.firstChild;
michael@0 198 if (grandChild) {
michael@0 199 child = grandChild;
michael@0 200 continue;
michael@0 201 }
michael@0 202 }
michael@0 203
michael@0 204 var sibling = child.nextSibling;
michael@0 205 if (sibling) {
michael@0 206 child = sibling;
michael@0 207 walkDown = true;
michael@0 208 continue;
michael@0 209 }
michael@0 210
michael@0 211 child = child.parent;
michael@0 212 walkDown = false;
michael@0 213 }
michael@0 214
michael@0 215 // Fire 'TreeInvalidated' event by InvalidateColumn()
michael@0 216 var firstCol = gTree.columns.getFirstColumn();
michael@0 217 for (var i = 0; i < gView.rowCount; i++)
michael@0 218 gView.setCellText(i, firstCol, "hey " + String(i) + "x0");
michael@0 219
michael@0 220 gTreeBox.invalidateColumn(firstCol);
michael@0 221 }
michael@0 222
michael@0 223 this.eventSeq =
michael@0 224 [
michael@0 225 new nameChangeChecker("invalidateColumn: ", 0, 0),
michael@0 226 new nameChangeChecker("invalidateColumn: ", 1, 0),
michael@0 227 new nameChangeChecker("invalidateColumn: ", 2, 0),
michael@0 228 new nameChangeChecker("invalidateColumn: ", 3, 0),
michael@0 229 new nameChangeChecker("invalidateColumn: ", 4, 0),
michael@0 230 new nameChangeChecker("invalidateColumn: ", 5, 0),
michael@0 231 new treeInvalidatedChecker("invalidateColumn", null, null, 0, 0)
michael@0 232 ];
michael@0 233
michael@0 234 this.getID = function invalidateColumn_getID()
michael@0 235 {
michael@0 236 return "invalidate column";
michael@0 237 }
michael@0 238 }
michael@0 239
michael@0 240 /**
michael@0 241 * Invalidates second row and checks name changed event for first treeitem
michael@0 242 * (note, there are two name changed events on linux due to different
michael@0 243 * accessible tree for xul:tree element) plus TreeInvalidated event.
michael@0 244 */
michael@0 245 function invalidateRow()
michael@0 246 {
michael@0 247 this.invoke = function invalidateRow_invoke()
michael@0 248 {
michael@0 249 // Fire 'TreeInvalidated' event by InvalidateRow()
michael@0 250 var colCount = gTree.columns.count;
michael@0 251 var column = gTree.columns.getFirstColumn();
michael@0 252 while (column) {
michael@0 253 gView.setCellText(1, column, "aloha 1x" + String(column.index));
michael@0 254 column = column.getNext();
michael@0 255 }
michael@0 256
michael@0 257 gTreeBox.invalidateRow(1);
michael@0 258 }
michael@0 259
michael@0 260 this.eventSeq =
michael@0 261 [
michael@0 262 new nameChangeChecker("invalidateRow: ", 1, 0),
michael@0 263 new nameChangeChecker("invalidateRow: ", 1, 1),
michael@0 264 new rowNameChangeChecker("invalidateRow: ", 1),
michael@0 265 new treeInvalidatedChecker("invalidateRow", 1, 1, null, null)
michael@0 266 ];
michael@0 267
michael@0 268 this.getID = function invalidateRow_getID()
michael@0 269 {
michael@0 270 return "invalidate row";
michael@0 271 }
michael@0 272 }
michael@0 273
michael@0 274 ////////////////////////////////////////////////////////////////////////////
michael@0 275 // Test
michael@0 276
michael@0 277 var gTree = null;
michael@0 278 var gTreeBox = null;
michael@0 279 var gTreeView = null;
michael@0 280 var gQueue = null;
michael@0 281
michael@0 282 // gA11yEventDumpID = "debug";
michael@0 283 gA11yEventDumpToConsole = true; // debuggin
michael@0 284
michael@0 285 function doTest()
michael@0 286 {
michael@0 287 // Initialize the tree
michael@0 288 gTree = document.getElementById("tree");
michael@0 289 gTreeBox = gTree.treeBoxObject;
michael@0 290 gView = new nsTableTreeView(5);
michael@0 291
michael@0 292 // Perform actions
michael@0 293 gQueue = new eventQueue();
michael@0 294
michael@0 295 gQueue.push(new setTreeView());
michael@0 296 gQueue.push(new insertRow());
michael@0 297 gQueue.push(new invalidateColumn());
michael@0 298 gQueue.push(new invalidateRow());
michael@0 299
michael@0 300 gQueue.invoke();
michael@0 301 }
michael@0 302
michael@0 303 SimpleTest.waitForExplicitFinish();
michael@0 304 addA11yLoadEvent(doTest);
michael@0 305 ]]>
michael@0 306 </script>
michael@0 307
michael@0 308 <hbox flex="1" style="overflow: auto;">
michael@0 309 <body xmlns="http://www.w3.org/1999/xhtml">
michael@0 310 <a target="_blank"
michael@0 311 href="https://bugzilla.mozilla.org/show_bug.cgi?id=368835"
michael@0 312 title="Fire TreeViewChanged/TreeRowCountChanged events.">
michael@0 313 Mozilla Bug 368835
michael@0 314 </a><br/>
michael@0 315 <a target="_blank"
michael@0 316 href="https://bugzilla.mozilla.org/show_bug.cgi?id=308564"
michael@0 317 title="No accessibility events when data in a tree row changes.">
michael@0 318 Mozilla Bug 308564
michael@0 319 </a><br/>
michael@0 320 <a target="_blank"
michael@0 321 href="https://bugzilla.mozilla.org/show_bug.cgi?id=739524"
michael@0 322 title="replace TreeViewChanged DOM event on direct call from XUL tree.">
michael@0 323 Mozilla Bug 739524
michael@0 324 </a><br/>
michael@0 325 <a target="_blank"
michael@0 326 href="https://bugzilla.mozilla.org/show_bug.cgi?id=743568"
michael@0 327 title="Thunderbird message list tree emitting incorrect focus signals after message deleted.">
michael@0 328 Mozilla Bug 743568
michael@0 329 </a>
michael@0 330 <p id="display"></p>
michael@0 331 <div id="content" style="display: none">
michael@0 332 </div>
michael@0 333 <pre id="test">
michael@0 334 </pre>
michael@0 335 </body>
michael@0 336
michael@0 337 <vbox id="debug"/>
michael@0 338 <tree id="tree" flex="1">
michael@0 339 <treecols>
michael@0 340 <treecol id="col1" flex="1" primary="true" label="column"/>
michael@0 341 <treecol id="col2" flex="1" label="column 2"/>
michael@0 342 </treecols>
michael@0 343 <treechildren id="treechildren"/>
michael@0 344 </tree>
michael@0 345 </hbox>
michael@0 346
michael@0 347 </window>
michael@0 348

mercurial