@@ -2701,37 +2701,111 @@ test( "preventDefault() on focusin does not throw exception", function( assert )
2701
2701
. focus ( ) ;
2702
2702
} ) ;
2703
2703
2704
- test ( "jQuery.event.simulate() event has no originalEvent " , function ( assert ) {
2705
- expect ( 1 ) ;
2704
+ test ( "Donor event interference " , function ( assert ) {
2705
+ assert . expect ( 10 ) ;
2706
2706
2707
- var done = assert . async ( ) ,
2708
- input = jQuery ( "<input>" )
2709
- . on ( "click" , function ( event ) {
2710
- assert . strictEqual ( "originalEvent" in event , false ,
2711
- "originalEvent not present on simulated event" ) ;
2712
- done ( ) ;
2713
- } ) ;
2714
-
2715
- jQuery . event . simulate ( "click" , input [ 0 ] , new jQuery . Event ( ) , true ) ;
2716
- } ) ;
2707
+ var html = "<div id='donor-outer'>" +
2708
+ "<form id='donor-form'>" +
2709
+ "<input id='donor-input' type='radio' />" +
2710
+ "</form>" +
2711
+ "</div>" ;
2717
2712
2718
- test ( "Donor event interference" , function ( assert ) {
2719
- assert . expect ( 4 ) ;
2713
+ jQuery ( "#qunit-fixture" ) . append ( html ) ;
2720
2714
2721
- jQuery ( "#donor-outer" ) . on ( "click" , function ( ) {
2715
+ jQuery ( "#donor-outer" ) . on ( "click" , function ( event ) {
2722
2716
assert . ok ( true , "click bubbled to outer div" ) ;
2717
+ assert . equal ( typeof event . originalEvent , "object" , "make sure originalEvent exist" ) ;
2718
+ assert . equal ( event . type , "click" , "make sure event type is correct" ) ;
2723
2719
} ) ;
2724
2720
jQuery ( "#donor-input" ) . on ( "click" , function ( event ) {
2725
2721
assert . ok ( true , "got a click event from the input" ) ;
2726
2722
assert . ok ( ! event . isPropagationStopped ( ) , "propagation says it's not stopped" ) ;
2723
+ assert . equal ( event . type , "click" , "make sure event type is correct" ) ;
2724
+ assert . equal ( typeof event . originalEvent , "object" , "make sure originalEvent exist" ) ;
2727
2725
} ) ;
2728
2726
jQuery ( "#donor-input" ) . on ( "change" , function ( event ) {
2727
+ assert . equal ( typeof event . originalEvent , "object" , "make sure originalEvent exist" ) ;
2728
+ assert . equal ( event . type , "change" , "make sure event type is correct" ) ;
2729
2729
assert . ok ( true , "got a change event from the input" ) ;
2730
2730
event . stopPropagation ( ) ;
2731
2731
} ) ;
2732
2732
jQuery ( "#donor-input" ) [ 0 ] . click ( ) ;
2733
2733
} ) ;
2734
2734
2735
+ test ( "originalEvent property for IE8" , function ( assert ) {
2736
+ if ( ! ( / m s i e 8 \. 0 / i. test ( window . navigator . userAgent ) ) ) {
2737
+ assert . expect ( 1 ) ;
2738
+ assert . ok ( true , "Assertions should run only in IE" ) ;
2739
+ return ;
2740
+ }
2741
+
2742
+ assert . expect ( 12 ) ;
2743
+
2744
+ var html = "<div id='donor-outer'>" +
2745
+ "<form id='donor-form'>" +
2746
+ "<input id='donor-input' type='radio' />" +
2747
+ "</form>" +
2748
+ "</div>" ;
2749
+
2750
+ jQuery ( "#qunit-fixture" ) . append ( html ) ;
2751
+
2752
+ jQuery ( "#donor-outer" ) . on ( "change" , function ( event ) {
2753
+ assert . ok ( true , "click bubbled to outer div" ) ;
2754
+ assert . equal ( event . originalEvent . type , "click" , "make sure simulated event is a click" ) ;
2755
+ assert . equal ( event . type , "change" , "make sure event type is correct" ) ;
2756
+ } ) ;
2757
+
2758
+ jQuery ( "#donor-outer" ) . on ( "click" , function ( event ) {
2759
+ assert . ok ( true , "click bubbled to outer div" ) ;
2760
+ assert . equal ( event . originalEvent . type , "click" , "make sure originalEvent exist" ) ;
2761
+ } ) ;
2762
+ jQuery ( "#donor-input" ) . on ( "click" , function ( event ) {
2763
+ assert . ok ( true , "got a click event from the input" ) ;
2764
+ assert . ok ( ! event . isPropagationStopped ( ) , "propagation says it's not stopped" ) ;
2765
+ assert . equal ( event . originalEvent . type , "click" , "make sure originalEvent exist" ) ;
2766
+ assert . equal ( event . type , "click" , "make sure event type is correct" ) ;
2767
+ } ) ;
2768
+ jQuery ( "#donor-input" ) . on ( "change" , function ( event ) {
2769
+ assert . equal ( event . originalEvent . type , "click" , "make sure originalEvent exist" ) ;
2770
+ assert . equal ( event . type , "change" , "make sure event type is correct" ) ;
2771
+ assert . ok ( true , "got a change event from the input" ) ;
2772
+ } ) ;
2773
+ jQuery ( "#donor-input" ) [ 0 ] . click ( ) ;
2774
+ } ) ;
2775
+
2776
+ test ( "originalEvent property for Chrome, Safari and FF of simualted event" , function ( assert ) {
2777
+ var userAgent = window . navigator . userAgent ;
2778
+
2779
+ if ( ! ( / c h r o m e / i. test ( userAgent ) ||
2780
+ / f i r e f o x / i. test ( userAgent ) ||
2781
+ / s a f a r i / i. test ( userAgent ) ) ) {
2782
+ assert . expect ( 1 ) ;
2783
+ assert . ok ( true , "Assertions should run only in Chrome, Safari and FF" ) ;
2784
+ return ;
2785
+ }
2786
+
2787
+ assert . expect ( 4 ) ;
2788
+
2789
+ var html = "<div id='donor-outer'>" +
2790
+ "<form id='donor-form'>" +
2791
+ "<input id='donor-input' type='radio' />" +
2792
+ "</form>" +
2793
+ "</div>" ;
2794
+
2795
+ jQuery ( "#qunit-fixture" ) . append ( html ) ;
2796
+
2797
+ jQuery ( "#donor-outer" ) . on ( "focusin" , function ( event ) {
2798
+ assert . ok ( true , "focusin bubbled to outer div" ) ;
2799
+ assert . equal ( event . originalEvent . type , "focus" ,
2800
+ "make sure originalEvent type is correct" ) ;
2801
+ assert . equal ( event . type , "focusin" , "make sure type is correct" ) ;
2802
+ } ) ;
2803
+ jQuery ( "#donor-input" ) . on ( "focus" , function ( ) {
2804
+ assert . ok ( true , "got a focus event from the input" ) ;
2805
+ } ) ;
2806
+ jQuery ( "#donor-input" ) [ 0 ] . focus ( ) ;
2807
+ } ) ;
2808
+
2735
2809
// This tests are unreliable in Firefox
2736
2810
if ( ! ( / f i r e f o x / i. test ( window . navigator . userAgent ) ) ) {
2737
2811
test ( "Check order of focusin/focusout events" , 2 , function ( ) {
0 commit comments