Tizen 2.0 Release
[platform/framework/web/web-ui-fw.git] / libs / js / jquery-mobile-1.2.0 / tests / unit / popup / popup_core.js
1 /*
2  * mobile popup unit tests
3  */
4 (function($){
5
6         var urlObject = $.mobile.path.parseLocation(),
7                 home = urlObject.pathname + urlObject.search;
8
9         module( "jquery.mobile.popup.js", {
10                 setup: function() {
11                         $.testHelper.navReset( home );
12                 }
13         });
14
15         $.extend($.testHelper, {
16
17 // detailedEventCascade: call a function and expect a series of events to be triggered (or not to be triggered), and guard
18 // with a timeout against getting stood up. Record the result (timed out / was triggered) for each event, and the order
19 // in which the event arrived wrt. any other events expected.
20 //              seq : [
21 //                      fn(result),
22 //                      { key: {
23 //                                      src: event source (is jQuery object),
24 //                                      event: event name (is string),
25 //                                             NB: It's a good idea to namespace your events, because the handler will be removed
26 //                                             based on the name you give here if a timeout occurs before the event fires.
27 //                                      userData1: value,
28 //                                      ...
29 //                                      userDatan: value
30 //                        },
31 //                              ...
32 //                      ]
33 //                      ...
34 //              ]
35 //              result: {
36 //                      key: {
37 //                              idx: order in which the event fired
38 //                              src: event source (is jQuery object),
39 //                              event: event name (is string)
40 //                              timedOut: timed out (is boolean)
41 //                              userData1: value,
42 //                              ...
43 //                              userDatan: value
44 //                      }
45 //                      ...
46 //              }
47                 detailedEventCascade: function( seq, result ) {
48                         // grab one step from the sequence
49                         var fn = seq.shift(),
50                             events = seq.shift(),
51                             self = this,
52                             derefSrc = function( src ) {
53                                                 return ( $.isFunction( src ) ? src() : src );
54                                         };
55
56                         // we're done
57                         if ( fn === undefined ) {
58                                 return;
59                         }
60
61                         // Attach handlers to the various objects which are to be checked for correct event generation
62                         if ( events ) {
63                                 var newResult = {},
64                                     nEventsDone = 0,
65                                     nEvents = 0,
66                                     // set a failsafe timer in case one of the events never happens
67                                     warnTimer = setTimeout( function() {
68                                         $.each( events, function( key, event ) {
69                                                 if ( newResult[ key ] === undefined ) {
70                                                         // clean up the unused handler
71                                                         derefSrc( event.src ).unbind( event.event );
72                                                         newResult[ key ] = $.extend( {}, event, { timedOut: true } );
73                                                 }
74                                         });
75
76                                         // Move on to the next step
77                                         self.detailedEventCascade( seq, newResult );
78                                     }, 2000);
79
80                                 function recordResult( key, event, result ) {
81                                         // Record the result
82                                         newResult[ key ] = $.extend( {}, event, result );
83                                         // Increment the number of received responses
84                                         nEventsDone++;
85                                         if ( nEventsDone === nEvents ) {
86                                                 // clear the timeout and move on to the next step when all events have been received
87                                                 clearTimeout( warnTimer );
88                                                 setTimeout( function() {
89                                                         self.detailedEventCascade( seq, newResult );
90                                                 }, 0);
91                                         }
92                                 }
93
94                                 $.each( events, function( key, event ) {
95                                         // Count the events so that we may know how many responses to expect
96                                         nEvents++;
97                                         // If it's an event
98                                         if ( event.src ) {
99                                                 // Hook up to the event
100                                                 derefSrc( event.src ).one( event.event, function() {
101                                                         recordResult( key, event, { timedOut: false, idx: nEventsDone } );
102                                                 });
103                                         }
104                                         // If it's a timeout
105                                         else {
106                                                 setTimeout( function() {
107                                                         recordResult( key, event, { timedOut: true, idx: -1 } );
108                                                 }, event.length );
109                                         }
110                                 });
111                         }
112
113                         // Call the function with the result of the events
114                         fn( result );
115                 }
116         });
117
118         function popupEnhancementTests( $sel, prefix ) {
119                 var $container = $sel.parent(), $screen = $sel.parent().prev();
120
121                 ok( $sel.data( "popup" ),  prefix + ", popup div is associated with a popup widget" );
122                 ok( $sel.hasClass( "ui-popup" ),  prefix + ", popup payload has class 'ui-popup'" );
123                 ok( $container.hasClass( "ui-popup-container" ), prefix + ", popup div parent has class ui-popup-container" );
124                 ok( $container.parent().hasClass( "ui-page" ), prefix + ", popup container parent is the page" );
125                 ok( $screen.hasClass( "ui-popup-screen" ), prefix + ", popup div is preceded by its screen" );
126                 ok( $container.attr( "id" ) === $sel.attr( "id" ) + "-popup", prefix + ", popup container has the id of the payload + '-popup'" );
127                 ok( $screen.attr( "id" ) === $sel.attr( "id" ) + "-screen", prefix + ", popup screen has the id of the payload + '-screen'" );
128         }
129
130         function tolTest( el, popup, val, expected ) {
131                 el.popup( "option", "tolerance", val );
132                 deepEqual( popup._tolerance, expected, "Popup tolerance: '" + val + "' results in expected tolerances" );
133         }
134
135         test( "Popup tolerances are parsed correctly", function() {
136                 var tolTestElement = $( "#tolerance-test" ),
137                         tolTestPopup = tolTestElement.data( "popup" ),
138                         defaultValues = tolTestPopup._tolerance;
139
140                 ok( (
141                         $.type( defaultValues.t ) === "number" && !isNaN( defaultValues.t ) &&
142                         $.type( defaultValues.r ) === "number" && !isNaN( defaultValues.r ) &&
143                         $.type( defaultValues.b ) === "number" && !isNaN( defaultValues.b ) &&
144                         $.type( defaultValues.l ) === "number" && !isNaN( defaultValues.l ) ), "Default tolerances are numbers and not NaN" );
145
146                 tolTest( tolTestElement, tolTestPopup, "", defaultValues );
147                 tolTest( tolTestElement, tolTestPopup, "0", { t: 0, r: 0, b: 0, l: 0 } );
148                 tolTest( tolTestElement, tolTestPopup, "14,12", { t: 14, r: 12, b: 14, l: 12 } );
149                 tolTest( tolTestElement, tolTestPopup, "9,4,11,5", { t: 9, r: 4, b: 11, l: 5 } );
150                 tolTest( tolTestElement, tolTestPopup, null, defaultValues );
151         });
152
153         test( "Popup is enhanced correctly", function() {
154                 popupEnhancementTests( $( "#test-popup" ), "When autoenhanced" );
155                 ok( $( "#page-content" ).children().first().html() === "<!-- placeholder for test-popup -->", "When autoenhanced, there is a placeholder in the popup div's original location" );
156         });
157
158         test( "Popup rearranges DOM elements correctly when it is destroyed and again when it is re-created", function() {
159                 $( "#test-popup" ).popup( "destroy" );
160
161                 ok( $( "#page-content" ).children().first().attr( "id" ) === "test-popup", "After destroying a popup, its payload is returned to its original location" );
162                 ok( $( "#page-content" ).children().first().prev().html() !== "<!-- placeholder for test-popup -->", "No placeholder precedes the restored popup" );
163                 ok( $( "#page-content" ).children().first().next().html() !== "<!-- placeholder for test-popup -->", "No placeholder succeedes the restored popup" );
164
165                 $( "#test-popup" ).popup();
166
167                 popupEnhancementTests( $( "#test-popup" ), "When re-created" );
168                 ok( $( "#page-content" ).children().first().html() === "<!-- placeholder for test-popup -->", "When re-created, there is a placeholder in the popup div's original location" );
169         });
170
171         test( "On-the-fly popup is enhanced and de-enhanced correctly", function() {
172                 var $container = $( "<div></div>" ).appendTo( $( "#page-content" ) ),
173                         $payload = $( "<p id='otf-popup'>This is an on-the-fly-popup</p>" ).appendTo( $container );
174
175                 $payload.popup();
176
177                 popupEnhancementTests( $payload, "When created on-the-fly" );
178                 ok( $container.children().first().html() === "<!-- placeholder for otf-popup -->", "When created on-the-fly, there is a placeholder in the popup div's original location" );
179                 $payload.popup( "destroy" );
180                 ok( !$payload.attr( "class" ), "After destroying on-the-fly popup, the payload has no 'class' attribute" );
181                 ok( $container.children().is( $payload ), "After destroying on-the-fly popup, its payload is returned to its original location" );
182         });
183
184         asyncTest( "Popup opens and closes", function() {
185                 var $popup = $( "#test-popup" );
186                 expect( 9 );
187
188                 $.testHelper.detailedEventCascade([
189                         function() {
190                                 $popup.popup( "open" );
191                         },
192
193                         {
194                                 opened: { src: $popup, event: "popupafteropen.opensandcloses" },
195                                 hashchange: { src: $(document), event: "hashchange.opensandcloses" }
196                         },
197
198                         function( result ) {
199                                 var theOffset = $( "#test-popup p" ).offset();
200                                 ok( !$popup.parent().prev().hasClass( "ui-screen-hidden" ), "Open popup screen is not hidden" );
201                                 ok( $popup.attr( "class" ).match( /( |^)ui-body-[a-z]( |$)/ ), "Open popup has a valid overlay theme" );
202                                 ok( theOffset.left >= 15 && theOffset.top >= 30, "Open popup top left coord is at least (10, 30)" );
203
204                                 $popup.popup( "option", "overlayTheme", "a" );
205                                 ok( $popup.parent().prev().hasClass( "ui-overlay-a" ), "Setting an overlay theme while the popup is open causes the theme to be applied and the screen to be faded in" );
206                                 ok( $popup.parent().prev().hasClass( "in" ), "Setting an overlay theme while the popup is open causes the theme to be applied and the screen to be faded in" );
207                                 ok( $popup.parent().hasClass( "ui-popup-active" ), "Open popup has the 'ui-popup-active' class" );
208
209                                 $popup.popup( "close" );
210                         },
211
212                         {
213                                 closed: { src: $popup, event: "popupafterclose.opensandcloses2" },
214                                 hashchange: { src: $(document), event: "hashchange.opensandcloses2" }
215                         },
216
217                         function( result) {
218                                 ok( !$popup.parent().hasClass( "in" ), "Closed popup container does not have class 'in'" );
219                                 ok( $popup.parent().prev().hasClass( "ui-screen-hidden" ), "Closed popup screen is hidden" );
220                                 ok( !$popup.parent().hasClass( "ui-popup-active" ), "Open popup dos not have the 'ui-popup-active' class" );
221
222                                 start();
223                         }
224                 ]);
225         });
226
227
228         asyncTest( "Link that launches popup is deactivated", function() {
229
230                 expect( 4 );
231
232                 $.testHelper.detailedEventCascade([
233                         function() {
234                                 $( "a#open-test-popup" ).click();
235                         },
236
237                         {
238                                 opened: { src: $( "#test-popup" ), event: "popupafteropen.linkActiveTestStep1" },
239                                 hashchange: { src: $(document), event: "navigate.linkActive" }
240                         },
241
242                         function( result ) {
243                                 ok( !result.opened.timedOut, "Opening a popup did cause 'opened' event" );
244                                 ok( !$( "a#open-test-popup" ).closest( ".ui-btn" ).hasClass( "ui-btn-active" ), "Opening a popup removes active class from link that launched it" );
245                                 $( "#test-popup" ).popup( "close" );
246                         },
247
248                         {
249                                 closed: { src: $( "#test-popup" ), event: "popupafterclose.linkActiveTestStep2" },
250                                 hashchange: { src: $(document), event: "navigate.linkActive2" }
251                         },
252
253                         function( result ) {
254                                 ok( !result.closed.timedOut, "Opening a popup did cause 'closed' event" );
255                                 $( "a#open-xyzzy-popup" ).click();
256                                 ok( !$( "a#open-xyzzy-popup" ).closest( ".ui-btn" ).hasClass( "ui-btn-active" ), "Opening a non-existing popup removes active class from link that attempted to launch it" );
257
258                                 $( "test-popup" ).popup( "close" );
259                         },
260
261                         {
262                                 closed: { src: $( "#test-popup" ), event: "popupafterclose.linkActiveTestStep3" },
263                                 hashchange: { src: $(document), event: "navigate.linkActive3" }
264                         },
265
266                         start
267                 ]);
268         });
269
270         asyncTest( "Popup interacts correctly with hashchange", function() {
271                 var baseUrl, activeIndex, $popup = $( "#test-popup" );
272
273                 if( !$popup.data( "popup" ).options.history ) {
274                         expect( 1 )
275                         ok( true, "hash change disabled" );
276                         start();
277                         return;
278                 }
279
280                 expect( 6 );
281
282                 $.testHelper.detailedEventCascade([
283                         function() {
284                                 baseUrl = decodeURIComponent( location.href );
285                                 activeIndex = $.mobile.urlHistory.activeIndex;
286                                 $popup.popup( "open" );
287                         },
288
289                         {
290                                 opened: { src: $( "#test-popup" ), event: "popupafteropen.hashInteractStep1" },
291                                 hashchange: { src: $( window ), event: "hashchange.hashInteractStep1" }
292                         },
293
294                         function( result ) {
295                                 ok( !result.hashchange.timedOut, "Opening a popup from a non-dialogHashKey location causes a hashchange event" );
296                                 ok( decodeURIComponent( location.href ) === baseUrl + ( ( baseUrl.indexOf( "#" ) > -1 ) ? "" : "#" ) + $.mobile.dialogHashKey, "location.href has been updated correctly" );
297                                 ok( $.mobile.urlHistory.activeIndex === activeIndex + 1, "$.mobile.urlHistory has been advanced correctly" );
298                                 $( "#test-popup" ).popup( "close" );
299                         },
300
301                         {
302                                 closed: { src: $( "#test-popup" ), event: "popupafterclose.hashInteractStep2" },
303                                 navigate: { src: $.mobile.pageContainer, event: "navigate.hashInteractStep2" }
304                         },
305
306                         function( result ) {
307                                 ok( !result.navigate.timedOut, "Closing a popup from a non-dialogHashKey location causes a 'navigate' event" );
308                                 ok( decodeURIComponent( location.href ) === baseUrl, "location.href has been restored after the popup" );
309                                 ok( $.mobile.urlHistory.activeIndex === activeIndex, "$.mobile.urlHistory has been restored correctly" );
310
311                                 // TODO make sure that the afterclose is fired after the nav finishes
312                                 setTimeout(start, 300);
313                         }
314                 ]);
315         });
316
317         // This test assumes that the popup opens into a state that does not include dialogHashKey.
318         // This should be the case if the previous test has cleaned up correctly.
319         asyncTest( "Opening another page from the popup leaves no trace of the popup in history", function() {
320                 var initialActive = $.extend( {}, {}, $.mobile.urlHistory.getActive()),
321                         initialHRef = $.mobile.path.parseUrl( decodeURIComponent( location.href ) ),
322                         initialBase = initialHRef.protocol + initialHRef.doubleSlash + initialHRef.authority + initialHRef.directory,
323                         $popup = $( "#test-popup" );
324
325                 if( !$popup.data( "popup" ).options.history ) {
326                         expect( 1 )
327                         ok( true, "hash change disabled" );
328                         start();
329                         return;
330                 }
331
332                 expect( 6 );
333
334                 $.testHelper.detailedEventCascade([
335                         function() {
336                                 $( "#test-popup" ).popup( "open" );
337                         },
338
339                         {
340                                 opened: { src: $( "#test-popup" ), event: "popupafteropen.anotherPageStep1" },
341                                 hashchange: { src: $( window ), event: "hashchange.anotherPageStep1" }
342                         },
343
344                         function() {
345                                 $( "#test-popup a" ).click();
346                         },
347
348                         {
349                                 closed: { src: $( "#test-popup" ), event: "popupafterclose.anotherPageStep2" },
350                                 hashchange: { src: $( window ), event: "hashchange.anotherPageStep2" }
351                         },
352
353                         function( result ) {
354                                 var hRef = $.mobile.path.parseUrl( decodeURIComponent( location.href ) );
355                                 ok( !result.closed.timedOut, "Popup closed" );
356                                 ok( !result.hashchange.timedOut, "hashchange did occur" );
357                                 ok( decodeURIComponent( location.href ) === initialBase + hRef.filename, "New location is exactly the previous location (up to and including path) and the new filename" );
358                                 window.history.back();
359                         },
360
361                         {
362                                 hashchange: { src: $( window ), event: "hashchange.anotherPageStep3" },
363                                 pagechange: { src: $.mobile.pageContainer, event: "pagechange.anotherPageStep3" }
364                         },
365
366                         function( result ) {
367                                 var active = $.mobile.urlHistory.getActive(),
368                                                 identical = true;
369
370                                 $.each( initialActive, function( key, value ) {
371                                         if ( active[key] !== value ) {
372                                                 identical = false;
373                                                 return false;
374                                         }
375                                 });
376
377                                 if ( identical ) {
378                                         $.each( active, function( key, value ) {
379                                                 if ( initialActive[key] !== value ) {
380                                                         identical = false;
381                                                         return false;
382                                                 }
383                                         });
384                                 }
385
386                                 ok( decodeURIComponent( location.href ) === initialHRef.href, "Going back once places the browser on the initial page" );
387                                 ok( identical, "Going back returns $.mobile.urlHistory to its initial value" );
388                                 ok( $.mobile.urlHistory.activeIndex === $.mobile.urlHistory.stack.length - 3, "Going back leaves exactly two entries ahead in $.mobile.urlHistory" );
389
390                                 setTimeout( function() { start(); }, 500 );
391                         },
392                 ]);
393         });
394
395         asyncTest( "Sequence page -> popup -> dialog -> popup works", function() {
396                 var originallyActivePage = $.mobile.activePage[ 0 ], $popup = $( "#test-popup" );
397
398                 if( !$popup.data( "popup" ).options.history ) {
399                         expect( 1 )
400                         ok( true, "hash change disabled" );
401                         start();
402                         return;
403                 }
404
405                 expect( 15 );
406                 $.testHelper.detailedEventCascade([
407                         function() {
408                                 $( "#popup-sequence-test" ).popup( "open" );
409                         },
410
411                         {
412                                 opened: { src: $( "#popup-sequence-test" ), event: "popupafteropen.sequenceTestStep1" },
413                                 hashchange: { src: $( window ), event: "hashchange.sequenceTestStep1" }
414                         },
415
416                         function( result ) {
417                                 ok( !result.opened.timedOut, "Popup has emitted 'popupafteropen'" );
418                                 ok( !result.hashchange.timedOut, "A 'hashchange' event has occurred" );
419                                 $( "#popup-sequence-test-open-dialog" ).click();
420                         },
421
422                         {
423                                 closed: { src: $( "#popup-sequence-test" ), event: "popupafterclose.sequenceTestStep2" },
424                                 pageload: { src: $.mobile.pageContainer, event: "pageload.sequenceTestStep2" },
425                                 pagechange: { src: $.mobile.pageContainer, event: "pagechange.sequenceTestStep3" }
426                         },
427
428                         function( result ) {
429                                 ok( !result.closed.timedOut, "Popup has emitted 'popupafterclose'" );
430                                 ok( !result.pageload.timedOut, "A 'pageload' event (presumably to load the dialog) has occurred" );
431                                 ok( $( "#popup-sequence-test-dialog" ).length > 0, "The dialog has been loaded successfully" );
432                                 ok( !result.pagechange.timedOut, "A 'pagechange' event has occurred" );
433                                 ok( $.mobile.activePage[ 0 ] === $( "#popup-sequence-test-dialog" )[ 0 ], "The dialog is the active page" );
434                                 $( "a[href='#popup-sequence-test-popup-inside-dialog']" ).click();
435                         },
436
437                         {
438                                 opened: { src: function() { return $( "#popup-sequence-test-popup-inside-dialog" ); }, event: "popupafteropen.sequenceTestStep3" },
439                                 hashchange: { src: $( window ), event: "hashchange.sequenceTestStep3" }
440                         },
441
442                         function( result ) {
443                                 ok( !result.opened.timedOut, "Popup inside dialog has emitted 'popupafteropen'" );
444                                 ok( !result.hashchange.timedOut, "Popup inside dialog has caused a 'hashchange'" );
445                                 window.history.back();
446                         },
447
448                         {
449                                 close: { src: function() { return $( "#popup-sequence-test-popup-inside-dialog" ); }, event: "popupafterclose.sequenceTestStep4" },
450                                 hashchange: { src: $( window ), event: "hashchange.sequenceTestStep4" }
451                         },
452
453                         function( result ) {
454                                 ok( !result.close.timedOut, "Popup inside dialog has emitted 'popupafterclose'" );
455                                 ok( !result.hashchange.timedOut, "The closing of the inside popup has resulted in a 'hashchange'" );
456                                 ok( $.mobile.activePage[ 0 ] === $( "#popup-sequence-test-dialog" )[ 0 ], "The dialog is once more the active page" );
457                                 window.history.back();
458                         },
459
460                         {
461                                 pagechange: { src: $.mobile.pageContainer, event: "pagechange.sequenceTestStep5" },
462                                 hashchange: { src: $( window ), event: "hashchange.sequenceTestStep5" }
463                         },
464
465                         function( result ) {
466                                 ok( !result.pagechange.timedOut, "Going back from the dialog has resulted in a 'pagechange'" );
467                                 ok( !result.hashchange.timedOut, "Going back from the dialog has resulted in a 'hashchange'" );
468                                 ok( originallyActivePage === $.mobile.activePage[ 0 ], "After going back from the dialog, the originally active page is active once more" );
469                                 setTimeout( function() { start(); }, 300 );
470                         }
471                 ]);
472         });
473
474         asyncTest( "Popup focused after open", function() {
475                 var $link = $( "#open-test-popup" ), $popup = $( "#test-popup" );
476
477                 expect( 2 );
478
479                 $popup.parent().one( "focus", function() {
480                         ok( true, "focus fired after the popup opens" );
481                 });
482
483                 // check that after the popup is closed the focus is correct
484                 $popup.one( "popupafteropen", function() {
485                         ok( true, "afteropen has fired" );
486                         $popup.popup( "close" );
487                 });
488
489                 $popup.one( "popupafterclose", function() {
490                         // TODO make sure that the afterclose is fired after the nav finishes
491                         setTimeout(start, 300);
492                 });
493
494                 $popup.popup( "open" );
495         });
496
497         asyncTest( "Popup doesn't alter the url when the history option is disabled", function() {
498                 var $popup = $( "#test-history-popup" ), hash = $.mobile.path.parseLocation().hash;
499
500                 $popup.popup( "open" );
501
502                 equal( hash, $.mobile.path.parseLocation().hash, "the hash remains the same" );
503
504                 ok( $popup.is( ":visible" ), "popup is indeed visible" );
505
506                 $popup.one( "popupafterclose", function() {
507                         // TODO make sure that the afterclose is fired after the nav finishes
508                         setTimeout(start, 300);
509                 });
510
511                 $popup.popup( "close" );
512         });
513
514         asyncTest( "Navigating away from the popup page closes the popup without history enabled", function() {
515                 var $popup = $( "#test-history-popup" );
516
517                 expect( 3 );
518
519                 $.testHelper.detailedEventCascade([
520                         function() {
521                                 $popup.popup( "open" );
522                         },
523
524                         {
525                                 open: { src: $popup, event: "popupafterclose.historyOffTestStep1" }
526                         },
527
528                         function() {
529                                 ok( $popup.is( ":visible" ), "popup is indeed visible" );
530                                 $.mobile.changePage( "#no-popups" );
531                         },
532
533                         {
534                                 hashchange: { src: $(window), event: "hashchange.historyOffTestStep2" },
535                                 close: { src: $popup, event: "popupafterclose.historyOffTestStep2" }
536                         },
537
538                         function( result ){
539                                 ok( !result.close.timedOut, "close happened" );
540                                 ok( !result.close.timedOut, "hashchange happened" );
541
542                                 // TODO make sure that the afterclose is fired after the nav finishes
543                                 setTimeout(start, 300);
544                         }
545                 ]);
546         });
547
548         // TODO would be nice to avoid checking the internal representation
549         //      of "openness" but :visible didn't seem to be working in this case
550         //      (offscreen?)
551         asyncTest( "Close links work on a history disabled popup", function() {
552                 var $popup = $( "#test-history-popup" );
553
554                 expect( 3 );
555
556                 ok( !$popup.data( "popup" )._isOpen, "popup is initially closed" );
557
558                 $popup.popup( 'open' );
559                 ok( $popup.data( "popup" )._isOpen, "popup is opened with open method" );
560
561                 $popup.one( "popupafterclose", function() {
562                         ok( !$popup.data( "popup" )._isOpen, "popup is closed on link click" );
563                         start();
564                 });
565
566                 $popup.find( "a" ).click();
567         });
568
569         asyncTest( "Destroy closes the popup first", function() {
570                 var $popup = $( "#test-destroy-popup" );
571
572                 expect( 1 );
573
574                 $popup.one( "popupafterclose", function() {
575                         ok( true, "closed on destroy" );
576                         start();
577                 });
578
579                 $popup.popup( "destroy" );
580         });
581 })( jQuery );