Permalink
Browse files

Event: Remove fake originalEvent from jQuery.Event.simulate

Fixes gh-2300
Closes gh-2303
  • Loading branch information...
gabrielschulhof authored and markelog committed May 12, 2015
1 parent 3c92770 commit 7475d5debeb7c53158921ed40f6c2fdb25a2cc86
Showing with 65 additions and 2 deletions.
  1. +6 −2 src/event.js
  2. +5 −0 test/index.html
  3. +54 −0 test/unit/event.js
View
@@ -610,10 +610,14 @@ jQuery.event = {
event,
{
type: type,
isSimulated: true,
originalEvent: {}
isSimulated: true
}
);
// This prevents stopPropagation(), stopImmediatePropagation(), and preventDefault() from
// preventing default on the donor event.
delete e.originalEvent;
if ( bubble ) {
jQuery.event.trigger( e, null, elem );
} else {
View
@@ -42,6 +42,11 @@
<!-- this iframe is outside the #qunit-fixture so it won't reload constantly wasting time, but it means the tests must be "safe" and clean up after themselves -->
<iframe id="loadediframe" name="loadediframe" style="display:none;" src="data/iframe.html"></iframe>
<dl id="dl" style="position:absolute;top:-32767px;left:-32767px;width:1px;">
<div id="donor-outer">
<form id="donor-form">
<input id="donor-input" type="radio" />
</form>
</div>
<div id="qunit-fixture">
<p id="firstp">See <a id="simon1" href="http://simon.incutio.com/archive/2003/03/25/#getElementsBySelector" rel="bookmark">this blog entry</a> for more information.</p>
<p id="ap">
View
@@ -2671,6 +2671,60 @@ test( ".off() removes the expando when there's no more data", function() {
}
});
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();
} )
.focus();
} );
test( "jQuery.event.simulate() event has no originalEvent", function( assert ) {
expect( 1 );
var done = assert.async(),
input = jQuery( "<input>" )
.on( "click", function( event ) {
assert.strictEqual( "originalEvent" in event, false,
"originalEvent not present on simulated event" );
done();
} );
jQuery.event.simulate( "click", input[ 0 ], new jQuery.Event(), true );
} );
test( "Donor event interference", function( assert ) {
assert.expect( 4 );
jQuery( "#donor-outer" ).on( "click", function() {
assert.ok( true, "click bubbled to outer div" );
} );
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" );
} );
jQuery( "#donor-input" ).on( "change", function( event ) {
assert.ok( true, "got a change event from the input" );
event.stopPropagation();
} );
jQuery( "#donor-input" )[0].click();
} );
// This tests are unreliable in Firefox
if ( !(/firefox/i.test( window.navigator.userAgent )) ) {
test( "Check order of focusin/focusout events", 2, function() {

0 comments on commit 7475d5d

Please sign in to comment.