X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=test%2Funit%2Fevent.js;h=d5d6790d4450a7c1ac14240d3a0861358067d3a3;hb=007e2d152e10a8feffa347b5f328d2cb4bd45327;hp=a647e5f3bff07fa7cd0953e888aa13b5606d3690;hpb=89b771daefcd0cc6a31b7285b06cbc4e5ecede57;p=jquery.git diff --git a/test/unit/event.js b/test/unit/event.js index a647e5f..d5d6790 100644 --- a/test/unit/event.js +++ b/test/unit/event.js @@ -295,6 +295,48 @@ test("live/delegate immediate propagation", function() { $p.undelegate( "click" ); }); +test("bind/delegate bubbling, isDefaultPrevented", function() { + expect(2); + var $anchor2 = jQuery( "#anchor2" ), + $main = jQuery( "#main" ), + fakeClick = function($jq) { + // Use a native click so we don't get jQuery simulated bubbling + if ( document.createEvent ) { + var e = document.createEvent( 'MouseEvents' ); + e.initEvent( "click", true, true ); + $jq[0].dispatchEvent(e); + } + else if ( $jq[0].click ) { + $jq[0].click(); // IE + } + }; + $anchor2.click(function(e) { + e.preventDefault(); + }); + $main.delegate("#foo", "click", function(e) { + var orig = e.originalEvent; + if ( typeof(orig.defaultPrevented) === "boolean" || typeof(orig.returnValue) === "boolean" || orig.getPreventDefault ) { + equals( e.isDefaultPrevented(), true, "isDefaultPrevented true passed to bubbled event" ); + } + else { + // Opera < 11 doesn't implement any interface we can use, so give it a pass + ok( true, "isDefaultPrevented not supported by this browser, test skipped" ); + } + }); + fakeClick( $anchor2 ); + $anchor2.unbind( "click" ); + $main.undelegate( "click" ); + $anchor2.click(function(e) { + // Let the default action occur + }); + $main.delegate("#foo", "click", function(e) { + equals( e.isDefaultPrevented(), false, "isDefaultPrevented false passed to bubbled event" ); + }); + fakeClick( $anchor2 ); + $anchor2.unbind( "click" ); + $main.undelegate( "click" ); +}); + test("bind(), iframes", function() { // events don't work with iframes, see #939 - this test fails in IE because of contentDocument var doc = jQuery("#loadediframe").contents();