]> source.dussan.org Git - jquery-ui.git/commitdiff
Dialog: Fix focus tests in IE8 with jQuery 1.7
authorScott González <scott.gonzalez@gmail.com>
Tue, 10 Mar 2015 19:16:27 +0000 (15:16 -0400)
committerScott González <scott.gonzalez@gmail.com>
Wed, 11 Mar 2015 12:42:04 +0000 (08:42 -0400)
Ref gh-1481

tests/unit/dialog/dialog_core.js

index d72fef7b5bf21a16cbeb8682965040620b4159ef..56f1e3da8e7711e72a014d09945e2de990770900 100644 (file)
@@ -59,90 +59,94 @@ asyncTest( "focus tabbable", function() {
 
                element = $( markup ).dialog( options );
                setTimeout(function() {
-                       testFn();
-                       element.remove();
-                       setTimeout( next );
+                       testFn(function done() {
+                               element.remove();
+                               setTimeout( next );
+                       });
                });
        }
 
        function step1() {
-               element = $( "<div><input><input></div>" ).dialog( options );
-               setTimeout(function() {
+               checkFocus( "<div><input><input></div>", options, function( done ) {
                        var input = element.find( "input:last" ).focus().blur();
                        element.dialog( "instance" )._focusTabbable();
                        setTimeout(function() {
                                equal( document.activeElement, input[ 0 ],
                                        "1. an element that was focused previously." );
-                               element.remove();
-                               setTimeout( step2 );
+                               done();
                        });
-               });
+               }, step2 );
        }
 
        function step2() {
-               checkFocus( "<div><input><input autofocus></div>", options, function() {
+               checkFocus( "<div><input><input autofocus></div>", options, function( done ) {
                        equal( document.activeElement, element.find( "input" )[ 1 ],
                                "2. first element inside the dialog matching [autofocus]" );
+                       done();
                }, step3 );
        }
 
        function step3() {
-               checkFocus( "<div><input><input></div>", options, function() {
+               checkFocus( "<div><input><input></div>", options, function( done ) {
                        equal( document.activeElement, element.find( "input" )[ 0 ],
                                "3. tabbable element inside the content element" );
+                       done();
                }, step4 );
        }
 
        function step4() {
-               checkFocus( "<div>text</div>", options, function() {
+               checkFocus( "<div>text</div>", options, function( done ) {
                        equal( document.activeElement,
                                element.dialog( "widget" ).find( ".ui-dialog-buttonpane button" )[ 0 ],
                                "4. tabbable element inside the buttonpane" );
+                       done();
                }, step5 );
        }
 
        function step5() {
-               checkFocus( "<div>text</div>", {}, function() {
+               checkFocus( "<div>text</div>", {}, function( done ) {
                        equal( document.activeElement,
                                element.dialog( "widget" ).find( ".ui-dialog-titlebar .ui-dialog-titlebar-close" )[ 0 ],
                                "5. the close button" );
+                       done();
                }, step6 );
        }
 
        function step6() {
-               element = $( "<div>text</div>" ).dialog({
-                       autoOpen: false
-               });
-               element.dialog( "widget" ).find( ".ui-dialog-titlebar-close" ).hide();
-               element.dialog( "open" );
-               setTimeout(function() {
-                       equal( document.activeElement, element.parent()[ 0 ], "6. the dialog itself" );
-                       element.remove();
-                       setTimeout( step7 );
-               });
+               checkFocus( "<div>text</div>", { autoOpen: false }, function( done ) {
+                       element.dialog( "widget" ).find( ".ui-dialog-titlebar-close" ).hide();
+                       element.dialog( "open" );
+                       setTimeout(function() {
+                               equal( document.activeElement, element.parent()[ 0 ], "6. the dialog itself" );
+                               done();
+                       });
+               }, step7 );
        }
 
        function step7() {
-               element = $( "<div><input name='0'><input name='1' autofocus></div>" ).dialog({
-                       open: function() {
-                               var inputs = $( this ).find( "input" );
-                               inputs.last().keydown(function( event ) {
-                                       event.preventDefault();
-                                       inputs.first().focus();
-                               });
-                       }
-               });
-               setTimeout(function() {
-                       var inputs = element.find( "input" );
-                       equal( document.activeElement, inputs[ 1 ], "Focus starts on second input" );
-                       inputs.last().simulate( "keydown", { keyCode: $.ui.keyCode.TAB });
-                       setTimeout(function() {
-                               equal( document.activeElement, inputs[ 0 ],
-                                       "Honor preventDefault, allowing custom focus management" );
-                               element.remove();
-                               start();
-                       }, 50 );
-               });
+               checkFocus(
+                       "<div><input><input autofocus></div>",
+                       {
+                               open: function() {
+                                       var inputs = $( this ).find( "input" );
+                                       inputs.last().keydown(function( event ) {
+                                               event.preventDefault();
+                                               inputs.first().focus();
+                                       });
+                               }
+                       },
+                       function( done ) {
+                               var inputs = element.find( "input" );
+                               equal( document.activeElement, inputs[ 1 ], "Focus starts on second input" );
+                               inputs.last().simulate( "keydown", { keyCode: $.ui.keyCode.TAB });
+                               setTimeout(function() {
+                                       equal( document.activeElement, inputs[ 0 ],
+                                               "Honor preventDefault, allowing custom focus management" );
+                                       done();
+                               }, 50 );
+                       },
+                       start
+               );
        }
 
        step1();