| 1 | <!DOCTYPE html> |
| 2 | <html> |
| 3 | <head> |
| 4 | <title>Dialog Widget Automated (non-robot) Tests</title> |
| 5 | |
| 6 | <script src="boilerplate.js"></script> |
| 7 | |
| 8 | <script type="text/javascript"> |
| 9 | require([ |
| 10 | "doh/runner", |
| 11 | "dojo/_base/declare", "dojo/dom", "dojo/dom-geometry", "dojo/dom-style", "dojo/window", |
| 12 | "dijit/focus", "dijit/registry", "dijit/Dialog", "dijit/DialogUnderlay", "dijit/_WidgetBase", |
| 13 | "dijit/tests/helpers", "dojo/domReady!" |
| 14 | ], function(doh, declare, dom, domGeom, domStyle, winUtils, |
| 15 | focus, registry, Dialog, DialogUnderlay, _WidgetBase, helpers){ |
| 16 | // Non robot tests to see if nested dialogs work correctly |
| 17 | // when obscured dialogs are destroyed/hidden, on race conditions of |
| 18 | // multiple dialogs fading in/out at once, etc. |
| 19 | |
| 20 | doh.register("setup", function(){ |
| 21 | // Start focus on a button on the page (although we aren't going |
| 22 | // to click the button) |
| 23 | var d = new doh.Deferred(); |
| 24 | |
| 25 | setTimeout(d.getTestErrback(function(){ |
| 26 | dom.byId("button").focus(); |
| 27 | |
| 28 | setTimeout(d.getTestCallback(function(){ |
| 29 | doh.is("button", focus.curNode.id, "focus is on the main page"); |
| 30 | }), 100); |
| 31 | }), 300); |
| 32 | |
| 33 | return d; |
| 34 | }); |
| 35 | |
| 36 | doh.register("out-of-order dialog hide/destroy", [ |
| 37 | { |
| 38 | name: "open first dialog", |
| 39 | timeout: 10000, |
| 40 | runTest: function(){ |
| 41 | var d = new doh.Deferred(), |
| 42 | dlg1; |
| 43 | |
| 44 | // Create and show first dialog |
| 45 | dlg1 = new Dialog({ |
| 46 | id: "dlg1", |
| 47 | title: "dialog 1", |
| 48 | content: |
| 49 | "<input id='dlg1_inputA'><br>" + |
| 50 | "<input id='dlg1_inputB'><br>" + |
| 51 | "<input id='dlg1_inputC'><br>" + |
| 52 | "<input id='dlg1_inputD'><br>" + |
| 53 | "<input id='dlg1_inputE'><br>" + |
| 54 | "<input id='dlg1_inputF'><br>" + |
| 55 | "<input id='dlg1_inputG'><br>" + |
| 56 | "<input id='dlg1_inputH'><br>" |
| 57 | }); |
| 58 | dlg1.show().then(d.getTestCallback(function(){ |
| 59 | doh.t(helpers.isVisible(dlg1), "dialog 1 is visible"); |
| 60 | |
| 61 | var dialog1Z = domStyle.get(dlg1.domNode, "zIndex"), |
| 62 | underlayZ = domStyle.get(DialogUnderlay._singleton.domNode, "zIndex"); |
| 63 | |
| 64 | doh.t(dialog1Z > underlayZ, "dialog1 (zIndex=" + dialog1Z + |
| 65 | ") above underlay (zIndex=" + underlayZ + ")"); |
| 66 | |
| 67 | doh.is("dlg1_inputA", focus.curNode.id, "focus is on the first field"); |
| 68 | |
| 69 | // For back-compat, startup() should be called on children even if Dialog.startup() |
| 70 | // isn't called explicitly. |
| 71 | doh.t(dlg1._started, "dlg1 started"); |
| 72 | })); |
| 73 | |
| 74 | return d; |
| 75 | } |
| 76 | }, |
| 77 | { |
| 78 | name: "open second dialog", |
| 79 | timeout: 20000, |
| 80 | runTest: function(){ |
| 81 | var d = new doh.Deferred(), |
| 82 | dlg1 = registry.byId("dlg1"), |
| 83 | dlg2; |
| 84 | |
| 85 | // Create and show second dialog |
| 86 | dlg2 = new Dialog({ |
| 87 | id: "dlg2", |
| 88 | title: "dialog 2", |
| 89 | content: |
| 90 | "<input id='dlg2_inputA'><br>" + |
| 91 | "<input id='dlg2_inputB'><br>" + |
| 92 | "<input id='dlg2_inputC'><br>" + |
| 93 | "<input id='dlg2_inputD'><br>" + |
| 94 | "<input id='dlg2_inputE'><br>" + |
| 95 | "<input id='dlg2_inputF'><br>" |
| 96 | }); |
| 97 | dlg2.show().then(d.getTestCallback(function(){ |
| 98 | doh.t(helpers.isVisible(dlg2), "dialog 2 is visible"); |
| 99 | |
| 100 | var dialog1Z = domStyle.get(dlg1.domNode, "zIndex"), |
| 101 | dialog2Z = domStyle.get(dlg2.domNode, "zIndex"), |
| 102 | underlayZ = domStyle.get(DialogUnderlay._singleton.domNode, "zIndex"); |
| 103 | |
| 104 | doh.t(underlayZ > dialog1Z, "underlay (zIndex=" + underlayZ + |
| 105 | ") above dialog1 (zIndex=" + dialog1Z + ")"); |
| 106 | doh.t(dialog2Z > underlayZ, "dialog2 (zIndex=" + dialog2Z + |
| 107 | ") above underlay (zIndex=" + underlayZ + ")"); |
| 108 | |
| 109 | doh.is("dlg2_inputA", focus.curNode.id, "focus is on the first field"); |
| 110 | })); |
| 111 | |
| 112 | return d; |
| 113 | } |
| 114 | }, |
| 115 | { |
| 116 | name: "destroy first dialog", |
| 117 | timeout: 20000, |
| 118 | runTest: function(){ |
| 119 | var d = new doh.Deferred(), |
| 120 | dlg1 = registry.byId("dlg1"), |
| 121 | dlg2 = registry.byId("dlg2"); |
| 122 | |
| 123 | dlg1.destroy(); |
| 124 | |
| 125 | setTimeout(d.getTestCallback(function(){ |
| 126 | doh.t(helpers.isVisible(dlg2), "dialog 2 is still visible"); |
| 127 | doh.t(helpers.isVisible(DialogUnderlay._singleton), "underlay is still visible"); |
| 128 | |
| 129 | doh.is("dlg2_inputA", focus.curNode.id, "dialog 2 still has focus"); |
| 130 | |
| 131 | var dialog2Z = domStyle.get(dlg2.domNode, "zIndex"), |
| 132 | underlayZ = domStyle.get(DialogUnderlay._singleton.domNode, "zIndex"); |
| 133 | |
| 134 | doh.t(dialog2Z > underlayZ, "dialog2 (zIndex=" + dialog2Z + |
| 135 | ") above underlay (zIndex=" + underlayZ + ")"); |
| 136 | |
| 137 | }), 2000); |
| 138 | |
| 139 | return d; |
| 140 | } |
| 141 | }, |
| 142 | { |
| 143 | name: "open third dialog", |
| 144 | timeout: 20000, |
| 145 | runTest: function(){ |
| 146 | var d = new doh.Deferred(), |
| 147 | dlg2 = registry.byId("dlg2"), |
| 148 | dlg3; |
| 149 | |
| 150 | // Create and show third dialog |
| 151 | dlg3 = new Dialog({ |
| 152 | id: "dlg3", |
| 153 | title: "dialog 3", |
| 154 | content: |
| 155 | "<input id='dlg3_inputA'><br>" + |
| 156 | "<input id='dlg3_inputB'><br>" + |
| 157 | "<input id='dlg3_inputC'><br>" + |
| 158 | "<input id='dlg3_inputD'><br>" |
| 159 | |
| 160 | }); |
| 161 | dlg3.show().then(d.getTestCallback(function(){ |
| 162 | doh.t(helpers.isVisible(dlg3), "dialog 3 is visible"); |
| 163 | |
| 164 | // Even though a dialog was deleted, the zIndex of the dialog 3 |
| 165 | // should be above dialog 2. This test is to make sure we don't |
| 166 | // merely use _dialogStack.length to compute zIndex |
| 167 | var dialog2Z = domStyle.get(dlg2.domNode, "zIndex"), |
| 168 | dialog3Z = domStyle.get(dlg3.domNode, "zIndex"), |
| 169 | underlayZ = domStyle.get(DialogUnderlay._singleton.domNode, "zIndex"); |
| 170 | doh.t(underlayZ > dialog2Z, "underlay (zIndex=" + underlayZ + |
| 171 | ") above dialog2 (zIndex=" + dialog2Z + ")"); |
| 172 | doh.t(dialog3Z > underlayZ, "dialog3 (zIndex=" + dialog3Z + |
| 173 | ") above underlay (zIndex=" + underlayZ + ")"); |
| 174 | |
| 175 | doh.is("dlg3_inputA", focus.curNode.id, "focus is on the first field"); |
| 176 | })); |
| 177 | |
| 178 | return d; |
| 179 | } |
| 180 | }, |
| 181 | { |
| 182 | name: "open fourth dialog", |
| 183 | timeout: 30000, |
| 184 | runTest: function(){ |
| 185 | var d = new doh.Deferred(), |
| 186 | dlg3 = registry.byId("dlg3"), |
| 187 | dlg4; |
| 188 | |
| 189 | // Create and show fourth dialog |
| 190 | dlg4 = new Dialog({ |
| 191 | id: "dlg4", |
| 192 | title: "dialog 4", |
| 193 | content: |
| 194 | "<input id='dlg4_inputA'><br>" + |
| 195 | "<input id='dlg4_inputB'>" |
| 196 | }); |
| 197 | dlg4.show().then(d.getTestCallback(function(){ |
| 198 | doh.t(helpers.isVisible(dlg4), "dialog 4 is visible"); |
| 199 | |
| 200 | var dialog3Z = domStyle.get(dlg3.domNode, "zIndex"), |
| 201 | dialog4Z = domStyle.get(dlg4.domNode, "zIndex"), |
| 202 | underlayZ = domStyle.get(DialogUnderlay._singleton.domNode, "zIndex"); |
| 203 | doh.t(underlayZ > dialog3Z, "underlay (zIndex=" + underlayZ + |
| 204 | ") above dialog3 (zIndex=" + dialog3Z + ")"); |
| 205 | doh.t(dialog4Z > underlayZ, "dialog4 (zIndex=" + dialog4Z + |
| 206 | ") above underlay (zIndex=" + underlayZ + ")"); |
| 207 | |
| 208 | doh.is("dlg4_inputA", focus.curNode.id, "focus is on the first field"); |
| 209 | })); |
| 210 | |
| 211 | return d; |
| 212 | } |
| 213 | }, |
| 214 | { |
| 215 | name: "hide third dialog", |
| 216 | timeout: 40000, |
| 217 | runTest: function(){ |
| 218 | var d = new doh.Deferred(), |
| 219 | dlg3 = registry.byId("dlg3"), |
| 220 | dlg4 = registry.byId("dlg4"); |
| 221 | |
| 222 | dlg3.hide().then(d.getTestCallback(function(){ |
| 223 | doh.t(helpers.isVisible(dlg4), "dialog 4 is still visible"); |
| 224 | doh.t(helpers.isVisible(DialogUnderlay._singleton), "underlay is still visible"); |
| 225 | |
| 226 | doh.is("dlg4_inputA", focus.curNode.id, "dialog 4 still has focus"); |
| 227 | |
| 228 | var dialog4Z = domStyle.get(dlg4.domNode, "zIndex"), |
| 229 | underlayZ = domStyle.get(DialogUnderlay._singleton.domNode, "zIndex"); |
| 230 | |
| 231 | doh.t(dialog4Z > underlayZ, "dialog4 (zIndex=" + dialog4Z + |
| 232 | ") above underlay (zIndex=" + underlayZ + ")"); |
| 233 | |
| 234 | })); |
| 235 | |
| 236 | return d; |
| 237 | } |
| 238 | }, |
| 239 | { |
| 240 | name: "close fourth dialog", |
| 241 | timeout: 30000, |
| 242 | runTest: function(){ |
| 243 | var d = new doh.Deferred(), |
| 244 | dlg2 = registry.byId("dlg2"), |
| 245 | dlg3 = registry.byId("dlg3"), |
| 246 | dlg4 = registry.byId("dlg4"); |
| 247 | |
| 248 | // Closing fourth dialog should move focus to second dialog, since we already destroyed the |
| 249 | // third dialog. Delay needed for IE9+ where focus shift is asynchronous. |
| 250 | dlg4.hide().then(function(){ |
| 251 | setTimeout(d.getTestCallback(function(){ |
| 252 | doh.t(helpers.isHidden(dlg4), "dialog 4 is hidden"); |
| 253 | doh.t(helpers.isHidden(dlg3), "dialog 3 is hidden"); |
| 254 | doh.t(helpers.isVisible(dlg2), "dialog 2 is visible"); |
| 255 | |
| 256 | var dialog2Z = domStyle.get(dlg2.domNode, "zIndex"), |
| 257 | underlayZ = domStyle.get(DialogUnderlay._singleton.domNode, "zIndex"); |
| 258 | doh.t(dialog2Z > underlayZ, "dialog2 (zIndex=" + dialog2Z + |
| 259 | ") above underlay (zIndex=" + underlayZ + ")"); |
| 260 | |
| 261 | doh.is("dlg2_inputA", focus.curNode.id, "focus is on the first field"); |
| 262 | })); |
| 263 | }); |
| 264 | |
| 265 | return d; |
| 266 | } |
| 267 | }, |
| 268 | { |
| 269 | name: "close second dialog", |
| 270 | timeout: 30000, |
| 271 | runTest: function(){ |
| 272 | var d = new doh.Deferred(), |
| 273 | dlg2 = registry.byId("dlg2"); |
| 274 | |
| 275 | // Since we already destroyed first dialog, closing second dialog should hide underlay and |
| 276 | // revert focus to the main page. Need the setTimeout() for IE9+ where focus change is not |
| 277 | // instant. |
| 278 | dlg2.hide().then(function(){ |
| 279 | setTimeout(d.getTestCallback(function(){ |
| 280 | doh.t(helpers.isHidden(dlg2), "dialog 4 is hidden"); |
| 281 | doh.t(helpers.isHidden(DialogUnderlay._singleton), "underlay hidden"); |
| 282 | |
| 283 | doh.is("button", focus.curNode.id, "focus is on the main page"); |
| 284 | })); |
| 285 | }); |
| 286 | |
| 287 | return d; |
| 288 | } |
| 289 | } |
| 290 | ]); |
| 291 | |
| 292 | var dlgA, dlgB; |
| 293 | doh.register("concurrent hide show (multiple dialogs)", { |
| 294 | name: "concurrent hide show", |
| 295 | timeout: 20000, |
| 296 | setUp: function(){ |
| 297 | // Create and show first dialog |
| 298 | dlgA = new Dialog({ |
| 299 | id: "dlgA", |
| 300 | title: "Dialog A", |
| 301 | content: |
| 302 | "<button type='button'>OK</button>" |
| 303 | }); |
| 304 | dlgB = new Dialog({ |
| 305 | id: "dlgB", |
| 306 | title: "dialog B", |
| 307 | content: |
| 308 | "<button type='button'>OK</button>" |
| 309 | }); |
| 310 | dlgA.show(); |
| 311 | |
| 312 | }, |
| 313 | runTest: function(){ |
| 314 | var d = new doh.Deferred(), |
| 315 | cnt=0; |
| 316 | |
| 317 | handle = setInterval(d.getTestErrback(function(){ |
| 318 | var hidden = cnt%2 ? dlgA : dlgB, |
| 319 | shown = cnt%2 ? dlgB : dlgA; |
| 320 | |
| 321 | if(cnt > 10){ |
| 322 | clearInterval(handle); |
| 323 | handle = null; |
| 324 | d.callback(true); |
| 325 | return; |
| 326 | } |
| 327 | |
| 328 | doh.t(helpers.isVisible(shown), shown.title + " visible"); |
| 329 | doh.t(helpers.isHidden(hidden), hidden.title + " hidden"); |
| 330 | doh.t(helpers.isVisible(DialogUnderlay._singleton), "underlay visible"); |
| 331 | |
| 332 | var shownZ = domStyle.get(shown.domNode, "zIndex"), |
| 333 | underlayZ = domStyle.get(DialogUnderlay._singleton.domNode, "zIndex"); |
| 334 | doh.t(shownZ > underlayZ, "visible dialog (zIndex=" + shownZ + |
| 335 | ") above underlay (zIndex=" + underlayZ + ")"); |
| 336 | |
| 337 | hidden.show(); |
| 338 | shown.hide(); |
| 339 | |
| 340 | cnt++; |
| 341 | }), 1000); |
| 342 | |
| 343 | return d; |
| 344 | }, |
| 345 | tearDown: function(){ |
| 346 | dlgA.hide(); |
| 347 | dlgB.hide(); |
| 348 | if(handle){ |
| 349 | clearInterval(handle); |
| 350 | } |
| 351 | } |
| 352 | }); |
| 353 | |
| 354 | var slow, fast; |
| 355 | doh.register("fast double show", [ |
| 356 | function create(){ |
| 357 | console.log("creating slow, fast"); |
| 358 | var d = new doh.Deferred(); |
| 359 | slow = new Dialog({ |
| 360 | id: "slow", |
| 361 | title: "Dialog C", |
| 362 | content: |
| 363 | "Hello world " + |
| 364 | "<button type='button' id='slowOK' onfocus='window.slowFocused=true;'>OK</button>" + |
| 365 | "<button type='button' id='slowCancel'>Cancel</button>", |
| 366 | duration: 500 |
| 367 | }); |
| 368 | fast = new Dialog({ |
| 369 | id: "fast", |
| 370 | title: "dialog D", |
| 371 | content: |
| 372 | "<button type='button'>OK</button>", |
| 373 | duration: 100 |
| 374 | }); |
| 375 | |
| 376 | }, |
| 377 | { |
| 378 | name: "show Dialog C then show Dialog D before Dialog C fade-in completes", |
| 379 | timeout: 20000, |
| 380 | runTest: function(){ |
| 381 | var d = new doh.Deferred(); |
| 382 | |
| 383 | slow.show(); |
| 384 | |
| 385 | setTimeout(d.getTestErrback(function(){ |
| 386 | fast.show(); |
| 387 | }), slow.duration / 2); |
| 388 | |
| 389 | setTimeout(d.getTestCallback(function(){ |
| 390 | doh.t(helpers.isVisible(slow), "dialog C visible"); |
| 391 | doh.t(helpers.isVisible(fast), "dialog D visible"); |
| 392 | doh.f(window.slowFocused, "dialog C never got focus") |
| 393 | }), slow.duration * 2); |
| 394 | return d; |
| 395 | } |
| 396 | }, |
| 397 | { |
| 398 | name: "close dialogD", |
| 399 | timeout: 20000, |
| 400 | runTest: function(){ |
| 401 | var d = new doh.Deferred(); |
| 402 | |
| 403 | fast.hide(); |
| 404 | |
| 405 | setTimeout(d.getTestCallback(function(){ |
| 406 | doh.is("slowOK", focus.curNode.id, "focused to dialog C"); |
| 407 | doh.t(window.slowFocused, "onfocus handler working"); |
| 408 | }), fast.duration * 2); |
| 409 | |
| 410 | return d; |
| 411 | } |
| 412 | }, |
| 413 | { |
| 414 | name: "close dialogC", |
| 415 | timeout: 20000, |
| 416 | runTest: function(){ |
| 417 | return slow.hide(); |
| 418 | } |
| 419 | } |
| 420 | ]); |
| 421 | |
| 422 | doh.register("fast double hide", [ |
| 423 | function create(){ |
| 424 | var d = new doh.Deferred(); |
| 425 | |
| 426 | // Create a test dialog |
| 427 | dlg = new Dialog({ |
| 428 | id: "doubleHide", |
| 429 | title: "Double Hide", |
| 430 | content: "Hello World", |
| 431 | duration: 100 |
| 432 | }); |
| 433 | |
| 434 | // First show it |
| 435 | var secondHideCalled; |
| 436 | dlg.show().then(d.getTestErrback(function(){ |
| 437 | // Then call hide(), as though user had clicked close icon. |
| 438 | // Return from this test when this hide() call completes. |
| 439 | dlg.hide().then(d.getTestCallback(function(){ |
| 440 | doh.t(secondHideCalled, "hide() was called while hide() in progress and no problems"); |
| 441 | dlg.hide(); // this should also have no effect |
| 442 | })); |
| 443 | |
| 444 | // While first hide() is in progress, call hide() a few more times to make sure it |
| 445 | // doesn't break anything |
| 446 | dlg.hide(); // should do nothing |
| 447 | setTimeout(d.getTestErrback(function(){ |
| 448 | dlg.hide(); // should also do nothing |
| 449 | secondHideCalled = true; |
| 450 | }), 10); |
| 451 | })); |
| 452 | return d; |
| 453 | } |
| 454 | ]); |
| 455 | |
| 456 | doh.register("concurrent show hide (single dialog)", [ |
| 457 | function show(){ |
| 458 | var d = new doh.Deferred(); |
| 459 | |
| 460 | var onShowCtr = 0, |
| 461 | dlg = new Dialog({ |
| 462 | id: "show", |
| 463 | title: "onShow Dialog", |
| 464 | content:"Hello world ", |
| 465 | onShow: function(){ onShowCtr++; } |
| 466 | }); |
| 467 | |
| 468 | doh.is(1, Dialog._dialogStack.length, "initially, no dialogs in stack"); |
| 469 | dlg.show(); |
| 470 | doh.is(1, onShowCtr, "onShow first time"); |
| 471 | dlg.hide(); |
| 472 | doh.is(1, onShowCtr, "onHide first time"); |
| 473 | dlg.show(); |
| 474 | doh.is(2, onShowCtr, "onShow second time"); |
| 475 | dlg.hide().then(d.getTestCallback(function(){ |
| 476 | doh.is(2, onShowCtr, "onHide second time"); |
| 477 | doh.is(1, Dialog._dialogStack.length, "at end, no dialogs in stack"); |
| 478 | })); |
| 479 | |
| 480 | return d; |
| 481 | } |
| 482 | ]); |
| 483 | |
| 484 | doh.register("zero duration", [ |
| 485 | { |
| 486 | name: "open", |
| 487 | timeout: 10000, |
| 488 | runTest: function(){ |
| 489 | dlg1 = new Dialog({ |
| 490 | id: "dlg1", |
| 491 | title: "dialog 1", |
| 492 | duration: 0, |
| 493 | content: "<input id='dlg1_inputA'>" |
| 494 | }); |
| 495 | |
| 496 | var promise = dlg1.show(); |
| 497 | doh.t(promise.isResolved(), "resolved"); |
| 498 | doh.t(helpers.isVisible(dlg1), "dialog visible"); |
| 499 | } |
| 500 | }, |
| 501 | { |
| 502 | name: "close", |
| 503 | timeout: 10000, |
| 504 | runTest: function(){ |
| 505 | var promise = dlg1.hide(); |
| 506 | doh.t(promise.isResolved(), "resolved"); |
| 507 | doh.t(helpers.isHidden(dlg1), "dialog hidden"); |
| 508 | } |
| 509 | } |
| 510 | ]); |
| 511 | |
| 512 | doh.register("show/hide return", [ |
| 513 | { |
| 514 | name: "open", |
| 515 | timeout: 10000, |
| 516 | runTest: function(){ |
| 517 | var d = new doh.Deferred(); |
| 518 | |
| 519 | dlg5 = new Dialog({ |
| 520 | id: "dlg5", |
| 521 | title: "dialog 1", |
| 522 | content: "<input id='dlg1_inputA'>" |
| 523 | }); |
| 524 | |
| 525 | // This tests that show() returns a promise. |
| 526 | dlg5.show().then(d.getTestCallback(function(){ |
| 527 | // And this tests that it still returns a promise even when the Dialog is already shown. |
| 528 | var promise = dlg5.show(); |
| 529 | doh.t(promise.isResolved(), "resolved"); |
| 530 | doh.t(helpers.isVisible(dlg5), "dialog visible"); |
| 531 | })); |
| 532 | |
| 533 | return d; |
| 534 | } |
| 535 | }, |
| 536 | { |
| 537 | name: "close", |
| 538 | timeout: 10000, |
| 539 | runTest: function(){ |
| 540 | var d = new doh.Deferred(); |
| 541 | |
| 542 | // This tests that hide() returns a promise. |
| 543 | dlg5.hide().then(d.getTestCallback(function(){ |
| 544 | // And this tests that it still returns a promise even when the Dialog is already hidden. |
| 545 | var promise = dlg5.hide(); |
| 546 | doh.t(promise.isResolved(), "resolved"); |
| 547 | doh.t(helpers.isHidden(dlg5), "dialog hidden"); |
| 548 | })); |
| 549 | |
| 550 | return d; |
| 551 | } |
| 552 | } |
| 553 | ]); |
| 554 | |
| 555 | LayoutWidget = declare(_WidgetBase, { |
| 556 | resize: function(dim){ |
| 557 | this._resized = true; |
| 558 | this._resizeArg = dim; |
| 559 | } |
| 560 | }); |
| 561 | |
| 562 | doh.register("sizing", [ |
| 563 | { |
| 564 | name: "href", |
| 565 | timeout: 10000, |
| 566 | runTest: function(){ |
| 567 | hrefDlg = new Dialog({ |
| 568 | id: "bigHref", |
| 569 | title: "big dialog with href", |
| 570 | href: "loremIpsum" |
| 571 | }); |
| 572 | |
| 573 | return hrefDlg.show().then(function(){ |
| 574 | var dlgPos = domGeom.position(hrefDlg.domNode), |
| 575 | viewport = winUtils.getBox(); |
| 576 | doh.t(dlgPos.h < viewport.h, "viewport height"); |
| 577 | doh.t(dlgPos.y > 0, "position"); |
| 578 | }); |
| 579 | } |
| 580 | }, |
| 581 | { |
| 582 | name: "resize", |
| 583 | timeout: 10000, |
| 584 | runTest: function(){ |
| 585 | hrefDlg.resize({h: 200, w: 300}); |
| 586 | |
| 587 | var domPos = domGeom.position(hrefDlg.domNode); |
| 588 | doh.is(200, domPos.h, "domNode.h"); |
| 589 | doh.is(300, domPos.w, "domNode.w"); |
| 590 | |
| 591 | // containerNode should be slightly smaller |
| 592 | var containerPos = domGeom.position(hrefDlg.containerNode); |
| 593 | doh.t(containerPos.h > 150 && containerPos.h < 190, "containerNode.h " + containerPos.h); |
| 594 | doh.is(298, containerPos.w, "containerNode.w"); |
| 595 | doh.is("auto", hrefDlg.containerNode.style.overflow, "overflow style") |
| 596 | } |
| 597 | }, |
| 598 | { |
| 599 | name: "single layout child", |
| 600 | timeout: 10000, |
| 601 | runTest: function(){ |
| 602 | single = new Dialog({ |
| 603 | id: "singleLayoutChild", |
| 604 | title: "single layout child", |
| 605 | content: "<div data-dojo-type=LayoutWidget data-dojo-id=layout1></div>" |
| 606 | }); |
| 607 | |
| 608 | // resize() should be called on the child layout widget, but without any size specified, |
| 609 | // because the Dialog itself doesn't have a size specified |
| 610 | single.show(); |
| 611 | doh.t(layout1._resized, "resized"); |
| 612 | doh.is(undefined, layout1._resizeArg, "resize arg"); |
| 613 | |
| 614 | // Calling resize on the Dialog should resize the single layout child widget |
| 615 | single.resize({h: 200, w: 300}); |
| 616 | doh.isNot(undefined, layout1._resizeArg, "resize arg"); |
| 617 | doh.t(layout1._resizeArg.h > 150 && layout1._resizeArg.h < 190, "single child resize() call param"); |
| 618 | } |
| 619 | }, |
| 620 | { |
| 621 | name: "multiple layout children", |
| 622 | timeout: 10000, |
| 623 | runTest: function(){ |
| 624 | multiple = new Dialog({ |
| 625 | id: "multipleLayoutChildren", |
| 626 | title: "multiple layout children", |
| 627 | content: |
| 628 | "<div data-dojo-type=LayoutWidget data-dojo-id=layout2></div>" + |
| 629 | "<div data-dojo-type=LayoutWidget data-dojo-id=layout3></div>" |
| 630 | }); |
| 631 | |
| 632 | // resize() should be called on each child layout widget, but without any size specified |
| 633 | multiple.show(); |
| 634 | doh.t(layout2._resized, "layout2 resized"); |
| 635 | doh.is(undefined, layout2._resizeArg, "layout2 resize arg"); |
| 636 | doh.t(layout3._resized, "layout3 resized"); |
| 637 | doh.is(undefined, layout3._resizeArg, "layout3 resize arg"); |
| 638 | |
| 639 | // Calling resize on the Dialog might resize the layout child widgets, but they still |
| 640 | // shouldn't get a size specified |
| 641 | multiple.resize({h: 200, w: 300}); |
| 642 | doh.is(undefined, layout2._resizeArg, "layout2 resize arg after dialog resize"); |
| 643 | doh.is(undefined, layout3._resizeArg, "layout3 resize arg after dialog resize"); |
| 644 | } |
| 645 | }, |
| 646 | |
| 647 | // titlebar is optional for back-compat and to support dojox.image.LightboxDialog |
| 648 | { |
| 649 | name: "no titlebar node", |
| 650 | timeout: 10000, |
| 651 | runTest: function() { |
| 652 | noTbDialog = new Dialog({ |
| 653 | id: "noTbDialog", |
| 654 | templateString: '<div style="border: 1px solid black">' + |
| 655 | '<span data-dojo-attach-point="closeButtonNode" role="button" tabindex="-1">x</span>' + |
| 656 | '<div data-dojo-attach-point="containerNode"></div>' + |
| 657 | "</div>", |
| 658 | content: "custom template w/no titlebar" |
| 659 | }); |
| 660 | |
| 661 | return noTbDialog.show().then(function () { |
| 662 | noTbDialog.resize({h: 200, w: 300}); |
| 663 | |
| 664 | var domPos = domGeom.position(noTbDialog.domNode); |
| 665 | doh.is(200, domPos.h, "domNode.h"); |
| 666 | doh.is(300, domPos.w, "domNode.w"); |
| 667 | |
| 668 | // containerNode should be slightly smaller |
| 669 | var containerPos = domGeom.position(noTbDialog.containerNode); |
| 670 | doh.is(198, containerPos.h, "containerNode.h"); |
| 671 | doh.is(298, containerPos.w, "containerNode.w"); |
| 672 | }); |
| 673 | } |
| 674 | } |
| 675 | ]); |
| 676 | |
| 677 | doh.run(); |
| 678 | }); |
| 679 | </script> |
| 680 | </head> |
| 681 | <body> |
| 682 | <h1 class="testTitle">Dijit Dialog Automated (non-robot) tests</h1> |
| 683 | <button id="button">focus point</button> |
| 684 | </body> |
| 685 | </html> |
| 686 | |
| 687 |