Sha256: 1d6212f52012b7753e539b754a3df69001cabdffc502e0dde9721b32bb04ce01

Contents?: true

Size: 1.96 KB

Versions: 13

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 ;
  
  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 ;
  var 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.
  var 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 ;
  var 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

13 entries across 13 versions & 2 rubygems

Version Path
sproutit-sproutcore-1.0.0.20090408130025 frameworks/sproutcore/frameworks/foundation/tests/system/timer/isPaused.js
sproutit-sproutcore-1.0.0.20090416161445 frameworks/sproutcore/frameworks/foundation/tests/system/timer/isPaused.js
sproutit-sproutcore-1.0.0.20090720093355 frameworks/sproutcore/frameworks/foundation/tests/system/timer/isPaused.js
sproutit-sproutcore-1.0.0.20090720202429 frameworks/sproutcore/frameworks/foundation/tests/system/timer/isPaused.js
sproutit-sproutcore-1.0.0.20090721125122 frameworks/sproutcore/frameworks/foundation/tests/system/timer/isPaused.js
sproutit-sproutcore-1.0.126 frameworks/sproutcore/frameworks/foundation/tests/system/timer/isPaused.js
sproutit-sproutcore-1.0.20090721145251 frameworks/sproutcore/frameworks/foundation/tests/system/timer/isPaused.js
sproutit-sproutcore-1.0.20090721145280 frameworks/sproutcore/frameworks/foundation/tests/system/timer/isPaused.js
sproutit-sproutcore-1.0.20090721145281 frameworks/sproutcore/frameworks/foundation/tests/system/timer/isPaused.js
sproutit-sproutcore-1.0.20090721145282 frameworks/sproutcore/frameworks/foundation/tests/system/timer/isPaused.js
sproutit-sproutcore-1.0.20090721145285 frameworks/sproutcore/frameworks/foundation/tests/system/timer/isPaused.js
sproutit-sproutcore-1.0.203 frameworks/sproutcore/frameworks/foundation/tests/system/timer/isPaused.js
sproutcore-1.0.1003 frameworks/sproutcore/frameworks/foundation/tests/system/timer/isPaused.js