Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(74)

Unified Diff: third_party/WebKit/LayoutTests/shapedetection/detection-ImageData.html

Issue 2550413005: ShapeDetection: use ImageBitmapSource as input and support ImageData (Closed)
Patch Set: xianglu@ comments and added forgotten LayoutTest detection-ImageData.html Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | third_party/WebKit/Source/modules/shapedetection/BarcodeDetector.idl » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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>
« no previous file with comments | « no previous file | third_party/WebKit/Source/modules/shapedetection/BarcodeDetector.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698