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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/shapedetection/detection-HTMLImageElement.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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(createDetector,
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();
19 canvas.getContext("2d").drawImage(img, 0, 0);
20
21 var theMock = null;
22 mockReady()
23 .then(mock => {
24 theMock = mock;
25 var detector = createDetector();
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";
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 () => { return new FaceDetector(); },
68 () => { return document.createElement("canvas"); },
69 () => { return mockFaceDetectionReady; },
70 FaceDetectorDetectionResultTest
71 ],
72 [
73 "Face - OffscreenCanvas",
74 () => { return new FaceDetector(); },
75 () => { return new OffscreenCanvas(300, 150); },
76 () => { return mockFaceDetectionReady; },
77 FaceDetectorDetectionResultTest
78 ],
79 [
80 "Barcode - HTMLCanvasElement",
81 () => { return new BarcodeDetector(); },
82 () => { return document.createElement("canvas"); },
83 () => { return mockBarcodeDetectionReady; },
84 BarcodeDetectorDetectionResultTest
85 ],
86 [
87 "Barcode - OffscreenCanvas",
88 () => { return new BarcodeDetector(); },
89 () => { return new OffscreenCanvas(300, 150); },
90 () => { return mockBarcodeDetectionReady; },
91 BarcodeDetectorDetectionResultTest
92 ]
93 ]);
94
95 </script>
OLDNEW
« 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