Index: third_party/WebKit/LayoutTests/shapedetection/detection-ImageData.html |
diff --git a/third_party/WebKit/LayoutTests/shapedetection/detection-ImageData.html b/third_party/WebKit/LayoutTests/shapedetection/detection-ImageData.html |
new file mode 100644 |
index 0000000000000000000000000000000000000000..45842afc1691aaba78ac141b09b779b25d9369f0 |
--- /dev/null |
+++ b/third_party/WebKit/LayoutTests/shapedetection/detection-ImageData.html |
@@ -0,0 +1,77 @@ |
+<!DOCTYPE html> |
+<script src="../resources/testharness.js"></script> |
+<script src="../resources/testharnessreport.js"></script> |
+<script src="../resources/mojo-helpers.js"></script> |
+<script src="resources/mock-barcodedetection.js"></script> |
+<script src="resources/mock-facedetection.js"></script> |
+<script> |
+ |
+var createTestForImageData = function(createDetector, mockReady, |
+ detectionResultTest) { |
+ async_test(function(t) { |
+ |
+ var img = new Image(); |
+ img.onload = function() { |
+ |
+ var canvas = document.createElement("canvas");; |
+ canvas.getContext("2d").drawImage(img, 0, 0); |
+ |
+ var theMock = null; |
+ mockReady() |
+ .then(mock => { |
+ theMock = mock; |
+ var detector = createDetector(); |
+ return detector; |
+ }) |
+ .catch(error => { |
+ assert_unreached("Error creating Mock Detector: " + error); |
+ }) |
+ .then(detector => { |
+ return detector.detect(canvas.getContext("2d").getImageData( |
+ 0, 0, canvas.width, canvas.height)); |
+ }) |
+ .then(detectionResult => { |
+ detectionResultTest(detectionResult, theMock); |
+ t.done(); |
+ }) |
+ .catch(error => { |
+ assert_unreached("Error during detect(canvas): " + error); |
+ }); |
+ } |
+ |
+ img.src = "../media/content/greenbox.png"; |
+ }, "Detector detect(ImageData)"); |
+}; |
+ |
+function FaceDetectorDetectionResultTest(detectionResult, mock) { |
+ const imageReceivedByMock = mock.getFrameData(); |
+ assert_equals(imageReceivedByMock.byteLength, 180000,"Image length"); |
+ const GREEN_PIXEL = 0xFF00FF00; |
+ assert_equals(imageReceivedByMock[0], GREEN_PIXEL, "Pixel color"); |
+ assert_equals(detectionResult.length, 3, "Number of faces"); |
+} |
+ |
+function BarcodeDetectorDetectionResultTest(detectionResult, mock) { |
+ assert_equals(detectionResult.length, 2, "Number of barcodes"); |
+ assert_equals(detectionResult[0].rawValue, "cats", "barcode 1"); |
+ assert_equals(detectionResult[1].rawValue, "dogs", "barcode 2"); |
+} |
+ |
+// These tests verify that a Detector's detect() works on an ImageBitmap. Use |
+// the mock mojo server implemented in mock-{barcode,face}detection.js. |
+generate_tests(createTestForImageData, [ |
+ [ |
+ "Face - ImageData", |
+ () => { return new FaceDetector(); }, |
+ () => { return mockFaceDetectionProviderReady; }, |
+ FaceDetectorDetectionResultTest |
+ ], |
+ [ |
+ "Barcode - ImageData", |
+ () => { return new BarcodeDetector(); }, |
+ () => { return mockBarcodeDetectionReady; }, |
+ BarcodeDetectorDetectionResultTest |
+ ], |
+]); |
+ |
+</script> |