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(
|
QUnit.test(
|
||||||
"native stop(Immediate)Propagation/preventDefault methods shouldn't be called",
|
"simulated events shouldn't forward stopPropagation/preventDefault methods",
|
||||||
function( assert ) {
|
function( assert ) {
|
||||||
assert.expect( 3 );
|
assert.expect( 3 );
|
||||||
|
|
||||||
var done = assert.async(),
|
var outer = jQuery(
|
||||||
outer = jQuery(
|
|
||||||
"<div id='donor-outer'>" +
|
"<div id='donor-outer'>" +
|
||||||
"<form id='donor-form'>" +
|
"<form id='donor-form'>" +
|
||||||
"<input id='donor-input' type='checkbox' />" +
|
"<input id='donor-input' type='checkbox' />" +
|
||||||
@ -2871,46 +2870,39 @@ QUnit.test(
|
|||||||
"</div>"
|
"</div>"
|
||||||
).appendTo( "#qunit-fixture" ),
|
).appendTo( "#qunit-fixture" ),
|
||||||
input = jQuery( "#donor-input" ),
|
input = jQuery( "#donor-input" ),
|
||||||
spy = {},
|
spy = {};
|
||||||
finish = function() {
|
|
||||||
finish = null;
|
|
||||||
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
|
jQuery( "#donor-form" )
|
||||||
outer.off( "focusin" );
|
.on( "simulated", function( event ) {
|
||||||
|
|
||||||
done();
|
|
||||||
};
|
|
||||||
|
|
||||||
outer
|
|
||||||
.on( "focusin", function( event ) {
|
|
||||||
spy.prevent = sinon.stub( event.originalEvent, "preventDefault" );
|
spy.prevent = sinon.stub( event.originalEvent, "preventDefault" );
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
setTimeout( finish );
|
|
||||||
} )
|
} )
|
||||||
.on( "focusin", function( event ) {
|
.on( "simulated", function( event ) {
|
||||||
spy.stop = sinon.stub( event.originalEvent, "stopPropagation" );
|
spy.stop = sinon.stub( event.originalEvent, "stopPropagation" );
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
} )
|
} )
|
||||||
.on( "focusin", function( event ) {
|
.on( "simulated", function( event ) {
|
||||||
spy.immediate = sinon.stub( event.originalEvent, "stopImmediatePropagation" );
|
spy.immediate = sinon.stub( event.originalEvent, "stopImmediatePropagation" );
|
||||||
event.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" );
|
||||||
} );
|
} );
|
||||||
input.trigger( "focus" );
|
|
||||||
|
|
||||||
// DOM focus is unreliable in TestSwarm; set a simulated event workaround timeout
|
// Force a simulated event
|
||||||
setTimeout( function() {
|
input[ 0 ].addEventListener( "click", function( nativeEvent ) {
|
||||||
if ( !finish ) {
|
jQuery.event.simulate( "simulated", this, jQuery.event.fix( nativeEvent ) );
|
||||||
return;
|
} );
|
||||||
}
|
input[ 0 ].click();
|
||||||
input[ 0 ].addEventListener( "click", function( nativeEvent ) {
|
|
||||||
jQuery.event.simulate( "focusin", this, jQuery.event.fix( nativeEvent ) );
|
assert.strictEqual( spy.prevent.called, false, "Native preventDefault not called" );
|
||||||
} );
|
assert.strictEqual( spy.stop.called, false, "Native stopPropagation not called" );
|
||||||
input[ 0 ].click();
|
assert.strictEqual( spy.immediate.called, false,
|
||||||
}, QUnit.config.testTimeout / 4 || 1000 );
|
"Native stopImmediatePropagation not called" );
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -2926,7 +2918,7 @@ QUnit.test( "originalEvent type of simulated event", function( assert ) {
|
|||||||
"</div>"
|
"</div>"
|
||||||
).appendTo( "#qunit-fixture" ),
|
).appendTo( "#qunit-fixture" ),
|
||||||
input = jQuery( "#donor-input" ),
|
input = jQuery( "#donor-input" ),
|
||||||
expectedType = "focus",
|
expectedType = jQuery.support.focusin ? "focusin" : "focus",
|
||||||
finish = function() {
|
finish = function() {
|
||||||
finish = null;
|
finish = null;
|
||||||
|
|
||||||
@ -3034,80 +3026,97 @@ QUnit.test( "VML with special event handlers (trac-7071)", function( assert ) {
|
|||||||
ns.remove();
|
ns.remove();
|
||||||
} );
|
} );
|
||||||
|
|
||||||
// These tests are unreliable in Firefox
|
QUnit.test( "Check order of focusin/focusout events", function( assert ) {
|
||||||
if ( !( /firefox/i.test( window.navigator.userAgent ) ) ) {
|
assert.expect( 2 );
|
||||||
QUnit.test( "Check order of focusin/focusout events", function( assert ) {
|
|
||||||
assert.expect( 2 );
|
|
||||||
|
|
||||||
var focus, blur,
|
var focus, blur,
|
||||||
input = jQuery( "#name" );
|
input = jQuery( "#name" );
|
||||||
|
|
||||||
input.on( "focus", function() {
|
input
|
||||||
|
.on( "focus", function() {
|
||||||
focus = true;
|
focus = true;
|
||||||
|
} )
|
||||||
} ).on( "focusin", function() {
|
.on( "focusin", function() {
|
||||||
assert.ok( !focus, "Focusin event should fire before focus does" );
|
assert.ok( !focus, "Focusin event should fire before focus does" );
|
||||||
|
focus = true;
|
||||||
} ).on( "blur", function() {
|
} )
|
||||||
|
.on( "blur", function() {
|
||||||
blur = true;
|
blur = true;
|
||||||
|
} )
|
||||||
} ).on( "focusout", function() {
|
.on( "focusout", function() {
|
||||||
assert.ok( !blur, "Focusout event should fire before blur does" );
|
assert.ok( !blur, "Focusout event should fire before blur does" );
|
||||||
|
blur = true;
|
||||||
} );
|
} );
|
||||||
|
|
||||||
// gain focus
|
// gain focus
|
||||||
input.trigger( "focus" );
|
input.trigger( "focus" );
|
||||||
|
|
||||||
// then lose it
|
// then lose it
|
||||||
jQuery( "#search" ).trigger( "focus" );
|
jQuery( "#search" ).trigger( "focus" );
|
||||||
|
|
||||||
// cleanup
|
// cleanup
|
||||||
input.off();
|
input.off();
|
||||||
} );
|
|
||||||
|
|
||||||
QUnit.test( "focus-blur order (#12868)", function( assert ) {
|
// DOM focus is unreliable in TestSwarm
|
||||||
assert.expect( 5 );
|
if ( !focus ) {
|
||||||
|
assert.ok( true, "GAP: Could not observe focus change" );
|
||||||
|
assert.ok( true, "GAP: Could not observe focus change" );
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
|
||||||
var order,
|
QUnit.test( "focus-blur order (#12868)", function( assert ) {
|
||||||
$text = jQuery( "#text1" ),
|
assert.expect( 5 );
|
||||||
$radio = jQuery( "#radio1" ).trigger( "focus" );
|
|
||||||
|
var order,
|
||||||
|
$text = jQuery( "#text1" ),
|
||||||
|
$radio = jQuery( "#radio1" ).trigger( "focus" ),
|
||||||
|
|
||||||
// Support: IE <=10 only
|
// Support: IE <=10 only
|
||||||
// IE8-10 fire focus/blur events asynchronously; this is the resulting mess.
|
// IE8-10 fire focus/blur events asynchronously; this is the resulting mess.
|
||||||
// IE's browser window must be topmost for this to work properly!!
|
// IE's browser window must be topmost for this to work properly!!
|
||||||
QUnit.stop();
|
done = assert.async();
|
||||||
$radio[ 0 ].focus();
|
|
||||||
|
|
||||||
|
$radio[ 0 ].focus();
|
||||||
|
|
||||||
|
setTimeout( function() {
|
||||||
|
|
||||||
|
$text
|
||||||
|
.on( "focus", function() {
|
||||||
|
assert.equal( order++, 1, "text focus" );
|
||||||
|
} )
|
||||||
|
.on( "blur", function() {
|
||||||
|
assert.equal( order++, 0, "text blur" );
|
||||||
|
} );
|
||||||
|
$radio
|
||||||
|
.on( "focus", function() {
|
||||||
|
assert.equal( order++, 1, "radio focus" );
|
||||||
|
} )
|
||||||
|
.on( "blur", function() {
|
||||||
|
assert.equal( order++, 0, "radio blur" );
|
||||||
|
} );
|
||||||
|
|
||||||
|
// Enabled input getting focus
|
||||||
|
order = 0;
|
||||||
|
assert.equal( document.activeElement, $radio[ 0 ], "radio has focus" );
|
||||||
|
$text.trigger( "focus" );
|
||||||
setTimeout( function() {
|
setTimeout( function() {
|
||||||
|
|
||||||
$text
|
// DOM focus is unreliable in TestSwarm
|
||||||
.on( "focus", function() {
|
if ( order === 0 ) {
|
||||||
assert.equal( order++, 1, "text focus" );
|
assert.ok( true, "GAP: Could not observe focus change" );
|
||||||
} )
|
assert.ok( true, "GAP: Could not observe focus change" );
|
||||||
.on( "blur", function() {
|
}
|
||||||
assert.equal( order++, 0, "text blur" );
|
|
||||||
} );
|
|
||||||
$radio
|
|
||||||
.on( "focus", function() {
|
|
||||||
assert.equal( order++, 1, "radio focus" );
|
|
||||||
} )
|
|
||||||
.on( "blur", function() {
|
|
||||||
assert.equal( order++, 0, "radio blur" );
|
|
||||||
} );
|
|
||||||
|
|
||||||
// Enabled input getting focus
|
assert.equal( document.activeElement, $text[ 0 ], "text has focus" );
|
||||||
order = 0;
|
|
||||||
assert.equal( document.activeElement, $radio[ 0 ], "radio has focus" );
|
|
||||||
$text.trigger( "focus" );
|
|
||||||
setTimeout( function() {
|
|
||||||
assert.equal( document.activeElement, $text[ 0 ], "text has focus" );
|
|
||||||
|
|
||||||
// Run handlers without native method on an input
|
// Run handlers without native method on an input
|
||||||
order = 1;
|
order = 1;
|
||||||
$radio.triggerHandler( "focus" );
|
$radio.triggerHandler( "focus" );
|
||||||
$text.off();
|
|
||||||
QUnit.start();
|
// Clean up
|
||||||
}, 50 );
|
$text.off();
|
||||||
|
$radio.off();
|
||||||
|
done();
|
||||||
}, 50 );
|
}, 50 );
|
||||||
} );
|
}, 50 );
|
||||||
}
|
} );
|
||||||
|
Loading…
Reference in New Issue
Block a user