tor-browser

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

detected-boundingBox-read-only.https.html (1912B)


      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 detected{Face, Barcode, Text}'s boundingBox
      8 // should be DOMRectReadOnly.
      9 const imageDataTests =
     10    [
     11      {
     12        createDetector: () => { return new FaceDetector(); },
     13        mockTestName: "FaceDetectionTest",
     14        name: "Face - detectedFace.boundingBox should be DOMRectReadOnly"
     15      },
     16      {
     17        createDetector: () => { return new BarcodeDetector(); },
     18        mockTestName: "BarcodeDetectionTest",
     19        name: "Barcode - detectedBarcode.boundingBox should be DOMRectReadOnly"
     20      },
     21      {
     22        createDetector: () => { return new TextDetector(); },
     23        mockTestName: "TextDetectionTest",
     24        name: "Text - detectedText.boundingBox should be DOMRectReadOnly"
     25      }
     26    ];
     27 
     28 for (let imageDataTest of imageDataTests) {
     29  detection_test(imageDataTest.mockTestName, async t => {
     30    const img = new Image();
     31    const imgWatcher = new EventWatcher(t, img, ["load", "error"]);
     32    img.src = "/images/green-16x16.png";
     33    await imgWatcher.wait_for("load");
     34 
     35    const canvas = document.createElement("canvas");
     36    canvas.getContext("2d").drawImage(img, 0, 0);
     37 
     38    const detector = imageDataTest.createDetector();
     39    const detectionResult = await detector.detect(canvas.getContext("2d")
     40        .getImageData(0, 0, canvas.width, canvas.height));
     41    CheckDetectedReadOnlyBoundingBoxes(detectionResult);
     42  }, imageDataTest.name);
     43 }
     44 
     45 function CheckDetectedReadOnlyBoundingBoxes(detectedObjects) {
     46  const properties =
     47      ['x', 'y', 'width', 'height', 'top', 'right', 'bottom', 'left'];
     48 
     49  detectedObjects.forEach(detectedObject => {
     50    properties.forEach(property => {
     51      assert_readonly(detectedObject.boundingBox, property);
     52    });
     53  });
     54 }
     55 
     56 </script>