chromium/third_party/blink/web_tests/fast/canvas/OffscreenCanvas-placeholder-createImageBitmap.html

<!DOCTYPE HTML>
<html>
<head>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
</head>
<body>
<script>
async_test(function(t) {
  const canvas = document.createElement('canvas');
  const offscreen = canvas.transferControlToOffscreen();
  const ctx = offscreen.getContext('2d');
  ctx.fillStyle = '#0f0';
  ctx.fillRect(0, 0, canvas.width, canvas.height);

  const testCanvas = document.createElement('canvas');
  const testCtx = testCanvas.getContext('2d', {willReadFrequently: true});

  function testImage() {
    createImageBitmap(canvas).then(image => {
      testCtx.drawImage(image, 0, 0);
      const pixel = testCtx.getImageData(0, 0, 1, 1).data;
      if (pixel[3]) {
        t.step( function() {
          const expectedValue = [0, 255, 0, 255];
          assert_array_equals(pixel, expectedValue, "Verify that the canvas has been drawn.");
        });
        t.done();
      } else {
        // Data not yet available, try again.
        requestAnimationFrame(testImage);
      }
    });
  }

  requestAnimationFrame(testImage);

}, "Test whether createImageBitmap on a placeholder canvas captures the image committed to the associated OffscreenCanvas.");

</script>
</body>
</html>