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

Side by Side Diff: third_party/WebKit/LayoutTests/shapedetection/detection-ImageBitmap.html

Issue 2522143002: ShapeDetection: split mojom into face and barcode interfaces (Closed)
Patch Set: Smart rebase to https://crrev.com/2527503003 (FaceDetectorOptions) 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
OLDNEW
1 <!DOCTYPE html> 1 <!DOCTYPE html>
2 <script src="../resources/testharness.js"></script> 2 <script src="../resources/testharness.js"></script>
3 <script src="../resources/testharnessreport.js"></script> 3 <script src="../resources/testharnessreport.js"></script>
4 <script src="../resources/mojo-helpers.js"></script> 4 <script src="../resources/mojo-helpers.js"></script>
5 <script src="resources/mock-shapedetection.js"></script> 5 <script src="resources/mock-barcodedetection.js"></script>
6 <script src="resources/mock-facedetection.js"></script>
6 <script> 7 <script>
7 8
8 var createTestForImageBitmap = function(detectorName, detectionResultTest) { 9 var createTestForImageBitmap = function(detectorName, mockReady,
10 detectionResultTest) {
9 async_test(function(t) { 11 async_test(function(t) {
10 var img = new Image(); 12 var img = new Image();
11 13
12 img.onload = function() { 14 img.onload = function() {
13 var theImageBitmap = null; 15 var theImageBitmap = null;
14 var theMock = null; 16 var theMock = null;
15 17
16 createImageBitmap(img) 18 createImageBitmap(img)
17 .then(imageBitmap => { 19 .then(imageBitmap => {
18 theImageBitmap = imageBitmap; 20 theImageBitmap = imageBitmap;
19 return mockShapeDetectionReady; 21 return mockReady();
20 }) 22 })
21 .catch(error => { 23 .catch(error => {
22 assert_unreached('createImageBitmap() error: ' + error); 24 assert_unreached('createImageBitmap() error: ' + error);
23 }) 25 })
24 .then(mock => { 26 .then(mock => {
25 theMock = mock; 27 theMock = mock;
26 var detector = eval("new " + detectorName + "();"); 28 var detector = eval("new " + detectorName + "();");
27 return detector; 29 return detector;
28 }) 30 })
29 .catch(error => { 31 .catch(error => {
30 assert_unreached("Error creating MockShapeDetection: " + error); 32 assert_unreached("Error creating MockFaceDetection: " + error);
31 }) 33 })
32 .then(detector => { 34 .then(detector => {
33 return detector.detect(theImageBitmap); 35 return detector.detect(theImageBitmap);
34 }) 36 })
35 .then(detectionResult => { 37 .then(detectionResult => {
36 detectionResultTest(detectionResult, theMock); 38 detectionResultTest(detectionResult, theMock);
37 t.done(); 39 t.done();
38 }) 40 })
39 .catch(error => { 41 .catch(error => {
40 assert_unreached("Error during detect(img): " + error); 42 assert_unreached("Error during detect(img): " + error);
41 }); 43 });
42 } 44 }
43 img.src = '../media/content/greenbox.png'; 45 img.src = '../media/content/greenbox.png';
44 }, 'Detector detect(ImageBitmap)'); 46 }, "Detector detect(ImageBitmap)");
45 }; 47 };
46 48
47 function FaceDetectorDetectionResultTest(detectionResult, mock) { 49 function FaceDetectorDetectionResultTest(detectionResult, mock) {
48 const imageReceivedByMock = mock.getFrameData(); 50 const imageReceivedByMock = mock.getFrameData();
49 assert_equals(imageReceivedByMock.byteLength, 2500,"Image length"); 51 assert_equals(imageReceivedByMock.byteLength, 2500,"Image length");
50 const GREEN_PIXEL = 0xFF00FF00; 52 const GREEN_PIXEL = 0xFF00FF00;
51 assert_equals(imageReceivedByMock[0], GREEN_PIXEL, "Pixel color"); 53 assert_equals(imageReceivedByMock[0], GREEN_PIXEL, "Pixel color");
52 assert_equals(detectionResult.length, 3, "Number of faces"); 54 assert_equals(detectionResult.length, 3, "Number of faces");
53 } 55 }
54 56
55 function BarcodeDetectorDetectionResultTest(detectionResult, mock) { 57 function BarcodeDetectorDetectionResultTest(detectionResult, mock) {
56 assert_equals(detectionResult.length, 2, "Number of barcodes"); 58 assert_equals(detectionResult.length, 2, "Number of barcodes");
57 assert_equals(detectionResult[0].rawValue, "cats", "barcode 1"); 59 assert_equals(detectionResult[0].rawValue, "cats", "barcode 1");
58 assert_equals(detectionResult[1].rawValue, "dogs", "barcode 2"); 60 assert_equals(detectionResult[1].rawValue, "dogs", "barcode 2");
59 } 61 }
60 62
61 // These tests verify that a Detector's detect() works on an ImageBitmap. 63 // These tests verify that a Detector's detect() works on an ImageBitmap.
62 // Use the mock mojo server implemented in mock-shapedetection.js. 64 // Use the mock mojo server implemented in mock-{barcode,face}detection.js.
63 generate_tests(createTestForImageBitmap, [ 65 generate_tests(createTestForImageBitmap, [
64 [ "Face", "FaceDetector", FaceDetectorDetectionResultTest ], 66 [
65 [ "Barcode", "BarcodeDetector", BarcodeDetectorDetectionResultTest ] 67 "Face",
68 "FaceDetector",
69 () => { return mockFaceDetectionReady; },
70 FaceDetectorDetectionResultTest
71 ],
72 [
73 "Barcode",
74 "BarcodeDetector",
75 () => { return mockBarcodeDetectionReady; },
76 BarcodeDetectorDetectionResultTest
77 ]
66 ]); 78 ]);
67 79
68 </script> 80 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698