tor-browser

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

2d.text.measure.fillTextCluster-options.tentative.worker.js (2567B)


      1 // DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py.
      2 // OffscreenCanvas test in a worker:2d.text.measure.fillTextCluster-options.tentative
      3 // Description:Test that fillTextCluster() correctly applies the options passed as a dictionary.
      4 // Note:
      5 
      6 importScripts("/resources/testharness.js");
      7 importScripts("/html/canvas/resources/canvas-tests.js");
      8 
      9 promise_test(async t => {
     10  var canvas = new OffscreenCanvas(100, 300);
     11  var ctx = canvas.getContext('2d');
     12 
     13  var f = new FontFace("CanvasTest", "url('/fonts/CanvasTest.ttf')");
     14  f.load();
     15  self.fonts.add(f);
     16  await self.fonts.ready;
     17 
     18  ctx.font = '50px CanvasTest';
     19  ctx.textAlign = 'left';
     20  ctx.textBaseline = 'top';
     21  const text = 'E';
     22  const tm = ctx.measureText(text);
     23  const cluster = tm.getTextClusters()[0];
     24 
     25  // Background color.
     26  ctx.fillStyle = '#f00';
     27  ctx.fillRect(0, 0, canvas.width, canvas.height);
     28 
     29  ctx.fillStyle = '#0f0';
     30 
     31  // Override the align and baseline of the cluster.
     32  ctx.fillTextCluster(cluster, 50, 50, {align: 'right', baseline: 'bottom'});
     33  _assertPixelApprox(canvas, 5,5, 0,255,0,255, 2);
     34  _assertPixelApprox(canvas, 45,5, 0,255,0,255, 2);
     35  _assertPixelApprox(canvas, 5,45, 0,255,0,255, 2);
     36  _assertPixelApprox(canvas, 45,45, 0,255,0,255, 2);
     37  _assertPixelApprox(canvas, 55,5, 255,0,0,255, 2);
     38  _assertPixelApprox(canvas, 5,55, 255,0,0,255, 2);
     39  _assertPixelApprox(canvas, 55,55, 255,0,0,255, 2);
     40 
     41  // Override the x and y values of the cluster.
     42  ctx.fillTextCluster(cluster, 0, 100, {x: 10, y: 10});
     43  _assertPixelApprox(canvas, 15,115, 0,255,0,255, 2);
     44  _assertPixelApprox(canvas, 55,115, 0,255,0,255, 2);
     45  _assertPixelApprox(canvas, 15,155, 0,255,0,255, 2);
     46  _assertPixelApprox(canvas, 55,155, 0,255,0,255, 2);
     47  _assertPixelApprox(canvas, 65,115, 255,0,0,255, 2);
     48  _assertPixelApprox(canvas, 15,165, 255,0,0,255, 2);
     49  _assertPixelApprox(canvas, 65,165, 255,0,0,255, 2);
     50 
     51  // Override the align, baseline, x, and y values of the cluster.
     52  ctx.fillTextCluster(cluster, 50, 250,
     53                      {align: 'right', baseline: 'bottom', x: 10,  y: 10});
     54  _assertPixelApprox(canvas, 15,215, 0,255,0,255, 2);
     55  _assertPixelApprox(canvas, 55,215, 0,255,0,255, 2);
     56  _assertPixelApprox(canvas, 15,255, 0,255,0,255, 2);
     57  _assertPixelApprox(canvas, 55,255, 0,255,0,255, 2);
     58  _assertPixelApprox(canvas, 65,215, 255,0,0,255, 2);
     59  _assertPixelApprox(canvas, 15,265, 255,0,0,255, 2);
     60  _assertPixelApprox(canvas, 65,265, 255,0,0,255, 2);
     61 }, "Test that fillTextCluster() correctly applies the options passed as a dictionary.");
     62 done();