| 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 Toolbar Test</title> |
| 6 | |
| 7 | <style> |
| 8 | @import "../../../util/doh/robot/robot.css"; |
| 9 | </style> |
| 10 | |
| 11 | <script type="text/javascript" src="../../../dojo/dojo.js" |
| 12 | data-dojo-config="isDebug: true"></script> |
| 13 | |
| 14 | <script type="text/javascript"> |
| 15 | require([ |
| 16 | "doh/runner", "dojo/robotx", |
| 17 | "dojo/_base/array", "dojo/dom", "dojo/keys", "dojo/_base/lang", "dojo/query", |
| 18 | "dojo/domReady!" |
| 19 | ], function(doh, robot, array, dom, keys, lang, query){ |
| 20 | robot.initRobot('../test_Toolbar.html'); |
| 21 | |
| 22 | doh.register(function setup(){ |
| 23 | // get pointer to registry in the iframe |
| 24 | registry = robot.window.require("dijit/registry"); |
| 25 | dfocus = robot.window.require("dijit/focus"); |
| 26 | |
| 27 | toolbar1Before = dom.byId("toolbar1Before", robot.doc); |
| 28 | toolbar1 = registry.byId("toolbar1"); |
| 29 | toolbar1After = dom.byId("toolbar1After", robot.doc); |
| 30 | toolbar2 = registry.byId("toolbar2"); |
| 31 | toolbar3 = registry.byId("toolbar3"); |
| 32 | toolbar4 = registry.byId("toolbar4"); |
| 33 | }); |
| 34 | |
| 35 | var toolbar1Before, toolbar1After, toolbar1, toolbar2, toolbar3, toolbar4; |
| 36 | |
| 37 | doh.register("initial conditions", [ |
| 38 | { |
| 39 | name: "creation", |
| 40 | runTest: function(){ |
| 41 | // make sure that all the toolbars exist |
| 42 | doh.t(toolbar1, "toolbar 1"); |
| 43 | doh.t(toolbar2, "toolbar 2"); |
| 44 | doh.t(toolbar3, "toolbar 3"); |
| 45 | doh.t(toolbar4, "toolbar 4"); |
| 46 | |
| 47 | // and that labels are shown except when showLabel==false |
| 48 | var cutText = query("#toolbar1_cut .dijitButtonText", robot.doc)[0]; |
| 49 | doh.is(0, cutText.offsetWidth, "cut button - text hidden"); |
| 50 | |
| 51 | var copyText = query("#toolbar1_copy .dijitButtonText", robot.doc)[0]; |
| 52 | doh.t(copyText.offsetWidth > 0, "copy button - text shown"); |
| 53 | } |
| 54 | } |
| 55 | ]); |
| 56 | |
| 57 | doh.register("keyboard", [ |
| 58 | { |
| 59 | name: "tab in and out", |
| 60 | timeout: 20000, |
| 61 | runTest: function(){ |
| 62 | var d = new doh.Deferred(); |
| 63 | |
| 64 | robot.sequence(d.getTestErrback(lang.hitch(this, function(){ |
| 65 | toolbar1Before.focus(); |
| 66 | })), 500); |
| 67 | |
| 68 | robot.keyPress(keys.TAB, 500, {}); |
| 69 | robot.sequence(d.getTestErrback(lang.hitch(this, function(){ |
| 70 | doh.is("toolbar1_cut", dfocus.curNode.id, "cut, first visit"); |
| 71 | })), 1000); |
| 72 | |
| 73 | robot.keyPress(keys.TAB, 500, {}); |
| 74 | robot.sequence(d.getTestErrback(lang.hitch(this, function(){ |
| 75 | doh.is("toolbar1After", dfocus.curNode.id); |
| 76 | })), 1000); |
| 77 | |
| 78 | robot.keyPress(keys.TAB, 500, {shift: true}); |
| 79 | robot.sequence(d.getTestErrback(lang.hitch(this, function(){ |
| 80 | doh.is("toolbar1_cut", dfocus.curNode.id, "cut, second visit"); |
| 81 | })), 1000); |
| 82 | |
| 83 | robot.keyPress(keys.TAB, 500, {shift: true}); |
| 84 | robot.sequence(d.getTestCallback(lang.hitch(this, function(){ |
| 85 | doh.is("toolbar1Before", dfocus.curNode.id, "back before toolbar1"); |
| 86 | })), 1000); |
| 87 | |
| 88 | return d; |
| 89 | } |
| 90 | }, |
| 91 | |
| 92 | { |
| 93 | name: "left/right arrow keys", |
| 94 | timeout: 40000, |
| 95 | runTest: function(){ |
| 96 | var d = new doh.Deferred(); |
| 97 | |
| 98 | // Disable a bunch of buttons to make sure that left/right arrow |
| 99 | // keys skip over disabled buttons, and also that initial focus |
| 100 | // goes to the first enabled button |
| 101 | array.forEach(["toolbar1_cut", "toolbar1_copy", "toolbar1_bold", "toolbar1_backcolor", |
| 102 | "toolbar1_forecolor", "toolbar1_combo2"], function(widgetName){ |
| 103 | registry.byId(widgetName).set("disabled", true); |
| 104 | }); |
| 105 | |
| 106 | // Initial focus (upon tabbing into toolbar) should go to first enabled button |
| 107 | toolbar1Before.focus(); |
| 108 | robot.keyPress(keys.TAB, 500, {}); |
| 109 | robot.sequence(d.getTestErrback(lang.hitch(this, function(){ |
| 110 | doh.is("toolbar1_italic", dfocus.curNode.id, "italic, first visit"); |
| 111 | })), 1000); |
| 112 | |
| 113 | // Remaining enabled positions that left/right arrow should navigate to (not including the initial leftmost button), |
| 114 | var focusPoints = ["toolbar1_dialog", "toolbar1_combo_button", "toolbar1_combo_arrow", "toolbar1_insertorderedlist"]; |
| 115 | |
| 116 | // Use right arrow key to visit every enabled button (and for combobutton to hit left and right sides) |
| 117 | array.forEach(focusPoints, function(str){ |
| 118 | robot.keyPress(keys.RIGHT_ARROW, 500, {}); |
| 119 | robot.sequence(d.getTestErrback(lang.hitch(this, function(){ |
| 120 | doh.is(str, dfocus.curNode.id, str + ", first visit"); |
| 121 | })), 1000); |
| 122 | }); |
| 123 | |
| 124 | // Now go backwards |
| 125 | focusPoints.reverse(); |
| 126 | focusPoints.shift(); |
| 127 | array.forEach(focusPoints, function(str){ |
| 128 | robot.keyPress(keys.LEFT_ARROW, 500, {}); |
| 129 | robot.sequence(d.getTestErrback(lang.hitch(this, function(){ |
| 130 | doh.is(str, dfocus.curNode.id, str + ", second visit"); |
| 131 | })), 1000); |
| 132 | }); |
| 133 | |
| 134 | // Test the TAB key takes us to the <input> after the toolbar. |
| 135 | // This confirms that the currently focused toolbar button |
| 136 | // is in the correct position in the tab order (ie, the position specified |
| 137 | // for the toolbar itself), and that there are no stray tabstops on the toolbar itself |
| 138 | // or on the other buttons. |
| 139 | robot.keyPress(keys.TAB, 500, {}); |
| 140 | robot.sequence(d.getTestErrback(lang.hitch(this, function(){ |
| 141 | doh.is("toolbar1After", dfocus.curNode.id, "first time past toolbar1"); |
| 142 | })), 1000); |
| 143 | |
| 144 | // Make sure that we can still shift-tab back to before the toolbar too |
| 145 | robot.keyPress(keys.TAB, 500, {shift: true}); |
| 146 | robot.sequence(d.getTestErrback(lang.hitch(this, function(){ |
| 147 | doh.is("toolbar1_italic", dfocus.curNode.id, "italic, after shift-tab back into toolbar"); |
| 148 | })), 1000); |
| 149 | |
| 150 | robot.keyPress(keys.TAB, 500, {shift: true}); |
| 151 | robot.sequence(d.getTestCallback(lang.hitch(this, function(){ |
| 152 | doh.is("toolbar1Before", dfocus.curNode.id, "back before toolbar1"); |
| 153 | })), 1000); |
| 154 | |
| 155 | return d; |
| 156 | } |
| 157 | }, |
| 158 | |
| 159 | { |
| 160 | name: "home/end keys", |
| 161 | timeout: 40000, |
| 162 | runTest: function(){ |
| 163 | var d = new doh.Deferred(); |
| 164 | |
| 165 | // Initial focus (upon tabbing into toolbar) should go to first enabled button, |
| 166 | // which is "italic", since "cut" and "copy" are disabled |
| 167 | toolbar1Before.focus(); |
| 168 | robot.keyPress(keys.TAB, 500, {}); |
| 169 | robot.sequence(d.getTestErrback(lang.hitch(this, function(){ |
| 170 | doh.is("toolbar1_italic", dfocus.curNode.id, "first button"); |
| 171 | })), 1000); |
| 172 | |
| 173 | // End key should go to last button |
| 174 | robot.keyPress(keys.END, 500, {}); |
| 175 | robot.sequence(d.getTestErrback(lang.hitch(this, function(){ |
| 176 | doh.is("toolbar1_insertorderedlist", dfocus.curNode.id, "last button"); |
| 177 | })), 1000); |
| 178 | |
| 179 | // Home key should go to first enabled button again |
| 180 | // which is "italic", since "cut" and "copy" are disabled |
| 181 | robot.keyPress(keys.HOME, 500, {}); |
| 182 | robot.sequence(d.getTestCallback(lang.hitch(this, function(){ |
| 183 | doh.is("toolbar1_italic", dfocus.curNode.id, "first button again"); |
| 184 | })), 1000); |
| 185 | |
| 186 | return d; |
| 187 | } |
| 188 | }, |
| 189 | |
| 190 | // Test drop down ability. These tests are probably redundant with the Button tests themselves, |
| 191 | // so they aren't strictly necessary. |
| 192 | { |
| 193 | name: "drop downs", |
| 194 | timeout: 60000, |
| 195 | runTest: function(){ |
| 196 | var d = new doh.Deferred(); |
| 197 | |
| 198 | // Re-enable the ToolipDialog and ColorPalette drop down so that we can test it |
| 199 | registry.byId("toolbar1_dialog").set("disabled", false); |
| 200 | registry.byId("toolbar1_backcolor").set("disabled", false); |
| 201 | |
| 202 | robot.sequence(d.getTestErrback(lang.hitch(this, function(){ |
| 203 | toolbar1Before.focus(); |
| 204 | })), 500); |
| 205 | |
| 206 | // Tab into toolbar and move to tooltip dialog button |
| 207 | robot.keyPress(keys.TAB, 500, {}); |
| 208 | robot.keyPress(keys.RIGHT_ARROW, 500, {}); |
| 209 | |
| 210 | robot.sequence(d.getTestErrback(lang.hitch(this, function(){ |
| 211 | doh.is("toolbar1_dialog", dfocus.curNode.id, "dialog button, first visit"); |
| 212 | })), 1000); |
| 213 | |
| 214 | // Open the dialog, focus should go to first input |
| 215 | robot.keyPress(keys.DOWN_ARROW, 500, {}); |
| 216 | robot.sequence(d.getTestErrback(lang.hitch(this, function(){ |
| 217 | doh.is("user", dfocus.curNode.id); |
| 218 | })), 1000); |
| 219 | |
| 220 | // ESC should restore focus to toolbar dialog button |
| 221 | robot.keyPress(keys.ESCAPE, 500, {}); |
| 222 | robot.sequence(d.getTestErrback(lang.hitch(this, function(){ |
| 223 | doh.is("toolbar1_dialog", dfocus.curNode.id, "dialog button, second visit"); |
| 224 | })), 1000); |
| 225 | |
| 226 | // Open the dialog again |
| 227 | robot.keyPress(keys.DOWN_ARROW, 500, {}); |
| 228 | robot.sequence(d.getTestErrback(lang.hitch(this, function(){ |
| 229 | doh.is("user", dfocus.curNode.id, "user, again"); |
| 230 | })), 1000); |
| 231 | |
| 232 | // Submit should also restore focus to toolbar dialog button, assuming that it |
| 233 | // doesn't reset the focus somewhere else (like into the editor) |
| 234 | robot.keyPress(keys.TAB, 500); |
| 235 | robot.keyPress(keys.TAB, 500); |
| 236 | robot.keyPress(keys.ENTER, 500); |
| 237 | robot.sequence(d.getTestErrback(lang.hitch(this, function(){ |
| 238 | doh.is("toolbar1_dialog", dfocus.curNode.id, "dialog button, third visit"); |
| 239 | })), 1000); |
| 240 | |
| 241 | // Try the ColorPalette |
| 242 | robot.keyPress(keys.RIGHT_ARROW, 500); |
| 243 | robot.keyPress(keys.DOWN_ARROW, 500); |
| 244 | robot.sequence(d.getTestErrback(lang.hitch(this, function(){ |
| 245 | doh.t(dom.isDescendant(dfocus.curNode, registry.byId("toolbar1_colorPalette").domNode), |
| 246 | "focus inside colorpalette, actual focus is: " + (dfocus.curNode ? |
| 247 | (dfocus.curNode.id||"no id") : "no focus")); |
| 248 | })), 1000); |
| 249 | robot.keyPress(keys.RIGHT_ARROW, 500); // navigation in the ColorPalette |
| 250 | robot.keyPress(keys.DOWN_ARROW, 500); // navigation in the ColorPalette |
| 251 | robot.sequence(d.getTestErrback(lang.hitch(this, function(){ |
| 252 | doh.t(dom.isDescendant(dfocus.curNode, registry.byId("toolbar1_colorPalette").domNode), |
| 253 | "focus still inside colorpalette, actual focus is: " + (dfocus.curNode ? |
| 254 | (dfocus.curNode.id||"no id") : "no focus")); |
| 255 | })), 1000); |
| 256 | |
| 257 | // pressing tab in the colorpalette should move focus back to the toolbar |
| 258 | robot.keyPress(keys.TAB, 500); |
| 259 | robot.sequence(d.getTestErrback(lang.hitch(this, function(){ |
| 260 | doh.is("toolbar1_backcolor", dfocus.curNode.id, "back on colorpalette button"); |
| 261 | })), 1000); |
| 262 | |
| 263 | // try the ComboButton |
| 264 | robot.keyPress(keys.RIGHT_ARROW, 500); |
| 265 | robot.keyPress(keys.RIGHT_ARROW, 500); |
| 266 | robot.keyPress(keys.DOWN_ARROW, 500); |
| 267 | robot.sequence(d.getTestErrback(lang.hitch(this, function(){ |
| 268 | // TODO: test that focus is on menu |
| 269 | })), 1000); |
| 270 | robot.keyPress(keys.SPACE, 500); // select first menu option |
| 271 | robot.sequence(d.getTestCallback(lang.hitch(this, function(){ |
| 272 | // TODO: test that focus is returned to button |
| 273 | })), 1000); |
| 274 | |
| 275 | return d; |
| 276 | } |
| 277 | } |
| 278 | |
| 279 | ]); |
| 280 | // TODO: mouse |
| 281 | |
| 282 | |
| 283 | doh.run(); |
| 284 | }); |
| 285 | </script> |
| 286 | </head> |
| 287 | </html> |