4 <meta charset=
"utf-8" />
5 <script src=
"/tests/SimpleTest/SimpleTest.js"></script>
6 <link rel=
"stylesheet" href=
"/tests/SimpleTest/test.css" />
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
;
23 const deviceLostReason
= await lostPromise
;
26 deviceLostReason
.reason
,
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");
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
);
57 const firstPromise
= await Promise
.race([lostPromise
, timeoutPromise
]);
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();
71 .then(() => drop_causes_lost_is_unobservable())
72 .catch(e
=> ok(false, `Unhandled exception ${e}`))
73 .finally(() => SimpleTest
.finish());