1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63

content / test / data / gpu / webgpu-domain-blocking-page1.html [blame]

<script type="text/javascript">
function reportProgress(msg) {
  if (window.domAutomationController) {
    window.domAutomationController.send(msg);
  }
  console.log(msg);
}

// These must be "var" rather than "let" for the Telemetry harness to
// see them.
var gotDevice;
var deviceLost;
var proceed;

const later = (delay) =>
  new Promise(resolve => setTimeout(resolve, delay));

async function init()
{
  reportProgress('LOADED');

  // This bakes in knowledge that GpuDataManagerImplPrivate blocks
  // WebGPU from fetching an adapter after two device losses on the
  // same domain.
  for (idx = 0; idx < 2; ++idx) {
    let adapter = await navigator.gpu.requestAdapter();
    if (!adapter) {
      console.log('TEST FAILED - Could not get a GPUAdapter');
      reportProgress('FAILED');
      return;
    }

    let device;
    try {
      device = await adapter.requestDevice();
      gotDevice = true;
      deviceLost = false;
    } catch {
      console.log('TEST FAILED - Could not get a GPUDevice');
      reportProgress('FAILED');
      return;
    }

    console.log('Waiting for a GPU crash to cause device loss');
    const {reason} = await device.lost;
    gotDevice = false;
    deviceLost = true;
    if (reason !== undefined) {
      console.log('TEST FAILED - Expected undefined device lost reason');
      reportProgress('FAILED');
    }

    // The harness will tell us when to proceed to the second iteration.
    while (!proceed) {
      await later(100);
    }
  }

  window.location.href = 'webgpu-domain-blocking-page2.html';
}

init();
</script>