Debian Codegraph @

testing/web-platform/mozilla/tests/workers/worker_timer_nesting_level.html

raw
1 <!DOCTYPE html>
2 <title>Worker: Timer Nesting Level</title>
3 <Script src="/resources/testharness.js"></script>
4 <script src="/resources/testharnessreport.js"></script>
5 <script>
6 'use strict'
7
8 /**
9 * This test includes following four test stages.
10 * 1. CheckInitialValue: Checking the initial value of worker's current timer
11 * nesting level after the worker's top level script is loaded. The result
12 * is expected as 0.
13 * 2. TestSetInterval: Checking the worker's current timer nesting level with
14 * setInterval with following steps
15 * 1. call setInterval(callback, 0) to create a repeating timer.
16 * 2. checking the current timer nesting level in the callback. The value
17 * should increase every time executing the callback until it reaches the
18 * maximun nesting level(5).
19 * 3. Checking the worker's current timer nesting level with immediately
20 * resolved promise.
21 * 4. Checking the the time duration between two callback launching.
22 * 3. TestSetTimeout: Checking the worker's current timer nesting level with
23 * setTimeout. This stage has similar test steps with TestSetInterval.
24 * The difference is this stage using the recursive setTimeout to accumulate
25 * the timer nesting level.
26 * 4. CheckNoTimer: Checking the situation which the worker has no pending
27 * timer. The result is expected as 0.
28 */
29
30 let testStages = ["CheckInitialValue",
31 "TestSetInterval",
32 "TestSetTimeout",
33 "CheckNoTimer"];
34
35 promise_test(async function(t) {
36 let result = await new Promise( (resolve, reject) => {
37 let worker = new Worker("resources/worker.js");
38 worker.onmessage = (e) => {
39 if (e.data.status === "FAIL") {
40 resolve(e.data);
41 return;
42 }
43 if (testStages.length !== 0) {
44 worker.postMessage(testStages.shift());
45 } else {
46 resolve({status: "PASS", msg: "Timer nesting level for workers"});
47 }
48 };
49 });
50 assert_true(result.status === "PASS", result.msg);
51 }, 'Worker timer nesting level');
52 </script>