| 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 Tooltip A11Y Test</title> |
| 6 |
|
| 7 |
<style> |
| 8 |
@import "../../../util/doh/robot/robot.css"; |
| 9 |
</style> |
| 10 |
|
| 11 |
|
| 12 |
<script type="text/javascript" src="../../../dojo/dojo.js" |
| 13 |
data-dojo-config="isDebug: true"></script> |
| 14 |
|
| 15 |
<script type="text/javascript"> |
| 16 |
require([ |
| 17 |
"doh/runner", "dojo/robotx", |
| 18 |
"dojo/dom", "dojo/dom-geometry", "dojo/keys", "dojo/_base/lang", "dojo/_base/window", "dojo/window", |
| 19 |
"dijit/tests/helpers", "dojo/domReady!" |
| 20 |
], function(doh, robot, dom, domGeom, keys, lang, win, winUtils, helpers){ |
| 21 |
|
| 22 |
robot.initRobot('../test_Tooltip.html'); |
| 23 |
|
| 24 |
doh.register("setup", function(){ |
| 25 |
// get pointer to registry in the iframe |
| 26 |
registry = robot.window.require("dijit/registry"); |
| 27 |
Tooltip = robot.window.require("dijit/Tooltip"); |
| 28 |
|
| 29 |
// Avoid the page being scrolled when you run the test twice (via browser's refresh button) |
| 30 |
win.body().parentNode.scrollTop = 0; // works on FF |
| 31 |
win.body().scrollTop = 0; // works on safari |
| 32 |
}); |
| 33 |
|
| 34 |
// Pointer to master tooltip. This gets set in the first test when the |
| 35 |
// first tooltip is shown |
| 36 |
var masterTT; |
| 37 |
|
| 38 |
doh.register("dijit.Tooltip keyboard tests", [ |
| 39 |
{ |
| 40 |
name: "show on focus", |
| 41 |
timeout: 4000, |
| 42 |
runTest: function(){ |
| 43 |
var d = new doh.Deferred(), |
| 44 |
around = dom.byId("four"); |
| 45 |
|
| 46 |
robot.sequence(function(){ |
| 47 |
around.focus(); |
| 48 |
masterTT = Tooltip._masterTT; |
| 49 |
doh.t(!masterTT || helpers.isHidden(masterTT.domNode), "tooltip either hidden or doesn't exist yet"); |
| 50 |
}, 500); |
| 51 |
|
| 52 |
robot.sequence(d.getTestCallback(function(){ |
| 53 |
// At this point the master tooltip should have been created, so save in |
| 54 |
// global variable |
| 55 |
masterTT = Tooltip._masterTT; |
| 56 |
|
| 57 |
doh.t(masterTT && helpers.isVisible(masterTT.domNode), "tooltip shown"); |
| 58 |
|
| 59 |
// make sure tooltip is in right place (but note that it could be to the |
| 60 |
// left of the right depending on page BIDI setting) |
| 61 |
var aroundCoords = domGeom.position(around), |
| 62 |
tooltipCoords = domGeom.position(masterTT.domNode); |
| 63 |
doh.t((aroundCoords.y + aroundCoords.h) <= (tooltipCoords.y + tooltipCoords.h), "lower aligned"); |
| 64 |
doh.t(aroundCoords.y >= tooltipCoords.y, "upper aligned"); |
| 65 |
|
| 66 |
// Make sure it has right content |
| 67 |
doh.is("tooltip on a button", lang.trim(helpers.innerText(masterTT.domNode)), "tooltip text"); |
| 68 |
}), 2000); |
| 69 |
|
| 70 |
return d; |
| 71 |
} |
| 72 |
}, |
| 73 |
|
| 74 |
{ |
| 75 |
name: "hide on blur", |
| 76 |
timeout: 4000, |
| 77 |
runTest: function(){ |
| 78 |
var d = new doh.Deferred(); |
| 79 |
|
| 80 |
// Tab off of the "button w/tooltip" to the "remove button", |
| 81 |
// which doesn't have a tooltip |
| 82 |
robot.keyPress(keys.TAB, 500, {}); |
| 83 |
|
| 84 |
robot.sequence(d.getTestCallback(function(){ |
| 85 |
doh.t(masterTT && helpers.isHidden(masterTT.domNode), "tooltip hidden"); |
| 86 |
}), 2000); |
| 87 |
|
| 88 |
return d; |
| 89 |
} |
| 90 |
}, |
| 91 |
|
| 92 |
{ |
| 93 |
name: "show another tooltip", |
| 94 |
timeout: 4000, |
| 95 |
runTest: function(){ |
| 96 |
var d = new doh.Deferred(), |
| 97 |
around = dom.byId("seven"); |
| 98 |
|
| 99 |
// Tab off of the "remove button" to the <select> |
| 100 |
robot.keyPress(keys.TAB, 500, {}); |
| 101 |
|
| 102 |
robot.sequence(d.getTestCallback(function(){ |
| 103 |
doh.t(masterTT && helpers.isVisible(masterTT.domNode), "tooltip shown"); |
| 104 |
|
| 105 |
// make sure tooltip is on the screen (in LTR mode it needs to go to the |
| 106 |
// left of the <select>, not to the right like it usually does) |
| 107 |
var viewportCoords = winUtils.getBox(), |
| 108 |
tooltipCoords = domGeom.position(masterTT.domNode); |
| 109 |
console.log("viewport coords: ", viewportCoords, "tooltip coords: ", tooltipCoords); |
| 110 |
doh.t(tooltipCoords.x > 0, "x > 0"); |
| 111 |
doh.t(tooltipCoords.x + tooltipCoords.w <= viewportCoords.w, "t.x + t.w"); |
| 112 |
doh.t(tooltipCoords.y > 0, "y > 0"); |
| 113 |
doh.t(tooltipCoords.y + tooltipCoords.h <= viewportCoords.h, "t.y + t.h"); |
| 114 |
|
| 115 |
// Make sure it has the new content. |
| 116 |
// There's a newline in this tooltip text, so to make comparison easier do substr() |
| 117 |
doh.is("tooltip on a select", lang.trim(helpers.innerText(masterTT.domNode)).substr(0, 19), "tooltip text"); |
| 118 |
}), 2000); |
| 119 |
|
| 120 |
return d; |
| 121 |
} |
| 122 |
} |
| 123 |
|
| 124 |
]); |
| 125 |
|
| 126 |
doh.register("dijit.Tooltip negative keyboard tests", [ |
| 127 |
// Test that quickly going over a node doesn't cause the tooltip |
| 128 |
// to show up |
| 129 |
{ |
| 130 |
name: "jump over", |
| 131 |
timeout: 4000, |
| 132 |
runTest: function(){ |
| 133 |
var d = new doh.Deferred(), |
| 134 |
around = dom.byId("one"); |
| 135 |
|
| 136 |
// Focus onto something w/out a tooltip to make currently displayed tooltip disappear |
| 137 |
robot.sequence(d.getTestErrback(function(){ |
| 138 |
dom.byId("removeButton").focus(); |
| 139 |
}), 50); |
| 140 |
|
| 141 |
// Focus on a node w/a tooltip |
| 142 |
robot.sequence(d.getTestErrback(function(){ |
| 143 |
around.focus(); |
| 144 |
}), 500); |
| 145 |
|
| 146 |
robot.sequence(d.getTestErrback(function(){ |
| 147 |
doh.t(helpers.isHidden(masterTT.domNode), "tooltip should be hidden on initial focus, but text shown is: " + |
| 148 |
lang.trim(helpers.innerText(masterTT.domNode))); |
| 149 |
}), 50); |
| 150 |
|
| 151 |
// But then tab away after 100ms, before tooltip is shown |
| 152 |
robot.keyPress(keys.TAB, 50, {shift: true}); |
| 153 |
|
| 154 |
robot.sequence(d.getTestCallback(function(){ |
| 155 |
doh.t(helpers.isHidden(masterTT.domNode), "tooltip still hidden after tabbing away"); |
| 156 |
}), 1000); |
| 157 |
|
| 158 |
return d; |
| 159 |
} |
| 160 |
} |
| 161 |
]); |
| 162 |
|
| 163 |
doh.register("dijit.Tooltip API tests", [ |
| 164 |
|
| 165 |
// These tests are for a tooltip attached to multiple nodes, |
| 166 |
// and for dynamically changing the nodes that a tooltip is attached to. |
| 167 |
|
| 168 |
// Initially, the tooltip is attached to "t1 text" and "t3 text". |
| 169 |
// It should show for either of them. |
| 170 |
// "t2 text" shouldn't show until we connect the tooltip to that node. |
| 171 |
|
| 172 |
{ |
| 173 |
name: "setup", |
| 174 |
timeout: 4000, |
| 175 |
runTest: function(){ |
| 176 |
var d = new doh.Deferred(), |
| 177 |
tooltip = registry.byId("t_tooltip"); |
| 178 |
|
| 179 |
// While we are at it, test set('label', ...) too |
| 180 |
tooltip.set('label', 'bill was here'); |
| 181 |
|
| 182 |
var connectIds = tooltip.get("connectId"); |
| 183 |
doh.is(2, connectIds.length, "2 connect ids initially"); |
| 184 |
doh.is("t1", connectIds[0]); |
| 185 |
doh.is("t3", connectIds[1]); |
| 186 |
} |
| 187 |
}, |
| 188 |
|
| 189 |
{ |
| 190 |
name: "tooltip connected to 't1 text'", |
| 191 |
timeout: 5000, |
| 192 |
runTest: function(){ |
| 193 |
var d = new doh.Deferred(), |
| 194 |
around = dom.byId("t1"); |
| 195 |
|
| 196 |
robot.sequence(function(){ |
| 197 |
winUtils.scrollIntoView(around); |
| 198 |
around.focus(); |
| 199 |
}, 500); |
| 200 |
|
| 201 |
robot.sequence(d.getTestCallback(function(){ |
| 202 |
doh.t(masterTT && helpers.isVisible(masterTT.domNode), "tooltip shown"); |
| 203 |
|
| 204 |
// Make sure it has right content |
| 205 |
doh.is("bill was here", lang.trim(helpers.innerText(masterTT.domNode)), "tooltip text"); |
| 206 |
}), 2000); |
| 207 |
|
| 208 |
return d; |
| 209 |
} |
| 210 |
}, |
| 211 |
|
| 212 |
{ |
| 213 |
name: "tooltip *not* connected to 't2 text'", |
| 214 |
timeout: 5000, |
| 215 |
runTest: function(){ |
| 216 |
var d = new doh.Deferred(), |
| 217 |
around = dom.byId("t2"); |
| 218 |
|
| 219 |
robot.sequence(function(){ |
| 220 |
winUtils.scrollIntoView(around); |
| 221 |
around.focus(); |
| 222 |
}, 500); |
| 223 |
|
| 224 |
robot.sequence(d.getTestCallback(function(){ |
| 225 |
doh.t(masterTT && helpers.isHidden(masterTT.domNode), "tooltip hidden"); |
| 226 |
}), 2000); |
| 227 |
|
| 228 |
return d; |
| 229 |
} |
| 230 |
}, |
| 231 |
|
| 232 |
{ |
| 233 |
name: "'t3 text' is connected to the tooltip", |
| 234 |
timeout: 5000, |
| 235 |
runTest: function(){ |
| 236 |
var d = new doh.Deferred(), |
| 237 |
around = dom.byId("t3"); |
| 238 |
|
| 239 |
robot.sequence(function(){ |
| 240 |
winUtils.scrollIntoView(around); |
| 241 |
around.focus(); |
| 242 |
}, 500); |
| 243 |
|
| 244 |
robot.sequence(d.getTestCallback(function(){ |
| 245 |
doh.t(masterTT && helpers.isVisible(masterTT.domNode), "tooltip visible"); |
| 246 |
}), 2000); |
| 247 |
|
| 248 |
return d; |
| 249 |
} |
| 250 |
}, |
| 251 |
|
| 252 |
{ |
| 253 |
name: "connect to 't2 text'", |
| 254 |
timeout: 4000, |
| 255 |
runTest: function(){ |
| 256 |
var d = new doh.Deferred(), |
| 257 |
tooltip = registry.byId("t_tooltip"), |
| 258 |
around = dom.byId("t2"); |
| 259 |
|
| 260 |
tooltip.addTarget("t2"); |
| 261 |
|
| 262 |
var connectIds = tooltip.get("connectId"); |
| 263 |
doh.is(3, connectIds.length, "3 connect ids"); |
| 264 |
doh.is("t1", connectIds[0]); |
| 265 |
doh.is("t3", connectIds[1]); |
| 266 |
doh.is("t2", connectIds[2]); |
| 267 |
|
| 268 |
// Focus "t2 text" and make sure tooltip shows |
| 269 |
winUtils.scrollIntoView(around); |
| 270 |
around.focus(); |
| 271 |
|
| 272 |
robot.sequence(d.getTestCallback(function(){ |
| 273 |
doh.t(masterTT && helpers.isVisible(masterTT.domNode), "tooltip shown"); |
| 274 |
}), 2000); |
| 275 |
|
| 276 |
return d; |
| 277 |
} |
| 278 |
}, |
| 279 |
|
| 280 |
{ |
| 281 |
name: "disconnect from 't3 text'", |
| 282 |
timeout: 4000, |
| 283 |
runTest: function(){ |
| 284 |
var d = new doh.Deferred(), |
| 285 |
tooltip = registry.byId("t_tooltip"), |
| 286 |
around = dom.byId("t3"); |
| 287 |
|
| 288 |
tooltip.removeTarget("t3"); |
| 289 |
var connectIds = tooltip.get("connectId"); |
| 290 |
doh.is(2, connectIds.length, "2 connect ids"); |
| 291 |
doh.is("t1", connectIds[0]); |
| 292 |
doh.is("t2", connectIds[1]); |
| 293 |
|
| 294 |
// Focus "t3 text" and make sure tooltip doesn't show |
| 295 |
winUtils.scrollIntoView(around); |
| 296 |
around.focus(); |
| 297 |
|
| 298 |
robot.sequence(d.getTestCallback(function(){ |
| 299 |
doh.t(masterTT && helpers.isHidden(masterTT.domNode), "tooltip hidden"); |
| 300 |
}), 2000); |
| 301 |
|
| 302 |
return d; |
| 303 |
} |
| 304 |
}, |
| 305 |
|
| 306 |
{ |
| 307 |
name: "reset connectId array", |
| 308 |
timeout: 4000, |
| 309 |
runTest: function(){ |
| 310 |
var d = new doh.Deferred(), |
| 311 |
tooltip = registry.byId("t_tooltip"), |
| 312 |
around = dom.byId("t2"); |
| 313 |
|
| 314 |
// Move focus somewhere out of the way |
| 315 |
dom.byId("t5").focus(); |
| 316 |
|
| 317 |
// Disconnecting from "t2 text", and adding "t4 text" |
| 318 |
tooltip.set("connectId", ["t3", "t4"]); |
| 319 |
|
| 320 |
// Focus "t2 text" and make sure tooltip doesn't show anymore |
| 321 |
winUtils.scrollIntoView(around); |
| 322 |
around.focus(); |
| 323 |
|
| 324 |
robot.sequence(d.getTestCallback(function(){ |
| 325 |
doh.t(masterTT && helpers.isHidden(masterTT.domNode), "tooltip hidden"); |
| 326 |
}), 2000); |
| 327 |
|
| 328 |
return d; |
| 329 |
} |
| 330 |
}, |
| 331 |
{ |
| 332 |
name: "further testing connectId array reset worked", |
| 333 |
timeout: 4000, |
| 334 |
runTest: function(){ |
| 335 |
var d = new doh.Deferred(), |
| 336 |
tooltip = registry.byId("t_tooltip"), |
| 337 |
around = dom.byId("t4"); |
| 338 |
|
| 339 |
// Focus "t4 text" and make sure tooltip shows |
| 340 |
winUtils.scrollIntoView(around); |
| 341 |
around.focus(); |
| 342 |
|
| 343 |
robot.sequence(d.getTestCallback(function(){ |
| 344 |
doh.t(masterTT && helpers.isVisible(masterTT.domNode), "tooltip visible"); |
| 345 |
}), 2000); |
| 346 |
|
| 347 |
return d; |
| 348 |
} |
| 349 |
}, |
| 350 |
|
| 351 |
// Nominal tests for old dojoType syntax, remove in 2.0 |
| 352 |
function oldDojoTypeSyntax(){ |
| 353 |
var tooltip = registry.byId("oldmulti1,oldmulti2_tooltip"); |
| 354 |
doh.is(2, tooltip.get("connectId").length); |
| 355 |
doh.is("oldmulti1", tooltip.get("connectId")[0]); |
| 356 |
doh.is("oldmulti2", tooltip.get("connectId")[1]); |
| 357 |
} |
| 358 |
]); |
| 359 |
|
| 360 |
doh.register("Focus on nested element", [ |
| 361 |
{ |
| 362 |
name: "Focus on nested element", |
| 363 |
timeout: 4000, |
| 364 |
runTest: function(){ |
| 365 |
var d = new doh.Deferred(); |
| 366 |
|
| 367 |
// Focus an input where the containing div has a tooltip. |
| 368 |
// Should show a tooltip on the div. |
| 369 |
dom.byId("nestedInput").focus(); |
| 370 |
|
| 371 |
robot.sequence(d.getTestCallback(function(){ |
| 372 |
doh.t(masterTT && helpers.isVisible(masterTT.domNode), "tooltip shown"); |
| 373 |
|
| 374 |
var tooltipPos = domGeom.position(masterTT.domNode), |
| 375 |
anchorPos = domGeom.position("nested"); |
| 376 |
doh.t(Math.round(tooltipPos.x) >= Math.round(anchorPos.x + anchorPos.w), |
| 377 |
"tooltip pos " + tooltipPos.x + " > anchor right edge at " + |
| 378 |
anchorPos.x + " + " + anchorPos.w); |
| 379 |
}), 500); |
| 380 |
|
| 381 |
return d; |
| 382 |
} |
| 383 |
} |
| 384 |
]); |
| 385 |
|
| 386 |
doh.run(); |
| 387 |
}); |
| 388 |
</script> |
| 389 |
</head> |
| 390 |
</html> |