|
| 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." |
| 13 | + ); |
| 14 | + |
| 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"); |
| 20 | + |
| 21 | + const lostPromise = device.lost; |
| 22 | + device.destroy(); |
| 23 | + const deviceLostReason = await lostPromise; |
| 24 | + |
| 25 | + is( |
| 26 | + deviceLostReason.reason, |
| 27 | + "destroyed", |
| 28 | + "Destroy reason should correspond to GPUDeviceLostReason.destroyed" |
| 29 | + ); |
| 30 | + is(deviceLostReason.message, "", "Destroy message should be blank"); |
| 31 | + }; |
| 32 | + |
| 33 | + const drop_causes_lost_is_unobservable = async function () { |
| 34 | + const adapter = await navigator.gpu.requestAdapter(); |
| 35 | + ok(adapter !== undefined, "adapter !== undefined"); |
| 36 | + |
| 37 | + let lostPromise; |
| 38 | + // Create a scope with a device that will go out of scope |
| 39 | + // and then be dropped. |
| 40 | + { |
| 41 | + const device = await adapter.requestDevice(); |
| 42 | + ok(device !== undefined, "device !== undefined"); |
| 43 | + |
| 44 | + lostPromise = device.lost; |
| 45 | + } |
| 46 | + |
| 47 | + SimpleTest.requestFlakyTimeout( |
| 48 | + "Racing against promise that should never resolve." |
| 49 | + ); |
| 50 | + const TIMEOUT_MS = 5000; |
| 51 | + let timeoutPromise = new Promise(resolve => { |
| 52 | + let timeoutValue = { reason: "timeout" }; |
| 53 | + // eslint-disable-next-line mozilla/no-arbitrary-setTimeout |
| 54 | + setTimeout(() => resolve(timeoutValue), TIMEOUT_MS); |
| 55 | + }); |
| 56 | + |
| 57 | + const firstPromise = await Promise.race([lostPromise, timeoutPromise]); |
| 58 | + is( |
| 59 | + firstPromise.reason, |
| 60 | + "timeout", |
| 61 | + "timeoutPromise should return before lostPromise." |
| 62 | + ); |
| 63 | + }; |
| 64 | + |
| 65 | + SimpleTest.waitForExplicitFinish(); |
| 66 | + |
| 67 | + destroy_causes_lost() |
| 68 | + .then(() => drop_causes_lost_is_unobservable()) |
| 69 | + .catch(e => ok(false, `Unhandled exception ${e}`)) |
| 70 | + .finally(() => SimpleTest.finish()); |
| 71 | + </script> |
| 72 | + </body> |
| 73 | +</html> |
0 commit comments