Event: Remove fake originalEvent from jQuery.Event.simulate

Fixes gh-2300
Closes gh-2303
This commit is contained in:
Gabriel Schulhof 2015-05-12 15:30:05 +03:00 committed by Oleg Gaidarenko
parent 3c92770867
commit 7475d5debe
3 changed files with 65 additions and 2 deletions

View File

@ -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 File

@ -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 File

@ -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() {