Skip to content
This repository was archived by the owner on Oct 8, 2021. It is now read-only.

Commit aba09ca

Browse files
Gabriel Schulhofarschmitz
Gabriel Schulhof
authored andcommitted
All: Make sure events are well-formed
Fixes gh-8134 Closes gh-8135
1 parent 52218ed commit aba09ca

File tree

5 files changed

+28
-19
lines changed

5 files changed

+28
-19
lines changed

js/navigation/navigator.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,7 @@ $.extend( $.mobile.Navigator.prototype, {
151151

152152
if ( isPopStateEvent ) {
153153
popstateEvent = new $.Event( "popstate" );
154-
popstateEvent.originalEvent = {
155-
type: "popstate",
156-
state: null
157-
};
154+
popstateEvent.originalEvent = new $.Event( "popstate", { state: null } );
158155

159156
state.id = ( this.squash( url, state ) || {} ).id;
160157

tests/jquery.testHelper.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ $.testHelper = {
3535
loadSeq( seq, 0 );
3636
},
3737

38+
mockOriginalEvent: function( options ) {
39+
$.Event.prototype.originalEvent = $.extend( {}, { preventDefault: $.noop }, options );
40+
},
41+
3842
excludeFileProtocol: function( callback ) {
3943
var message = "Tests require script reload and cannot be run via file: protocol";
4044

tests/unit/event/event_core.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,6 @@ module( libName, {
2121
$( "#qunit-fixture" ).unbind();
2222
} );
2323

24-
//NOTE unmock
25-
Math.abs = absFn;
26-
$.Event.prototype.originalEvent = originalEventFn;
27-
$.Event.prototype.preventDefault = preventDefaultFn;
28-
2924
// make sure the event objects respond to touches to simulate
3025
// the collections existence in non touch enabled test browsers
3126
$.Event.prototype.touches = [ { pageX: 1, pageY: 1 } ];
@@ -36,6 +31,11 @@ module( libName, {
3631
},
3732
teardown: function() {
3833
$.mobile.pageContainer = originalPageContainer;
34+
35+
// NOTE unmock
36+
Math.abs = absFn;
37+
$.Event.prototype.originalEvent = originalEventFn;
38+
$.Event.prototype.preventDefault = preventDefaultFn;
3939
}
4040
} );
4141

@@ -149,9 +149,9 @@ var forceTouchSupport = function() {
149149
} );
150150

151151
//mock originalEvent information
152-
$.Event.prototype.originalEvent = {
152+
$.testHelper.mockOriginalEvent( {
153153
touches: [ { 'pageX': 0 }, { 'pageY': 0 } ]
154-
};
154+
} );
155155
};
156156

157157
asyncTest( "long press fires tap hold after taphold duration", function() {
@@ -412,12 +412,12 @@ var swipeTimedTest = function( opts ) {
412412
};
413413

414414
//NOTE bypass the trigger source check
415-
$.Event.prototype.originalEvent = {
415+
$.testHelper.mockOriginalEvent( {
416416
touches: [ {
417417
clientX: 0,
418418
clientY: 0
419419
} ]
420-
};
420+
} );
421421

422422
qunitFixture.trigger( "touchstart" );
423423

@@ -488,22 +488,22 @@ asyncTest( "scrolling prevented when coordinate change > 10", function() {
488488
};
489489

490490
//NOTE bypass the trigger source check
491-
$.Event.prototype.originalEvent = {
491+
$.testHelper.mockOriginalEvent( {
492492
touches: [ {
493493
clientX: 0,
494494
clientY: 0
495495
} ]
496-
};
496+
} );
497497

498498
$( "#qunit-fixture" ).trigger( "touchstart" );
499499

500500
//NOTE bypass the trigger source check
501-
$.Event.prototype.originalEvent = {
501+
$.testHelper.mockOriginalEvent( {
502502
touches: [ {
503503
clientX: 200,
504504
clientY: 0
505505
} ]
506-
};
506+
} );
507507

508508
$( "#qunit-fixture" ).trigger( "touchmove" );
509509
} );

tests/unit/event/swipe_core.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ $.testHelper.sequence( [
1414
function() {
1515
target.trigger( $.extend( $.Event( pointer.down ), {
1616
originalEvent: {
17+
preventDefault: $.noop,
1718
touches: false
1819
},
1920
pageX: 206,
@@ -28,6 +29,7 @@ $.testHelper.sequence( [
2829
return event;
2930
} )( $.extend( $.Event( pointer.move ), {
3031
originalEvent: {
32+
preventDefault: $.noop,
3133
touches: false
3234
},
3335
pageX: 206,
@@ -42,6 +44,7 @@ $.testHelper.sequence( [
4244
return event;
4345
} )( $.extend( $.Event( pointer.move ), {
4446
originalEvent: {
47+
preventDefault: $.noop,
4548
touches: false
4649
},
4750
pageX: 170,
@@ -56,6 +59,7 @@ $.testHelper.sequence( [
5659
return event;
5760
} )( $.extend( $.Event( pointer.up ), {
5861
originalEvent: {
62+
preventDefault: $.noop,
5963
touches: false
6064
},
6165
pageX: 170,

tests/unit/panel/panel_core.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,13 @@ asyncTest( "should be able to open a second panel", function() {
231231

232232
module( "dismissable panel", {
233233
setup: function() {
234-
$.Event.prototype.originalEvent = {
234+
this.originalOriginalEvent = $.Event.prototype.originalEvent;
235+
$.testHelper.mockOriginalEvent( {
235236
touches: [ { 'pageX': 0 }, { 'pageY': 0 } ]
236-
};
237+
} );
238+
},
239+
teardown: function() {
240+
$.Event.prototype.originalEvent = this.originalOriginalEvent;
237241
}
238242
} );
239243

0 commit comments

Comments
 (0)