tor-browser

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

detection-HTMLVideoElement.https.html (2650B)


      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 HTMLVideoElement.
      8 const videoElementTests =
      9    [
     10      {
     11        createDetector: () => { return new FaceDetector(); },
     12        mockTestName: "FaceDetectionTest",
     13        detectionResultTest: FaceDetectorDetectionResultTest,
     14        name: "Face - detect(HTMLVideoElement)"
     15      },
     16      {
     17        createDetector: () => { return new BarcodeDetector(); },
     18        mockTestName: "BarcodeDetectionTest",
     19        detectionResultTest: BarcodeDetectorDetectionResultTest,
     20        name: "Barcode - detect(HTMLVideoElement)"
     21      },
     22      {
     23        createDetector: () => { return new TextDetector(); },
     24        mockTestName: "TextDetectionTest",
     25        detectionResultTest: TextDetectorDetectionResultTest,
     26        name: "Text - detect(HTMLVideoElement)"
     27      }
     28    ];
     29 
     30 for (let videoElementTest of videoElementTests) {
     31  detection_test(videoElementTest.mockTestName, async (t, detectionTest) => {
     32    const video = document.createElement("video");
     33    video.src = "/media/white.webm";
     34    video.loop = true;
     35    video.autoplay = true;
     36    const videoWatcher = new EventWatcher(t, video, ["play", "error"]);
     37    video.load();
     38    await videoWatcher.wait_for("play");
     39 
     40    const detector = videoElementTest.createDetector();
     41    const detectionResult = await detector.detect(video);
     42    videoElementTest.detectionResultTest(detectionResult, detectionTest);
     43  }, videoElementTest.name);
     44 }
     45 
     46 function FaceDetectorDetectionResultTest(detectionResult, mockTest) {
     47  const imageReceivedByMock =
     48      mockTest.MockFaceDetectionProvider().getFrameData();
     49  assert_equals(imageReceivedByMock.byteLength, 307200, "Image length");
     50  assert_equals(detectionResult.length, 3, "Number of faces");
     51 }
     52 
     53 function BarcodeDetectorDetectionResultTest(detectionResult, mockTest) {
     54  assert_equals(detectionResult.length, 2, "Number of barcodes");
     55  assert_equals(detectionResult[0].rawValue, "cats", "barcode 1");
     56  assert_equals(detectionResult[0].format, "qr_code", "barcode 1 format");
     57  assert_equals(detectionResult[1].rawValue, "dogs", "barcode 2");
     58  assert_equals(detectionResult[1].format, "code_128", "barcode 2 format");
     59 }
     60 
     61 function TextDetectorDetectionResultTest(detectionResult, mockTest) {
     62  assert_equals(detectionResult.length, 2, "Number of textBlocks");
     63  assert_equals(detectionResult[0].rawValue, "cats", "textBlock 1");
     64  assert_equals(detectionResult[1].rawValue, "dogs", "textBlock 2");
     65 }
     66 
     67 </script>