@@ -2790,6 +2790,81 @@ QUnit.test( "Donor event interference", function( assert ) {
27902790 jQuery ( "#donor-input" ) [ 0 ] . click ( ) ;
27912791} ) ;
27922792
2793+ QUnit . test (
2794+ "native stop(Immediate)Propagation/preventDefault methods shouldn't be called" ,
2795+ function ( assert ) {
2796+ var userAgent = window . navigator . userAgent ;
2797+
2798+ if ( ! ( / f i r e f o x / i. test ( userAgent ) || / s a f a r i / i. test ( userAgent ) ) ) {
2799+ assert . expect ( 1 ) ;
2800+ assert . ok ( true , "Assertions should run only in Chrome, Safari, Fx & Edge" ) ;
2801+ return ;
2802+ }
2803+
2804+ assert . expect ( 3 ) ;
2805+
2806+ var checker = { } ;
2807+
2808+ var html = "<div id='donor-outer'>" +
2809+ "<form id='donor-form'>" +
2810+ "<input id='donor-input' type='radio' />" +
2811+ "</form>" +
2812+ "</div>" ;
2813+
2814+ jQuery ( "#qunit-fixture" ) . append ( html ) ;
2815+ var outer = jQuery ( "#donor-outer" ) ;
2816+
2817+ outer
2818+ . on ( "focusin" , function ( event ) {
2819+ checker . prevent = sinon . stub ( event . originalEvent , "preventDefault" ) ;
2820+ event . preventDefault ( ) ;
2821+ } )
2822+ . on ( "focusin" , function ( event ) {
2823+ checker . simple = sinon . stub ( event . originalEvent , "stopPropagation" ) ;
2824+ event . stopPropagation ( ) ;
2825+ } )
2826+ . on ( "focusin" , function ( event ) {
2827+ checker . immediate = sinon . stub ( event . originalEvent , "stopImmediatePropagation" ) ;
2828+ event . stopImmediatePropagation ( ) ;
2829+ } ) ;
2830+
2831+ jQuery ( "#donor-input" ) . trigger ( "focus" ) ;
2832+ assert . strictEqual ( checker . simple . called , false ) ;
2833+ assert . strictEqual ( checker . immediate . called , false ) ;
2834+ assert . strictEqual ( checker . prevent . called , false ) ;
2835+
2836+ // We need to "off" it, since yes QUnit always update the fixtures
2837+ // but "focus" event listener is attached to document for focus(in | out)
2838+ // event and document doesn't get cleared obviously :)
2839+ outer . off ( "focusin" ) ;
2840+ }
2841+ ) ;
2842+
2843+ QUnit . test (
2844+ "isSimulated property always exist on event object" ,
2845+ function ( assert ) {
2846+ var userAgent = window . navigator . userAgent ;
2847+
2848+ if ( ! ( / f i r e f o x / i. test ( userAgent ) || / s a f a r i / i. test ( userAgent ) ) ) {
2849+ assert . expect ( 1 ) ;
2850+ assert . ok ( true , "Assertions should run only in Chrome, Safari, Fx & Edge" ) ;
2851+ return ;
2852+ }
2853+
2854+ assert . expect ( 1 ) ;
2855+
2856+ var element = jQuery ( "<input/>" ) ;
2857+
2858+ jQuery ( "#qunit-fixture" ) . append ( element ) ;
2859+
2860+ element . on ( "focus" , function ( event ) {
2861+ assert . notOk ( event . isSimulated ) ;
2862+ } ) ;
2863+
2864+ element . trigger ( "focus" ) ;
2865+ }
2866+ ) ;
2867+
27932868QUnit . test ( "originalEvent property for Chrome, Safari, Fx & Edge of simulated event" , function ( assert ) {
27942869 var userAgent = window . navigator . userAgent ;
27952870
@@ -2800,6 +2875,7 @@ QUnit.test( "originalEvent property for Chrome, Safari, Fx & Edge of simulated e
28002875 }
28012876
28022877 assert . expect ( 4 ) ;
2878+ var done = assert . async ( ) ;
28032879
28042880 var html = "<div id='donor-outer'>" +
28052881 "<form id='donor-form'>" +
@@ -2808,19 +2884,26 @@ QUnit.test( "originalEvent property for Chrome, Safari, Fx & Edge of simulated e
28082884 "</div>" ;
28092885
28102886 jQuery ( "#qunit-fixture" ) . append ( html ) ;
2887+ var outer = jQuery ( "#donor-outer" ) ;
28112888
2812- jQuery ( "#donor-outer" ) . on ( "focusin" , function ( event ) {
2813- assert . ok ( true , "focusin bubbled to outer div" ) ;
2814- assert . equal ( event . originalEvent . type , "focus" ,
2815- "make sure originalEvent type is correct" ) ;
2816- assert . equal ( event . type , "focusin" , "make sure type is correct" ) ;
2817- } ) ;
2889+ outer
2890+ . on ( "focusin" , function ( event ) {
2891+ assert . ok ( true , "focusin bubbled to outer div" ) ;
2892+ assert . equal ( event . originalEvent . type , "focus" ,
2893+ "make sure originalEvent type is correct" ) ;
2894+ assert . equal ( event . type , "focusin" , "make sure type is correct" ) ;
2895+ } ) ;
28182896 jQuery ( "#donor-input" ) . on ( "focus" , function ( ) {
28192897 assert . ok ( true , "got a focus event from the input" ) ;
2898+ done ( ) ;
28202899 } ) ;
28212900 jQuery ( "#donor-input" ) . trigger ( "focus" ) ;
2822- } ) ;
28232901
2902+ // We need to "off" it, since yes QUnit always update the fixtures
2903+ // but "focus" event listener is attached to document for focus(in | out)
2904+ // event and document doesn't get cleared obviously :)
2905+ outer . off ( "focusin" ) ;
2906+ } ) ;
28242907
28252908QUnit [ jQuery . fn . click ? "test" : "skip" ] ( "trigger() shortcuts" , function ( assert ) {
28262909 assert . expect ( 5 ) ;
0 commit comments