diff options
Diffstat (limited to 'testing/web-platform/mozilla/tests/workers')
5 files changed, 200 insertions, 0 deletions
diff --git a/testing/web-platform/mozilla/tests/workers/2-mib-file.py b/testing/web-platform/mozilla/tests/workers/2-mib-file.py new file mode 100644 index 0000000000..cfb563ff21 --- /dev/null +++ b/testing/web-platform/mozilla/tests/workers/2-mib-file.py @@ -0,0 +1,7 @@ +import random +import string + + +def main(request, response): + r = "".join(random.choice(string.ascii_letters) for _ in range(2 * 1024 * 1024)) + return r diff --git a/testing/web-platform/mozilla/tests/workers/bug1674278-crash.html b/testing/web-platform/mozilla/tests/workers/bug1674278-crash.html new file mode 100644 index 0000000000..2b037e5b37 --- /dev/null +++ b/testing/web-platform/mozilla/tests/workers/bug1674278-crash.html @@ -0,0 +1,6 @@ +<html class='test-wait'> +<script> +var worker = new Worker('bug1674278.js'); +worker.postMessage('', []); +</script> +</html> diff --git a/testing/web-platform/mozilla/tests/workers/bug1674278.js b/testing/web-platform/mozilla/tests/workers/bug1674278.js new file mode 100644 index 0000000000..56105cb76e --- /dev/null +++ b/testing/web-platform/mozilla/tests/workers/bug1674278.js @@ -0,0 +1,6 @@ +self.onmessage = async function(e) { + var a = await self.fetch('2-mib-file.py'); + var b = await a.blob(); + self.close() + await b.arrayBuffer(); +} diff --git a/testing/web-platform/mozilla/tests/workers/resources/worker.js b/testing/web-platform/mozilla/tests/workers/resources/worker.js new file mode 100644 index 0000000000..cc1692eb9c --- /dev/null +++ b/testing/web-platform/mozilla/tests/workers/resources/worker.js @@ -0,0 +1,129 @@ +const maxNestingLevel = 5; +let expectedNestingLevel = 1; +let timer; +let isInterval = false; +let testStage = "ScriptLoaded"; +let stopIncreaseExpectedLevel = false; +let startClampedTimeStamp = 0; +let startRepeatingClamped = false; +let repeatCount = 0; +let maxRepeatTimes = 10; + +let timerCallback = async () => { + let now = Date.now(); + if (WorkerTestUtils.currentTimerNestingLevel() !== expectedNestingLevel) { + postMessage({ + stage: testStage, + status: "FAIL", + msg: `current timer nesting level is ${WorkerTestUtils.currentTimerNestingLevel()}, expected ${expectedNestingLevel}`, + }); + if (isInterval) { + clearInterval(timer); + } + return; + } + + if (!stopIncreaseExpectedLevel) { + if (expectedNestingLevel === maxNestingLevel) { + stopIncreaseExpectedLevel = true; + startClampedTimeStamp = now; + } else { + expectedNestingLevel = expectedNestingLevel + 1; + } + if (!isInterval) { + setTimeout(timerCallback, 0); + } + return; + } + + // This is the first time the timeout is clamped, checking if it is clamped + // to at least 2ms. + if (repeatCount === 0) { + await Promise.resolve(true).then(() => { + if (WorkerTestUtils.currentTimerNestingLevel() !== expectedNestingLevel) { + postMessage({ + stage: testStage, + status: "FAIL", + msg: `Timer nesting level should be in effect for immediately resolved micro-tasks`, + }); + } + }); + if (now - startClampedTimeStamp < 2 ) { + startRepeatingClamped = true; + } else { + postMessage({ stage: testStage, status: "PASS", msg: "" }); + } + } + + // If the first clamped timeout is less than 2ms, start to repeat the clamped + // timeout for 10 times. Then checking if total clamped time should be at least + // 25ms. + if (startRepeatingClamped) { + if (repeatCount === 10) { + if (now - startClampedTimeStamp < 25) { + postMessage({ + stage: testStage, + status: "FAIL", + msg: `total clamped time of repeating ten times should be at least 25ms(${now - startClampedTimeStamp})`, + }); + } else { + postMessage({ stage: testStage, status: "PASS", msg: "" }); + } + } else { + repeatCount = repeatCount + 1; + if (!isInterval) { + setTimeout(timerCallback, 0); + } + return; + } + } + + // reset testing variables + repeatCount = 0; + startRepeatingClamped = false; + stopIncreaseExpectedLevel = false; + if (isInterval) { + clearInterval(timer); + } +}; + +onmessage = async e => { + testStage = e.data; + switch (e.data) { + case "CheckInitialValue": + if (WorkerTestUtils.currentTimerNestingLevel() === 0) { + postMessage({ stage: testStage, status: "PASS", msg: "" }); + } else { + postMessage({ + stage: testStage, + status: "FAIL", + msg: `current timer nesting level should be 0(${WorkerTestUtils.currentTimerNestingLevel()}) after top level script loaded.`, + }); + } + break; + case "TestSetInterval": + expectedNestingLevel = 1; + isInterval = true; + timer = setInterval(timerCallback, 0); + break; + case "TestSetTimeout": + expectedNestingLevel = 1; + isInterval = false; + setTimeout(timerCallback, 0); + break; + case "CheckNoTimer": + if (WorkerTestUtils.currentTimerNestingLevel() === 0) { + postMessage({ stage: testStage, status: "PASS", msg: "" }); + } else { + postMessage({ + stage: testStage, + status: "FAIL", + msg: `current timer nesting level should be 0(${WorkerTestUtils.currentTimerNestingLevel()}) when there is no timer in queue.`, + }); + } + + break; + } +}; + +postMessage({ stage: testStage, status: "PASS" }); diff --git a/testing/web-platform/mozilla/tests/workers/worker_timer_nesting_level.html b/testing/web-platform/mozilla/tests/workers/worker_timer_nesting_level.html new file mode 100644 index 0000000000..e39f9e1b0e --- /dev/null +++ b/testing/web-platform/mozilla/tests/workers/worker_timer_nesting_level.html @@ -0,0 +1,52 @@ +<!DOCTYPE html> +<title>Worker: Timer Nesting Level</title> +<Script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script> +'use strict' + +/** + * This test includes following four test stages. + * 1. CheckInitialValue: Checking the initial value of worker's current timer + * nesting level after the worker's top level script is loaded. The result + * is expected as 0. + * 2. TestSetInterval: Checking the worker's current timer nesting level with + * setInterval with following steps + * 1. call setInterval(callback, 0) to create a repeating timer. + * 2. checking the current timer nesting level in the callback. The value + * should increase every time executing the callback until it reaches the + * maximun nesting level(5). + * 3. Checking the worker's current timer nesting level with immediately + * resolved promise. + * 4. Checking the the time duration between two callback launching. + * 3. TestSetTimeout: Checking the worker's current timer nesting level with + * setTimeout. This stage has similar test steps with TestSetInterval. + * The difference is this stage using the recursive setTimeout to accumulate + * the timer nesting level. + * 4. CheckNoTimer: Checking the situation which the worker has no pending + * timer. The result is expected as 0. + */ + +let testStages = ["CheckInitialValue", + "TestSetInterval", + "TestSetTimeout", + "CheckNoTimer"]; + +promise_test(async function(t) { + let result = await new Promise( (resolve, reject) => { + let worker = new Worker("resources/worker.js"); + worker.onmessage = (e) => { + if (e.data.status === "FAIL") { + resolve(e.data); + return; + } + if (testStages.length !== 0) { + worker.postMessage(testStages.shift()); + } else { + resolve({status: "PASS", msg: "Timer nesting level for workers"}); + } + }; + }); + assert_true(result.status === "PASS", result.msg); +}, 'Worker timer nesting level'); +</script> |