Permalink
Browse files

All: Make sure events are well-formed

Fixes gh-8134
Closes gh-8135
  • Loading branch information...
gabrielschulhof authored and arschmitz committed May 23, 2015
1 parent bd14eb4 commit cfe7e73623c9afe2ef7da6df8298b028fd3f2ba9
@@ -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;
@@ -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";
@@ -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 } ];
@@ -36,6 +31,11 @@ module( libName, {
},
teardown: function() {
$.mobile.pageContainer = originalPageContainer;
// NOTE unmock
Math.abs = absFn;
$.Event.prototype.originalEvent = originalEventFn;
$.Event.prototype.preventDefault = preventDefaultFn;
}
} );
@@ -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() {
@@ -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" );
@@ -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" );
} );
@@ -14,6 +14,7 @@ $.testHelper.sequence( [
function() {
target.trigger( $.extend( $.Event( pointer.down ), {
originalEvent: {
preventDefault: $.noop,
touches: false
},
pageX: 206,
@@ -28,6 +29,7 @@ $.testHelper.sequence( [
return event;
} )( $.extend( $.Event( pointer.move ), {
originalEvent: {
preventDefault: $.noop,
touches: false
},
pageX: 206,
@@ -42,6 +44,7 @@ $.testHelper.sequence( [
return event;
} )( $.extend( $.Event( pointer.move ), {
originalEvent: {
preventDefault: $.noop,
touches: false
},
pageX: 170,
@@ -56,6 +59,7 @@ $.testHelper.sequence( [
return event;
} )( $.extend( $.Event( pointer.up ), {
originalEvent: {
preventDefault: $.noop,
touches: false
},
pageX: 170,
@@ -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;
}
} );

0 comments on commit cfe7e73

Please sign in to comment.