Publish Vulpes Preview 15 sources for desktop, Android and Tundra
Share Gaia assets and adapters, keep private profiles and development documents local, and update both public READMEs.
This commit is contained in:
parent
93e3a48004
commit
b38dea0597
25901 changed files with 9982925 additions and 369 deletions
201
gaia/apps/clock/test/unit/timer_test.js
Executable file
201
gaia/apps/clock/test/unit/timer_test.js
Executable file
|
|
@ -0,0 +1,201 @@
|
|||
'use strict';
|
||||
suite('Timer', function() {
|
||||
|
||||
/**** TEST DISABLED for intermittent failure; see bug 1153495.
|
||||
|
||||
var Timer;
|
||||
var now, duration;
|
||||
|
||||
suiteSetup(function(done) {
|
||||
require(['timer'], function(timer) {
|
||||
Timer = timer;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
setup(function() {
|
||||
now = Date.now();
|
||||
duration = 5000;
|
||||
this.clock = this.sinon.useFakeTimers(Date.now());
|
||||
});
|
||||
|
||||
test('shape:static ', function() {
|
||||
assert.equal(Timer.INITIAL, 0);
|
||||
assert.equal(Timer.STARTED, 1);
|
||||
assert.equal(Timer.PAUSED, 2);
|
||||
});
|
||||
|
||||
function getTimer() {
|
||||
return new Timer({
|
||||
configuredDuration: duration
|
||||
});
|
||||
}
|
||||
|
||||
test('start new timer ', function() {
|
||||
var timer = getTimer();
|
||||
timer.start();
|
||||
this.clock.tick(200);
|
||||
assert.equal(timer.state, Timer.STARTED);
|
||||
assert.equal(timer.remaining, duration - 200);
|
||||
});
|
||||
|
||||
test('reactivate an un-paused timer ', function() {
|
||||
var timer = getTimer();
|
||||
|
||||
timer.start();
|
||||
this.clock.tick(200);
|
||||
|
||||
timer.start();
|
||||
this.clock.tick(200);
|
||||
timer.start();
|
||||
|
||||
assert.equal(timer.state, Timer.STARTED);
|
||||
assert.equal(timer.remaining, duration - 400);
|
||||
});
|
||||
|
||||
test('pause timer', function() {
|
||||
var timer = getTimer();
|
||||
|
||||
timer.start();
|
||||
this.clock.tick(200);
|
||||
|
||||
timer.pause();
|
||||
assert.equal(timer.state, Timer.PAUSED);
|
||||
});
|
||||
|
||||
test('reactivate a paused timer ', function() {
|
||||
var timer = getTimer();
|
||||
|
||||
timer.start();
|
||||
this.clock.tick(200);
|
||||
|
||||
timer.pause();
|
||||
assert.equal(timer.state, Timer.PAUSED);
|
||||
|
||||
this.clock.tick(200);
|
||||
timer.start();
|
||||
|
||||
assert.equal(timer.state, Timer.STARTED);
|
||||
assert.equal(timer.remaining, duration - 200);
|
||||
});
|
||||
|
||||
|
||||
test('cancel ', function() {
|
||||
var timer = getTimer();
|
||||
|
||||
timer.start();
|
||||
this.clock.tick(200);
|
||||
|
||||
timer.cancel();
|
||||
assert.equal(timer.state, Timer.INITIAL);
|
||||
});
|
||||
|
||||
test('plus ', function() {
|
||||
var timer = getTimer();
|
||||
var originalDuration = timer.duration;
|
||||
|
||||
timer.plus(60);
|
||||
|
||||
assert.equal(timer.duration, originalDuration + (60 * 1000));
|
||||
});
|
||||
|
||||
suite('commit', function() {
|
||||
setup(function() {
|
||||
this.addSpy = this.sinon.spy(navigator.mozAlarms, 'add');
|
||||
this.removeSpy = this.sinon.spy(navigator.mozAlarms, 'remove');
|
||||
this.timer = getTimer();
|
||||
});
|
||||
suite('timers without alarms', function() {
|
||||
test('when in initial state', function(done) {
|
||||
this.timer.commit(function() {
|
||||
assert.equal(
|
||||
this.addSpy.callCount, 0, 'does not create a new alarm'
|
||||
);
|
||||
assert.equal(this.removeSpy.callCount, 0, 'does not remove alarm');
|
||||
done();
|
||||
}.bind(this));
|
||||
this.clock.tick(10);
|
||||
});
|
||||
test('when started', function(done) {
|
||||
this.timer.start();
|
||||
this.timer.commit(function() {
|
||||
assert.equal(this.addSpy.callCount, 1, 'creates a new alarm');
|
||||
assert.equal(this.removeSpy.callCount, 0, 'does not remove alarm');
|
||||
done();
|
||||
}.bind(this));
|
||||
this.clock.tick(10);
|
||||
});
|
||||
});
|
||||
|
||||
suite('timers with previously-created alarms', function() {
|
||||
setup(function(done) {
|
||||
// Ensure that the timer is in a saved state and the spies are reset
|
||||
this.timer.start();
|
||||
this.timer.commit(function() {
|
||||
this.addSpy.reset();
|
||||
this.removeSpy.reset();
|
||||
this.origTimerId = this.timer.id;
|
||||
|
||||
// Return timer to initial state
|
||||
this.timer.cancel();
|
||||
|
||||
done();
|
||||
}.bind(this));
|
||||
this.clock.tick(10);
|
||||
});
|
||||
|
||||
test('when in initial state', function(done) {
|
||||
this.timer.commit(function() {
|
||||
assert.equal(
|
||||
this.addSpy.callCount, 0, 'does not create a new alarm'
|
||||
);
|
||||
assert.equal(
|
||||
this.removeSpy.args[0][0], this.origTimerId, 'removes old alarm'
|
||||
);
|
||||
done();
|
||||
}.bind(this));
|
||||
this.clock.tick(10);
|
||||
});
|
||||
test('when started', function(done) {
|
||||
this.timer.start();
|
||||
this.timer.commit(function() {
|
||||
assert.equal(
|
||||
this.addSpy.callCount, 1, 'creates a new alarm'
|
||||
);
|
||||
assert.equal(
|
||||
this.removeSpy.args[0][0], this.origTimerId, 'removes old alarm'
|
||||
);
|
||||
done();
|
||||
}.bind(this));
|
||||
this.clock.tick(10);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
suite('Timer.remaining ', function() {
|
||||
test('Initial time', function() {
|
||||
var timer = getTimer();
|
||||
timer.configuredDuration = 7200;
|
||||
assert.equal(timer.remaining, 7200,
|
||||
'Expected remaining time to equal configured time.');
|
||||
});
|
||||
test('Paused time', function() {
|
||||
var timer = getTimer();
|
||||
timer.start();
|
||||
this.clock.tick(200);
|
||||
timer.pause();
|
||||
this.clock.tick(200);
|
||||
assert.equal(timer.remaining, 4800,
|
||||
'Expected paused time to be 4.8 seconds');
|
||||
});
|
||||
test('Started time', function() {
|
||||
var timer = getTimer();
|
||||
timer.start();
|
||||
this.clock.tick(300);
|
||||
assert.equal(timer.remaining, 4700,
|
||||
'Expected started time to be 4.7 seconds');
|
||||
});
|
||||
});
|
||||
|
||||
*/
|
||||
});
|
||||
Loading…
Reference in a new issue