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

All: Make sure events are well-formed and offsets are valid #8135

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions js/navigation/navigator.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,7 @@ $.extend( $.mobile.Navigator.prototype, {

if ( isPopStateEvent ) {
popstateEvent = new $.Event( "popstate" );
popstateEvent.originalEvent = {
type: "popstate",
state: null
};
popstateEvent.originalEvent = new $.Event( "popstate", { state: null } );

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

Expand Down
4 changes: 4 additions & 0 deletions tests/jquery.testHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ $.testHelper = {
loadSeq( seq, 0 );
},

mockOriginalEvent: function( options ) {
$.Event.prototype.originalEvent = $.extend( {}, { preventDefault: $.noop }, options );
},

excludeFileProtocol: function( callback ) {
var message = "Tests require script reload and cannot be run via file: protocol";

Expand Down
26 changes: 13 additions & 13 deletions tests/unit/event/event_core.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ module( libName, {
$( "#qunit-fixture" ).unbind();
} );

//NOTE unmock
Math.abs = absFn;
$.Event.prototype.originalEvent = originalEventFn;
$.Event.prototype.preventDefault = preventDefaultFn;

// make sure the event objects respond to touches to simulate
// the collections existence in non touch enabled test browsers
$.Event.prototype.touches = [ { pageX: 1, pageY: 1 } ];
Expand All @@ -36,6 +31,11 @@ module( libName, {
},
teardown: function() {
$.mobile.pageContainer = originalPageContainer;

// NOTE unmock
Math.abs = absFn;
$.Event.prototype.originalEvent = originalEventFn;
$.Event.prototype.preventDefault = preventDefaultFn;
}
} );

Expand Down Expand Up @@ -149,9 +149,9 @@ var forceTouchSupport = function() {
} );

//mock originalEvent information
$.Event.prototype.originalEvent = {
$.testHelper.mockOriginalEvent( {
touches: [ { 'pageX': 0 }, { 'pageY': 0 } ]
};
} );
};

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

//NOTE bypass the trigger source check
$.Event.prototype.originalEvent = {
$.testHelper.mockOriginalEvent( {
touches: [ {
clientX: 0,
clientY: 0
} ]
};
} );

qunitFixture.trigger( "touchstart" );

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

//NOTE bypass the trigger source check
$.Event.prototype.originalEvent = {
$.testHelper.mockOriginalEvent( {
touches: [ {
clientX: 0,
clientY: 0
} ]
};
} );

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

//NOTE bypass the trigger source check
$.Event.prototype.originalEvent = {
$.testHelper.mockOriginalEvent( {
touches: [ {
clientX: 200,
clientY: 0
} ]
};
} );

$( "#qunit-fixture" ).trigger( "touchmove" );
} );
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/event/swipe_core.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ $.testHelper.sequence( [
function() {
target.trigger( $.extend( $.Event( pointer.down ), {
originalEvent: {
preventDefault: $.noop,
touches: false
},
pageX: 206,
Expand All @@ -28,6 +29,7 @@ $.testHelper.sequence( [
return event;
} )( $.extend( $.Event( pointer.move ), {
originalEvent: {
preventDefault: $.noop,
touches: false
},
pageX: 206,
Expand All @@ -42,6 +44,7 @@ $.testHelper.sequence( [
return event;
} )( $.extend( $.Event( pointer.move ), {
originalEvent: {
preventDefault: $.noop,
touches: false
},
pageX: 170,
Expand All @@ -56,6 +59,7 @@ $.testHelper.sequence( [
return event;
} )( $.extend( $.Event( pointer.up ), {
originalEvent: {
preventDefault: $.noop,
touches: false
},
pageX: 170,
Expand Down
8 changes: 6 additions & 2 deletions tests/unit/panel/panel_core.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,13 @@ asyncTest( "should be able to open a second panel", function() {

module( "dismissable panel", {
setup: function() {
$.Event.prototype.originalEvent = {
this.originalOriginalEvent = $.Event.prototype.originalEvent;
$.testHelper.mockOriginalEvent( {
touches: [ { 'pageX': 0 }, { 'pageY': 0 } ]
};
} );
},
teardown: function() {
$.Event.prototype.originalEvent = this.originalOriginalEvent;
}
} );

Expand Down