@@ -2858,59 +2858,51 @@ QUnit.test( "Donor event interference", function( assert ) {
2858
2858
} ) ;
2859
2859
2860
2860
QUnit . test (
2861
- "native stop(Immediate)Propagation/preventDefault methods shouldn't be called " ,
2861
+ "simulated events shouldn't forward stopPropagation/preventDefault methods " ,
2862
2862
function ( assert ) {
2863
2863
assert . expect ( 3 ) ;
2864
2864
2865
- var done = assert . async ( ) ,
2866
- outer = jQuery (
2865
+ var outer = jQuery (
2867
2866
"<div id='donor-outer'>" +
2868
2867
"<form id='donor-form'>" +
2869
2868
"<input id='donor-input' type='checkbox' />" +
2870
2869
"</form>" +
2871
2870
"</div>"
2872
2871
) . appendTo ( "#qunit-fixture" ) ,
2873
2872
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
- } ;
2873
+ spy = { } ;
2887
2874
2888
- outer
2889
- . on ( "focusin " , function ( event ) {
2875
+ jQuery ( "#donor-form" )
2876
+ . on ( "simulated " , function ( event ) {
2890
2877
spy . prevent = sinon . stub ( event . originalEvent , "preventDefault" ) ;
2891
2878
event . preventDefault ( ) ;
2892
- setTimeout ( finish ) ;
2893
2879
} )
2894
- . on ( "focusin " , function ( event ) {
2880
+ . on ( "simulated " , function ( event ) {
2895
2881
spy . stop = sinon . stub ( event . originalEvent , "stopPropagation" ) ;
2896
2882
event . stopPropagation ( ) ;
2897
2883
} )
2898
- . on ( "focusin " , function ( event ) {
2884
+ . on ( "simulated " , function ( event ) {
2899
2885
spy . immediate = sinon . stub ( event . originalEvent , "stopImmediatePropagation" ) ;
2900
2886
event . stopImmediatePropagation ( ) ;
2887
+ } )
2888
+ . on ( "simulated" , function ( event ) {
2889
+ assert . ok ( false , "simulated event immediate propagation stopped" ) ;
2901
2890
} ) ;
2902
- input . trigger ( "focus" ) ;
2903
-
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 ) ) ;
2891
+ outer
2892
+ . on ( "simulated" , function ( event ) {
2893
+ assert . ok ( false , "simulated event propagation stopped" ) ;
2911
2894
} ) ;
2912
- input [ 0 ] . click ( ) ;
2913
- } , QUnit . config . testTimeout / 4 || 1000 ) ;
2895
+
2896
+ // Force a simulated event
2897
+ input [ 0 ] . addEventListener ( "click" , function ( nativeEvent ) {
2898
+ jQuery . event . simulate ( "simulated" , this , jQuery . event . fix ( nativeEvent ) ) ;
2899
+ } ) ;
2900
+ input [ 0 ] . click ( ) ;
2901
+
2902
+ assert . strictEqual ( spy . prevent . called , false , "Native preventDefault not called" ) ;
2903
+ assert . strictEqual ( spy . stop . called , false , "Native stopPropagation not called" ) ;
2904
+ assert . strictEqual ( spy . immediate . called , false ,
2905
+ "Native stopImmediatePropagation not called" ) ;
2914
2906
}
2915
2907
) ;
2916
2908
@@ -2926,7 +2918,7 @@ QUnit.test( "originalEvent type of simulated event", function( assert ) {
2926
2918
"</div>"
2927
2919
) . appendTo ( "#qunit-fixture" ) ,
2928
2920
input = jQuery ( "#donor-input" ) ,
2929
- expectedType = "focus" ,
2921
+ expectedType = jQuery . support . focusin ? "focusin" : "focus" ,
2930
2922
finish = function ( ) {
2931
2923
finish = null ;
2932
2924
@@ -3034,80 +3026,97 @@ QUnit.test( "VML with special event handlers (trac-7071)", function( assert ) {
3034
3026
ns . remove ( ) ;
3035
3027
} ) ;
3036
3028
3037
- // These tests are unreliable in Firefox
3038
- if ( ! ( / f i r e f o x / i. test ( window . navigator . userAgent ) ) ) {
3039
- QUnit . test ( "Check order of focusin/focusout events" , function ( assert ) {
3040
- assert . expect ( 2 ) ;
3029
+ QUnit . test ( "Check order of focusin/focusout events" , function ( assert ) {
3030
+ assert . expect ( 2 ) ;
3041
3031
3042
- var focus , blur ,
3043
- input = jQuery ( "#name" ) ;
3032
+ var focus , blur ,
3033
+ input = jQuery ( "#name" ) ;
3044
3034
3045
- input . on ( "focus" , function ( ) {
3035
+ input
3036
+ . on ( "focus" , function ( ) {
3046
3037
focus = true ;
3047
-
3048
- } ) . on ( "focusin" , function ( ) {
3038
+ } )
3039
+ . on ( "focusin" , function ( ) {
3049
3040
assert . ok ( ! focus , "Focusin event should fire before focus does" ) ;
3050
-
3051
- } ) . on ( "blur" , function ( ) {
3041
+ focus = true ;
3042
+ } )
3043
+ . on ( "blur" , function ( ) {
3052
3044
blur = true ;
3053
-
3054
- } ) . on ( "focusout" , function ( ) {
3045
+ } )
3046
+ . on ( "focusout" , function ( ) {
3055
3047
assert . ok ( ! blur , "Focusout event should fire before blur does" ) ;
3048
+ blur = true ;
3056
3049
} ) ;
3057
3050
3058
- // gain focus
3059
- input . trigger ( "focus" ) ;
3051
+ // gain focus
3052
+ input . trigger ( "focus" ) ;
3060
3053
3061
- // then lose it
3062
- jQuery ( "#search" ) . trigger ( "focus" ) ;
3054
+ // then lose it
3055
+ jQuery ( "#search" ) . trigger ( "focus" ) ;
3063
3056
3064
- // cleanup
3065
- input . off ( ) ;
3066
- } ) ;
3057
+ // cleanup
3058
+ input . off ( ) ;
3067
3059
3068
- QUnit . test ( "focus-blur order (#12868)" , function ( assert ) {
3069
- assert . expect ( 5 ) ;
3060
+ // DOM focus is unreliable in TestSwarm
3061
+ if ( ! focus ) {
3062
+ assert . ok ( true , "GAP: Could not observe focus change" ) ;
3063
+ assert . ok ( true , "GAP: Could not observe focus change" ) ;
3064
+ }
3065
+ } ) ;
3066
+
3067
+ QUnit . test ( "focus-blur order (#12868)" , function ( assert ) {
3068
+ assert . expect ( 5 ) ;
3070
3069
3071
- var order ,
3072
- $text = jQuery ( "#text1" ) ,
3073
- $radio = jQuery ( "#radio1" ) . trigger ( "focus" ) ;
3070
+ var order ,
3071
+ $text = jQuery ( "#text1" ) ,
3072
+ $radio = jQuery ( "#radio1" ) . trigger ( "focus" ) ,
3074
3073
3075
3074
// Support: IE <=10 only
3076
3075
// IE8-10 fire focus/blur events asynchronously; this is the resulting mess.
3077
3076
// IE's browser window must be topmost for this to work properly!!
3078
- QUnit . stop ( ) ;
3079
- $radio [ 0 ] . focus ( ) ;
3077
+ done = assert . async ( ) ;
3078
+
3079
+ $radio [ 0 ] . focus ( ) ;
3080
+
3081
+ setTimeout ( function ( ) {
3082
+
3083
+ $text
3084
+ . on ( "focus" , function ( ) {
3085
+ assert . equal ( order ++ , 1 , "text focus" ) ;
3086
+ } )
3087
+ . on ( "blur" , function ( ) {
3088
+ assert . equal ( order ++ , 0 , "text blur" ) ;
3089
+ } ) ;
3090
+ $radio
3091
+ . on ( "focus" , function ( ) {
3092
+ assert . equal ( order ++ , 1 , "radio focus" ) ;
3093
+ } )
3094
+ . on ( "blur" , function ( ) {
3095
+ assert . equal ( order ++ , 0 , "radio blur" ) ;
3096
+ } ) ;
3080
3097
3098
+ // Enabled input getting focus
3099
+ order = 0 ;
3100
+ assert . equal ( document . activeElement , $radio [ 0 ] , "radio has focus" ) ;
3101
+ $text . trigger ( "focus" ) ;
3081
3102
setTimeout ( function ( ) {
3082
3103
3083
- $text
3084
- . on ( "focus" , function ( ) {
3085
- assert . equal ( order ++ , 1 , "text focus" ) ;
3086
- } )
3087
- . on ( "blur" , function ( ) {
3088
- assert . equal ( order ++ , 0 , "text blur" ) ;
3089
- } ) ;
3090
- $radio
3091
- . on ( "focus" , function ( ) {
3092
- assert . equal ( order ++ , 1 , "radio focus" ) ;
3093
- } )
3094
- . on ( "blur" , function ( ) {
3095
- assert . equal ( order ++ , 0 , "radio blur" ) ;
3096
- } ) ;
3104
+ // DOM focus is unreliable in TestSwarm
3105
+ if ( order === 0 ) {
3106
+ assert . ok ( true , "GAP: Could not observe focus change" ) ;
3107
+ assert . ok ( true , "GAP: Could not observe focus change" ) ;
3108
+ }
3109
+
3110
+ assert . equal ( document . activeElement , $text [ 0 ] , "text has focus" ) ;
3097
3111
3098
- // Enabled input getting focus
3099
- order = 0 ;
3100
- assert . equal ( document . activeElement , $radio [ 0 ] , "radio has focus" ) ;
3101
- $text . trigger ( "focus" ) ;
3102
- setTimeout ( function ( ) {
3103
- assert . equal ( document . activeElement , $text [ 0 ] , "text has focus" ) ;
3104
-
3105
- // Run handlers without native method on an input
3106
- order = 1 ;
3107
- $radio . triggerHandler ( "focus" ) ;
3108
- $text . off ( ) ;
3109
- QUnit . start ( ) ;
3110
- } , 50 ) ;
3112
+ // Run handlers without native method on an input
3113
+ order = 1 ;
3114
+ $radio . triggerHandler ( "focus" ) ;
3115
+
3116
+ // Clean up
3117
+ $text . off ( ) ;
3118
+ $radio . off ( ) ;
3119
+ done ( ) ;
3111
3120
} , 50 ) ;
3112
- } ) ;
3113
- }
3121
+ } , 50 ) ;
3122
+ } ) ;
0 commit comments