diff options
author | Richard Gibson <richard.gibson@gmail.com> | 2019-04-29 13:18:08 -0400 |
---|---|---|
committer | Michał Gołębiowski-Owczarek <m.goleb@gmail.com> | 2019-04-29 20:49:30 +0200 |
commit | ddfa83766478268391bc9da96683fc0d4973fcfe (patch) | |
tree | 93e6e74a4ea7db476fc2b8516c19eb0df56d2ced /test/unit | |
parent | b8d4712825a26a7f24c2bdb5a71aa3abcd345dfd (diff) | |
download | jquery-ddfa83766478268391bc9da96683fc0d4973fcfe.tar.gz jquery-ddfa83766478268391bc9da96683fc0d4973fcfe.zip |
Event: Fix handling of multiple async focus events
(cherry-picked from 24d71ac70406f522fc1b09bf7c4025251ec3aee6)
Fixes gh-4350
Closes gh-4354
Diffstat (limited to 'test/unit')
-rw-r--r-- | test/unit/event.js | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/test/unit/event.js b/test/unit/event.js index c7497b9b0..17706a8b1 100644 --- a/test/unit/event.js +++ b/test/unit/event.js @@ -3041,6 +3041,49 @@ QUnit.test( "focus-blur order (#12868)", function( assert ) { }, 50 ); } ); +QUnit.test( "Event handling works with multiple async focus events (gh-4350)", function( assert ) { + assert.expect( 3 ); + + var remaining = 3, + input = jQuery( "#name" ), + + // 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(); + + input + .on( "focus", function() { + remaining--; + assert.ok( true, "received focus event, expecting " + remaining + " more" ); + if ( remaining > 0 ) { + input.trigger( "blur" ); + } else { + done(); + } + } ) + .on( "blur", function() { + setTimeout( function() { + input.trigger( "focus" ); + } ); + } ); + + // gain focus + input.trigger( "focus" ); + + // DOM focus is unreliable in TestSwarm + setTimeout( function() { + if ( QUnit.isSwarm && remaining === 3 ) { + 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" ); + setTimeout( function() { + done(); + } ); + } + } ); +} ); + QUnit.test( "native-backed events preserve trigger data (gh-1741, gh-4139)", function( assert ) { assert.expect( 17 ); |