Sha256: e9e51b598352c3038caf8924b6c694c6cd448459a991246c2df15f8012704345

Contents?: true

Size: 1.96 KB

Versions: 40

Compression:

Stored size: 1.96 KB

Contents

// ========================================================================
// SC.Timer.isPaused Tests
// ========================================================================
/*globals module test ok isObj equals expects */

module("Timer.isPaused") ;

test("setting isPaused should stop firing", function() {
  
  var firedCount = 0, f1, f2, f3 ;
  
  SC.RunLoop.begin() ;
  var start = SC.RunLoop.currentRunLoop.get('startTime') ;
  var t = SC.Timer.schedule({
    target: this,
    action: function() { firedCount++ ; },
    interval: 100,
    repeats: YES
  });
  SC.RunLoop.end() ;
  
  // wait for timer to fire twice, then pause it.
  var tries1 = 10 ;
  f1 = function f1() {
    if(firedCount<2) {
      if (--tries1 >= 0) {
        setTimeout(f1, 100) ;
      } else {
        equals(NO, YES, 'Timer never fired 2 times - f1') ;
        window.start() ; // starts the test runner
      }
    } else {
      equals(NO, t.get('isPaused'), 'should start with isPaused = NO');
      t.set('isPaused', YES) ;
      firedCount = 0 ; // Reset count here.
      setTimeout(f2, 300) ;
    }
  };
  
  // once timer paused, make sure it did not fire again.
  f2 = function f2() {
    equals(0, firedCount, 'timer kept firing!') ;
    equals(YES, t.get('isPaused'), 'timer is not paused') ;
    t.set('isPaused', NO) ;
    setTimeout(f3, 300) ;
  } ;
  
  // once timer has verified paused, unpause and make sure it fires again.
  var tries2 = 10 ;
  f3 = function f3() {
    if (firedCount <= 2) {
      if (--tries2 >= 0) {
        setTimeout(f3, 100) ;
      } else {
        equals(NO, YES, "Timer did not resume") ;
        window.start() ; // starts the test runner
      }
      
    // timer fired, clean up.
    } else {
      t.invalidate() ;
      equals(NO, t.get('isPaused'), 'timer did not unpause') ;
      window.start() ; // starts the test runner
    }
  };
  
  stop() ; // stops the test runner
  setTimeout(f1, 300) ;
});

// using invalidate on a repeating timer is tested in schedule().

Version data entries

40 entries across 40 versions & 2 rubygems

Version Path
spade-0.0.1 sproutcore/frameworks/core_foundation/tests/system/timer/isPaused.js
sproutcore-1.5.0.pre.5 lib/frameworks/sproutcore/frameworks/core_foundation/tests/system/timer/isPaused.js
sproutcore-1.5.0.pre.4.1 lib/frameworks/sproutcore/frameworks/core_foundation/tests/system/timer/isPaused.js
sproutcore-1.5.0.pre.4 lib/frameworks/sproutcore/frameworks/core_foundation/tests/system/timer/isPaused.js
sproutcore-1.5.0.pre.3 lib/frameworks/sproutcore/frameworks/amber/tests/system/timer/isPaused.js
sproutcore-1.4.5 lib/frameworks/sproutcore/frameworks/foundation/tests/system/timer/isPaused.js
sproutcore-1.4.5-java lib/frameworks/sproutcore/frameworks/foundation/tests/system/timer/isPaused.js
sproutcore-1.4.4-java lib/frameworks/sproutcore/frameworks/foundation/tests/system/timer/isPaused.js
sproutcore-1.4.4 lib/frameworks/sproutcore/frameworks/foundation/tests/system/timer/isPaused.js
sproutcore-1.4.3.1 lib/frameworks/sproutcore/frameworks/foundation/tests/system/timer/isPaused.js
sproutcore-1.4.3-java lib/frameworks/sproutcore/frameworks/foundation/tests/system/timer/isPaused.js
sproutcore-1.4.3 lib/frameworks/sproutcore/frameworks/foundation/tests/system/timer/isPaused.js
sproutcore-1.4.2-java lib/frameworks/sproutcore/frameworks/foundation/tests/system/timer/isPaused.js
sproutcore-1.4.2 lib/frameworks/sproutcore/frameworks/foundation/tests/system/timer/isPaused.js
sproutcore-1.4.1-java lib/frameworks/sproutcore/frameworks/foundation/tests/system/timer/isPaused.js
sproutcore-1.4.1 lib/frameworks/sproutcore/frameworks/foundation/tests/system/timer/isPaused.js
sproutcore-1.4.0-java lib/frameworks/sproutcore/frameworks/foundation/tests/system/timer/isPaused.js
sproutcore-1.4.0 lib/frameworks/sproutcore/frameworks/foundation/tests/system/timer/isPaused.js
sproutcore-1.4.0.rc.5 lib/frameworks/sproutcore/frameworks/foundation/tests/system/timer/isPaused.js
sproutcore-1.4.0.rc.4 lib/frameworks/sproutcore/frameworks/foundation/tests/system/timer/isPaused.js