michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: 'use strict' michael@0: michael@0: const { setTimeout } = require('sdk/timers'); michael@0: const { waitUntil } = require('sdk/test/utils'); michael@0: michael@0: exports.testWaitUntil = function (assert, done) { michael@0: let bool = false; michael@0: let finished = false; michael@0: waitUntil(() => { michael@0: if (finished) michael@0: assert.fail('interval should be cleared after predicate is truthy'); michael@0: return bool; michael@0: }).then(function () { michael@0: assert.ok(bool, michael@0: 'waitUntil shouldn\'t call until predicate is truthy'); michael@0: finished = true; michael@0: done(); michael@0: }); michael@0: setTimeout(() => { bool = true; }, 20); michael@0: }; michael@0: michael@0: exports.testWaitUntilInterval = function (assert, done) { michael@0: let bool = false; michael@0: let finished = false; michael@0: let counter = 0; michael@0: waitUntil(() => { michael@0: if (finished) michael@0: assert.fail('interval should be cleared after predicate is truthy'); michael@0: counter++; michael@0: return bool; michael@0: }, 50).then(function () { michael@0: assert.ok(bool, michael@0: 'waitUntil shouldn\'t call until predicate is truthy'); michael@0: assert.equal(counter, 1, michael@0: 'predicate should only be called once with a higher interval'); michael@0: finished = true; michael@0: done(); michael@0: }); michael@0: setTimeout(() => { bool = true; }, 10); michael@0: }; michael@0: michael@0: require('sdk/test').run(exports);