| 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" |
| 2 | "http://www.w3.org/TR/html4/strict.dtd"> |
| 3 | <html> |
| 4 | <head> |
| 5 | <title>robot Tree A11y Test</title> |
| 6 | |
| 7 | <style> |
| 8 | @import "../../../../util/doh/robot/robot.css"; |
| 9 | </style> |
| 10 | |
| 11 | <script type="text/javascript" src="../../../../dojo/dojo.js"></script> |
| 12 | |
| 13 | <script type="text/javascript"> |
| 14 | require([ |
| 15 | "doh/runner", "dojo/robotx", |
| 16 | "dojo/_base/array", "dojo/dom", "dojo/keys", "dojo/query", "dojo/window", |
| 17 | "dijit/tests/helpers", "dojo/domReady!" |
| 18 | ], function(doh, robot, array, dom, keys, query, winUtils, helpers){ |
| 19 | |
| 20 | var treeIds = ["mytree", "tree2"]; |
| 21 | |
| 22 | function testTreeItemRole(/*dijit._TreeNode*/ inRoot, /*dijit.Tree*/ inTree){ |
| 23 | if(inRoot){ |
| 24 | var expectedrole = inTree.showRoot || inRoot !== inTree.rootNode ? 'treeitem' : 'presentation'; |
| 25 | doh.is(expectedrole, inRoot.labelNode.getAttribute("role"), inRoot.label + "[" + inTree.id + "]: aria role (" + expectedrole + ")"); |
| 26 | |
| 27 | // recurse |
| 28 | var children = inRoot.getChildren(); |
| 29 | for(var i = 0; i < children.length; i++){ |
| 30 | testTreeItemRole(children[i], inTree); |
| 31 | } |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | robot.initRobot('../test_Tree.html'); |
| 36 | |
| 37 | var registry, focus, mytree; |
| 38 | |
| 39 | doh.register("_setup", [ |
| 40 | { |
| 41 | name: "wait for widgets to load", |
| 42 | timeout: 20000, |
| 43 | runTest: helpers.waitForLoad |
| 44 | }, |
| 45 | function setVars(){ |
| 46 | registry = robot.window.require("dijit/registry"); |
| 47 | focus = robot.window.require("dijit/focus"); |
| 48 | mytree = registry.byId("mytree"); |
| 49 | } |
| 50 | ]); |
| 51 | |
| 52 | // Aria role and properties tests. |
| 53 | // These tests should probably be moved to the non-robot Tree_ObjectStoreModel.html. |
| 54 | doh.register("a11yAria", [ |
| 55 | function ariaTreeRole(){ |
| 56 | for(var i=0; i < treeIds.length; i++){ |
| 57 | var tree = registry.byId(treeIds[i]), expectedrole = tree.showRoot ? 'tree': 'presentation'; |
| 58 | doh.is(expectedrole, tree.domNode.getAttribute("role"), tree.id + ": aria role (" + expectedrole + ")"); |
| 59 | } |
| 60 | |
| 61 | tree = registry.byId("tree2"); // the rootless tree |
| 62 | doh.is("tree", tree.rootNode.containerNode.getAttribute("role"), "rootless tree has role on containerNode"); |
| 63 | doh.f(tree.rootNode.labelNode.hasAttribute("aria-selected"), "labelNode.hasAttribute('aria-selected')"); |
| 64 | }, |
| 65 | |
| 66 | { |
| 67 | name: "ariaTreeItemStateExpanded", |
| 68 | timeout: 8000, |
| 69 | runTest: function(){ |
| 70 | return mytree.expandAll().then(function(){ |
| 71 | query('[widgetId]', mytree.containerNode).map(registry.byNode).forEach(function(/*TreeNode*/ inItem){ |
| 72 | if(inItem.isExpandable){ |
| 73 | doh.is("true", inItem.labelNode.getAttribute("aria-expanded"), inItem.label + "[" + mytree.id + "]: aria state expanded=true"); |
| 74 | }else{ |
| 75 | // On IE9 getAttribute("aria-expanded") returns "", on other browsers null |
| 76 | var attr = inItem.labelNode.getAttribute("aria-expanded"); |
| 77 | doh.t(attr === null || attr === "", inItem.label + "[" + mytree.id + "]: aria state expanded=false"); |
| 78 | } |
| 79 | }); |
| 80 | }); |
| 81 | } |
| 82 | }, |
| 83 | |
| 84 | function ariaTreeItemRole(){ |
| 85 | for(var i=0; i < treeIds.length; i++){ |
| 86 | var tree = registry.byId(treeIds[i]); |
| 87 | testTreeItemRole(tree.rootNode, tree); |
| 88 | } |
| 89 | |
| 90 | // role=group containers should have aria label |
| 91 | var rn = mytree.rootNode; |
| 92 | var labelId1 = rn.containerNode.getAttribute('aria-labelledby'); |
| 93 | doh.is("Continents", innerText(dom.byId(labelId1)), "labelledby"); |
| 94 | |
| 95 | var firstChild = rn.getChildren()[0].containerNode; |
| 96 | var labelId2 = firstChild.getAttribute('aria-labelledby'); |
| 97 | doh.is("Africa", innerText(dom.byId(labelId2)), "labelledby"); |
| 98 | }, |
| 99 | |
| 100 | { |
| 101 | name: "ariaTreeItemStateCollapsed", |
| 102 | timeout: 8000, |
| 103 | runTest: function(){ |
| 104 | return mytree.collapseAll().then(function(){ |
| 105 | query('[widgetId]', mytree.containerNode).map(registry.byNode).forEach(function(/*TreeNode*/ inItem){ |
| 106 | if(inItem.isExpandable){ |
| 107 | doh.is("false", inItem.labelNode.getAttribute("aria-expanded"), inItem.label + "[" + mytree.id + "]: aria state expanded=false"); |
| 108 | }else{ |
| 109 | // On IE9 getAttribute("aria-expanded") returns "", on other browsers null |
| 110 | var attr = inItem.labelNode.getAttribute("aria-expanded"); |
| 111 | doh.t(attr === null || attr === "", inItem.label + "[" + mytree.id + "]: aria state expanded=false"); |
| 112 | } |
| 113 | }); |
| 114 | }); |
| 115 | } |
| 116 | } |
| 117 | ]); |
| 118 | |
| 119 | // Basic keyboard navigation: |
| 120 | // - tabbing in/out of tree |
| 121 | // - arrow keys |
| 122 | // - home/end |
| 123 | // - space/enter to select tree nodes (although this is also covered in Tree_selector.html) |
| 124 | |
| 125 | function toggle(func, expanded){ |
| 126 | return function(){ |
| 127 | var d = new doh.Deferred(); |
| 128 | |
| 129 | var mytree = registry.byId("mytree"); |
| 130 | |
| 131 | doh.is(expanded, mytree.focusedChild.isExpanded, "original state"); |
| 132 | |
| 133 | func(mytree.focusedChild.click ); |
| 134 | |
| 135 | robot.sequence(d.getTestCallback(function(){ |
| 136 | doh.is(!expanded, mytree.focusedChild.isExpanded, "after state"); |
| 137 | }), 500); |
| 138 | |
| 139 | return d; |
| 140 | }; |
| 141 | } |
| 142 | doh.register("basic keyboard", [ |
| 143 | { |
| 144 | name: "setup", |
| 145 | timeout: 8000, |
| 146 | runTest: function(){ |
| 147 | // Close all tree nodes except for Africa and Sudan, South America, and the root node itself |
| 148 | return mytree.collapseAll().then(function(){ |
| 149 | return mytree.set("paths", [ |
| 150 | ["continentRoot", "AF", "SD", "Khartoum"], |
| 151 | ["continentRoot", "SA", "AR"] // Argentina |
| 152 | ]); |
| 153 | }); |
| 154 | } |
| 155 | }, |
| 156 | |
| 157 | { |
| 158 | name: "tab in", |
| 159 | timeout: 4000, |
| 160 | runTest: function(){ |
| 161 | var d = new doh.Deferred(); |
| 162 | |
| 163 | dom.byId("mytree_before", robot.doc).focus(); |
| 164 | |
| 165 | robot.keyPress(keys.TAB, 300); // should go to Continents |
| 166 | |
| 167 | robot.sequence(d.getTestCallback(function(){ |
| 168 | var curNode = focus.curNode; |
| 169 | doh.is("Continents", curNode.innerHTML, "focused on continents"); |
| 170 | }), 500); |
| 171 | |
| 172 | return d; |
| 173 | } |
| 174 | }, |
| 175 | |
| 176 | { |
| 177 | name: "down arrow #1", |
| 178 | timeout: 4000, |
| 179 | runTest: function(){ |
| 180 | var d = new doh.Deferred(); |
| 181 | |
| 182 | robot.keyPress(keys.DOWN_ARROW, 300); // move down to Africa |
| 183 | |
| 184 | robot.sequence(d.getTestCallback(function(){ |
| 185 | doh.is("Africa", mytree.focusedChild.label, "Africa is focused"); |
| 186 | }), 500); |
| 187 | |
| 188 | return d; |
| 189 | } |
| 190 | }, |
| 191 | |
| 192 | { |
| 193 | name: "left arrow", |
| 194 | timeout: 6000, |
| 195 | runTest: function(){ |
| 196 | var d = new doh.Deferred(); |
| 197 | |
| 198 | doh.t(mytree.focusedChild.isExpanded, "initially expanded"); |
| 199 | |
| 200 | // first left arrow closes Africa, without moving focus |
| 201 | robot.keyPress(keys.LEFT_ARROW, 300); |
| 202 | robot.sequence(d.getTestErrback(function(){ |
| 203 | doh.f(mytree.focusedChild.isExpanded, "now it's closed"); |
| 204 | doh.is("Africa", mytree.focusedChild.label, "still on Africa"); |
| 205 | }), 1000); |
| 206 | |
| 207 | // second left arrow goes to Africa's parent |
| 208 | robot.keyPress(keys.LEFT_ARROW, 300); |
| 209 | robot.sequence(d.getTestCallback(function(){ |
| 210 | doh.is("Continents", mytree.focusedChild.label, "goes to parent"); |
| 211 | }), 500); |
| 212 | |
| 213 | return d; |
| 214 | } |
| 215 | }, |
| 216 | |
| 217 | { |
| 218 | name: "right arrow", |
| 219 | timeout: 6000, |
| 220 | runTest: function(){ |
| 221 | var d = new doh.Deferred(); |
| 222 | |
| 223 | // move from Continents to Africa |
| 224 | robot.keyPress(keys.RIGHT_ARROW, 300); |
| 225 | |
| 226 | robot.sequence(d.getTestErrback(function(){ |
| 227 | doh.is("Africa", focus.curNode.innerHTML, "Africa is focused"); |
| 228 | }), 500); |
| 229 | |
| 230 | // expand Africa node, focus still on Africa |
| 231 | robot.keyPress(keys.RIGHT_ARROW, 300); |
| 232 | |
| 233 | robot.sequence(d.getTestErrback(function(){ |
| 234 | doh.t(mytree.focusedChild.isExpanded, "now it's expanded"); |
| 235 | doh.is("Africa", focus.curNode.innerHTML, "Africa still focused"); |
| 236 | }), 1000); |
| 237 | |
| 238 | // next right arrow (or down arrow) will move to child |
| 239 | robot.keyPress(keys.RIGHT_ARROW, 300); |
| 240 | |
| 241 | robot.sequence(d.getTestCallback(function(){ |
| 242 | doh.is("Egypt", mytree.focusedChild.label, "Egypt is focused"); |
| 243 | }), 500); |
| 244 | |
| 245 | return d; |
| 246 | } |
| 247 | }, |
| 248 | |
| 249 | { |
| 250 | name: "down arrow #2", |
| 251 | timeout: 4000, |
| 252 | runTest: function(){ |
| 253 | var d = new doh.Deferred(); |
| 254 | |
| 255 | // testing that down arrow goes through all visible nodes, popping up and down parent-child |
| 256 | // hierarchy |
| 257 | |
| 258 | // Tests that down arrow goes to child, ie from Sudan to Khartoum |
| 259 | robot.keyPress(keys.DOWN_ARROW, 300); |
| 260 | robot.keyPress(keys.DOWN_ARROW, 300); |
| 261 | robot.keyPress(keys.DOWN_ARROW, 300); |
| 262 | |
| 263 | robot.sequence(d.getTestCallback(function(){ |
| 264 | doh.is("Khartoum", mytree.focusedChild.label, "went down to child of Sudan"); |
| 265 | }), 500); |
| 266 | |
| 267 | return d; |
| 268 | } |
| 269 | }, |
| 270 | |
| 271 | { |
| 272 | name: "select Khartoum", |
| 273 | timeout: 4000, |
| 274 | runTest: function(){ |
| 275 | var d = new doh.Deferred(); |
| 276 | |
| 277 | robot.keyPress(keys.ENTER, 300); // select it |
| 278 | |
| 279 | robot.sequence(d.getTestCallback(function(){ |
| 280 | var item = mytree.get("selectedItem"), |
| 281 | label = mytree.model.getLabel(item); |
| 282 | doh.is("Khartoum", label, "selected"); |
| 283 | doh.is("Khartoum", mytree.focusedChild.label, "and still focused"); |
| 284 | }), 500); |
| 285 | |
| 286 | return d; |
| 287 | } |
| 288 | }, |
| 289 | |
| 290 | { |
| 291 | name: "down arrow #3", |
| 292 | timeout: 4000, |
| 293 | runTest: function(){ |
| 294 | var d = new doh.Deferred(); |
| 295 | |
| 296 | // Test that down arrow pops up two levels |
| 297 | robot.keyPress(keys.DOWN_ARROW, 300); |
| 298 | robot.sequence(d.getTestCallback(function(){ |
| 299 | doh.is("Asia", mytree.focusedChild.label, "popped up to great uncle of Khartoum"); |
| 300 | |
| 301 | var item = mytree.get("selectedItem"), |
| 302 | label = mytree.model.getLabel(item); |
| 303 | doh.is("Khartoum", label, "but Khartoum is still selected"); |
| 304 | }), 500); |
| 305 | |
| 306 | return d; |
| 307 | } |
| 308 | }, |
| 309 | |
| 310 | { |
| 311 | name: "ENTER to open", |
| 312 | timeout: 4000, |
| 313 | runTest: toggle(function(){ |
| 314 | robot.keyPress(keys.ENTER, 300); // since openOnClick==true, this opens the node |
| 315 | }, false) |
| 316 | }, |
| 317 | |
| 318 | { |
| 319 | name: "ENTER to close", |
| 320 | timeout: 4000, |
| 321 | runTest: toggle(function(){ |
| 322 | robot.keyPress(keys.ENTER, 300); // since openOnClick==true, this closes the node |
| 323 | }, true) |
| 324 | }, |
| 325 | |
| 326 | { |
| 327 | name: "up arrow", |
| 328 | timeout: 4000, |
| 329 | runTest: function(){ |
| 330 | var d = new doh.Deferred(); |
| 331 | |
| 332 | // up arrow should go to node visually above current node, not necessarily it's |
| 333 | // previous sibling |
| 334 | robot.keyPress(keys.UP_ARROW, 300); |
| 335 | robot.sequence(d.getTestErrback(function(){ |
| 336 | doh.is("Khartoum", focus.curNode.innerHTML, "not Africa"); |
| 337 | }), 500); |
| 338 | |
| 339 | |
| 340 | robot.keyPress(keys.UP_ARROW, 300); |
| 341 | |
| 342 | robot.sequence(d.getTestCallback(function(){ |
| 343 | doh.is("Sudan", focus.curNode.innerHTML, "not Africa"); |
| 344 | }), 500); |
| 345 | |
| 346 | return d; |
| 347 | } |
| 348 | }, |
| 349 | |
| 350 | { |
| 351 | name: "end", |
| 352 | timeout: 4000, |
| 353 | runTest: function(){ |
| 354 | var d = new doh.Deferred(); |
| 355 | |
| 356 | robot.keyPress(keys.END, 300); |
| 357 | |
| 358 | robot.sequence(d.getTestCallback(function(){ |
| 359 | doh.is("Argentina", focus.curNode.innerHTML); |
| 360 | }), 500); |
| 361 | |
| 362 | return d; |
| 363 | } |
| 364 | }, |
| 365 | |
| 366 | { |
| 367 | name: "home", |
| 368 | timeout: 4000, |
| 369 | runTest: function(){ |
| 370 | var d = new doh.Deferred(); |
| 371 | |
| 372 | robot.keyPress(keys.HOME, 300); // go to Continents |
| 373 | |
| 374 | robot.sequence(d.getTestCallback(function(){ |
| 375 | doh.is("Continents", focus.curNode.innerHTML, "Africa is focused"); |
| 376 | }), 500); |
| 377 | |
| 378 | return d; |
| 379 | } |
| 380 | }, |
| 381 | |
| 382 | { |
| 383 | name: "tab out", |
| 384 | timeout: 4000, |
| 385 | runTest: function(){ |
| 386 | var d = new doh.Deferred(); |
| 387 | |
| 388 | robot.keyPress(keys.TAB, 300); |
| 389 | |
| 390 | robot.sequence(d.getTestCallback(function(){ |
| 391 | doh.is("mytreeDestroyButton", focus.curNode.id); |
| 392 | }), 500); |
| 393 | |
| 394 | return d; |
| 395 | } |
| 396 | }, |
| 397 | |
| 398 | { |
| 399 | name: "shift-tab in", |
| 400 | timeout: 4000, |
| 401 | runTest: function(){ |
| 402 | var d = new doh.Deferred(); |
| 403 | |
| 404 | robot.keyPress(keys.TAB, 300, {shift: true}); |
| 405 | |
| 406 | robot.sequence(d.getTestCallback(function(){ |
| 407 | doh.is("Continents", focus.curNode.innerHTML, "focused on continents"); |
| 408 | }), 500); |
| 409 | |
| 410 | return d; |
| 411 | } |
| 412 | }, |
| 413 | |
| 414 | { |
| 415 | name: "shift-tab out", |
| 416 | timeout: 4000, |
| 417 | runTest: function(){ |
| 418 | var d = new doh.Deferred(); |
| 419 | |
| 420 | robot.keyPress(keys.TAB, 300, {shift: true}); |
| 421 | |
| 422 | robot.sequence(d.getTestCallback(function(){ |
| 423 | doh.is("mytree_before", focus.curNode.id, "focus went to input before tree"); |
| 424 | query(".dijitTreeLabel", "mytree").every(function(node, idx){ |
| 425 | var ti = node.getAttribute("tabindex"); |
| 426 | doh.is("-1", ti, "-1 tab index on TreeNode" + idx); |
| 427 | }); |
| 428 | doh.is(0, mytree.domNode.getAttribute("tabindex"), "0 tabindex on Tree.domNode itself"); |
| 429 | }), 500); |
| 430 | |
| 431 | return d; |
| 432 | } |
| 433 | } |
| 434 | ]); |
| 435 | |
| 436 | // TODO: tests on tree with showRoot=false |
| 437 | |
| 438 | // Test for typing "a" to navigate to nodes that start with "a", etc. |
| 439 | doh.register("keyboard search tests", [ |
| 440 | { |
| 441 | name: "Setup tree", |
| 442 | timeout: 4000, |
| 443 | runTest: function(){ |
| 444 | var d = new doh.Deferred(); |
| 445 | |
| 446 | var tree = registry.byId("mytree"); |
| 447 | |
| 448 | // Close all tree nodes except for Asia and Oceania |
| 449 | array.forEach(tree.rootNode.getChildren(), function(child, idx){ |
| 450 | if(child.label == "Asia" || child.label == "Oceania"){ |
| 451 | console.log("expanding " + child.label); |
| 452 | if(!child.isExpanded){ |
| 453 | tree._expandNode(child); |
| 454 | } |
| 455 | }else{ |
| 456 | console.log("collapsing " + child.label); |
| 457 | if(child.isExpanded){ |
| 458 | tree._collapseNode(child); |
| 459 | } |
| 460 | } |
| 461 | }); |
| 462 | |
| 463 | robot.sequence(d.getTestCallback(function(){ |
| 464 | // Just waiting for animation to finish... |
| 465 | }), 500); |
| 466 | |
| 467 | return d; |
| 468 | } |
| 469 | }, |
| 470 | { |
| 471 | name: "Focus on Continents", |
| 472 | timeout: 4000, |
| 473 | runTest: function(){ |
| 474 | var d = new doh.Deferred(); |
| 475 | |
| 476 | var tree = registry.byId("mytree"); |
| 477 | tree.focusNode(tree.rootNode); |
| 478 | |
| 479 | robot.sequence(d.getTestCallback(function(){ |
| 480 | doh.t(tree.rootNode.labelNode, "focused on continents"); |
| 481 | }), 500); |
| 482 | |
| 483 | return d; |
| 484 | } |
| 485 | }, |
| 486 | { |
| 487 | name: "First 'A' key goes to Africa", |
| 488 | timeout: 4000, |
| 489 | runTest: function(){ |
| 490 | var d = new doh.Deferred(); |
| 491 | |
| 492 | // From Continents node, press "A". Should go to Africa. |
| 493 | robot.keyPress("a", 100); |
| 494 | robot.sequence(d.getTestCallback(function(){ |
| 495 | var focusedWidget = registry.getEnclosingWidget(focus.curNode); |
| 496 | doh.t(focusedWidget, "there is a focused widget"); |
| 497 | doh.is("Africa", focusedWidget.label); |
| 498 | }), 500); |
| 499 | |
| 500 | return d; |
| 501 | } |
| 502 | }, |
| 503 | { |
| 504 | name: "Second 'A' key goes to Asia", |
| 505 | timeout: 4000, |
| 506 | runTest: function(){ |
| 507 | var d = new doh.Deferred(); |
| 508 | |
| 509 | // From Africa node, press "A" again. Should go to Asia. |
| 510 | robot.keyPress("a", 100); |
| 511 | robot.sequence(d.getTestCallback(function(){ |
| 512 | var focusedWidget = registry.getEnclosingWidget(focus.curNode); |
| 513 | doh.t(focusedWidget, "there is a focused widget"); |
| 514 | doh.is("Asia", focusedWidget.label); |
| 515 | }), 500); |
| 516 | |
| 517 | return d; |
| 518 | } |
| 519 | }, |
| 520 | { |
| 521 | name: "Third 'A' key goes to Australia (nested node)", |
| 522 | timeout: 4000, |
| 523 | runTest: function(){ |
| 524 | var d = new doh.Deferred(); |
| 525 | |
| 526 | var oceania = registry.byId("mytree").rootNode.getChildren()[2]; |
| 527 | doh.t(oceania, "found Oceania node"); |
| 528 | doh.t(oceania.isExpanded, "Oceania node is expanded"); |
| 529 | |
| 530 | robot.keyPress("a", 100); |
| 531 | robot.sequence(d.getTestCallback(function(){ |
| 532 | var focusedWidget = registry.getEnclosingWidget(focus.curNode); |
| 533 | doh.t(focusedWidget, "there is a focused widget"); |
| 534 | doh.is("Australia", focusedWidget.label); |
| 535 | }), 500); |
| 536 | |
| 537 | return d; |
| 538 | } |
| 539 | }, |
| 540 | { |
| 541 | name: "Fourth 'A' key loops back to Africa", |
| 542 | timeout: 4000, |
| 543 | runTest: function(){ |
| 544 | var d = new doh.Deferred(); |
| 545 | |
| 546 | robot.keyPress("a", 100); |
| 547 | robot.sequence(d.getTestCallback(function(){ |
| 548 | var focusedWidget = registry.getEnclosingWidget(focus.curNode); |
| 549 | doh.t(focusedWidget, "there is a focused widget"); |
| 550 | doh.is("Africa", focusedWidget.label); |
| 551 | }), 500); |
| 552 | |
| 553 | return d; |
| 554 | } |
| 555 | }, |
| 556 | { |
| 557 | name: "multi-key navigation (co)", |
| 558 | timeout: 4000, |
| 559 | runTest: function(){ |
| 560 | var d = new doh.Deferred(); |
| 561 | |
| 562 | // After the 500ms delay above plus 750 delay here, character should start a new search. |
| 563 | // Skip over China and go to Continents. |
| 564 | robot.typeKeys("co", 750); |
| 565 | |
| 566 | robot.sequence(d.getTestCallback(function(){ |
| 567 | var focusedWidget = registry.getEnclosingWidget(focus.curNode); |
| 568 | doh.t(focusedWidget, "there is a focused widget"); |
| 569 | doh.is("Continents", focusedWidget.label); |
| 570 | }), 500); |
| 571 | |
| 572 | return d; |
| 573 | } |
| 574 | }, |
| 575 | { |
| 576 | name: "multi-key navigation (as)", |
| 577 | timeout: 4000, |
| 578 | runTest: function(){ |
| 579 | var d = new doh.Deferred(); |
| 580 | |
| 581 | // After the 500ms delay above plus 750 delay here, character should start a new search. |
| 582 | // By typing AS should skip over Africa and go to Asia. |
| 583 | robot.typeKeys("as", 750); |
| 584 | |
| 585 | robot.sequence(d.getTestCallback(function(){ |
| 586 | var focusedWidget = registry.getEnclosingWidget(focus.curNode); |
| 587 | doh.t(focusedWidget, "there is a focused widget"); |
| 588 | doh.is("Asia", focusedWidget.label); |
| 589 | }), 500); |
| 590 | |
| 591 | return d; |
| 592 | } |
| 593 | }, |
| 594 | { |
| 595 | name: "multi-key navigation clears", |
| 596 | timeout: 4000, |
| 597 | runTest: function(){ |
| 598 | var d = new doh.Deferred(); |
| 599 | |
| 600 | // After the 500ms delay above plus 750 delay here, character should start a new search |
| 601 | robot.typeKeys("n", 750); |
| 602 | |
| 603 | robot.sequence(d.getTestCallback(function(){ |
| 604 | var focusedWidget = registry.getEnclosingWidget(focus.curNode); |
| 605 | doh.t(focusedWidget, "there is a focused widget"); |
| 606 | doh.is("North America", focusedWidget.label); |
| 607 | }), 500); |
| 608 | |
| 609 | return d; |
| 610 | } |
| 611 | } |
| 612 | ]); |
| 613 | |
| 614 | doh.register("keyboard on auto expand tree", [ |
| 615 | { |
| 616 | name: "end key", |
| 617 | timeout: 4000, |
| 618 | runTest: function(){ |
| 619 | var d = new doh.Deferred(); |
| 620 | |
| 621 | var node = dom.byId("mytree3_before", robot.doc); |
| 622 | winUtils.scrollIntoView(node); |
| 623 | node.focus(); |
| 624 | |
| 625 | robot.keyPress(keys.TAB, 300); // go to start of tree |
| 626 | robot.keyPress(keys.END, 300); // go to end |
| 627 | |
| 628 | robot.sequence(d.getTestCallback(function(){ |
| 629 | doh.is("Argentina", robot.window.require("dijit/focus").curNode.innerHTML, "end key went to this node"); |
| 630 | }), 500); |
| 631 | |
| 632 | return d; |
| 633 | } |
| 634 | } |
| 635 | ]); |
| 636 | |
| 637 | doh.register("destroy and focus", [ |
| 638 | { |
| 639 | name: "setup", |
| 640 | timeout: 8000, |
| 641 | runTest: function(){ |
| 642 | return mytree.expandAll(); |
| 643 | } |
| 644 | }, |
| 645 | |
| 646 | { |
| 647 | name: "destroy previously focused node", |
| 648 | timeout: 20000, |
| 649 | runTest: function(){ |
| 650 | var d = new doh.Deferred(); |
| 651 | |
| 652 | // Go to Africa node |
| 653 | dom.byId("mytree_before", robot.doc).focus(); |
| 654 | robot.keyPress(keys.TAB, 300); |
| 655 | robot.keyPress(keys.HOME, 300); |
| 656 | robot.keyPress(keys.DOWN_ARROW, 300); |
| 657 | |
| 658 | var previouslyFocusedChild; |
| 659 | robot.sequence(d.getTestErrback(function(){ |
| 660 | doh.is("Africa", mytree.focusedChild.label, "focus"); |
| 661 | previouslyFocusedChild = mytree.focusedChild; |
| 662 | }), 500); |
| 663 | |
| 664 | |
| 665 | // Tab out of Tree, and then destroy previously focused node. |
| 666 | robot.keyPress(keys.TAB, 300, {shift: true}); |
| 667 | robot.sequence(d.getTestErrback(function(){ |
| 668 | doh.is("mytree_before", focus.curNode.id, "focus"); |
| 669 | |
| 670 | var store = mytree.model.store; |
| 671 | var item = previouslyFocusedChild.item; |
| 672 | store.deleteItem(item); |
| 673 | }), 500); |
| 674 | |
| 675 | // Refocus Tree. Since previously focused node was destroyed, focus should go to Continents. |
| 676 | robot.keyPress(keys.TAB, 300); |
| 677 | robot.sequence(d.getTestCallback(function(){ |
| 678 | doh.is("Continents", focus.curNode.innerHTML, "focus"); |
| 679 | }), 500); |
| 680 | |
| 681 | return d; |
| 682 | } |
| 683 | }, |
| 684 | |
| 685 | { |
| 686 | name: "destroy previously focused node's ancestor", |
| 687 | timeout: 20000, |
| 688 | runTest: function(){ |
| 689 | var d = new doh.Deferred(); |
| 690 | |
| 691 | dom.byId("mytree_before", robot.doc).focus(); |
| 692 | robot.keyPress(keys.TAB, 300); |
| 693 | robot.keyPress(keys.HOME, 300); |
| 694 | robot.keyPress(keys.DOWN_ARROW, 300); // move down to Asia (since Africa is gone) |
| 695 | robot.keyPress(keys.DOWN_ARROW, 300); // move down to China |
| 696 | |
| 697 | var previouslyFocusedChild; |
| 698 | robot.sequence(d.getTestErrback(function(){ |
| 699 | doh.is("China", mytree.focusedChild.label, "focus"); |
| 700 | previouslyFocusedChild = mytree.focusedChild; |
| 701 | }), 500); |
| 702 | |
| 703 | // Tab out, and then destroy Asia (previously focused node's ancestor) |
| 704 | robot.keyPress(keys.TAB, 300, {shift: true}); |
| 705 | robot.sequence(d.getTestErrback(function(){ |
| 706 | doh.is("mytree_before", focus.curNode.id, "focus"); |
| 707 | |
| 708 | var store = mytree.model.store; |
| 709 | var item = previouslyFocusedChild.getParent().item; |
| 710 | store.deleteItem(item); |
| 711 | }), 500); |
| 712 | |
| 713 | // Refocus Tree. Since previously focused node's ancestor was destroyed, |
| 714 | // focus should go to Continents. |
| 715 | robot.keyPress(keys.TAB, 300); |
| 716 | robot.sequence(d.getTestCallback(function(){ |
| 717 | doh.is("Continents", focus.curNode.innerHTML, "focus"); |
| 718 | }), 500); |
| 719 | |
| 720 | return d; |
| 721 | } |
| 722 | }, |
| 723 | |
| 724 | { |
| 725 | name: "destroy currently focused node", |
| 726 | timeout: 4000, |
| 727 | runTest: function(){ |
| 728 | var d = new doh.Deferred(); |
| 729 | |
| 730 | // Go to Oceania node |
| 731 | dom.byId("mytree_before", robot.doc).focus(); |
| 732 | robot.keyPress(keys.TAB, 300); |
| 733 | robot.keyPress(keys.HOME, 300); |
| 734 | robot.keyPress(keys.DOWN_ARROW, 300); |
| 735 | |
| 736 | // Destroy it |
| 737 | robot.sequence(d.getTestErrback(function(){ |
| 738 | doh.is("Oceania", mytree.focusedChild.label, "focus"); |
| 739 | |
| 740 | var store = mytree.model.store; |
| 741 | var item = mytree.focusedChild.item; |
| 742 | store.deleteItem(item); |
| 743 | }), 500); |
| 744 | |
| 745 | // Focus should go to Continents |
| 746 | robot.sequence(d.getTestCallback(function(){ |
| 747 | doh.is("Continents", mytree.focusedChild.label, "focus"); |
| 748 | }), 500); |
| 749 | |
| 750 | return d; |
| 751 | } |
| 752 | }, |
| 753 | |
| 754 | { |
| 755 | name: "destroy currently focused node's ancestor", |
| 756 | timeout: 4000, |
| 757 | runTest: function(){ |
| 758 | var d = new doh.Deferred(); |
| 759 | |
| 760 | // Go to Germany node |
| 761 | dom.byId("mytree_before", robot.doc).focus(); |
| 762 | robot.keyPress(keys.TAB, 300); |
| 763 | robot.keyPress(keys.HOME, 300); |
| 764 | robot.keyPress(keys.DOWN_ARROW, 300); // to Europe |
| 765 | robot.keyPress(keys.DOWN_ARROW, 300); // to Germany |
| 766 | |
| 767 | // Destroy Europe (Germany's ancestor) |
| 768 | robot.sequence(d.getTestErrback(function(){ |
| 769 | doh.is("Germany", mytree.focusedChild.label, "focus"); |
| 770 | |
| 771 | var store = mytree.model.store; |
| 772 | var item = mytree.focusedChild.getParent().item; |
| 773 | store.deleteItem(item); |
| 774 | }), 500); |
| 775 | |
| 776 | // Focus should go to Continents |
| 777 | robot.sequence(d.getTestCallback(function(){ |
| 778 | doh.is("Continents", mytree.focusedChild.label, "focus"); |
| 779 | }), 500); |
| 780 | |
| 781 | return d; |
| 782 | } |
| 783 | } |
| 784 | ]); |
| 785 | |
| 786 | doh.run(); |
| 787 | }); |
| 788 | |
| 789 | </script> |
| 790 | </head> |
| 791 | </html> |
| 792 |