@@ -2172,12 +2172,12 @@ QUnit.test( "focusin bubbles", function( assert ) {
21722172
21732173// Removed since DOM focus is unreliable on test swarm
21742174 // DOM focus method
2175- // input[0 ].focus();
2175+ // input[ 0 ].focus();
21762176
21772177 // To make the next focus test work, we need to take focus off the input.
21782178 // This will fire another focusin event, so set order to reflect that.
21792179// order = 1;
2180- // jQuery("#text1")[0 ].focus();
2180+ // jQuery( "#text1" )[ 0 ].focus();
21812181
21822182 // jQuery trigger, which calls DOM focus
21832183 order = 0 ;
@@ -2187,6 +2187,42 @@ QUnit.test( "focusin bubbles", function( assert ) {
21872187 jQuery ( "body" ) . off ( "focusin.focusinBubblesTest" ) ;
21882188} ) ;
21892189
2190+ QUnit . test ( "focus does not bubble" , function ( assert ) {
2191+ assert . expect ( 1 ) ;
2192+
2193+ var done = assert . async ( ) ,
2194+ input = jQuery ( "<input type='text' />" ) . prependTo ( "body" ) ;
2195+
2196+ // focus the element so DOM focus won't fire
2197+ input [ 0 ] . focus ( ) ;
2198+
2199+ jQuery ( "body" ) . on ( "focus.focusDoesNotBubbleTest" , function ( ) {
2200+ assert . ok ( false , "focus doesn't fire on body" ) ;
2201+ } ) ;
2202+
2203+ input . on ( "focus.focusDoesNotBubbleTest" , function ( ) {
2204+ assert . ok ( true , "focus on the element" ) ;
2205+ } ) ;
2206+
2207+ // Removed since DOM focus is unreliable on test swarm
2208+ // DOM focus method
2209+ // input[ 0 ].focus();
2210+
2211+ // To make the next focus test work, we need to take focus off the input.
2212+ // This will fire another focusin event, so set order to reflect that.
2213+ // jQuery( "#text1" )[ 0 ].focus();
2214+
2215+ // jQuery trigger, which calls DOM focus
2216+ input . trigger ( "focus" ) ;
2217+
2218+ input . remove ( ) ;
2219+ jQuery ( "body" ) . off ( "focus.focusDoesNotBubbleTest" ) ;
2220+
2221+ setTimeout ( function ( ) {
2222+ done ( ) ;
2223+ } , 50 ) ;
2224+ } ) ;
2225+
21902226QUnit . test ( "custom events with colons (trac-3533, trac-8272)" , function ( assert ) {
21912227 assert . expect ( 1 ) ;
21922228
@@ -2652,6 +2688,10 @@ QUnit.test( "element removed during focusout (gh-4417)", function( assert ) {
26522688 button [ 0 ] . blur = function ( ) {
26532689 jQuery . cleanData ( [ this ] ) ;
26542690 this . parentNode . removeChild ( this ) ;
2691+
2692+ // Redefine `blur` to avoid a hard crash in Karma tests that stop
2693+ // the test runner in case this test fails.
2694+ this . blur = jQuery . noop ;
26552695 } ;
26562696
26572697 button [ 0 ] . click ( ) ;
@@ -3189,6 +3229,17 @@ QUnit.test( "Event handling works with multiple async focus events (gh-4350)", f
31893229 if ( remaining > 0 ) {
31903230 input . trigger ( "blur" ) ;
31913231 } else {
3232+
3233+ if ( QUnit . isIE ) {
3234+
3235+ // Support: <=IE 11+
3236+ // In IE, one of the blurs sometimes triggers a focus on body
3237+ // which in turn restores focus to the input, leading to 4 assertions
3238+ // firing instead of three. This only happens if other tests are
3239+ // running on the same test page. Avoid this issue in tests by removing
3240+ // the handler early.
3241+ input . off ( "focus" ) ;
3242+ }
31923243 done ( ) ;
31933244 }
31943245 } )
@@ -3214,6 +3265,45 @@ QUnit.test( "Event handling works with multiple async focus events (gh-4350)", f
32143265 } ) ;
32153266} ) ;
32163267
3268+ // Support: IE <=9 - 11+
3269+ // focus and blur events are asynchronous.
3270+ // The browser window must be topmost for this to work properly!!
3271+ QUnit . test ( "async focus queues properly (gh-4859)" , function ( assert ) {
3272+ assert . expect ( 1 ) ;
3273+
3274+ var $text = jQuery ( "#text1" ) ,
3275+ $radio = jQuery ( "#radio1" ) ,
3276+ done = assert . async ( ) ;
3277+
3278+ $text . trigger ( "focus" ) ;
3279+ $radio . trigger ( "focus" ) ;
3280+ $text . trigger ( "focus" ) ;
3281+
3282+ setTimeout ( function ( ) {
3283+ assert . equal ( document . activeElement , $text [ 0 ] , "focus follows the last trigger" ) ;
3284+ done ( ) ;
3285+ } , 500 ) ;
3286+ } ) ;
3287+
3288+ // Support: IE <=9 - 11+
3289+ // focus and blur events are asynchronous.
3290+ // The browser window must be topmost for this to work properly!!
3291+ QUnit . test ( "async focus queues properly with blur (gh-4856)" , function ( assert ) {
3292+ assert . expect ( 1 ) ;
3293+
3294+ var $text = jQuery ( "#text1" ) ,
3295+ done = assert . async ( ) ;
3296+
3297+ $text . trigger ( "focus" ) ;
3298+ $text . trigger ( "blur" ) ;
3299+ $text . trigger ( "focus" ) ;
3300+
3301+ setTimeout ( function ( ) {
3302+ assert . equal ( document . activeElement , $text [ 0 ] , "focus-after-blur is respected" ) ;
3303+ done ( ) ;
3304+ } , 500 ) ;
3305+ } ) ;
3306+
32173307QUnit . test ( "native-backed events preserve trigger data (gh-1741, gh-4139)" , function ( assert ) {
32183308 assert . expect ( 17 ) ;
32193309
@@ -3254,6 +3344,17 @@ QUnit.test( "native-backed events preserve trigger data (gh-1741, gh-4139)", fun
32543344 var type = event . type ;
32553345 assert . deepEqual ( slice . call ( arguments , 1 ) , data ,
32563346 type + " handler received correct data" ) ;
3347+
3348+ if ( QUnit . isIE && type === "focus" ) {
3349+
3350+ // Support: <=IE 11+
3351+ // In IE, one of the blurs sometimes triggers a focus on body
3352+ // which in turn restores focus to the input, leading to 4 assertions
3353+ // firing instead of three. This only happens if other tests are
3354+ // running on the same test page. Avoid this issue in tests by removing
3355+ // the handler early.
3356+ checkbox . off ( "focus" ) ;
3357+ }
32573358 } ) ;
32583359 checkbox . trigger ( "focus" , data ) ;
32593360 setTimeout ( function ( ) {
0 commit comments