aboutsummaryrefslogtreecommitdiffstats
path: root/test/unit
diff options
context:
space:
mode:
authorOleg Gaidarenko <markelog@gmail.com>2015-05-20 18:14:13 +0300
committerOleg Gaidarenko <markelog@gmail.com>2015-05-29 20:33:08 +0300
commit37c3d087824b51e742126252ced8be592858102d (patch)
tree73ee8866e41337c0b837d8b34c0f0d50dfc46042 /test/unit
parente6a492d3b6a1b219a36ef1485c1e1a06967c26e7 (diff)
downloadjquery-37c3d087824b51e742126252ced8be592858102d.tar.gz
jquery-37c3d087824b51e742126252ced8be592858102d.zip
Event: improve originalEvent hack
Ref 6df669f0fb87cd9975a18bf6bbe3c3548afa4fee Ref gh-2336
Diffstat (limited to 'test/unit')
-rw-r--r--test/unit/event.js129
1 files changed, 129 insertions, 0 deletions
diff --git a/test/unit/event.js b/test/unit/event.js
index 0476b8e92..785698a47 100644
--- a/test/unit/event.js
+++ b/test/unit/event.js
@@ -2686,6 +2686,135 @@ test( "Inline event result is returned (#13993)", function() {
equal( result, 42, "inline handler returned value" );
});
+test( "preventDefault() on focusin does not throw exception", function( assert ) {
+ expect( 1 );
+
+ var done = assert.async(),
+ input = jQuery( "<input/>" ).appendTo( "#form" );
+
+ input.on( "focusin", function( event ) {
+ var exceptionCaught;
+
+ try {
+ event.preventDefault();
+ } catch ( theException ) {
+ exceptionCaught = theException;
+ }
+
+ assert.strictEqual( exceptionCaught, undefined,
+ "Preventing default on focusin throws no exception" );
+
+ done();
+ } ).trigger( "focus" );
+} );
+
+test( "Donor event interference", function( assert ) {
+ assert.expect( 10 );
+
+ var html = "<div id='donor-outer'>" +
+ "<form id='donor-form'>" +
+ "<input id='donor-input' type='radio' />" +
+ "</form>" +
+ "</div>";
+
+ jQuery( "#qunit-fixture" ).append( html );
+
+ jQuery( "#donor-outer" ).on( "click", function( event ) {
+ assert.ok( true, "click bubbled to outer div" );
+ assert.equal( typeof event.originalEvent, "object", "make sure originalEvent exist" );
+ assert.equal( event.type, "click", "make sure event type is correct" );
+ } );
+ jQuery( "#donor-input" ).on( "click", function( event ) {
+ assert.ok( true, "got a click event from the input" );
+ assert.ok( !event.isPropagationStopped(), "propagation says it's not stopped" );
+ assert.equal( event.type, "click", "make sure event type is correct" );
+ assert.equal( typeof event.originalEvent, "object", "make sure originalEvent exist" );
+ } );
+ jQuery( "#donor-input" ).on( "change", function( event ) {
+ assert.equal( typeof event.originalEvent, "object", "make sure originalEvent exist" );
+ assert.equal( event.type, "change", "make sure event type is correct" );
+ assert.ok( true, "got a change event from the input" );
+ event.stopPropagation();
+ } );
+
+ jQuery( "#donor-input" )[ 0 ].click();
+} );
+
+test( "originalEvent property for IE8", function( assert ) {
+ if ( !(/msie 8\.0/i.test( window.navigator.userAgent )) ) {
+ assert.expect( 1 );
+ assert.ok( true, "Assertions should run only in IE" );
+ return;
+ }
+
+ assert.expect( 12 );
+
+ var html = "<div id='donor-outer'>" +
+ "<form id='donor-form'>" +
+ "<input id='donor-input' type='radio' />" +
+ "</form>" +
+ "</div>";
+
+ jQuery( "#qunit-fixture" ).append( html );
+
+ jQuery( "#donor-outer" ).on( "change", function( event ) {
+ assert.ok( true, "click bubbled to outer div" );
+ assert.equal( event.originalEvent.type, "click", "make sure simulated event is a click" );
+ assert.equal( event.type, "change", "make sure event type is correct" );
+ } );
+
+ jQuery( "#donor-outer" ).on( "click", function( event ) {
+ assert.ok( true, "click bubbled to outer div" );
+ assert.equal( event.originalEvent.type, "click", "make sure originalEvent exist" );
+ } );
+ jQuery( "#donor-input" ).on( "click", function( event ) {
+ assert.ok( true, "got a click event from the input" );
+ assert.ok( !event.isPropagationStopped(), "propagation says it's not stopped" );
+ assert.equal( event.originalEvent.type, "click", "make sure originalEvent exist" );
+ assert.equal( event.type, "click", "make sure event type is correct" );
+ } );
+ jQuery( "#donor-input" ).on( "change", function( event ) {
+ assert.equal( event.originalEvent.type, "click", "make sure originalEvent exist" );
+ assert.equal( event.type, "change", "make sure event type is correct" );
+ assert.ok( true, "got a change event from the input" );
+ } );
+
+ jQuery( "#donor-input" )[ 0 ].click();
+} );
+
+test( "originalEvent property for Chrome, Safari and FF of simulated event", function( assert ) {
+ var userAgent = window.navigator.userAgent;
+
+ if ( !(/chrome/i.test( userAgent ) ||
+ /firefox/i.test( userAgent ) ||
+ /safari/i.test( userAgent ) ) ) {
+ assert.expect( 1 );
+ assert.ok( true, "Assertions should run only in Chrome, Safari and FF" );
+ return;
+ }
+
+ assert.expect( 4 );
+
+ var html = "<div id='donor-outer'>" +
+ "<form id='donor-form'>" +
+ "<input id='donor-input' type='radio' />" +
+ "</form>" +
+ "</div>";
+
+ jQuery( "#qunit-fixture" ).append( html );
+
+ jQuery( "#donor-outer" ).on( "focusin", function( event ) {
+ assert.ok( true, "focusin bubbled to outer div" );
+ assert.equal( event.originalEvent.type, "focus",
+ "make sure originalEvent type is correct" );
+ assert.equal( event.type, "focusin", "make sure type is correct" );
+ } );
+ jQuery( "#donor-input" ).on( "focus", function() {
+ assert.ok( true, "got a focus event from the input" );
+ } );
+ jQuery( "#donor-input" ).trigger( "focus" );
+} );
+
// This tests are unreliable in Firefox
if ( !(/firefox/i.test( window.navigator.userAgent )) ) {
test( "Check order of focusin/focusout events", 2, function() {