Commit b32714e6 authored by Wanming Lin's avatar Wanming Lin Committed by Commit Bot

Reland: [shapedetection] Upstream TextDetection tests to WPT

The original CL has been reverted because the test
external/wpt/shape-detection/idlharness.https.any.shareworker.html
is flaky on Mac. This reland CL disables this test on Mac.

Original change's description:
> [shapedetection] Upstream TextDetection tests to WPT
>
> This CL upstreams the reset of shapedetection tests(mainly
> TextDetection tests) to WPT.
>
> - Moves tests under
>   third_party/blink/web_tests/shapedetection/,
>   third_party/blink/web_tests/fast/shapedetection/,
>   third_party/blink/web_tests/http/tests/shapedetection/,
>   to third_party/blink/web_tests/external/wpt/shape-detection.
> - Moves third_party/blink/web_tests/shapedetection/resources/mock-textdetection.js
>   to third_party/blink/web_tests/external/wpt/resources/chromium/.
> - Removes third_party/blink/web_tests/fast/shapedetection/shapedetection-creation.html
>   as which should be covered in idlharness tests.
> - Introduces simulateClosedPipe() to MockBarcodeDetectionProvider to simulate
>   'no implementation available' case for
>   third_party/blink/web_tests/external/wpt/shape-detection/detection-getSupportedFormats.https.html
> - Improves third_party/blink/web_tests/external/wpt/shape-detection/detection-options.https.html
>   by using assert_throws_js BTW.
>
> Bug: 932382
> Change-Id: I2f795e4fa4f23b33c49b7924cdbcbccde5ac6ed4
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2131154
> Reviewed-by: Reilly Grant <reillyg@chromium.org>
> Commit-Queue: Wanming Lin <wanming.lin@intel.com>
> Cr-Commit-Position: refs/heads/master@{#756131}

Bug: 932382, 1067533
Change-Id: I85b5dcc841185e2edd20a76ed3aec8add7f08954
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2134924Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Commit-Queue: Wanming Lin <wanming.lin@intel.com>
Cr-Commit-Position: refs/heads/master@{#756647}
parent 41299540
......@@ -284,6 +284,7 @@ external/wpt/shadow-dom/Element-interface-shadowRoot-attribute.html
external/wpt/shadow-dom/event-with-related-target.html
external/wpt/shadow-dom/untriaged/shadow-trees/upper-boundary-encapsulation/dom-tree-accessors-002.html
external/wpt/shadow-dom/untriaged/styles/test-008.html
external/wpt/shape-detection/shapedetection-empty-input.https.html
external/wpt/streams/byte-length-queuing-strategy.html
external/wpt/streams/piping/close-propagation-backward.html
external/wpt/streams/piping/multiple-propagation.html
......@@ -726,7 +727,6 @@ fast/scrolling/scrollable-area-overflow-not-set.html
fast/selectors/018.html
fast/selectors/061.html
fast/serviceworker/serviceworkercontainer-interface.html
fast/shapedetection/shapedetection-empty-input.html
fast/shapes/crash-caused-by-dirtying-a-shape-while-computing-it-requires-a-long-filename-to-crash.html
fast/shapes/parsing/parsing-shape-property-aliases.html
fast/shapes/shape-outside-floats/shape-outside-floats-ellipse-margin-right.html
......
......@@ -5542,7 +5542,6 @@ crbug.com/942134 [ Win ] virtual/exotic-color-space/images/feature-policy-oversi
crbug.com/943388 [ Win ] http/tests/devtools/network/network-recording-after-reload-with-screenshots-enabled.js [ Pass Failure ]
# Sheriff 2019-03-20
crbug.com/732103 [ Mac10.11 ] http/tests/shapedetection/shapedetection-cross-origin.html [ Timeout Pass ]
crbug.com/943969 [ Win ] inspector-protocol/css/css-get-media-queries.js [ Pass Failure ]
crbug.com/943969 [ Mac10.10 ] inspector-protocol/css/css-get-media-queries.js [ Pass Failure ]
crbug.com/943969 [ Mac10.11 ] inspector-protocol/css/css-get-media-queries.js [ Pass Failure ]
......@@ -6609,3 +6608,5 @@ crbug.com/1066122 virtual/threaded-no-composited-antialiasing/animations/events/
crbug.com/1066732 fast/events/platform-wheelevent-paging-y-in-scrolling-div.html [ Pass Failure ]
# Sheriff 2020-04-02
crbug.com/1067084 virtual/paint-timing/external/wpt/paint-timing/fcp-only/fcp-with-rtl.html [ Pass Failure ]
# Sheriff 2020-04-04
crbug.com/1067533 [ Mac10.10 ] external/wpt/shape-detection/idlharness.https.any.sharedworker.html [ Pass Failure ]
// Content was manually copied April 1 2020
// Source: Accelerated Text Detection in Images (https://wicg.github.io/shape-detection-api/text.html)
// This is currently a sister informative spec of Shape Detection API,
// so it could not be merged into /interfaces/shape-detection-api.idl
[
Constructor,
Exposed=(Window,Worker),
SecureContext
] interface TextDetector {
Promise<sequence<DetectedText>> detect(ImageBitmapSource image);
};
dictionary DetectedText {
required DOMRectReadOnly boundingBox;
required DOMString rawValue;
required FrozenArray<Point2D> cornerPoints;
};
\ No newline at end of file
......@@ -10,9 +10,14 @@ var BarcodeDetectionTest = (() => {
this.interceptor_ = new MojoInterfaceInterceptor(
shapeDetection.mojom.BarcodeDetectionProvider.name);
this.interceptor_.oninterfacerequest =
e => this.bindingSet_.addBinding(this, e.handle);
this.interceptor_.oninterfacerequest = e => {
if (this.should_close_pipe_on_request_)
e.handle.close();
else
this.bindingSet_.addBinding(this, e.handle);
}
this.interceptor_.start();
this.should_close_pipe_on_request_ = false;
}
createBarcodeDetection(request, options) {
......@@ -39,9 +44,15 @@ var BarcodeDetectionTest = (() => {
reset() {
this.mockService_ = null;
this.should_close_pipe_on_request_ = false;
this.bindingSet_.closeAllBindings();
this.interceptor_.stop();
}
// simulate a 'no implementation available' case
simulateNoImplementation() {
this.should_close_pipe_on_request_ = true;
}
}
// Class that mocks BarcodeDetection interface defined in
......
"use strict";
var TextDetectionTest = (() => {
// Class that mocks TextDetection interface defined in
// https://cs.chromium.org/chromium/src/services/shape_detection/public/mojom/textdetection.mojom
class MockTextDetection {
constructor() {
this.bindingSet_ =
new mojo.BindingSet(shapeDetection.mojom.TextDetection);
this.interceptor_ =
new MojoInterfaceInterceptor(shapeDetection.mojom.TextDetection.name);
this.interceptor_.oninterfacerequest =
e => this.bindingSet_.addBinding(this, e.handle);
this.interceptor_.start();
}
detect(bitmapData) {
this.bufferData_ =
new Uint32Array(getArrayBufferFromBigBuffer(bitmapData.pixelData));
return Promise.resolve({
results: [
{
rawValue : "cats",
boundingBox: { x: 1.0, y: 1.0, width: 100.0, height: 100.0 },
cornerPoints: [
{ x: 1.0, y: 1.0 },
{ x: 101.0, y: 1.0 },
{ x: 101.0, y: 101.0 },
{ x: 1.0, y: 101.0 }
]
},
{
rawValue : "dogs",
boundingBox: { x: 2.0, y: 2.0, width: 50.0, height: 50.0 },
cornerPoints: [
{ x: 2.0, y: 2.0 },
{ x: 52.0, y: 2.0 },
{ x: 52.0, y: 52.0 },
{ x: 2.0, y: 52.0 }
]
},
],
});
}
getFrameData() {
return this.bufferData_;
}
reset() {
this.bindingSet_.closeAllBindings();
this.interceptor_.stop();
}
}
let testInternal = {
initialized: false,
MockTextDetection: null
}
class TextDetectionTestChromium {
constructor() {
Object.freeze(this); // Make it immutable.
}
initialize() {
if (testInternal.initialized)
throw new Error('Call reset() before initialize().');
testInternal.MockTextDetection = new MockTextDetection;
testInternal.initialized = true;
}
// Resets state of text detection mocks between test runs.
async reset() {
if (!testInternal.initialized)
throw new Error('Call initialize() before reset().');
testInternal.MockTextDetection.reset();
testInternal.MockTextDetection = null;
testInternal.initialized = false;
await new Promise(resolve => setTimeout(resolve, 0));
}
MockTextDetection() {
return testInternal.MockTextDetection;
}
}
return TextDetectionTestChromium;
})();
Content-Type: text/javascript; charset=utf-8
\ No newline at end of file
The `shapedetection-helpers.js` tests require implementations of
the `FaceDetectionTest` and `BarcodeDetectionTest` interfaces, which
should emulate platform shape detection backends.
the `FaceDetectionTest`, `BarcodeDetectionTest` and `TextDetectionTest`
interfaces, which should emulate platform shape detection backends.
The `FaceDetectionTest` interface is defined as:
......@@ -34,11 +34,30 @@ The `BarcodeDetectionTest` interface is defined as:
async enumerateSupportedFormats(); //Enumerates supported formats
getFrameData(); //Gets frame data of detection result.
getFormats(); //Gets value of `formats` in `BarcodeDetector` constructor
simulateNoImplementation(); // simulate a 'no implementation available' case
};
```
The Chromium implementation of the `BarcodeDetectionTest` interface is located in
[mock-barcodedetection.js](../resources/chromium/mock-barcodedetection.js).
The `TextDetectionTest` interface is defined as:
```
class TextDetectionTest {
async initialize(); // Sets up the testing environment.
async reset(); // Frees the resources.
MockTextDetection(); //Returns `MockTextDetection` interface.
};
class MockTextDetection {
getFrameData(); //Gets frame data of detection result.
};
```
The Chromium implementation of the `TextDetectionTest` interface is located in
[mock-textdetection.js](../resources/chromium/mock-textdetection.js).
Other browser vendors should provide their own implementations of
the `FaceDetectionTest` and `BarcodeDetectionTest` interfaces.
the `FaceDetectionTest`, `BarcodeDetectionTest` and `TextDetectionTest`
interfaces.
......@@ -4,7 +4,7 @@
<script src="resources/shapedetection-helpers.js"></script>
<script>
// These tests verify that detected{Face, Barcode}'s boundingBox
// These tests verify that detected{Face, Barcode, Text}'s boundingBox
// should be DOMRectReadOnly.
const imageDataTests =
[
......@@ -17,6 +17,11 @@ const imageDataTests =
createDetector: () => { return new BarcodeDetector(); },
mockTestName: "BarcodeDetectionTest",
name: "Barcode - detectedBarcode.boundingBox should be DOMRectReadOnly"
},
{
createDetector: () => { return new TextDetector(); },
mockTestName: "TextDetectionTest",
name: "Text - detectedText.boundingBox should be DOMRectReadOnly"
}
];
......
......@@ -4,7 +4,7 @@
<script src="resources/shapedetection-helpers.js"></script>
<script>
// These tests verify that Detected{Face, Barcode} can be passed to
// These tests verify that Detected{Face, Barcode, Text} can be passed to
// postMessage().
const postMessageTests =
[
......@@ -19,7 +19,13 @@ const postMessageTests =
mockTestName: "BarcodeDetectionTest",
detectionResultTest: BarcodeDetectorDetectionResultTest,
name: "Barcode - DetectedBarcode can be passed to postMessage()"
}
},
{
createDetector: () => { return new TextDetector(); },
mockTestName: "TextDetectionTest",
detectionResultTest: TextDetectorDetectionResultTest,
name: "Text - DetectedText can be passed to postMessage()",
},
];
for (let postMessageTest of postMessageTests) {
......@@ -66,4 +72,19 @@ function BarcodeDetectorDetectionResultTest(detectionResult) {
assert_equals(detectionResult[1].format, "code_128", "barcode 2 format");
}
function TextDetectorDetectionResultTest(detectionResult) {
assert_equals(detectionResult.length, 2, "Number of textBlocks");
assert_equals(detectionResult[0].rawValue, "cats", "textBlock 1");
assert_equals(detectionResult[1].rawValue, "dogs", "textBlock 2");
for (let i = 0; i < detectionResult.length; i++) {
assert_equals(detectionResult[i].boundingBox.x, detectionResult[i].cornerPoints[0].x);
assert_equals(detectionResult[i].boundingBox.y, detectionResult[i].cornerPoints[0].y);
assert_equals(detectionResult[i].boundingBox.width,
detectionResult[i].cornerPoints[2].x - detectionResult[i].cornerPoints[3].x);
assert_equals(detectionResult[i].boundingBox.height,
detectionResult[i].cornerPoints[2].y - detectionResult[i].cornerPoints[1].y);
}
}
</script>
......@@ -35,6 +35,20 @@ const canvasElementTests =
mockTestName: "BarcodeDetectionTest",
detectionResultTest: BarcodeDetectorDetectionResultTest,
name: "Barcode - detect(OffscreenCanvas)"
},
{
createDetector: () => { return new TextDetector(); },
createCanvas: () => { return document.createElement("canvas"); },
mockTestName: "TextDetectionTest",
detectionResultTest: TextDetectorDetectionResultTest,
name: "Text - detect(HTMLCanvasElement)"
},
{
createDetector: () => { return new TextDetector(); },
createCanvas: () => { return new OffscreenCanvas(300, 150); },
mockTestName: "TextDetectionTest",
detectionResultTest: TextDetectorDetectionResultTest,
name: "Text - detect(OffscreenCanvas)"
}
];
......@@ -70,4 +84,10 @@ function BarcodeDetectorDetectionResultTest(detectionResult, mockTest) {
assert_equals(detectionResult[1].format, "code_128", "barcode 2 format");
}
function TextDetectorDetectionResultTest(detectionResult, mockTest) {
assert_equals(detectionResult.length, 2, "Number of textBlocks");
assert_equals(detectionResult[0].rawValue, "cats", "textBlock 1");
assert_equals(detectionResult[1].rawValue, "dogs", "textBlock 2");
}
</script>
......@@ -21,6 +21,12 @@ const imageElementTests =
mockTestName: "BarcodeDetectionTest",
detectionResultTest: BarcodeDetectorDetectionResultTest,
name: "Barcode - detect(HTMLImageElement)",
},
{
createDetector: () => { return new TextDetector(); },
mockTestName: "TextDetectionTest",
detectionResultTest: TextDetectorDetectionResultTest,
name: "Text - detect(HTMLImageElement)"
}
];
......@@ -62,4 +68,19 @@ function BarcodeDetectorDetectionResultTest(detectionResult, mockTest) {
assert_equals(detectionResult[1].format, "code_128", "barcode 2 format");
}
function TextDetectorDetectionResultTest(detectionResult, mockTest) {
assert_equals(detectionResult.length, 2, "Number of textBlocks");
assert_equals(detectionResult[0].rawValue, "cats", "textBlock 1");
assert_equals(detectionResult[1].rawValue, "dogs", "textBlock 2");
for (let i = 0; i < detectionResult.length; i++) {
assert_equals(detectionResult[i].boundingBox.x, detectionResult[i].cornerPoints[0].x);
assert_equals(detectionResult[i].boundingBox.y, detectionResult[i].cornerPoints[0].y);
assert_equals(detectionResult[i].boundingBox.width,
detectionResult[i].cornerPoints[2].x - detectionResult[i].cornerPoints[3].x);
assert_equals(detectionResult[i].boundingBox.height,
detectionResult[i].cornerPoints[2].y - detectionResult[i].cornerPoints[1].y);
}
}
</script>
......@@ -17,7 +17,13 @@ const videoElementTests =
createDetector: () => { return new BarcodeDetector(); },
mockTestName: "BarcodeDetectionTest",
detectionResultTest: BarcodeDetectorDetectionResultTest,
name: "Barcode - detect(HTMLVideoElement)",
name: "Barcode - detect(HTMLVideoElement)"
},
{
createDetector: () => { return new TextDetector(); },
mockTestName: "TextDetectionTest",
detectionResultTest: TextDetectorDetectionResultTest,
name: "Text - detect(HTMLVideoElement)"
}
];
......@@ -52,4 +58,10 @@ function BarcodeDetectorDetectionResultTest(detectionResult, mockTest) {
assert_equals(detectionResult[1].format, "code_128", "barcode 2 format");
}
function TextDetectorDetectionResultTest(detectionResult, mockTest) {
assert_equals(detectionResult.length, 2, "Number of textBlocks");
assert_equals(detectionResult[0].rawValue, "cats", "textBlock 1");
assert_equals(detectionResult[1].rawValue, "dogs", "textBlock 2");
}
</script>
......@@ -17,7 +17,13 @@ const imageBitmapTests =
createDetector: () => { return new BarcodeDetector(); },
mockTestName: "BarcodeDetectionTest",
detectionResultTest: BarcodeDetectorDetectionResultTest,
name: "Barcode - detect(ImageBitmap)",
name: "Barcode - detect(ImageBitmap)"
},
{
createDetector: () => { return new TextDetector(); },
mockTestName: "TextDetectionTest",
detectionResultTest: TextDetectorDetectionResultTest,
name: "Text - detect(ImageBitmap)",
}
];
......@@ -51,4 +57,10 @@ function BarcodeDetectorDetectionResultTest(detectionResult, mockTest) {
assert_equals(detectionResult[1].format, "code_128", "barcode 2 format");
}
function TextDetectorDetectionResultTest(detectionResult, mockTest) {
assert_equals(detectionResult.length, 2, "Number of textBlocks");
assert_equals(detectionResult[0].rawValue, "cats", "textBlock 1");
assert_equals(detectionResult[1].rawValue, "dogs", "textBlock 2");
}
</script>
......@@ -31,4 +31,16 @@ promise_test(async () => {
}
}, 'BarcodeDetector.detect() rejects on a detached buffer');
promise_test(async () => {
let data = new ImageData(1024, 1024);
detachBuffer(data.data.buffer);
let detector = new TextDetector();
try {
await detector.detect(data);
assert_unreached();
} catch (e) {
assert_equals(e.code, DOMException.INVALID_STATE_ERR);
}
}, 'TextDetector.detect() rejects on a detached buffer');
</script>
......@@ -18,6 +18,12 @@ const imageDataTests =
mockTestName: "BarcodeDetectionTest",
detectionResultTest: BarcodeDetectorDetectionResultTest,
name: "Barcode - detect(ImageData)"
},
{
createDetector: () => { return new TextDetector(); },
mockTestName: "TextDetectionTest",
detectionResultTest: TextDetectorDetectionResultTest,
name: "Text - detect(ImageData)",
}
];
......@@ -53,4 +59,10 @@ function BarcodeDetectorDetectionResultTest(detectionResult, mockTest) {
assert_equals(detectionResult[1].format, "code_128", "barcode 2 format");
}
function TextDetectorDetectionResultTest(detectionResult, mockTest) {
assert_equals(detectionResult.length, 2, "Number of textBlocks");
assert_equals(detectionResult[0].rawValue, "cats", "textBlock 1");
assert_equals(detectionResult[1].rawValue, "dogs", "textBlock 2");
}
</script>
......@@ -13,4 +13,13 @@ detection_test('BarcodeDetectionTest', async t => {
assert_equals(result[2], 'qr_code', 'format 3');
}, 'get supported barcode formats');
detection_test('BarcodeDetectionTest', async (t, detectionTest) => {
// Disable built-in support for barcode detection to test fallback handling.
detectionTest.MockBarcodeDetectionProvider().simulateNoImplementation();
const result = await BarcodeDetector.getSupportedFormats();
assert_equals(result.length, 0, 'result.length');
}, 'getSupportedFormats() resolves with empty list when unsupported');
</script>
......@@ -18,6 +18,12 @@ const imageBitmapTests =
mockTestName: "BarcodeDetectionTest",
resultSize: 2, // Number of barcodes
detectorType: "Barcode"
},
{
createDetector: () => { return new TextDetector(); },
mockTestName: "TextDetectionTest",
resultSize: 2, // Number of text blocks
detectorType: "Text"
}
];
......
......@@ -40,27 +40,16 @@ detection_test("BarcodeDetectionTest", async (t, detectionTest) => {
shapeDetection.mojom.BarcodeFormat.QR_CODE],
"formats");
try {
new BarcodeDetector({formats: []});
assert_unreached("providing hint option that is empty should fail");
} catch (error) {
assert_equals(error.name, "TypeError");
}
const invalidFormats = [
[],
["unknown"],
["foo", "bar"]
];
try {
new BarcodeDetector({formats: ["unknown"]});
assert_unreached("providing \"unknown\" as a hint option should fail");
} catch (error) {
assert_equals(error.name, "TypeError");
}
invalidFormats.forEach(invalidFormat => {
assert_throws_js(TypeError, () => new BarcodeDetector({formats: invalidFormat}));
});
try {
new BarcodeDetector({formats: ["foo", "bar"]});
assert_unreached(
"providing hint option with unrecognized formats should fail");
} catch (error) {
assert_equals(error.name, "TypeError");
}
}, "Test that BarcodeDetectorOptions are correctly propagated");
</script>
......@@ -13,7 +13,11 @@ const badImageTests =
},
{
createDetector: () => { return new BarcodeDetector(); },
name: "Barcode - detect(broken image)",
name: "Barcode - detect(broken image)"
},
{
createDetector: () => { return new TextDetector(); },
name: "Text - detect(broken image)"
}
];
......@@ -38,6 +42,10 @@ const badVideoTests =
{
createDetector: () => { return new BarcodeDetector(); },
name: "Barcode - detect(broken video)"
},
{
createDetector: () => { return new TextDetector(); },
name: "Text - detect(broken video)"
}
];
......
......@@ -4,7 +4,7 @@
<script src="resources/shapedetection-helpers.js"></script>
<script>
// These tests verify that detect()ed Detected{Barcode,Face}'s individual
// These tests verify that detect()ed Detected{Barcode,Face, Text}'s individual
// fields are [SameObject].
const imageDataTests =
[
......@@ -19,6 +19,12 @@ const imageDataTests =
mockTestName: "BarcodeDetectionTest",
detectionResultTest: CheckDetectedBarcodesSameObjects,
name: "Barcode - detect(ImageData), [SameObject]"
},
{
createDetector: () => { return new TextDetector(); },
mockTestName: "TextDetectionTest",
detectionResultTest: CheckDetectedTextBlocksSameObjects,
name: "Text - detect(ImageData), [SameObject]",
}
];
......@@ -52,4 +58,10 @@ function CheckDetectedBarcodesSameObjects(detectedBarcodes) {
assert_equals(detectedBarcodes[0].cornerPoints, detectedBarcodes[0].cornerPoints);
}
function CheckDetectedTextBlocksSameObjects(detectedTextBlocks) {
assert_greater_than(detectedTextBlocks.length, 0, "Number of textBlocks");
assert_equals(detectedTextBlocks[0].rawValue, detectedTextBlocks[0].rawValue);
assert_equals(detectedTextBlocks[0].boundingBox, detectedTextBlocks[0].boundingBox);
}
</script>
......@@ -7,12 +7,13 @@
'use strict';
idl_test(
['shape-detection-api'],
['shape-detection-api', 'text-detection-api.tentative'],
['dom', 'geometry'],
async idl_array => {
idl_array.add_objects({
FaceDetector: ['new FaceDetector()'],
BarcodeDetector: ['new BarcodeDetector()'],
TextDetector: ['new TextDetector()'],
});
}
);
......@@ -28,8 +28,10 @@ let loadChromiumResources = Promise.resolve().then(() => {
`${prefix}/barcodedetection_provider.mojom.js`,
`${prefix}/facedetection.mojom.js`,
`${prefix}/facedetection_provider.mojom.js`,
`${prefix}/textdetection.mojom.js`,
'/resources/chromium/mock-barcodedetection.js',
'/resources/chromium/mock-facedetection.js',
'/resources/chromium/mock-textdetection.js',
].forEach(path => {
// Use importScripts for workers.
if (typeof document === 'undefined') {
......@@ -51,7 +53,8 @@ let loadChromiumResources = Promise.resolve().then(() => {
/**
* @param {String} detectionTestName
* name of mock shape detection test interface,
* must be the item of ["FaceDetectionTest", "BarcodeDetectionTest"]
* must be the item of ["FaceDetectionTest", "BarcodeDetectionTest",
* "TextDetectionTest"]
*/
async function initialize_detection_tests(detectionTestName) {
let detectionTest;
......
......@@ -18,6 +18,10 @@ const crossOriginTests =
{
createDetector: () => { return new BarcodeDetector(); },
detectorType: "BarcodeDetector"
},
{
createDetector: () => { return new TextDetector(); },
detectorType: "TextDetector"
}
];
......
......@@ -14,6 +14,10 @@ const emptyInputTests =
{
createDetector: () => { return new BarcodeDetector(); },
name: "Barcode - detect(empty)"
},
{
createDetector: () => { return new TextDetector(); },
name: "Text - detect(empty)"
}
];
......
<!DOCTYPE html>
<script src=../../resources/testharness.js></script>
<script src=../../resources/testharnessreport.js></script>
<script>
// This test verifies that TextDetector can be created
test(function() {
var textDetector = new TextDetector();
assert_true(textDetector instanceof TextDetector);
}, 'TextDetector instance can be created.');
</script>
<!DOCTYPE html>
<script src=../../resources/testharness.js></script>
<script src=../../resources/testharnessreport.js></script>
<script>
// This test verifies TextDetector.detect() returns an empty list when fed with
// an empty HTMLImageElement.
async_test(function(t) {
var image = new Image();
var detector = new TextDetector();
var tryDetection = function() {
detector.detect(image)
.then(detectionResult => {
assert_equals(detectionResult.length, 0);
t.done();
})
.catch(error => {
assert_unreached("detect() rejected with error: " + error)
});
};
image.onload = tryDetection;
image.onerror = tryDetection;
image.src = "";
}, "Text - detect(empty)");
</script>
<!DOCTYPE html>
<script src=../../../../resources/testharness.js></script>
<script src=../../../../resources/testharnessreport.js></script>
<script>
// http:// resources are considered cross-origin from the current file://.
const IMAGE_URL = "http://localhost:8080/security/resources/abe.png";
const VIDEO_URL = "http://localhost:8080/external/wpt/media/white.webm";
// Returns a Promise that is resolve()d if detect() is rejected. Needs an input
// |element| (e.g. an HTMLImageElement or HTMLVideoElement) and a |url| to load.
function detectTextOnElementAndExpectError(element, url) {
return new Promise(function(resolve, reject) {
var tryTextDetection = function() {
var textDetector = new TextDetector();
textDetector.detect(element)
.then(textDetectionResult => {
reject("Promise should have been rejected.");
})
.catch(error => {
resolve(error);
});
};
element.onload = tryTextDetection;
element.onerror = tryTextDetection;
element.src = url;
});
}
function detectTextOnImageBitmapAndExpectError(imageUrl) {
return new Promise(function(resolve, reject) {
var image = new Image();
image.onload = function() {
createImageBitmap(image)
.then(imageBitmap => {
var textDetector = new TextDetector();
return textDetector.detect(imageBitmap);
})
.then(textDetectionResult => {
reject("Promise should have been rejected.");
})
.catch(error => {
resolve(error);
});
};
image.onerror = () => {}; // Explicitly ignore expected error events.
image.src = imageUrl;
});
}
// Verifies that TextDetector rejects a cross-origin HTMLImageElement.
promise_test(function(t) {
var image = new Image();
return detectTextOnElementAndExpectError(image, IMAGE_URL)
.then(error => {
assert_equals(error.name, "SecurityError");
});
},
"TextDetector should reject cross-origin HTMLImageElements with a SecurityError.");
// Verifies that TextDetector rejects a cross-origin ImageBitmap.
promise_test(function(t) {
return detectTextOnImageBitmapAndExpectError(IMAGE_URL)
.then(error => {
assert_equals(error.name, "SecurityError");
});
},
"TextDetector should reject cross-origin ImageBitmaps with a SecurityError.");
// Verifies that TextDetector rejects a cross-origin HTMLVideoElement.
promise_test(function(t) {
var video = document.createElement('video');
return detectTextOnElementAndExpectError(video, VIDEO_URL)
.then(error => {
assert_equals(error.name, "SecurityError");
});
},
"TextDetector should reject cross-origin HTMLVideoElements with a SecurityError.");
</script>
<!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/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>
const createTestForImageData = (createDetector, mock, detectionResultTest) => {
async_test(t => {
const img = new Image();
img.onload = async() => {
const canvas = document.createElement("canvas");;
canvas.getContext("2d").drawImage(img, 0, 0);
const detector = createDetector();
try {
const detectionResult = await detector.detect(canvas.getContext("2d")
.getImageData(0, 0, canvas.width, canvas.height));
detectionResultTest(detectionResult);
t.done();
} catch(error) {
assert_unreached("Error during detect(canvas): " + error);
}
}
img.src = "../media/content/greenbox.png";
});
};
function CheckDetectedReadOnlyBoundingBoxes(detectedObjects) {
var properties = ['x', 'y', 'width', 'height', 'top', 'right', 'bottom', 'left'];
detectedObjects.forEach(detectedObject => {
properties.forEach(property => {
assert_readonly(detectedObject.boundingBox, property);
});
});
}
// These tests verify that detected Text's boundingBox should be DOMRectReadOnly.
generate_tests(createTestForImageData, [
[
"Text - detectedText.boundingBox should be DOMRectReadOnly",
() => { return new TextDetector(); },
mockTextDetection,
CheckDetectedReadOnlyBoundingBoxes
]
]);
</script>
<!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/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>
const createTestForPostMessage = (createDetector, mock, detectionResultTest) => {
async_test(t => {
const img = new Image();
img.onload = async() => {
const canvas = document.createElement("canvas");;
canvas.getContext("2d").drawImage(img, 0, 0);
const detector = createDetector();
try {
const detectionResult = await detector.detect(canvas.getContext("2d")
.getImageData(0, 0, canvas.width, canvas.height));
const msgWatcher = new EventWatcher(t, window, ['message']);
window.postMessage(detectionResult);
const evt = await msgWatcher.wait_for('message');
detectionResultTest(evt.data);
t.done();
} catch(error) {
assert_unreached("Error during detect(canvas): " + error);
}
}
img.src = "../media/content/greenbox.png";
});
};
function CheckDetectedReadOnlyBoundingBoxes(detectionResult) {
assert_equals(detectionResult.length, 2, "Number of textBlocks");
assert_equals(detectionResult[0].rawValue, "cats", "textBlock 1");
assert_equals(detectionResult[1].rawValue, "dogs", "textBlock 2");
for (i = 0; i < detectionResult.length; i++) {
assert_equals(detectionResult[i].boundingBox.x, detectionResult[i].cornerPoints[0].x);
assert_equals(detectionResult[i].boundingBox.y, detectionResult[i].cornerPoints[0].y);
assert_equals(detectionResult[i].boundingBox.width,
detectionResult[i].cornerPoints[2].x - detectionResult[i].cornerPoints[3].x);
assert_equals(detectionResult[i].boundingBox.height,
detectionResult[i].cornerPoints[2].y - detectionResult[i].cornerPoints[1].y);
}
}
// These tests verify that a DetectedText can be passed to postMessage().
generate_tests(createTestForPostMessage, [
[
"Text - DetectedText can be passed to postMessage()",
() => { return new TextDetector(); },
mockTextDetection,
CheckDetectedReadOnlyBoundingBoxes
]
]);
</script>
<!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>
<!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>
<body>
<img id="img" src="../media/content/greenbox.png"/>
</body>
<script>
var createTestForImageElement = function(createDetector, mock,
detectionResultTest) {
promise_test(async function() {
var img = document.getElementById("img");
var detector = createDetector();
try {
var detectionResult = await detector.detect(img);
detectionResultTest(detectionResult, mock);
} catch(error) {
assert_unreached("Error during detect(img): " + error);
}
});
};
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");
for (i = 0; i < detectionResult.length; i++) {
assert_equals(detectionResult[i].boundingBox.x, detectionResult[i].cornerPoints[0].x);
assert_equals(detectionResult[i].boundingBox.y, detectionResult[i].cornerPoints[0].y);
assert_equals(detectionResult[i].boundingBox.width,
detectionResult[i].cornerPoints[2].x - detectionResult[i].cornerPoints[3].x);
assert_equals(detectionResult[i].boundingBox.height,
detectionResult[i].cornerPoints[2].y - detectionResult[i].cornerPoints[1].y);
}
}
// These tests verify that a Detector's detect() works on an HTMLImageElement.
// Use the mock mojo server implemented in mock-textdetection.js.
generate_tests(createTestForImageElement, [
[
"Text - detect(HTMLImageElement)",
() => { return new TextDetector(); },
mockTextDetection,
TextDetectorDetectionResultTest
]
]);
</script>
<!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 createTestForVideoElement = function(createDetector, mock,
detectionResultTest) {
async_test(function(t) {
var video = document.createElement("video");
video.src = "../external/wpt/media/white.webm";
video.loop = true;
video.autoplay = true;
video.onerror = this.unreached_func("<video> error");
video.onplay = this.step_func(async function() {
var detector = createDetector();
try {
var detectionResult = await detector.detect(video);
detectionResultTest(detectionResult, mock);
t.done();
} catch (error) {
assert_unreached("Error during detect(video): " + error);
}
});
video.load();
});
};
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 HTMLVideoElement.
// Use the mock mojo server implemented in mock-textdetection.js.
generate_tests(createTestForVideoElement, [
[
"Text - detect(HTMLVideoElement)",
() => { return new TextDetector(); },
mockTextDetection,
TextDetectorDetectionResultTest
]
]);
</script>
<!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>
<!DOCTYPE html>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script>
function detachBuffer(buffer) {
window.postMessage('', '*', [buffer]);
}
promise_test(async () => {
let data = new ImageData(1024, 1024);
detachBuffer(data.data.buffer);
let detector = new TextDetector();
try {
await detector.detect(data);
assert_unreached();
} catch (e) {
assert_equals(e.code, DOMException.INVALID_STATE_ERR);
}
}, 'TextDetector.detect() rejects on a detached buffer');
</script>
<!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 createTestForImageData = function(createDetector, mock,
detectionResultTest) {
async_test(async function(t) {
var img = new Image();
img.onload = async function() {
var canvas = document.createElement("canvas");;
canvas.getContext("2d").drawImage(img, 0, 0);
var detector = createDetector();
try {
var detectionResult = await detector.detect(canvas.getContext("2d")
.getImageData(0, 0, canvas.width, canvas.height));
detectionResultTest(detectionResult, mock);
t.done();
} catch (error) {
assert_unreached("Error during detect(canvas): " + 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(createTestForImageData, [
[
"Text - detect(ImageData)",
() => { return new TextDetector(); },
mockTextDetection,
TextDetectorDetectionResultTest
]
]);
</script>
<!DOCTYPE html>
<link rel="help" href="https://wicg.github.io/shape-detection-api/#dom-barcodedetector-getsupportedformats">
<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/services/shape_detection/public/mojom/barcodedetection_provider.mojom.js"></script>
<script>
promise_test(async t => {
// Disable built-in support for barcode detection to test fallback handling.
const interceptor = new MojoInterfaceInterceptor(
shapeDetection.mojom.BarcodeDetectionProvider.name);
interceptor.oninterfacerequest = e => e.handle.close();
interceptor.start();
const result = await BarcodeDetector.getSupportedFormats();
assert_equals(result.length, 0, 'result.length');
interceptor.stop();
}, 'getSupportedFormats() resolves with empty list when unsupported');
</script>
<!DOCTYPE html>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script>
// ImageBitmap is of transferable type and can be sent to and tested on worker.
var createTestForImageBitmap = function(detectorType, resultSize) {
async_test(function(t) {
let img = new Image();
img.onload = async function() {
let theImageBitmap = await createImageBitmap(img);
let worker = new Worker("resources/worker.js");
worker.postMessage({
detectorType: detectorType,
bitmap: theImageBitmap,
expectedLength: resultSize
}, [theImageBitmap]);
worker.onmessage = function(e) {
if(e.data=="PASS")
t.done();
}
}
img.src = "../media/content/greenbox.png";
}, detectorType + "Detector detect(ImageBitmap) on worker");
};
// These tests verify that a Detector's detect() works on an ImageBitmap on
// workers. Use the mock mojo server implemented in mock-textdetection.js.
generate_tests(createTestForImageBitmap, [
[
"Text",
"Text",
2 // Number of text blocks
]
]);
</script>
<!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>
// Returns a Promise that is resolve()d if detect() is rejected. Needs an input
// |element| (e.g. an HTMLImageElement or HTMLVideoElement) and a |url| to load.
function detectOnElementAndExpectError(createDetector, element, url) {
return new Promise(function(resolve, reject) {
var tryDetection = async function() {
var detector = createDetector();
try {
var detectionResult = await detector.detect(element);
reject("Promise should have been rejected.");
} catch (error) {
resolve(error);
}
};
element.onload = tryDetection;
element.onerror = tryDetection;
element.src = url;
});
};
// This test verifies that a Detector will reject an undecodable image.
var createTestForBadImage = function(createDetector) {
promise_test(function(t) {
var image = new Image();
return detectOnElementAndExpectError(createDetector, image,
"../external/wpt/images/broken.png")
.then(function(error) {
assert_equals(error.name, "InvalidStateError");
});
});
};
// Detectors should reject undecodable images with an InvalidStateError.
generate_tests(createTestForBadImage, [
[ "Text - detect(broken image)", () => { return new TextDetector(); } ]
]);
// This test verifies that a Detector will reject a broken video.
var createTestForBadVideo = function(createDetector) {
promise_test(function(t) {
var video = document.createElement('video');
return detectOnElementAndExpectError(createDetector, video,
"content/garbage.webm")
.then(function(error) {
assert_equals(error.name, "InvalidStateError");
});
});
};
// Detectors should reject undecodable videos with an InvalidStateError.
generate_tests(createTestForBadVideo, [
[ "Text - detect(broken video)", () => { return new TextDetector(); } ]
]);
</script>
<!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 createTestForImageData = function(createDetector, mock,
detectionResultTest) {
async_test(function(t) {
var img = new Image();
img.onload = async function() {
var canvas = document.createElement("canvas");;
canvas.getContext("2d").drawImage(img, 0, 0);
var detector = createDetector();
try {
var detectionResult = await detector.detect(canvas.getContext("2d")
.getImageData(0, 0, canvas.width, canvas.height));
detectionResultTest(detectionResult);
t.done();
} catch(error) {
assert_unreached("Error during detect(canvas): " + error);
}
}
img.src = "../media/content/greenbox.png";
});
};
function CheckDetectedTextBlocksSameObjects(detectedTextBlocks) {
assert_greater_than(detectedTextBlocks.length, 0, "Number of textBlocks");
assert_equals(detectedTextBlocks[0].rawValue, detectedTextBlocks[0].rawValue);
assert_equals(detectedTextBlocks[0].boundingBox, detectedTextBlocks[0].boundingBox);
}
// These tests verify that detect()ed Detected Text's individual
// fields are [SameObject].
generate_tests(createTestForImageData, [
[
"Text - detect(ImageData), [SameObject]",
() => { return new TextDetector(); },
mockTextDetection,
CheckDetectedTextBlocksSameObjects
]
]);
</script>
"use strict";
function getArrayBufferFromBigBuffer(bigBuffer) {
if (bigBuffer.$tag == mojoBase.mojom.BigBuffer.Tags.bytes) {
return new Uint8Array(bigBuffer.bytes).buffer;
}
return bigBuffer.sharedMemory.bufferHandle.mapBuffer(0,
bigBuffer.sharedMemory.size).buffer;
}
"use strict";
class MockTextDetection {
constructor() {
this.bindingSet_ =
new mojo.BindingSet(shapeDetection.mojom.TextDetection);
this.interceptor_ =
new MojoInterfaceInterceptor(shapeDetection.mojom.TextDetection.name);
this.interceptor_.oninterfacerequest =
e => this.bindingSet_.addBinding(this, e.handle);
this.interceptor_.start();
}
detect(bitmapData) {
this.bufferData_ =
new Uint32Array(getArrayBufferFromBigBuffer(bitmapData.pixelData));
return Promise.resolve({
results: [
{
rawValue : "cats",
boundingBox: { x: 1.0, y: 1.0, width: 100.0, height: 100.0 },
cornerPoints: [
{ x: 1.0, y: 1.0 },
{ x: 101.0, y: 1.0 },
{ x: 101.0, y: 101.0 },
{ x: 1.0, y: 101.0 }
]
},
{
rawValue : "dogs",
boundingBox: { x: 2.0, y: 2.0, width: 50.0, height: 50.0 },
cornerPoints: [
{ x: 2.0, y: 2.0 },
{ x: 52.0, y: 2.0 },
{ x: 52.0, y: 52.0 },
{ x: 2.0, y: 52.0 }
]
},
],
});
}
getFrameData() {
return this.bufferData_;
}
}
let mockTextDetection = new MockTextDetection();
importScripts("../../resources/testharness.js");
importScripts("file:///gen/layout_test_data/mojo/public/js/mojo_bindings.js");
importScripts("file:///gen/mojo/public/mojom/base/big_buffer.mojom.js");
importScripts("file:///gen/skia/public/mojom/image_info.mojom.js");
importScripts("file:///gen/skia/public/mojom/bitmap.mojom.js");
importScripts("file:///gen/ui/gfx/geometry/mojom/geometry.mojom.js");
importScripts("file:///gen/services/shape_detection/public/mojom/textdetection.mojom.js");
importScripts("big-buffer-helpers.js");
importScripts("mock-textdetection.js");
onmessage = async function(e) {
let detector;
switch (e.data.detectorType) {
case "Face": detector = new FaceDetector(); break;
case "Barcode": detector = new BarcodeDetector(); break;
case "Text": detector = new TextDetector(); break;
}
let imageBitmap = e.data.bitmap;
try {
let detectionResult = await detector.detect(imageBitmap);
assert_equals(detectionResult.length, e.data.expectedLength,
"Number of " + e.data.detectorType);
postMessage("PASS");
} catch (error) {
assert_unreached("Error during detect(img): " + error);
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment