gecko-dev/testing/web-platform/tests/resources/chromium/mock-facedetection.js
Wanming Lin 39d6e2da87 Bug 1535435 [wpt PR 15761] - Upstream shapedetection tests to WPT, a=testonly
Automatic update from web-platform-tests
Upstream shapedetection tests to WPT

Moved shapedetection 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/, excludes
the Text detection part as which is still a sister informative
specification of Shape Detection.

Copyed third_party/blink/web_tests/shapedetection/resources/big-buffer-helpers.js
to wpt/shape-detection/resources/shapedetection-helpers.js and extended it by
adding a wrapper promise test, detection_test.

Moved third_party/blink/web_tests/shapedetection/resources/mock-barcodedetection.js
and third_party/blink/web_tests/shapedetection/resources/mock-facedetection.js
to wpt/resources/chromium/

Used the testharness from wpt/ and rewrited tests to remove use of
generate_tests as which is discouraged in wpt.

Rewrite detection-on-worker.html as detection-on-worker.worker.js by using
wpt preferred worker test framework.

Rename detection-support.html as detection-getSupportedFormats.html as *-support.html
is treated as support file rather than test file in wpt.

No new tests have been added.

BUG=932382

Change-Id: I321e7b9f986f407b83325bb4c6bdc366c9769264
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1510754
Commit-Queue: Wanming Lin <wanming.lin@intel.com>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Reviewed-by: Reilly Grant <reillyg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#641504}

--

wpt-commits: 7183ea12000b9edaac650b1211c35aa6e0abba88
wpt-pr: 15761
2019-04-24 11:18:03 +01:00

131 lines
4 KiB
JavaScript

"use strict";
var FaceDetectionTest = (() => {
// Class that mocks FaceDetectionProvider interface defined in
// https://cs.chromium.org/chromium/src/services/shape_detection/public/mojom/facedetection_provider.mojom
class MockFaceDetectionProvider {
constructor() {
this.bindingSet_ = new mojo.BindingSet(
shapeDetection.mojom.FaceDetectionProvider);
this.interceptor_ = new MojoInterfaceInterceptor(
shapeDetection.mojom.FaceDetectionProvider.name);
this.interceptor_.oninterfacerequest =
e => this.bindingSet_.addBinding(this, e.handle);
this.interceptor_.start();
}
createFaceDetection(request, options) {
this.mockService_ = new MockFaceDetection(request, options);
}
getFrameData() {
return this.mockService_.bufferData_;
}
getMaxDetectedFaces() {
return this.mockService_.maxDetectedFaces_;
}
getFastMode () {
return this.mockService_.fastMode_;
}
reset() {
this.mockService_ = null;
this.bindingSet_.closeAllBindings();
this.interceptor_.stop();
}
}
// Class that mocks FaceDetection interface defined in
// https://cs.chromium.org/chromium/src/services/shape_detection/public/mojom/facedetection.mojom
class MockFaceDetection {
constructor(request, options) {
this.maxDetectedFaces_ = options.maxDetectedFaces;
this.fastMode_ = options.fastMode;
this.binding_ =
new mojo.Binding(shapeDetection.mojom.FaceDetection,
this, request);
}
detect(bitmapData) {
this.bufferData_ =
new Uint32Array(getArrayBufferFromBigBuffer(bitmapData.pixelData));
return Promise.resolve({
results: [
{
boundingBox: {x: 1.0, y: 1.0, width: 100.0, height: 100.0},
landmarks: [{
type: shapeDetection.mojom.LandmarkType.EYE,
locations: [{x: 4.0, y: 5.0}]
},
{
type: shapeDetection.mojom.LandmarkType.EYE,
locations: [
{x: 4.0, y: 5.0}, {x: 5.0, y: 4.0}, {x: 6.0, y: 3.0},
{x: 7.0, y: 4.0}, {x: 8.0, y: 5.0}, {x: 7.0, y: 6.0},
{x: 6.0, y: 7.0}, {x: 5.0, y: 6.0}
]
}]
},
{
boundingBox: {x: 2.0, y: 2.0, width: 200.0, height: 200.0},
landmarks: [{
type: shapeDetection.mojom.LandmarkType.NOSE,
locations: [{x: 100.0, y: 50.0}]
},
{
type: shapeDetection.mojom.LandmarkType.NOSE,
locations: [
{x: 80.0, y: 50.0}, {x: 70.0, y: 60.0}, {x: 60.0, y: 70.0},
{x: 70.0, y: 60.0}, {x: 80.0, y: 70.0}, {x: 90.0, y: 80.0},
{x: 100.0, y: 70.0}, {x: 90.0, y: 60.0}, {x: 80.0, y: 50.0}
]
}]
},
{
boundingBox: {x: 3.0, y: 3.0, width: 300.0, height: 300.0},
landmarks: []
},
]
});
}
}
let testInternal = {
initialized: false,
MockFaceDetectionProvider: null
}
class FaceDetectionTestChromium {
constructor() {
Object.freeze(this); // Make it immutable.
}
initialize() {
if (testInternal.initialized)
throw new Error('Call reset() before initialize().');
testInternal.MockFaceDetectionProvider = new MockFaceDetectionProvider;
testInternal.initialized = true;
}
// Resets state of face detection mocks between test runs.
async reset() {
if (!testInternal.initialized)
throw new Error('Call initialize() before reset().');
testInternal.MockFaceDetectionProvider.reset();
testInternal.MockFaceDetectionProvider = null;
testInternal.initialized = false;
await new Promise(resolve => setTimeout(resolve, 0));
}
MockFaceDetectionProvider() {
return testInternal.MockFaceDetectionProvider;
}
}
return FaceDetectionTestChromium;
})();