 Chromium Code Reviews
 Chromium Code Reviews Issue 2553343003:
  ShapeDetection: add support for all CanvasImageSource input types  (Closed)
    
  
    Issue 2553343003:
  ShapeDetection: add support for all CanvasImageSource input types  (Closed) 
  | OLD | NEW | 
|---|---|
| (Empty) | |
| 1 <!DOCTYPE html> | |
| 2 <script src="../resources/testharness.js"></script> | |
| 3 <script src="../resources/testharnessreport.js"></script> | |
| 4 <script src="../resources/mojo-helpers.js"></script> | |
| 5 <script src="resources/mock-barcodedetection.js"></script> | |
| 6 <script src="resources/mock-facedetection.js"></script> | |
| 7 <script> | |
| 8 | |
| 9 var createTestForCanvasElement = function(detectorName, | |
| 10 createCanvas, | |
| 11 mockReady, | |
| 12 detectionResultTest) { | |
| 13 async_test(function(t) { | |
| 14 | |
| 15 var img = new Image(); | |
| 16 img.onload = function() { | |
| 17 | |
| 18 var canvas = createCanvas(); ////document.createElement('canvas'); | |
| 
Reilly Grant (use Gerrit)
2016/12/07 21:37:06
Leftover comment?
 
mcasas
2016/12/07 22:02:37
Oops, yes, removed.
 | |
| 19 canvas.getContext("2d").drawImage(img, 0, 0); | |
| 20 | |
| 21 var theMock = null; | |
| 22 mockReady() | |
| 23 .then(mock => { | |
| 24 theMock = mock; | |
| 25 var detector = eval("new " + detectorName + "();"); | |
| 
Reilly Grant (use Gerrit)
2016/12/07 21:37:06
Why not pass the constructor function instead of a
 
mcasas
2016/12/07 22:02:37
Done. Note that you can't pass |bla| and
evaluate
 | |
| 26 return detector; | |
| 27 }) | |
| 28 .catch(error => { | |
| 29 assert_unreached("Error creating Mock Detector: " + error); | |
| 30 }) | |
| 31 .then(detector => { | |
| 32 return detector.detect(canvas); | |
| 33 }) | |
| 34 .then(detectionResult => { | |
| 35 detectionResultTest(detectionResult, theMock); | |
| 36 t.done(); | |
| 37 }) | |
| 38 .catch(error => { | |
| 39 assert_unreached("Error during detect(canvas): " + error); | |
| 40 }); | |
| 41 } | |
| 42 | |
| 43 img.src = '../media/content/greenbox.png'; | |
| 
Reilly Grant (use Gerrit)
2016/12/07 21:37:06
Be consistent about ' vs. ".
 
mcasas
2016/12/07 22:02:37
Done.
 | |
| 44 }, "Detector detect(HTMLCanvasElement)"); | |
| 45 }; | |
| 46 | |
| 47 function FaceDetectorDetectionResultTest(detectionResult, mock) { | |
| 48 const imageReceivedByMock = mock.getFrameData(); | |
| 49 assert_equals(imageReceivedByMock.byteLength, 180000,"Image length"); | |
| 50 const GREEN_PIXEL = 0xFF00FF00; | |
| 51 assert_equals(imageReceivedByMock[0], GREEN_PIXEL, "Pixel color"); | |
| 52 assert_equals(detectionResult.length, 3, "Number of faces"); | |
| 53 } | |
| 54 | |
| 55 function BarcodeDetectorDetectionResultTest(detectionResult, mock) { | |
| 56 assert_equals(detectionResult.length, 2, "Number of barcodes"); | |
| 57 assert_equals(detectionResult[0].rawValue, "cats", "barcode 1"); | |
| 58 assert_equals(detectionResult[1].rawValue, "dogs", "barcode 2"); | |
| 59 } | |
| 60 | |
| 61 // These tests verify that a Detector's detect() works on an HTMLCanvasElement | |
| 62 // and on an OffscreenCanvas. Use the mock mojo server implemented in | |
| 63 // mock-{barcode,face}detection.js. | |
| 64 generate_tests(createTestForCanvasElement, [ | |
| 65 [ | |
| 66 "Face - HTMLCanvasElement", | |
| 67 "FaceDetector", | |
| 68 () => { return document.createElement('canvas'); }, | |
| 69 () => { return mockFaceDetectionReady; }, | |
| 70 FaceDetectorDetectionResultTest | |
| 71 ], | |
| 72 [ | |
| 73 "Face - OffscreenCanvas", | |
| 74 "FaceDetector", | |
| 75 () => { return new OffscreenCanvas(300, 150); }, | |
| 76 () => { return mockFaceDetectionReady; }, | |
| 77 FaceDetectorDetectionResultTest | |
| 78 ], | |
| 79 [ | |
| 80 "Barcode - HTMLCanvasElement", | |
| 81 "BarcodeDetector", | |
| 82 () => { return document.createElement('canvas'); }, | |
| 83 () => { return mockBarcodeDetectionReady; }, | |
| 84 BarcodeDetectorDetectionResultTest | |
| 85 ], | |
| 86 [ | |
| 87 "Barcode - OffscreenCanvas", | |
| 88 "BarcodeDetector", | |
| 89 () => { return new OffscreenCanvas(300, 150); }, | |
| 90 () => { return mockBarcodeDetectionReady; }, | |
| 91 BarcodeDetectorDetectionResultTest | |
| 92 ] | |
| 93 ]); | |
| 94 | |
| 95 </script> | |
| OLD | NEW |