From 66fc726321fc62941ae6cc8d1d6da99aa7775643 Mon Sep 17 00:00:00 2001 From: John Bender Date: Mon, 20 Jun 2011 13:21:02 -0700 Subject: [PATCH 1/2] whitespace fix for event core tests --- tests/unit/event/event_core.js | 39 ++++++++++++++++------------------ 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/tests/unit/event/event_core.js b/tests/unit/event/event_core.js index cf31e4bb..256a63fa 100644 --- a/tests/unit/event/event_core.js +++ b/tests/unit/event/event_core.js @@ -69,8 +69,6 @@ $('#qunit-fixture').touchstart(); stop(); }); - - test( "defining event functions sets the attrFn to true", function(){ $.each(events, function(i, name){ @@ -380,9 +378,9 @@ returnValue: undefined //NOTE result of unbind function call }); }); - + /* The following 4 tests are async so that the throttled event triggers don't interfere with subsequent tests */ - + asyncTest( "throttledresize event proxies resize events", function(){ var called = false; $(window).bind( "throttledresize", function(){ @@ -390,12 +388,12 @@ }); $(window).trigger("resize"); - + setTimeout(function(){ ok( called ); $(window).unbind( "throttledresize" ); setTimeout(start, 500); - }, 500); + }, 500); }); asyncTest( "throttledresize event prevents resize events from firing more frequently than 250ms", function(){ @@ -405,17 +403,17 @@ }); $(window).trigger( "resize" ).trigger( "resize" ); - + setTimeout(function(){ ok( called == 1 ); $(window).unbind( "throttledresize" ); setTimeout(start, 500); - }, 100); + }, 100); }); - + asyncTest( "throttledresize event promises that a held call will execute after trottled timeout", function(){ - var called = 0; - + var called = 0; + $(window).bind( "throttledresize", function(){ called ++; }); @@ -424,24 +422,23 @@ setTimeout(function(){ ok( called == 2 ); $(window).unbind( "throttledresize" ); - setTimeout(start, 500); - }, 500); - }); - + setTimeout(start, 500); + }, 500); + }); + asyncTest( "throttledresize event promises that a held call will execute only once after trottled timeout", function(){ - var called = 0; - + var called = 0; + $(window).bind( "throttledresize", function(){ called ++; }); $(window).trigger( "resize" ).trigger( "resize" ).trigger( "resize" ); - + setTimeout(function(){ ok( called == 2 ); $(window).unbind( "throttledresize" ); - setTimeout(start, 500); - }, 500); + setTimeout(start, 500); + }, 500); }); - })(jQuery); From 7451a4b30e877826c2541d678be0a57795d11283 Mon Sep 17 00:00:00 2001 From: John Bender Date: Mon, 20 Jun 2011 22:26:14 -0700 Subject: [PATCH 2/2] event test fixes with one test removal. still _very_ time sensitive --- tests/jquery.testHelper.js | 3 ++ tests/unit/event/event_core.js | 77 ++++++++++++++++++---------------- tests/unit/event/index.html | 5 +++ 3 files changed, 48 insertions(+), 37 deletions(-) diff --git a/tests/jquery.testHelper.js b/tests/jquery.testHelper.js index 5bd1c0d9..384d7efb 100644 --- a/tests/jquery.testHelper.js +++ b/tests/jquery.testHelper.js @@ -75,6 +75,8 @@ }); }, + // TODO move to eventSequence and invoke pageSequence with default of + // changepage event pageSequence: function(fns, event){ var fn = fns.shift(), self = this; @@ -94,6 +96,7 @@ clearTimeout(warnTimer); // Let the current stack unwind before we fire off the next item in the sequence. + // TODO setTimeout(self.pageSequence, 0, [fns, event]); setTimeout(function(){ self.pageSequence(fns, event); }, 0); }); diff --git a/tests/unit/event/event_core.js b/tests/unit/event/event_core.js index 256a63fa..9958023b 100644 --- a/tests/unit/event/event_core.js +++ b/tests/unit/event/event_core.js @@ -28,6 +28,8 @@ Math.abs = absFn; $.Event.prototype.originalEvent = originalEventFn; $.Event.prototype.preventDefault = preventDefaultFn; + + $(window).unbind( "throttledresize" ); } }); @@ -387,58 +389,59 @@ called = true; }); - $(window).trigger("resize"); - - setTimeout(function(){ - ok( called ); - $(window).unbind( "throttledresize" ); - setTimeout(start, 500); - }, 500); + $.testHelper.sequence([ + function(){ $(window).trigger( "resize" ); }, + function(){ ok( called ); }, + function(){ + start(); + } + ], 200); }); asyncTest( "throttledresize event prevents resize events from firing more frequently than 250ms", function(){ var called = 0; + $(window).bind( "throttledresize", function(){ - called ++; + called++; }); - $(window).trigger( "resize" ).trigger( "resize" ); + // NOTE 250 ms * 3 = 750ms which is plenty of time + // for the events to trigger before the next test, but + // not so much time that the second resize will be triggered + // before the call to same() is made + $.testHelper.sequence([ + function(){ + $(window).trigger( "resize" ).trigger( "resize" ); + }, - setTimeout(function(){ - ok( called == 1 ); - $(window).unbind( "throttledresize" ); - setTimeout(start, 500); - }, 100); + // verify that only one throttled resize was called after 250ms + function(){ same( called, 1 ); }, + + function(){ + start(); + } + ], 250); }); - asyncTest( "throttledresize event promises that a held call will execute after trottled timeout", function(){ + asyncTest( "throttledresize event promises that a held call will execute only once after throttled timeout", function(){ var called = 0; $(window).bind( "throttledresize", function(){ - called ++; + called++; }); - $(window).trigger( "resize" ).trigger( "resize" ); - setTimeout(function(){ - ok( called == 2 ); - $(window).unbind( "throttledresize" ); - setTimeout(start, 500); - }, 500); - }); + $.testHelper.sequence([ + // trigger a ton of throttledresize events + function(){ + $(window).trigger( "resize" ).trigger( "resize" ).trigger( "resize" ); + }, - asyncTest( "throttledresize event promises that a held call will execute only once after trottled timeout", function(){ - var called = 0; - - $(window).bind( "throttledresize", function(){ - called ++; - }); - - $(window).trigger( "resize" ).trigger( "resize" ).trigger( "resize" ); - - setTimeout(function(){ - ok( called == 2 ); - $(window).unbind( "throttledresize" ); - setTimeout(start, 500); - }, 500); + // verify that after enough time has gone by to accomodate all of them + // ie 750ms, only to calls to the bound function were made + function(){ + same( called, 2 ); + start(); + } + ], 750); }); })(jQuery); diff --git a/tests/unit/event/index.html b/tests/unit/event/index.html index 29568c0e..f582a6c1 100644 --- a/tests/unit/event/index.html +++ b/tests/unit/event/index.html @@ -6,6 +6,7 @@ jQuery Mobile Event Test Suite + @@ -26,5 +27,9 @@
+
+ +
+