@@ -3107,142 +3107,115 @@ QUnit.test( "focusout/focusin support", function( assert ) {
31073107 var focus ,
31083108 parent = jQuery ( "<div>" ) ,
31093109 input = jQuery ( "<input>" ) ,
3110- inputExternal = jQuery ( "<input>" ) ,
3111-
3112- // Support: IE <=9 - 11+
3113- // focus and blur events are asynchronous; this is the resulting mess.
3114- // The browser window must be topmost for this to work properly!!
3115- done = assert . async ( ) ;
3110+ inputExternal = jQuery ( "<input>" ) ;
31163111
31173112 parent . append ( input ) ;
31183113 jQuery ( "#qunit-fixture" ) . append ( parent ) . append ( inputExternal ) ;
31193114
31203115 // initially, lose focus
31213116 inputExternal [ 0 ] . focus ( ) ;
31223117
3123- setTimeout ( function ( ) {
3124- parent
3125- . on ( "focus" , function ( ) {
3126- assert . ok ( false , "parent: focus not fired" ) ;
3127- } )
3128- . on ( "focusin" , function ( ) {
3129- assert . ok ( true , "parent: focusin fired" ) ;
3130- } )
3131- . on ( "blur" , function ( ) {
3132- assert . ok ( false , "parent: blur not fired" ) ;
3133- } )
3134- . on ( "focusout" , function ( ) {
3135- assert . ok ( true , "parent: focusout fired" ) ;
3136- } ) ;
3137-
3138- input
3139- . on ( "focus" , function ( ) {
3140- assert . ok ( true , "element: focus fired" ) ;
3141- } )
3142- . on ( "focusin" , function ( ) {
3143- assert . ok ( true , "element: focusin fired" ) ;
3144- focus = true ;
3145- } )
3146- . on ( "blur" , function ( ) {
3147- assert . ok ( true , "parent: blur fired" ) ;
3148- } )
3149- . on ( "focusout" , function ( ) {
3150- assert . ok ( true , "element: focusout fired" ) ;
3151- } ) ;
3152-
3153- // gain focus
3154- input [ 0 ] . focus ( ) ;
3118+ parent
3119+ . on ( "focus" , function ( ) {
3120+ assert . ok ( false , "parent: focus not fired" ) ;
3121+ } )
3122+ . on ( "focusin" , function ( ) {
3123+ assert . ok ( true , "parent: focusin fired" ) ;
3124+ } )
3125+ . on ( "blur" , function ( ) {
3126+ assert . ok ( false , "parent: blur not fired" ) ;
3127+ } )
3128+ . on ( "focusout" , function ( ) {
3129+ assert . ok ( true , "parent: focusout fired" ) ;
3130+ } ) ;
31553131
3156- // then lose it
3157- inputExternal [ 0 ] . focus ( ) ;
3132+ input
3133+ . on ( "focus" , function ( ) {
3134+ assert . ok ( true , "element: focus fired" ) ;
3135+ } )
3136+ . on ( "focusin" , function ( ) {
3137+ assert . ok ( true , "element: focusin fired" ) ;
3138+ focus = true ;
3139+ } )
3140+ . on ( "blur" , function ( ) {
3141+ assert . ok ( true , "parent: blur fired" ) ;
3142+ } )
3143+ . on ( "focusout" , function ( ) {
3144+ assert . ok ( true , "element: focusout fired" ) ;
3145+ } ) ;
31583146
3159- setTimeout ( function ( ) {
3147+ // gain focus
3148+ input [ 0 ] . focus ( ) ;
31603149
3161- // DOM focus is unreliable in TestSwarm
3162- if ( QUnit . isSwarm && ! focus ) {
3163- assert . ok ( true , "GAP: Could not observe focus change" ) ;
3164- assert . ok ( true , "GAP: Could not observe focus change" ) ;
3165- assert . ok ( true , "GAP: Could not observe focus change" ) ;
3166- assert . ok ( true , "GAP: Could not observe focus change" ) ;
3167- assert . ok ( true , "GAP: Could not observe focus change" ) ;
3168- assert . ok ( true , "GAP: Could not observe focus change" ) ;
3169- }
3150+ // then lose it
3151+ inputExternal [ 0 ] . focus ( ) ;
31703152
3171- // cleanup
3172- parent . off ( ) ;
3173- input . off ( ) ;
3153+ // DOM focus is unreliable in TestSwarm
3154+ if ( QUnit . isSwarm && ! focus ) {
3155+ assert . ok ( true , "GAP: Could not observe focus change" ) ;
3156+ assert . ok ( true , "GAP: Could not observe focus change" ) ;
3157+ assert . ok ( true , "GAP: Could not observe focus change" ) ;
3158+ assert . ok ( true , "GAP: Could not observe focus change" ) ;
3159+ assert . ok ( true , "GAP: Could not observe focus change" ) ;
3160+ assert . ok ( true , "GAP: Could not observe focus change" ) ;
3161+ }
31743162
3175- done ( ) ;
3176- } , 50 ) ;
3177- } , 50 ) ;
3163+ // cleanup
3164+ parent . off ( ) ;
3165+ input . off ( ) ;
31783166} ) ;
31793167
31803168QUnit . test ( "focus-blur order (trac-12868)" , function ( assert ) {
31813169 assert . expect ( 5 ) ;
31823170
31833171 var order ,
31843172 $text = jQuery ( "#text1" ) ,
3185- $radio = jQuery ( "#radio1" ) ,
3186-
3187- // Support: IE <=9 - 11+
3188- // focus and blur events are asynchronous; this is the resulting mess.
3189- // The browser window must be topmost for this to work properly!!
3190- done = assert . async ( ) ;
3173+ $radio = jQuery ( "#radio1" ) ;
31913174
31923175 $radio [ 0 ] . focus ( ) ;
31933176
3194- setTimeout ( function ( ) {
3195-
3196- $text
3197- . on ( "focus" , function ( ) {
3198- assert . equal ( order ++ , 1 , "text focus" ) ;
3199- } )
3200- . on ( "blur" , function ( ) {
3201- assert . equal ( order ++ , 0 , "text blur" ) ;
3202- } ) ;
3203- $radio
3204- . on ( "focus" , function ( ) {
3205- assert . equal ( order ++ , 1 , "radio focus" ) ;
3206- } )
3207- . on ( "blur" , function ( ) {
3208- assert . equal ( order ++ , 0 , "radio blur" ) ;
3209- } ) ;
3177+ $text
3178+ . on ( "focus" , function ( ) {
3179+ assert . equal ( order ++ , 1 , "text focus" ) ;
3180+ } )
3181+ . on ( "blur" , function ( ) {
3182+ assert . equal ( order ++ , 0 , "text blur" ) ;
3183+ } ) ;
3184+ $radio
3185+ . on ( "focus" , function ( ) {
3186+ assert . equal ( order ++ , 1 , "radio focus" ) ;
3187+ } )
3188+ . on ( "blur" , function ( ) {
3189+ assert . equal ( order ++ , 0 , "radio blur" ) ;
3190+ } ) ;
32103191
3211- // Enabled input getting focus
3212- order = 0 ;
3213- assert . equal ( document . activeElement , $radio [ 0 ] , "radio has focus" ) ;
3214- $text . trigger ( "focus" ) ;
3215- setTimeout ( function ( ) {
3192+ // Enabled input getting focus
3193+ order = 0 ;
3194+ assert . equal ( document . activeElement , $radio [ 0 ] , "radio has focus" ) ;
3195+ $text . trigger ( "focus" ) ;
32163196
3217- // DOM focus is unreliable in TestSwarm
3218- if ( QUnit . isSwarm && order === 0 ) {
3219- assert . ok ( true , "GAP: Could not observe focus change" ) ;
3220- assert . ok ( true , "GAP: Could not observe focus change" ) ;
3221- }
3197+ // DOM focus is unreliable in TestSwarm
3198+ if ( QUnit . isSwarm && order === 0 ) {
3199+ assert . ok ( true , "GAP: Could not observe focus change" ) ;
3200+ assert . ok ( true , "GAP: Could not observe focus change" ) ;
3201+ }
32223202
3223- assert . equal ( document . activeElement , $text [ 0 ] , "text has focus" ) ;
3203+ assert . equal ( document . activeElement , $text [ 0 ] , "text has focus" ) ;
32243204
3225- // Run handlers without native method on an input
3226- order = 1 ;
3227- $radio . triggerHandler ( "focus" ) ;
3205+ // Run handlers without native method on an input
3206+ order = 1 ;
3207+ $radio . triggerHandler ( "focus" ) ;
32283208
3229- // Clean up
3230- $text . off ( ) ;
3231- $radio . off ( ) ;
3232- done ( ) ;
3233- } , 50 ) ;
3234- } , 50 ) ;
3209+ // Clean up
3210+ $text . off ( ) ;
3211+ $radio . off ( ) ;
32353212} ) ;
32363213
32373214QUnit . test ( "Event handling works with multiple async focus events (gh-4350)" , function ( assert ) {
32383215 assert . expect ( 3 ) ;
32393216
32403217 var remaining = 3 ,
32413218 input = jQuery ( "#name" ) ,
3242-
3243- // Support: IE <=9 - 11+
3244- // focus and blur events are asynchronous; this is the resulting mess.
3245- // The browser window must be topmost for this to work properly!!
32463219 done = assert . async ( ) ;
32473220
32483221 input
@@ -3336,12 +3309,7 @@ QUnit.test( "native-backed events preserve trigger data (gh-1741, gh-4139)", fun
33363309 targets = jQuery ( parent [ 0 ] . childNodes ) ,
33373310 checkbox = jQuery ( targets [ 0 ] ) ,
33383311 data = [ "arg1" , "arg2" ] ,
3339- slice = data . slice ,
3340-
3341- // Support: IE <=9 - 11+
3342- // focus and blur events are asynchronous; this is the resulting mess.
3343- // The browser window must be topmost for this to work properly!!
3344- done = assert . async ( ) ;
3312+ slice = data . slice ;
33453313
33463314 // click (gh-4139)
33473315 assert . strictEqual ( targets [ 0 ] . checked , false , "checkbox unchecked before click" ) ;
@@ -3380,16 +3348,13 @@ QUnit.test( "native-backed events preserve trigger data (gh-1741, gh-4139)", fun
33803348 }
33813349 } ) ;
33823350 checkbox . trigger ( "focus" , data ) ;
3383- setTimeout ( function ( ) {
3384- assert . strictEqual ( document . activeElement , checkbox [ 0 ] ,
3385- "element focused after focus event (default action)" ) ;
3386- checkbox . trigger ( "blur" , data ) ;
3387- setTimeout ( function ( ) {
3388- assert . notEqual ( document . activeElement , checkbox [ 0 ] ,
3389- "element not focused after blur event (default action)" ) ;
3390- done ( ) ;
3391- } , 50 ) ;
3392- } , 50 ) ;
3351+
3352+ assert . strictEqual ( document . activeElement , checkbox [ 0 ] ,
3353+ "element focused after focus event (default action)" ) ;
3354+ checkbox . trigger ( "blur" , data ) ;
3355+
3356+ assert . notEqual ( document . activeElement , checkbox [ 0 ] ,
3357+ "element not focused after blur event (default action)" ) ;
33933358} ) ;
33943359
33953360QUnit . test ( "focus change during a focus handler (gh-4382)" , function ( assert ) {
0 commit comments