tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_device_lost.html (2709B)


      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        info("destroy_causes_lost START");
     17        const adapter = await navigator.gpu.requestAdapter();
     18        ok(adapter !== undefined, "adapter !== undefined");
     19        const device = await adapter.requestDevice();
     20        ok(device !== undefined, "device !== undefined");
     21 
     22        const lostPromise = device.lost;
     23        device.destroy();
     24        info("waiting for lostPromise");
     25        const deviceLostReason = await lostPromise;
     26        info("lostPromise has resolved");
     27 
     28        is(
     29          deviceLostReason.reason,
     30          "destroyed",
     31          "Destroy reason should correspond to GPUDeviceLostReason.destroyed"
     32        );
     33        is(deviceLostReason.message, "Device destroyed", "Destroy message does not match");
     34        info("destroy_causes_lost END");
     35      };
     36 
     37      const drop_causes_lost_is_unobservable = async function () {
     38        info("drop_causes_lost_is_unobservable START");
     39        const adapter = await navigator.gpu.requestAdapter();
     40        ok(adapter !== undefined, "adapter !== undefined");
     41 
     42        let lostPromise;
     43        // Create a scope with a device that will go out of scope
     44        // and then be dropped.
     45        {
     46          const device = await adapter.requestDevice();
     47          ok(device !== undefined, "device !== undefined");
     48 
     49          // Create a new promise that will resolve when the original
     50          // lost promise resolves or rejects, either of which will be
     51          // noted as an error.
     52          lostPromise = device.lost.then(
     53            resolve => {
     54              ok(false, "device.lost should never resolve");
     55              resolve("unexpected resolve");
     56            },
     57            reject => {
     58              ok(false, "device.lost should never reject");
     59              reject("unexpected reject");
     60            }
     61          );
     62        }
     63 
     64        // Give a chance (one event cycle) for the lostPromise to resolve or
     65        // reject, but don't wait for any specific amount of time.
     66        await new Promise(SimpleTest.executeSoon);
     67        info("drop_causes_lost_is_unobservable END");
     68      };
     69 
     70      SimpleTest.waitForExplicitFinish();
     71 
     72      destroy_causes_lost()
     73        .then(() => drop_causes_lost_is_unobservable())
     74        .catch(e => ok(false, `Unhandled exception ${e}`))
     75        .finally(() => SimpleTest.finish());
     76    </script>
     77  </body>
     78 </html>