tor-browser

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

detection-on-worker.https.worker.js (1777B)


      1 importScripts("/resources/testharness.js");
      2 importScripts("/resources/test-only-api.js");
      3 importScripts("resources/shapedetection-helpers.js");
      4 
      5 'use strict';
      6 
      7 // These tests verify that a Detector's detect() works on an
      8 // ImageBitmap on workers.
      9 const imageBitmapTests =
     10    [
     11      {
     12        createDetector: () => { return new FaceDetector(); },
     13        mockTestName: "FaceDetectionTest",
     14        resultSize: 3, // Number of faces
     15        detectorType: "Face"
     16      },
     17      {
     18        createDetector: () => { return new BarcodeDetector(); },
     19        mockTestName: "BarcodeDetectionTest",
     20        resultSize: 2, // Number of barcodes
     21        detectorType: "Barcode"
     22      },
     23      {
     24        createDetector: () => { return new TextDetector(); },
     25        mockTestName: "TextDetectionTest",
     26        resultSize: 2, // Number of text blocks
     27        detectorType: "Text"
     28      }
     29    ];
     30 
     31 for (let imageBitmapTest of imageBitmapTests) {
     32  // ImageBitmap is of transferable type and can be sent to and
     33  // tested on worker.
     34  detection_test(imageBitmapTest.mockTestName, async (t, detectionTest) => {
     35    const img = createTestImage();
     36    const theImageBitmap = await createImageBitmap(img);
     37    const detector = imageBitmapTest.createDetector();
     38    const detectionResult = await detector.detect(theImageBitmap);
     39    assert_equals(detectionResult.length, imageBitmapTest.resultSize,
     40      `Number of ${imageBitmapTest.detectorType}`);
     41  }, `${imageBitmapTest.detectorType} Detector detect(ImageBitmap) on worker`);
     42 }
     43 
     44 function createTestImage() {
     45  const image = new OffscreenCanvas(100, 50);
     46  const imgctx = image.getContext('2d');
     47  imgctx.fillStyle = "#F00";
     48  imgctx.fillRect(0, 0, 2, 2);
     49  imgctx.fillStyle = "#0F0";
     50  imgctx.fillRect(0, 0, 1, 1);
     51  return image;
     52 }
     53 
     54 done();