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

Unified Diff: third_party/WebKit/LayoutTests/shapedetection/detectshape-HTMLVideoElement.html

Issue 2502723002: ShapeDetection: implement barcode detection, blink part (Closed)
Patch Set: haraken@ comments Created 4 years, 1 month 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
Index: third_party/WebKit/LayoutTests/shapedetection/detectshape-HTMLVideoElement.html
diff --git a/third_party/WebKit/LayoutTests/shapedetection/detectshape-HTMLVideoElement.html b/third_party/WebKit/LayoutTests/shapedetection/detectshape-HTMLVideoElement.html
new file mode 100644
index 0000000000000000000000000000000000000000..78a53c8843da8fcaaf2d1b209c2f57d6b4abc683
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/shapedetection/detectshape-HTMLVideoElement.html
@@ -0,0 +1,64 @@
+<!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-shapedetection.js"></script>
+<script>
+
+var createTestForVideoElement = function(detectorName, detectionResultTest) {
+ async_test(function(t) {
+ var video = document.createElement('video');
+ video.src = "../imported/wpt/media/white.webm";
+ video.loop = true;
+ video.autoplay = true;
+ video.onerror = this.unreached_func("<video> error");
+ video.onplay = this.step_func(function() {
+ var theMock = null;
+ mockShapeDetectionReady
+ .then(mock => {
+ theMock = mock;
+ var detector = eval("new " + detectorName + "();");
+ return detector;
+ })
+ .catch(error => {
+ assert_unreached("Error creating MockShapeDetection: " + error);
+ })
+ .then(detector => {
+ return detector.detect(video);
+ })
+ .then(detectionResult => {
+ detectionResultTest(detectionResult, theMock);
+ t.done();
+ })
+ .catch(error => {
+ assert_unreached("Error during detect(video): " + error);
+ });
+ });
+
+ video.load();
+ }, 'Detector detect(HTMLVideoElement)');
+};
+
+function FaceDetectorDetectionResultTest(detectionResult, mock) {
+ const imageReceivedByMock = mock.getFrameData();
+ assert_equals(imageReceivedByMock.byteLength, 307200,
+ "Image length");
+ const WHITE_PIXEL = 0xFFFFFFFF;
+ assert_equals(imageReceivedByMock[0], WHITE_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 HTMLVideoElement.
+// Use the mock mojo server implemented in mock-shapedetection.js.
+generate_tests(createTestForVideoElement, [
+ [ "Face", "FaceDetector", FaceDetectorDetectionResultTest ],
+ [ "Barcode", "BarcodeDetector", BarcodeDetectorDetectionResultTest ]
+]);
+
+</script>

Powered by Google App Engine
This is Rietveld 408576698