Files
palemoon27/toolkit/modules/tests/xpcshell/test_timer.js
T
roytam1 dd3d18022d import changes from `dev' branch of rmottola/Arctic-Fox:
- include limits for  numeric_limits in gcc 11 (e46f1407b)
- Bug 1201057 - Move AutoEnterOOMUnsafeRegion to Utility.h with the other OOM simulation infrastructure r=terrence (ba11ded16)
- Bug 1189490 - Part 0: Add a FIFO queue container type to js/public. r=terrence (97bd6e58d)
- Bug 1189490 - Part 1: Add a JS::Traceable version of the FIFO queue for use with GC things. r=terrence (0e397ee31)
- Bug 1144797 - Add setInterval and clearInterval to Timer.jsm. r=smacleod. (8aee45f35)
- Bug 1182316: Part 3 - Add assertions to most other WebIDL entry points, clean up nsIDOMJSWindow cruft. r=peterv (d2af349b5)
- Bug 1181762. Remove uses of mozRequestAnimationFrame from toolkit code. r=gijs (c5d4fe108)
- Bug 1181765. Remove uses of mozRequestAnimationFrame from layout tests. r=bkelly (bd0b1300b)
- Bug 1181966. Remove uses of mozRequestAnimationFrame from browser code. r=gijs,paul (64ce1b945)
- Bug 909154. Remove the prefixed mozRequestAnimationFrame and its accoutrements. r=bkelly (0257521ce)
- Bug 1185028. Fix GCJsonifierMethod to correctly handle worker descriptors. r=nsm (32c80ced6)
- Bug 1181678 - Expose an attribute on DOMWindowUtils to see if APZ is enabled. r=botond (842c775c7)
2021-07-13 16:16:10 +08:00

58 lines
1.9 KiB
JavaScript

/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
// Tests exports from Timer.jsm
let imported = {};
Components.utils.import("resource://gre/modules/Timer.jsm", imported);
function run_test() {
run_next_test();
}
add_task(function* test_setTimeout() {
let timeout1 = imported.setTimeout(() => do_throw("Should not be called"), 100);
do_check_eq(typeof timeout1, "number", "setTimeout returns a number");
do_check_true(timeout1 > 0, "setTimeout returns a positive number");
imported.clearTimeout(timeout1);
yield new Promise((resolve) => {
let timeout2 = imported.setTimeout((param1, param2) => {
do_check_true(true, "Should be called");
do_check_eq(param1, 5, "first parameter is correct");
do_check_eq(param2, "test", "second parameter is correct");
resolve();
}, 100, 5, "test");
do_check_eq(typeof timeout2, "number", "setTimeout returns a number");
do_check_true(timeout2 > 0, "setTimeout returns a positive number");
do_check_neq(timeout1, timeout2, "Calling setTimeout again returns a different value");
});
});
add_task(function* test_setInterval() {
let interval1 = imported.setInterval(function() do_throw("Should not be called!"), 100);
do_check_eq(typeof interval1, "number", "setInterval returns a number");
do_check_true(interval1 > 0, "setTimeout returns a positive number");
imported.clearInterval(interval1);
const EXPECTED_CALLS = 5;
let calls = 0;
yield new Promise((resolve) => {
let interval2 = imported.setInterval((param1, param2) => {
do_check_true(true, "Should be called");
do_check_eq(param1, 15, "first parameter is correct");
do_check_eq(param2, "hola", "second parameter is correct");
if (calls >= EXPECTED_CALLS) {
resolve();
}
calls++;
}, 100, 15, "hola");
});
});