Commit 38f087b5 authored by timmywil's avatar timmywil

Add a way to fire native events using dispatchEvent/fireEvent in testinit.js;...

Add a way to fire native events using dispatchEvent/fireEvent in testinit.js; fixes failing click test in FF3.6
parent fa0e801f
...@@ -2,7 +2,7 @@ var jQuery = this.jQuery || "jQuery", // For testing .noConflict() ...@@ -2,7 +2,7 @@ var jQuery = this.jQuery || "jQuery", // For testing .noConflict()
$ = this.$ || "$", $ = this.$ || "$",
originaljQuery = jQuery, originaljQuery = jQuery,
original$ = $, original$ = $,
amdDefined; amdDefined;
/** /**
* Set up a mock AMD define function for testing AMD registration. * Set up a mock AMD define function for testing AMD registration.
...@@ -44,6 +44,20 @@ function t(a,b,c) { ...@@ -44,6 +44,20 @@ function t(a,b,c) {
same(f, q.apply(q,c), a + " (" + b + ")"); same(f, q.apply(q,c), a + " (" + b + ")");
} }
var fireNative;
if ( document.createEvent ) {
fireNative = function( node, type ) {
var event = document.createEvent('HTMLEvents');
event.initEvent( type, true, true );
node.dispatchEvent( event );
};
} else {
fireNative = function( node, type ) {
var event = document.createEventObject();
node.fireEvent( 'on' + type, event );
};
}
/** /**
* Add random number to url to stop IE from caching * Add random number to url to stop IE from caching
* *
......
...@@ -19,8 +19,8 @@ test("bind(),live(),delegate() with non-null,defined data", function() { ...@@ -19,8 +19,8 @@ test("bind(),live(),delegate() with non-null,defined data", function() {
expect(3); expect(3);
var handler = function( event, data ) { var handler = function( event, data ) {
equal( data, 0, "non-null, defined data (zero) is correctly passed" ); equal( data, 0, "non-null, defined data (zero) is correctly passed" );
}; };
jQuery("#foo").bind("foo", handler); jQuery("#foo").bind("foo", handler);
jQuery("#foo").live("foo", handler); jQuery("#foo").live("foo", handler);
...@@ -35,14 +35,14 @@ test("bind(),live(),delegate() with non-null,defined data", function() { ...@@ -35,14 +35,14 @@ test("bind(),live(),delegate() with non-null,defined data", function() {
}); });
test("Handler changes and .trigger() order", function() { test("Handler changes and .trigger() order", function() {
expect(1); expect(1);
var markup = jQuery( var markup = jQuery(
'<div><div><p><span><b class="a">b</b></span></p></div></div>' '<div><div><p><span><b class="a">b</b></span></p></div></div>'
), ),
path = ""; path = "";
markup markup
.find( "*" ).andSelf().on( "click", function( e ) { .find( "*" ).andSelf().on( "click", function( e ) {
path += this.nodeName.toLowerCase() + " "; path += this.nodeName.toLowerCase() + " ";
}) })
...@@ -53,11 +53,11 @@ test("Handler changes and .trigger() order", function() { ...@@ -53,11 +53,11 @@ test("Handler changes and .trigger() order", function() {
} }
}); });
markup.find( "b" ).trigger( "click" ); markup.find( "b" ).trigger( "click" );
equals( path, "b p div div ", "Delivered all events" ); equals( path, "b p div div ", "Delivered all events" );
markup.remove(); markup.remove();
}); });
test("bind(), with data", function() { test("bind(), with data", function() {
...@@ -118,16 +118,16 @@ test("bind(), five events at once", function() { ...@@ -118,16 +118,16 @@ test("bind(), five events at once", function() {
expect(1); expect(1);
var count = 0, var count = 0,
handler = function(event) { handler = function(event) {
count++; count++;
}; };
jQuery("#firstp").bind("click mouseover foo bar baz", handler) jQuery("#firstp").bind("click mouseover foo bar baz", handler)
.trigger("click").trigger("mouseover") .trigger("click").trigger("mouseover")
.trigger("foo").trigger("bar") .trigger("foo").trigger("bar")
.trigger("baz"); .trigger("baz");
equals( count, 5, "bind() five events at once" ); equals( count, 5, "bind() five events at once" );
}); });
test("bind(), multiple events at once and namespaces", function() { test("bind(), multiple events at once and namespaces", function() {
...@@ -997,7 +997,7 @@ test("trigger(type, [data], [fn])", function() { ...@@ -997,7 +997,7 @@ test("trigger(type, [data], [fn])", function() {
$elem.die('mouseleave'); $elem.die('mouseleave');
// Triggers handlrs and native // Triggers handlrs and native
// Trigger 5 // Trigger 5
$elem.bind("click", handler).trigger("click", [1, "2", "abc"]); $elem.bind("click", handler).trigger("click", [1, "2", "abc"]);
...@@ -2477,12 +2477,13 @@ test("fixHooks extensions", function() { ...@@ -2477,12 +2477,13 @@ test("fixHooks extensions", function() {
// IE requires focusable elements to be visible, so append to body // IE requires focusable elements to be visible, so append to body
var $fixture = jQuery( "<input type='text' id='hook-fixture' />" ).appendTo( "body" ), var $fixture = jQuery( "<input type='text' id='hook-fixture' />" ).appendTo( "body" ),
saved = jQuery.event.fixHooks.click; saved = jQuery.event.fixHooks.click;
// Ensure the property doesn't exist // Ensure the property doesn't exist
$fixture.bind( "click", function( event ) { $fixture.bind( "click", function( event ) {
ok( !("blurrinessLevel" in event), "event.blurrinessLevel does not exist" ); ok( !("blurrinessLevel" in event), "event.blurrinessLevel does not exist" );
})[0].click(); });
fireNative( $fixture[0], 'click' );
$fixture.unbind( "click" ); $fixture.unbind( "click" );
jQuery.event.fixHooks.click = { jQuery.event.fixHooks.click = {
...@@ -2495,7 +2496,8 @@ test("fixHooks extensions", function() { ...@@ -2495,7 +2496,8 @@ test("fixHooks extensions", function() {
// Trigger a native click and ensure the property is set // Trigger a native click and ensure the property is set
$fixture.bind( "click", function( event ) { $fixture.bind( "click", function( event ) {
equals( event.blurrinessLevel, 42, "event.blurrinessLevel was set" ); equals( event.blurrinessLevel, 42, "event.blurrinessLevel was set" );
})[0].click(); });
fireNative( $fixture[0], 'click' );
delete jQuery.event.fixHooks.click; delete jQuery.event.fixHooks.click;
$fixture.unbind( "click" ).remove(); $fixture.unbind( "click" ).remove();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment