@@ -2812,162 +2812,149 @@ QUnit.test( "preventDefault() on focusin does not throw exception", function( as
2812
2812
} ) ;
2813
2813
input . trigger ( "focus" ) ;
2814
2814
2815
- // DOM focus is unreliable in TestSwarm CI ; set an abort timeout
2815
+ // DOM focus is unreliable in TestSwarm; set a simulated event workaround timeout
2816
2816
setTimeout ( function ( ) {
2817
2817
if ( ! done ) {
2818
2818
return ;
2819
2819
}
2820
- assert . ok ( true , "Did not intercept focusin" ) ;
2821
- done ( ) ;
2822
- done = null ;
2820
+ input [ 0 ] . addEventListener ( "click" , function ( nativeEvent ) {
2821
+ jQuery . event . simulate ( "focusin" , this , jQuery . event . fix ( nativeEvent ) ) ;
2822
+ } ) ;
2823
+ input [ 0 ] . click ( ) ;
2823
2824
} , QUnit . config . testTimeout / 4 || 1000 ) ;
2824
2825
} ) ;
2825
2826
2826
2827
QUnit . test ( "Donor event interference" , function ( assert ) {
2827
- assert . expect ( 10 ) ;
2828
-
2829
- var html = "<div id='donor-outer'>" +
2830
- "<form id='donor-form'>" +
2831
- "<input id='donor-input' type='radio' />" +
2832
- "</form>" +
2833
- "</div>" ;
2834
-
2835
- jQuery ( "#qunit-fixture" ) . append ( html ) ;
2836
-
2837
- jQuery ( "#donor-outer" ) . on ( "click" , function ( event ) {
2838
- assert . ok ( true , "click bubbled to outer div" ) ;
2839
- assert . equal ( typeof event . originalEvent , "object" , "make sure originalEvent exist" ) ;
2840
- assert . equal ( event . type , "click" , "make sure event type is correct" ) ;
2841
- } ) ;
2842
- jQuery ( "#donor-input" ) . on ( "click" , function ( event ) {
2843
- assert . ok ( true , "got a click event from the input" ) ;
2844
- assert . ok ( ! event . isPropagationStopped ( ) , "propagation says it's not stopped" ) ;
2845
- assert . equal ( event . type , "click" , "make sure event type is correct" ) ;
2846
- assert . equal ( typeof event . originalEvent , "object" , "make sure originalEvent exist" ) ;
2847
- } ) ;
2848
- jQuery ( "#donor-input" ) . on ( "change" , function ( event ) {
2849
- assert . equal ( typeof event . originalEvent , "object" , "make sure originalEvent exist" ) ;
2850
- assert . equal ( event . type , "change" , "make sure event type is correct" ) ;
2851
- assert . ok ( true , "got a change event from the input" ) ;
2828
+ assert . expect ( 8 ) ;
2829
+
2830
+ var outer = jQuery (
2831
+ "<div id='donor-outer'>" +
2832
+ "<form id='donor-form'>" +
2833
+ "<input id='donor-input' type='checkbox' />" +
2834
+ "</form>" +
2835
+ "</div>"
2836
+ ) . appendTo ( "#qunit-fixture" ) ,
2837
+ input = jQuery ( "#donor-input" ) ;
2838
+
2839
+ input . on ( "click" , function ( event ) {
2840
+ assert . equal ( event . type , "click" , "click event at input" ) ;
2841
+ assert . ok ( ! event . isPropagationStopped ( ) , "click event at input is still propagating" ) ;
2842
+ assert . equal ( typeof event . originalEvent , "object" ,
2843
+ "click event at input has originalEvent property" ) ;
2844
+ } ) ;
2845
+ outer . on ( "click" , function ( event ) {
2846
+ assert . equal ( event . type , "click" , "click event at ancestor" ) ;
2847
+ assert . ok ( ! event . isPropagationStopped ( ) , "click event at ancestor is still propagating" ) ;
2848
+ assert . equal ( typeof event . originalEvent , "object" ,
2849
+ "click event at ancestor has originalEvent property" ) ;
2850
+ } ) ;
2851
+ input . on ( "change" , function ( event ) {
2852
+ assert . equal ( event . type , "change" , "change event at input" ) ;
2853
+ assert . equal ( typeof event . originalEvent , "object" ,
2854
+ "change event at input has originalEvent property" ) ;
2852
2855
event . stopPropagation ( ) ;
2853
2856
} ) ;
2854
- jQuery ( "#donor- input" ) [ 0 ] . click ( ) ;
2857
+ input [ 0 ] . click ( ) ;
2855
2858
} ) ;
2856
2859
2857
2860
QUnit . test (
2858
2861
"native stop(Immediate)Propagation/preventDefault methods shouldn't be called" ,
2859
2862
function ( assert ) {
2860
- var userAgent = window . navigator . userAgent ;
2861
-
2862
- if ( ! ( / f i r e f o x / i. test ( userAgent ) || / s a f a r i / i. test ( userAgent ) ) ) {
2863
- assert . expect ( 1 ) ;
2864
- assert . ok ( true , "Assertions should run only in Chrome, Safari, Fx & Edge" ) ;
2865
- return ;
2866
- }
2867
-
2868
2863
assert . expect ( 3 ) ;
2869
2864
2870
- var checker = { } ;
2871
-
2872
- var html = "<div id='donor-outer'>" +
2873
- "<form id='donor-form'>" +
2874
- "<input id='donor-input' type='radio' />" +
2875
- "</form>" +
2876
- "</div>" ;
2877
-
2878
- jQuery ( "#qunit-fixture" ) . append ( html ) ;
2879
- var outer = jQuery ( "#donor-outer" ) ;
2865
+ var done = assert . async ( ) ,
2866
+ outer = jQuery (
2867
+ "<div id='donor-outer'>" +
2868
+ "<form id='donor-form'>" +
2869
+ "<input id='donor-input' type='checkbox' />" +
2870
+ "</form>" +
2871
+ "</div>"
2872
+ ) . appendTo ( "#qunit-fixture" ) ,
2873
+ input = jQuery ( "#donor-input" ) ,
2874
+ spy = { } ,
2875
+ finish = function ( ) {
2876
+ finish = null ;
2877
+ assert . strictEqual ( spy . prevent . called , false , "Native preventDefault not called" ) ;
2878
+ assert . strictEqual ( spy . stop . called , false , "Native stopPropagation not called" ) ;
2879
+ assert . strictEqual ( spy . immediate . called , false ,
2880
+ "Native stopImmediatePropagation not called" ) ;
2881
+
2882
+ // Remove jQuery handlers to ensure removal of capturing handlers on the document
2883
+ outer . off ( "focusin" ) ;
2884
+
2885
+ done ( ) ;
2886
+ } ;
2880
2887
2881
2888
outer
2882
2889
. on ( "focusin" , function ( event ) {
2883
- checker . prevent = sinon . stub ( event . originalEvent , "preventDefault" ) ;
2890
+ spy . prevent = sinon . stub ( event . originalEvent , "preventDefault" ) ;
2884
2891
event . preventDefault ( ) ;
2892
+ setTimeout ( finish ) ;
2885
2893
} )
2886
2894
. on ( "focusin" , function ( event ) {
2887
- checker . simple = sinon . stub ( event . originalEvent , "stopPropagation" ) ;
2895
+ spy . stop = sinon . stub ( event . originalEvent , "stopPropagation" ) ;
2888
2896
event . stopPropagation ( ) ;
2889
2897
} )
2890
2898
. on ( "focusin" , function ( event ) {
2891
- checker . immediate = sinon . stub ( event . originalEvent , "stopImmediatePropagation" ) ;
2899
+ spy . immediate = sinon . stub ( event . originalEvent , "stopImmediatePropagation" ) ;
2892
2900
event . stopImmediatePropagation ( ) ;
2893
2901
} ) ;
2902
+ input . trigger ( "focus" ) ;
2894
2903
2895
- jQuery ( "#donor-input" ) . trigger ( "focus" ) ;
2896
- assert . strictEqual ( checker . simple . called , false ) ;
2897
- assert . strictEqual ( checker . immediate . called , false ) ;
2898
- assert . strictEqual ( checker . prevent . called , false ) ;
2899
-
2900
- // We need to "off" it, since yes QUnit always update the fixtures
2901
- // but "focus" event listener is attached to document for focus(in | out)
2902
- // event and document doesn't get cleared obviously :)
2903
- outer . off ( "focusin" ) ;
2904
- }
2905
- ) ;
2906
-
2907
- QUnit . test (
2908
- "isSimulated property always exist on event object" ,
2909
- function ( assert ) {
2910
- var userAgent = window . navigator . userAgent ;
2911
-
2912
- if ( ! ( / f i r e f o x / i. test ( userAgent ) || / s a f a r i / i. test ( userAgent ) ) ) {
2913
- assert . expect ( 1 ) ;
2914
- assert . ok ( true , "Assertions should run only in Chrome, Safari, Fx & Edge" ) ;
2915
- return ;
2916
- }
2917
-
2918
- assert . expect ( 1 ) ;
2919
-
2920
- var element = jQuery ( "<input/>" ) ;
2921
-
2922
- jQuery ( "#qunit-fixture" ) . append ( element ) ;
2923
-
2924
- element . on ( "focus" , function ( event ) {
2925
- assert . notOk ( event . isSimulated ) ;
2926
- } ) ;
2927
-
2928
- element . trigger ( "focus" ) ;
2904
+ // DOM focus is unreliable in TestSwarm; set a simulated event workaround timeout
2905
+ setTimeout ( function ( ) {
2906
+ if ( ! finish ) {
2907
+ return ;
2908
+ }
2909
+ input [ 0 ] . addEventListener ( "click" , function ( nativeEvent ) {
2910
+ jQuery . event . simulate ( "focusin" , this , jQuery . event . fix ( nativeEvent ) ) ;
2911
+ } ) ;
2912
+ input [ 0 ] . click ( ) ;
2913
+ } , QUnit . config . testTimeout / 4 || 1000 ) ;
2929
2914
}
2930
2915
) ;
2931
2916
2932
- QUnit . test ( "originalEvent property for Chrome, Safari, Fx & Edge of simulated event" , function ( assert ) {
2933
- var userAgent = window . navigator . userAgent ;
2934
-
2935
- if ( ! ( / f i r e f o x / i. test ( userAgent ) || / s a f a r i / i. test ( userAgent ) ) ) {
2936
- assert . expect ( 1 ) ;
2937
- assert . ok ( true , "Assertions should run only in Chrome, Safari, Fx & Edge" ) ;
2938
- return ;
2939
- }
2940
-
2941
- assert . expect ( 4 ) ;
2942
- var done = assert . async ( ) ;
2917
+ QUnit . test ( "originalEvent type of simulated event" , function ( assert ) {
2918
+ assert . expect ( 2 ) ;
2943
2919
2944
- var html = "<div id='donor-outer'>" +
2945
- "<form id='donor-form'>" +
2946
- "<input id='donor-input' type='radio' />" +
2947
- "</form>" +
2948
- "</div>" ;
2949
-
2950
- jQuery ( "#qunit-fixture" ) . append ( html ) ;
2951
- var outer = jQuery ( "#donor-outer" ) ;
2952
-
2953
- outer
2954
- . on ( "focusin" , function ( event ) {
2955
- assert . ok ( true , "focusin bubbled to outer div" ) ;
2956
- assert . equal ( event . originalEvent . type , "focus" ,
2957
- "make sure originalEvent type is correct" ) ;
2958
- assert . equal ( event . type , "focusin" , "make sure type is correct" ) ;
2959
- } ) ;
2920
+ var done = assert . async ( ) ,
2921
+ outer = jQuery (
2922
+ "<div id='donor-outer'>" +
2923
+ "<form id='donor-form'>" +
2924
+ "<input id='donor-input' type='checkbox' />" +
2925
+ "</form>" +
2926
+ "</div>"
2927
+ ) . appendTo ( "#qunit-fixture" ) ,
2928
+ input = jQuery ( "#donor-input" ) ,
2929
+ expectedType = "focus" ,
2930
+ finish = function ( ) {
2931
+ finish = null ;
2932
+
2933
+ // Remove jQuery handlers to ensure removal of capturing handlers on the document
2934
+ outer . off ( "focusin" ) ;
2935
+
2936
+ done ( ) ;
2937
+ } ;
2960
2938
2961
- jQuery ( "#donor-input" ) . on ( "focus" , function ( ) {
2962
- assert . ok ( true , "got a focus event from the input" ) ;
2963
- done ( ) ;
2939
+ outer . on ( "focusin" , function ( event ) {
2940
+ assert . equal ( event . type , "focusin" , "focusin event at ancestor" ) ;
2941
+ assert . equal ( event . originalEvent . type , expectedType ,
2942
+ "focus event at ancestor has correct originalEvent type" ) ;
2943
+ setTimeout ( finish ) ;
2964
2944
} ) ;
2965
- jQuery ( "#donor- input" ) . trigger ( "focus" ) ;
2945
+ input . trigger ( "focus" ) ;
2966
2946
2967
- // We need to "off" it, since yes QUnit always update the fixtures
2968
- // but "focus" event listener is attached to document for focus(in | out)
2969
- // event and document doesn't get cleared obviously :)
2970
- outer . off ( "focusin" ) ;
2947
+ // DOM focus is unreliable in TestSwarm; set a simulated event workaround timeout
2948
+ setTimeout ( function ( ) {
2949
+ if ( ! finish ) {
2950
+ return ;
2951
+ }
2952
+ input [ 0 ] . addEventListener ( "click" , function ( nativeEvent ) {
2953
+ expectedType = nativeEvent . type ;
2954
+ jQuery . event . simulate ( "focusin" , this , jQuery . event . fix ( nativeEvent ) ) ;
2955
+ } ) ;
2956
+ input [ 0 ] . click ( ) ;
2957
+ } , QUnit . config . testTimeout / 4 || 1000 ) ;
2971
2958
} ) ;
2972
2959
2973
2960
QUnit . test ( "trigger('click') on radio passes extra params" , function ( assert ) {
0 commit comments