mirror of
https://github.com/jquery/jquery.git
synced 2025-01-10 18:24:24 +00:00
Tests: Fix the new focusin/focusout test in IE
In IE, focus & blur events fire asynchronously, the test now accounts for that. Ref gh-4362
This commit is contained in:
parent
8a74137693
commit
6f2fae7c41
@ -2952,59 +2952,74 @@ QUnit.test( "focusout/focusin support", function( assert ) {
|
|||||||
var focus,
|
var focus,
|
||||||
parent = jQuery( "<div>" ),
|
parent = jQuery( "<div>" ),
|
||||||
input = jQuery( "<input>" ),
|
input = jQuery( "<input>" ),
|
||||||
inputExternal = jQuery( "<input>" );
|
inputExternal = jQuery( "<input>" ),
|
||||||
|
|
||||||
|
// Support: IE <=9 - 11+
|
||||||
|
// focus and blur events are asynchronous; this is the resulting mess.
|
||||||
|
// The browser window must be topmost for this to work properly!!
|
||||||
|
done = assert.async();
|
||||||
|
|
||||||
parent.append( input );
|
parent.append( input );
|
||||||
jQuery( "#qunit-fixture" ).append( parent ).append( inputExternal );
|
jQuery( "#qunit-fixture" ).append( parent ).append( inputExternal );
|
||||||
|
|
||||||
parent
|
// initially, lose focus
|
||||||
.on( "focus", function() {
|
inputExternal[ 0 ].focus();
|
||||||
assert.ok( false, "parent: focus not fired" );
|
|
||||||
} )
|
|
||||||
.on( "focusin", function() {
|
|
||||||
assert.ok( true, "parent: focusin fired" );
|
|
||||||
} )
|
|
||||||
.on( "blur", function() {
|
|
||||||
assert.ok( false, "parent: blur not fired" );
|
|
||||||
} )
|
|
||||||
.on( "focusout", function() {
|
|
||||||
assert.ok( true, "parent: focusout fired" );
|
|
||||||
} );
|
|
||||||
|
|
||||||
input
|
setTimeout( function() {
|
||||||
.on( "focus", function() {
|
parent
|
||||||
assert.ok( true, "element: focus fired" );
|
.on( "focus", function() {
|
||||||
focus = true;
|
assert.ok( false, "parent: focus not fired" );
|
||||||
} )
|
} )
|
||||||
.on( "focusin", function() {
|
.on( "focusin", function() {
|
||||||
assert.ok( true, "element: focusin fired" );
|
assert.ok( true, "parent: focusin fired" );
|
||||||
} )
|
} )
|
||||||
.on( "blur", function() {
|
.on( "blur", function() {
|
||||||
assert.ok( true, "parent: blur fired" );
|
assert.ok( false, "parent: blur not fired" );
|
||||||
} )
|
} )
|
||||||
.on( "focusout", function() {
|
.on( "focusout", function() {
|
||||||
assert.ok( true, "element: focusout fired" );
|
assert.ok( true, "parent: focusout fired" );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
// gain focus
|
input
|
||||||
input.trigger( "focus" );
|
.on( "focus", function() {
|
||||||
|
assert.ok( true, "element: focus fired" );
|
||||||
|
} )
|
||||||
|
.on( "focusin", function() {
|
||||||
|
assert.ok( true, "element: focusin fired" );
|
||||||
|
focus = true;
|
||||||
|
} )
|
||||||
|
.on( "blur", function() {
|
||||||
|
assert.ok( true, "parent: blur fired" );
|
||||||
|
} )
|
||||||
|
.on( "focusout", function() {
|
||||||
|
assert.ok( true, "element: focusout fired" );
|
||||||
|
} );
|
||||||
|
|
||||||
// then lose it
|
// gain focus
|
||||||
inputExternal.trigger( "focus" );
|
input[ 0 ].focus();
|
||||||
|
|
||||||
// cleanup
|
// then lose it
|
||||||
parent.off();
|
inputExternal[ 0 ].focus();
|
||||||
input.off();
|
|
||||||
|
|
||||||
// DOM focus is unreliable in TestSwarm
|
setTimeout( function() {
|
||||||
if ( QUnit.isSwarm && !focus ) {
|
|
||||||
assert.ok( true, "GAP: Could not observe focus change" );
|
// DOM focus is unreliable in TestSwarm
|
||||||
assert.ok( true, "GAP: Could not observe focus change" );
|
if ( QUnit.isSwarm && !focus ) {
|
||||||
assert.ok( true, "GAP: Could not observe focus change" );
|
assert.ok( true, "GAP: Could not observe focus change" );
|
||||||
assert.ok( true, "GAP: Could not observe focus change" );
|
assert.ok( true, "GAP: Could not observe focus change" );
|
||||||
assert.ok( true, "GAP: Could not observe focus change" );
|
assert.ok( true, "GAP: Could not observe focus change" );
|
||||||
assert.ok( true, "GAP: Could not observe focus change" );
|
assert.ok( true, "GAP: Could not observe focus change" );
|
||||||
}
|
assert.ok( true, "GAP: Could not observe focus change" );
|
||||||
|
assert.ok( true, "GAP: Could not observe focus change" );
|
||||||
|
}
|
||||||
|
|
||||||
|
// cleanup
|
||||||
|
parent.off();
|
||||||
|
input.off();
|
||||||
|
|
||||||
|
done();
|
||||||
|
}, 50 );
|
||||||
|
}, 50 );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
QUnit.test( "focus-blur order (#12868)", function( assert ) {
|
QUnit.test( "focus-blur order (#12868)", function( assert ) {
|
||||||
|
Loading…
Reference in New Issue
Block a user