mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-11-11 21:58:41 +02:00
Automatic update from web-platform-tests 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/+/2134924 Reviewed-by: Reilly Grant <reillyg@chromium.org> Commit-Queue: Wanming Lin <wanming.lin@intel.com> Cr-Commit-Position: refs/heads/master@{#756647} -- wpt-commits: dfc0080d132ac25c4cf824a25735203b3a2b6853 wpt-pr: 22690
135 lines
4 KiB
JavaScript
135 lines
4 KiB
JavaScript
"use strict";
|
|
|
|
var BarcodeDetectionTest = (() => {
|
|
// Class that mocks BarcodeDetectionProvider interface defined in
|
|
// https://cs.chromium.org/chromium/src/services/shape_detection/public/mojom/barcodedetection_provider.mojom
|
|
class MockBarcodeDetectionProvider {
|
|
constructor() {
|
|
this.bindingSet_ = new mojo.BindingSet(
|
|
shapeDetection.mojom.BarcodeDetectionProvider);
|
|
|
|
this.interceptor_ = new MojoInterfaceInterceptor(
|
|
shapeDetection.mojom.BarcodeDetectionProvider.name);
|
|
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) {
|
|
this.mockService_ = new MockBarcodeDetection(request, options);
|
|
}
|
|
|
|
enumerateSupportedFormats() {
|
|
return Promise.resolve({
|
|
supportedFormats: [
|
|
shapeDetection.mojom.BarcodeFormat.AZTEC,
|
|
shapeDetection.mojom.BarcodeFormat.DATA_MATRIX,
|
|
shapeDetection.mojom.BarcodeFormat.QR_CODE,
|
|
]
|
|
});
|
|
}
|
|
|
|
getFrameData() {
|
|
return this.mockService_.bufferData_;
|
|
}
|
|
|
|
getFormats() {
|
|
return this.mockService_.options_.formats;
|
|
}
|
|
|
|
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
|
|
// https://cs.chromium.org/chromium/src/services/shape_detection/public/mojom/barcodedetection.mojom
|
|
class MockBarcodeDetection {
|
|
constructor(request, options) {
|
|
this.options_ = options;
|
|
this.binding_ =
|
|
new mojo.Binding(shapeDetection.mojom.BarcodeDetection,
|
|
this, request);
|
|
}
|
|
|
|
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 },
|
|
format: shapeDetection.mojom.BarcodeFormat.QR_CODE,
|
|
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 },
|
|
format: shapeDetection.mojom.BarcodeFormat.CODE_128,
|
|
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 }
|
|
],
|
|
},
|
|
],
|
|
});
|
|
}
|
|
}
|
|
|
|
let testInternal = {
|
|
initialized: false,
|
|
MockBarcodeDetectionProvider: null
|
|
}
|
|
|
|
class BarcodeDetectionTestChromium {
|
|
constructor() {
|
|
Object.freeze(this); // Make it immutable.
|
|
}
|
|
|
|
initialize() {
|
|
if (testInternal.initialized)
|
|
throw new Error('Call reset() before initialize().');
|
|
|
|
testInternal.MockBarcodeDetectionProvider = new MockBarcodeDetectionProvider;
|
|
testInternal.initialized = true;
|
|
}
|
|
|
|
// Resets state of barcode detection mocks between test runs.
|
|
async reset() {
|
|
if (!testInternal.initialized)
|
|
throw new Error('Call initialize() before reset().');
|
|
testInternal.MockBarcodeDetectionProvider.reset();
|
|
testInternal.MockBarcodeDetectionProvider = null;
|
|
testInternal.initialized = false;
|
|
|
|
await new Promise(resolve => setTimeout(resolve, 0));
|
|
}
|
|
|
|
MockBarcodeDetectionProvider() {
|
|
return testInternal.MockBarcodeDetectionProvider;
|
|
}
|
|
}
|
|
|
|
return BarcodeDetectionTestChromium;
|
|
})();
|