testing/web-platform/tests/html/canvas/offscreen/text/2d.text.draw.baseline.hanging.html
author Gabriel Luong <gabriel.luong@gmail.com>
Sun, 13 Jul 2025 02:28:40 +0000 (14 hours ago)
changeset 796385 23185ed855a5b168943bde8ebe8ec946cd83f675
parent 752939 1996e4a4973941fa87e76e5646d5bb0088c0de84
permissions -rw-r--r--
Bug 1972159 - Part 25: Enable Compose Homepage by default and remove associated settings and Nimbus flags r=android-reviewers,devota Differential Revision: https://phabricator.services.mozilla.com/D254598
<!DOCTYPE html>
<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
<meta charset="UTF-8">
<title>OffscreenCanvas test: 2d.text.draw.baseline.hanging</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/html/canvas/resources/canvas-tests.js"></script>

<h1>2d.text.draw.baseline.hanging</h1>
<p class="desc"></p>


<script>
promise_test(async t => {

  var canvas = new OffscreenCanvas(100, 50);
  var ctx = canvas.getContext('2d');

  var f = new FontFace("CanvasTest", "url('/fonts/CanvasTest.ttf')");
  f.load();
  document.fonts.add(f);
  await document.fonts.ready;
  ctx.font = '50px CanvasTest';
  ctx.fillStyle = '#f00';
  ctx.fillRect(0, 0, 100, 50);
  ctx.fillStyle = '#0f0';
  ctx.textBaseline = 'hanging';
  ctx.fillText('CC', 0, 12.5);
  _assertPixelApprox(canvas, 5,5, 0,255,0,255, 2);
  _assertPixelApprox(canvas, 95,5, 0,255,0,255, 2);
  _assertPixelApprox(canvas, 25,25, 0,255,0,255, 2);
  _assertPixelApprox(canvas, 75,25, 0,255,0,255, 2);
  _assertPixelApprox(canvas, 5,45, 0,255,0,255, 2);
  _assertPixelApprox(canvas, 95,45, 0,255,0,255, 2);

}, "");
</script>