Chromium Code Reviews| Index: third_party/WebKit/LayoutTests/shapedetection/resources/mock-textdetection.js |
| diff --git a/third_party/WebKit/LayoutTests/shapedetection/resources/mock-textdetection.js b/third_party/WebKit/LayoutTests/shapedetection/resources/mock-textdetection.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..7053b1a8a44fe395f7e37c92dd9094e709c96324 |
| --- /dev/null |
| +++ b/third_party/WebKit/LayoutTests/shapedetection/resources/mock-textdetection.js |
| @@ -0,0 +1,48 @@ |
| +"use strict"; |
| + |
| +let mockTextDetectionReady = define( |
| + 'mockTextDetection', |
| + ['third_party/WebKit/public/platform/modules/shapedetection/textdetection.mojom', |
| + 'mojo/public/js/bindings', |
| + 'mojo/public/js/connection', |
| + 'mojo/public/js/core', |
| + 'content/public/renderer/frame_interfaces', |
| + ], (textDetection, bindings, connection, mojo, interfaces) => { |
| + |
| + class MockTextDetection { |
| + constructor() { |
| + interfaces.addInterfaceOverrideForTesting( |
| + textDetection.TextDetection.name, |
| + pipe => this.bindToPipe(pipe)); |
| + } |
| + |
| + bindToPipe(pipe) { |
| + this.stub_ = connection.bindHandleToStub(pipe, |
| + textDetection.TextDetection); |
|
Reilly Grant (use Gerrit)
2016/12/23 02:24:28
yzshen@ recently sent me a patch with a new API fo
xianglu
2017/01/03 20:47:27
Done.
|
| + bindings.StubBindings(this.stub_).delegate = this; |
| + } |
| + |
| + detect(frame_data, width, height) { |
| + let receivedStruct = mojo.mapBuffer(frame_data, 0, width*height*4, 0); |
| + this.buffer_data_ = new Uint32Array(receivedStruct.buffer); |
| + return Promise.resolve({ |
| + results: [ |
| + { |
| + raw_value : "cats", |
| + bounding_box: { x: 1.0, y: 1.0, width: 100.0, height: 100.0 } |
| + }, |
| + { |
| + raw_value : "dogs", |
| + bounding_box: { x: 2.0, y: 2.0, width: 50.0, height: 50.0 } |
| + }, |
| + ], |
| + }); |
| + mojo.unmapBuffer(receivedStruct.buffer); |
| + } |
| + |
| + getFrameData() { |
| + return this.buffer_data_; |
| + } |
| + } |
| + return new MockTextDetection(); |
| +}); |