tor-browser

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

detection-ImageData.https.html (2786B)


      1 <!DOCTYPE html>
      2 <script src="/resources/testharness.js"></script>
      3 <script src="/resources/testharnessreport.js"></script>
      4 <script src="resources/shapedetection-helpers.js"></script>
      5 <script>
      6 
      7 // These tests verify that a Detector's detect() works on an ImageBitmap.
      8 const imageDataTests =
      9    [
     10      {
     11        createDetector: () => { return new FaceDetector(); },
     12        mockTestName: "FaceDetectionTest",
     13        detectionResultTest: FaceDetectorDetectionResultTest,
     14        name: "Face - detect(ImageData)"
     15      },
     16      {
     17        createDetector: () => { return new BarcodeDetector(); },
     18        mockTestName: "BarcodeDetectionTest",
     19        detectionResultTest: BarcodeDetectorDetectionResultTest,
     20        name: "Barcode - detect(ImageData)"
     21      },
     22      {
     23        createDetector: () => { return new TextDetector(); },
     24        mockTestName: "TextDetectionTest",
     25        detectionResultTest: TextDetectorDetectionResultTest,
     26        name: "Text - detect(ImageData)",
     27      }
     28    ];
     29 
     30 for (let imageDataTest of imageDataTests) {
     31  detection_test(imageDataTest.mockTestName, async (t, detectionTest) => {
     32    const img = new Image();
     33    const imgWatcher = new EventWatcher(t, img, ["load", "error"]);
     34    img.src = "/images/green-16x16.png";
     35    await imgWatcher.wait_for("load");
     36    const canvas = document.createElement("canvas");
     37    canvas.getContext("2d").drawImage(img, 0, 0);
     38 
     39    const detector = imageDataTest.createDetector();
     40    const detectionResult = await detector.detect(canvas.getContext("2d")
     41        .getImageData(0, 0, canvas.width, canvas.height));
     42    imageDataTest.detectionResultTest(detectionResult, detectionTest);
     43  }, imageDataTest.name);
     44 }
     45 
     46 function FaceDetectorDetectionResultTest(detectionResult, mockTest) {
     47  const imageReceivedByMock = mockTest.MockFaceDetectionProvider().getFrameData();
     48  assert_equals(imageReceivedByMock.byteLength, 180000,"Image length");
     49  const GREEN_PIXEL = 0xFF00FF00;
     50  assert_equals(imageReceivedByMock[0], GREEN_PIXEL, "Pixel color");
     51  assert_equals(detectionResult.length, 3, "Number of faces");
     52 }
     53 
     54 function BarcodeDetectorDetectionResultTest(detectionResult, mockTest) {
     55  assert_equals(detectionResult.length, 2, "Number of barcodes");
     56  assert_equals(detectionResult[0].rawValue, "cats", "barcode 1");
     57  assert_equals(detectionResult[0].format, "qr_code", "barcode 1 format");
     58  assert_equals(detectionResult[1].rawValue, "dogs", "barcode 2");
     59  assert_equals(detectionResult[1].format, "code_128", "barcode 2 format");
     60 }
     61 
     62 function TextDetectorDetectionResultTest(detectionResult, mockTest) {
     63  assert_equals(detectionResult.length, 2, "Number of textBlocks");
     64  assert_equals(detectionResult[0].rawValue, "cats", "textBlock 1");
     65  assert_equals(detectionResult[1].rawValue, "dogs", "textBlock 2");
     66 }
     67 
     68 </script>