mirror of
https://github.com/jquery/jquery.git
synced 2025-01-10 18:24:24 +00:00
Tests: Account for TestSwarm focus issues
Closes gh-3732
This commit is contained in:
parent
deba37e53d
commit
d65bdd5fc8
@ -2858,12 +2858,11 @@ QUnit.test( "Donor event interference", function( assert ) {
|
||||
} );
|
||||
|
||||
QUnit.test(
|
||||
"native stop(Immediate)Propagation/preventDefault methods shouldn't be called",
|
||||
"simulated events shouldn't forward stopPropagation/preventDefault methods",
|
||||
function( assert ) {
|
||||
assert.expect( 3 );
|
||||
|
||||
var done = assert.async(),
|
||||
outer = jQuery(
|
||||
var outer = jQuery(
|
||||
"<div id='donor-outer'>" +
|
||||
"<form id='donor-form'>" +
|
||||
"<input id='donor-input' type='checkbox' />" +
|
||||
@ -2871,46 +2870,39 @@ QUnit.test(
|
||||
"</div>"
|
||||
).appendTo( "#qunit-fixture" ),
|
||||
input = jQuery( "#donor-input" ),
|
||||
spy = {},
|
||||
finish = function() {
|
||||
finish = null;
|
||||
spy = {};
|
||||
|
||||
jQuery( "#donor-form" )
|
||||
.on( "simulated", function( event ) {
|
||||
spy.prevent = sinon.stub( event.originalEvent, "preventDefault" );
|
||||
event.preventDefault();
|
||||
} )
|
||||
.on( "simulated", function( event ) {
|
||||
spy.stop = sinon.stub( event.originalEvent, "stopPropagation" );
|
||||
event.stopPropagation();
|
||||
} )
|
||||
.on( "simulated", function( event ) {
|
||||
spy.immediate = sinon.stub( event.originalEvent, "stopImmediatePropagation" );
|
||||
event.stopImmediatePropagation();
|
||||
} )
|
||||
.on( "simulated", function( event ) {
|
||||
assert.ok( false, "simulated event immediate propagation stopped" );
|
||||
} );
|
||||
outer
|
||||
.on( "simulated", function( event ) {
|
||||
assert.ok( false, "simulated event propagation stopped" );
|
||||
} );
|
||||
|
||||
// Force a simulated event
|
||||
input[ 0 ].addEventListener( "click", function( nativeEvent ) {
|
||||
jQuery.event.simulate( "simulated", this, jQuery.event.fix( nativeEvent ) );
|
||||
} );
|
||||
input[ 0 ].click();
|
||||
|
||||
assert.strictEqual( spy.prevent.called, false, "Native preventDefault not called" );
|
||||
assert.strictEqual( spy.stop.called, false, "Native stopPropagation not called" );
|
||||
assert.strictEqual( spy.immediate.called, false,
|
||||
"Native stopImmediatePropagation not called" );
|
||||
|
||||
// Remove jQuery handlers to ensure removal of capturing handlers on the document
|
||||
outer.off( "focusin" );
|
||||
|
||||
done();
|
||||
};
|
||||
|
||||
outer
|
||||
.on( "focusin", function( event ) {
|
||||
spy.prevent = sinon.stub( event.originalEvent, "preventDefault" );
|
||||
event.preventDefault();
|
||||
setTimeout( finish );
|
||||
} )
|
||||
.on( "focusin", function( event ) {
|
||||
spy.stop = sinon.stub( event.originalEvent, "stopPropagation" );
|
||||
event.stopPropagation();
|
||||
} )
|
||||
.on( "focusin", function( event ) {
|
||||
spy.immediate = sinon.stub( event.originalEvent, "stopImmediatePropagation" );
|
||||
event.stopImmediatePropagation();
|
||||
} );
|
||||
input.trigger( "focus" );
|
||||
|
||||
// DOM focus is unreliable in TestSwarm; set a simulated event workaround timeout
|
||||
setTimeout( function() {
|
||||
if ( !finish ) {
|
||||
return;
|
||||
}
|
||||
input[ 0 ].addEventListener( "click", function( nativeEvent ) {
|
||||
jQuery.event.simulate( "focusin", this, jQuery.event.fix( nativeEvent ) );
|
||||
} );
|
||||
input[ 0 ].click();
|
||||
}, QUnit.config.testTimeout / 4 || 1000 );
|
||||
}
|
||||
);
|
||||
|
||||
@ -2926,7 +2918,7 @@ QUnit.test( "originalEvent type of simulated event", function( assert ) {
|
||||
"</div>"
|
||||
).appendTo( "#qunit-fixture" ),
|
||||
input = jQuery( "#donor-input" ),
|
||||
expectedType = "focus",
|
||||
expectedType = jQuery.support.focusin ? "focusin" : "focus",
|
||||
finish = function() {
|
||||
finish = null;
|
||||
|
||||
@ -3034,25 +3026,26 @@ QUnit.test( "VML with special event handlers (trac-7071)", function( assert ) {
|
||||
ns.remove();
|
||||
} );
|
||||
|
||||
// These tests are unreliable in Firefox
|
||||
if ( !( /firefox/i.test( window.navigator.userAgent ) ) ) {
|
||||
QUnit.test( "Check order of focusin/focusout events", function( assert ) {
|
||||
assert.expect( 2 );
|
||||
|
||||
var focus, blur,
|
||||
input = jQuery( "#name" );
|
||||
|
||||
input.on( "focus", function() {
|
||||
input
|
||||
.on( "focus", function() {
|
||||
focus = true;
|
||||
|
||||
} ).on( "focusin", function() {
|
||||
} )
|
||||
.on( "focusin", function() {
|
||||
assert.ok( !focus, "Focusin event should fire before focus does" );
|
||||
|
||||
} ).on( "blur", function() {
|
||||
focus = true;
|
||||
} )
|
||||
.on( "blur", function() {
|
||||
blur = true;
|
||||
|
||||
} ).on( "focusout", function() {
|
||||
} )
|
||||
.on( "focusout", function() {
|
||||
assert.ok( !blur, "Focusout event should fire before blur does" );
|
||||
blur = true;
|
||||
} );
|
||||
|
||||
// gain focus
|
||||
@ -3063,6 +3056,12 @@ if ( !( /firefox/i.test( window.navigator.userAgent ) ) ) {
|
||||
|
||||
// cleanup
|
||||
input.off();
|
||||
|
||||
// DOM focus is unreliable in TestSwarm
|
||||
if ( !focus ) {
|
||||
assert.ok( true, "GAP: Could not observe focus change" );
|
||||
assert.ok( true, "GAP: Could not observe focus change" );
|
||||
}
|
||||
} );
|
||||
|
||||
QUnit.test( "focus-blur order (#12868)", function( assert ) {
|
||||
@ -3070,12 +3069,13 @@ if ( !( /firefox/i.test( window.navigator.userAgent ) ) ) {
|
||||
|
||||
var order,
|
||||
$text = jQuery( "#text1" ),
|
||||
$radio = jQuery( "#radio1" ).trigger( "focus" );
|
||||
$radio = jQuery( "#radio1" ).trigger( "focus" ),
|
||||
|
||||
// Support: IE <=10 only
|
||||
// IE8-10 fire focus/blur events asynchronously; this is the resulting mess.
|
||||
// IE's browser window must be topmost for this to work properly!!
|
||||
QUnit.stop();
|
||||
done = assert.async();
|
||||
|
||||
$radio[ 0 ].focus();
|
||||
|
||||
setTimeout( function() {
|
||||
@ -3100,14 +3100,23 @@ if ( !( /firefox/i.test( window.navigator.userAgent ) ) ) {
|
||||
assert.equal( document.activeElement, $radio[ 0 ], "radio has focus" );
|
||||
$text.trigger( "focus" );
|
||||
setTimeout( function() {
|
||||
|
||||
// DOM focus is unreliable in TestSwarm
|
||||
if ( order === 0 ) {
|
||||
assert.ok( true, "GAP: Could not observe focus change" );
|
||||
assert.ok( true, "GAP: Could not observe focus change" );
|
||||
}
|
||||
|
||||
assert.equal( document.activeElement, $text[ 0 ], "text has focus" );
|
||||
|
||||
// Run handlers without native method on an input
|
||||
order = 1;
|
||||
$radio.triggerHandler( "focus" );
|
||||
|
||||
// Clean up
|
||||
$text.off();
|
||||
QUnit.start();
|
||||
$radio.off();
|
||||
done();
|
||||
}, 50 );
|
||||
}, 50 );
|
||||
} );
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user