blob: b9669238192bab46c72c9f008c2a186facf20144 [file] [log] [blame]
<!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>
function detectShapeForCanvas(createDetector,
createCanvas,
mock,
detectionResultTest) {
return new Promise(function(resolve, reject) {
var img = new Image();
img.onload = function() {
var canvas = createCanvas();
canvas.getContext("2d").drawImage(img, 0, 0);
var detector = createDetector();
detector.detect(canvas)
.then(detectionResult => {
detectionResultTest(detectionResult, mock);
resolve("Success");
}, error => {
assert_unreached("Error during detect(canvas): " + error);
});
};
img.src = "../media/content/greenbox.png";
});
}
var createTestForCanvasElement = function(createDetector,
createCanvas,
mock,
detectionResultTest) {
promise_test(function() {
return detectShapeForCanvas(createDetector,
createCanvas,
mock,
detectionResultTest)
.then(function(result) {
assert_equals(result, "Success", "Detect 'Success'");
});
});
};
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 HTMLCanvasElement
// and on an OffscreenCanvas. Use the mock mojo server implemented in
// mock-textdetection.js.
generate_tests(createTestForCanvasElement, [
[
"Text - detect(HTMLCanvasElement)",
() => { return new TextDetector(); },
() => { return document.createElement("canvas"); },
mockTextDetection,
TextDetectorDetectionResultTest
],
[
"Text - detect(OffscreenCanvas)",
() => { return new TextDetector(); },
() => { return new OffscreenCanvas(300, 150); },
mockTextDetection,
TextDetectorDetectionResultTest
]
]);
</script>