Bug 1935611 - Fix libyuv/libpng link failed for loongarch64. r=glandium,tnikkel,ng
[gecko.git] / dom / webgpu / mochitest / test_device_lost.html
blobb0b45b4c7cdbbb847170d19f10cef1cde5137f6e
1 <!doctype html>
2 <html>
3 <head>
4 <meta charset="utf-8" />
5 <script src="/tests/SimpleTest/SimpleTest.js"></script>
6 <link rel="stylesheet" href="/tests/SimpleTest/test.css" />
7 </head>
8 <body>
9 <script>
10 ok(
11 SpecialPowers.getBoolPref("dom.webgpu.enabled"),
12 "Pref should be enabled."
15 const destroy_causes_lost = async function () {
16 const adapter = await navigator.gpu.requestAdapter();
17 ok(adapter !== undefined, "adapter !== undefined");
18 const device = await adapter.requestDevice();
19 ok(device !== undefined, "device !== undefined");
21 const lostPromise = device.lost;
22 device.destroy();
23 const deviceLostReason = await lostPromise;
25 is(
26 deviceLostReason.reason,
27 "destroyed",
28 "Destroy reason should correspond to GPUDeviceLostReason.destroyed"
30 is(deviceLostReason.message, "", "Destroy message should be blank");
33 const drop_causes_lost_is_unobservable = async function () {
34 const adapter = await navigator.gpu.requestAdapter();
35 ok(adapter !== undefined, "adapter !== undefined");
37 let lostPromise;
38 // Create a scope with a device that will go out of scope
39 // and then be dropped.
41 const device = await adapter.requestDevice();
42 ok(device !== undefined, "device !== undefined");
44 lostPromise = device.lost;
47 SimpleTest.requestFlakyTimeout(
48 "Racing against promise that should never resolve."
50 const TIMEOUT_MS = 5000;
51 let timeoutPromise = new Promise(resolve => {
52 let timeoutValue = { reason: "timeout", message: "" };
53 // eslint-disable-next-line mozilla/no-arbitrary-setTimeout
54 setTimeout(() => resolve(timeoutValue), TIMEOUT_MS);
55 });
57 const firstPromise = await Promise.race([lostPromise, timeoutPromise]);
58 is(
59 firstPromise.reason,
60 "timeout",
61 "timeoutPromise should return before lostPromise."
63 // Check the message so we output some indication of what incorrectly
64 // resolved the lost promise.
65 is(firstPromise.message, "", "the message should be blank.");
68 SimpleTest.waitForExplicitFinish();
70 destroy_causes_lost()
71 .then(() => drop_causes_lost_is_unobservable())
72 .catch(e => ok(false, `Unhandled exception ${e}`))
73 .finally(() => SimpleTest.finish());
74 </script>
75 </body>
76 </html>