| <!DOCTYPE html> |
| <script src="../resources/testharness.js"></script> |
| <script src="../resources/testharnessreport.js"></script> |
| <script src="file:///gen/layout_test_data/mojo/public/js/mojo_bindings.js"></script> |
| <script src="file:///gen/mojo/public/mojom/base/big_buffer.mojom.js"></script> |
| <script src="file:///gen/services/shape_detection/public/mojom/textdetection.mojom.js"></script> |
| <script src="resources/big-buffer-helpers.js"></script> |
| <script src="resources/mock-textdetection.js"></script> |
| <script> |
| |
| var createTestForImageBitmap = function(createDetector, mock, |
| detectionResultTest) { |
| async_test(function(t) { |
| var img = new Image(); |
| |
| img.onload = async function() { |
| var imageBitmap = await createImageBitmap(img); |
| var detector = createDetector(); |
| |
| try { |
| var detectionResult = await detector.detect(imageBitmap); |
| detectionResultTest(detectionResult, mock); |
| t.done(); |
| } catch (error) { |
| assert_unreached("Error during detect(img): " + error); |
| } |
| } |
| img.src = "../media/content/greenbox.png"; |
| }); |
| }; |
| |
| function TextDetectorDetectionResultTest(detectionResult, mock) { |
| assert_equals(detectionResult.length, 2, "Number of textBlocks"); |
| assert_equals(detectionResult[0].rawValue, "cats", "textBlock 1"); |
| assert_equals(detectionResult[1].rawValue, "dogs", "textBlock 2"); |
| } |
| |
| // These tests verify that a Detector's detect() works on an ImageBitmap. |
| // Use the mock mojo server implemented in mock-textdetection.js. |
| generate_tests(createTestForImageBitmap, [ |
| [ |
| "Text - detect(ImageBitmap)", |
| () => { return new TextDetector(); }, |
| mockTextDetection, |
| TextDetectorDetectionResultTest |
| ] |
| ]); |
| |
| </script> |