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

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

Issue 2553343003: ShapeDetection: add support for all CanvasImageSource input types (Closed)
Patch Set: reillyg@s comments 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/LayoutTests/shapedetection/detection-HTMLImageElement.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/LayoutTests/shapedetection/detection-HTMLCanvasElement.html
diff --git a/third_party/WebKit/LayoutTests/shapedetection/detection-HTMLCanvasElement.html b/third_party/WebKit/LayoutTests/shapedetection/detection-HTMLCanvasElement.html
new file mode 100644
index 0000000000000000000000000000000000000000..816b9de163014ad5a59cf627874748a534b714a7
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/shapedetection/detection-HTMLCanvasElement.html
@@ -0,0 +1,95 @@
+<!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 createTestForCanvasElement = function(createDetector,
+ createCanvas,
+ mockReady,
+ detectionResultTest) {
+ async_test(function(t) {
+
+ var img = new Image();
+ img.onload = function() {
+
+ var canvas = createCanvas();
+ 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);
+ })
+ .then(detectionResult => {
+ detectionResultTest(detectionResult, theMock);
+ t.done();
+ })
+ .catch(error => {
+ assert_unreached("Error during detect(canvas): " + error);
+ });
+ }
+
+ img.src = "../media/content/greenbox.png";
+ }, "Detector detect(HTMLCanvasElement)");
+};
+
+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 HTMLCanvasElement
+// and on an OffscreenCanvas. Use the mock mojo server implemented in
+// mock-{barcode,face}detection.js.
+generate_tests(createTestForCanvasElement, [
+ [
+ "Face - HTMLCanvasElement",
+ () => { return new FaceDetector(); },
+ () => { return document.createElement("canvas"); },
+ () => { return mockFaceDetectionReady; },
+ FaceDetectorDetectionResultTest
+ ],
+ [
+ "Face - OffscreenCanvas",
+ () => { return new FaceDetector(); },
+ () => { return new OffscreenCanvas(300, 150); },
+ () => { return mockFaceDetectionReady; },
+ FaceDetectorDetectionResultTest
+ ],
+ [
+ "Barcode - HTMLCanvasElement",
+ () => { return new BarcodeDetector(); },
+ () => { return document.createElement("canvas"); },
+ () => { return mockBarcodeDetectionReady; },
+ BarcodeDetectorDetectionResultTest
+ ],
+ [
+ "Barcode - OffscreenCanvas",
+ () => { return new BarcodeDetector(); },
+ () => { return new OffscreenCanvas(300, 150); },
+ () => { return mockBarcodeDetectionReady; },
+ BarcodeDetectorDetectionResultTest
+ ]
+]);
+
+</script>
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/shapedetection/detection-HTMLImageElement.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698