Skip to content
This repository has been archived by the owner on Feb 26, 2022. It is now read-only.

Commit

Permalink
Bug 1116534 - sdk/timers module needs gc tests
Browse files Browse the repository at this point in the history
  • Loading branch information
erikvold committed Dec 30, 2014
1 parent 12391f8 commit d358ed1
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions test/test-timer.js
@@ -1,9 +1,12 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";

var timer = require("sdk/timers");
const { Loader } = require("sdk/test/loader");
const { gc } = require("sdk/test/memory");
const { all, defer } = require("sdk/core/promise");

exports.testSetTimeout = function(assert, end) {
timer.setTimeout(function() {
Expand All @@ -12,6 +15,19 @@ exports.testSetTimeout = function(assert, end) {
}, 1);
};

exports.testSetTimeoutGC = function*(assert) {
let called = defer();
let gcDone = defer();

timer.setTimeout(called.resolve, 300);
gc().then(gcDone.resolve);

yield called.promise;
yield gcDone.promise;

assert.pass("setTimeout passed!");
};

exports.testParamedSetTimeout = function(assert, end) {
let params = [1, 'foo', { bar: 'test' }, null, undefined];
timer.setTimeout.apply(null, [function() {
Expand Down Expand Up @@ -61,6 +77,42 @@ exports.testSetInterval = function (assert, end) {
}, 1);
};

exports.testSetIntervalGC = function*(assert) {
let called = defer();
let gcDone = defer();
let done = false;
let count = 0;

let id = timer.setInterval(() => {
assert.pass("call count is " + count);

if (done) {
timer.clearInterval(id);
called.resolve();
return null;
}

if (count++ == 0) {
assert.pass("first call to setInterval worked!");

gc().then(() => {
assert.pass("gc is complete!");
done = true;
gcDone.resolve();
});

assert.pass("called gc()!");
}

return null;
}, 1);

yield gcDone.promise;
yield called.promise;

assert.pass("setInterval was called after the gc!");
};

exports.testParamedSetInerval = function(assert, end) {
let params = [1, 'foo', { bar: 'test' }, null, undefined];
let count = 0;
Expand Down

0 comments on commit d358ed1

Please sign in to comment.