tor-browser

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

2d.text.draw.generic.family.w.html (2110B)


      1 <!DOCTYPE html>
      2 <title>OffscreenCanvas test: 2d.text.draw.generic.family.w</title>
      3 <script src="/resources/testharness.js"></script>
      4 <script src="/resources/testharnessreport.js"></script>
      5 <script src="/html/canvas/resources/canvas-tests.js"></script>
      6 <script id='myWorker' type='text/worker'>
      7 self.onmessage = function(e) {
      8    let oc = new OffscreenCanvas(88, 24);
      9    let ctx = oc.getContext('2d');
     10    ctx.font = '32px ' + e.data.family;
     11    ctx.fillText(e.data.family, 0, 16);
     12    self.postMessage(ctx.getImageData(0, 0, 88, 24).data);
     13 };
     14 </script>
     15 <script>
     16 function testDrawGenericFamily(t, family)
     17 {
     18    let blob = new Blob([document.getElementById('myWorker').textContent]);
     19    let worker = new Worker(URL.createObjectURL(blob));
     20    worker.addEventListener('message', msg => {
     21        let ctx = document.createElement('canvas').getContext('2d');
     22        ctx.font = '32px ' + family;
     23        ctx.fillText(family, 0, 16);
     24        assert_array_equals(ctx.getImageData(0, 0, 88, 24).data, msg.data,
     25          "The image data generated by drawing generic font family '" + family +
     26          "' should be the same for both OffscreenCanvas and regular canvas");
     27      t.done();
     28    });
     29    worker.postMessage({family: family});
     30 }
     31 
     32 async_test(function(t) {
     33    testDrawGenericFamily(t, 'sans-serif');
     34 }, "Test that drawing sans-serif produces the same result between canvas and OffscreenCanvas in a Worker");
     35 
     36 async_test(function(t) {
     37    testDrawGenericFamily(t, 'serif');
     38 }, "Test that drawing serif produces the same result between canvas and OffscreenCanvas in a Worker");
     39 
     40 async_test(function(t) {
     41    testDrawGenericFamily(t, 'cursive');
     42 }, "Test that drawing cursive produces the same result between canvas and OffscreenCanvas in a Worker");
     43 
     44 async_test(function(t) {
     45    testDrawGenericFamily(t, 'fantasy');
     46 }, "Test that drawing fantasy produces the same result between canvas and OffscreenCanvas in a Worker");
     47 
     48 async_test(function(t) {
     49    testDrawGenericFamily(t, 'monospace');
     50 }, "Test that drawing monospace produces the same result between canvas and OffscreenCanvas in a Worker");
     51 </script>