| OLD | NEW |
| 1 "use strict"; | 1 "use strict"; |
| 2 | 2 |
| 3 let mockFaceDetectionProviderReady = define( | 3 let mockFaceDetectionProviderReady = define( |
| 4 'mockFaceDetectionProvider', | 4 'mockFaceDetectionProvider', |
| 5 ['third_party/WebKit/public/platform/modules/shapedetection/facedetection.mojo
m', | 5 ['third_party/WebKit/public/platform/modules/shapedetection/facedetection.mojo
m', |
| 6 'third_party/WebKit/public/platform/modules/shapedetection/facedetection_prov
ider.mojom', | 6 'third_party/WebKit/public/platform/modules/shapedetection/facedetection_prov
ider.mojom', |
| 7 'mojo/public/js/bindings', | 7 'mojo/public/js/bindings', |
| 8 'mojo/public/js/connection', |
| 8 'mojo/public/js/core', | 9 'mojo/public/js/core', |
| 9 'content/public/renderer/frame_interfaces', | 10 'content/public/renderer/frame_interfaces', |
| 10 ], (faceDetection, faceDetectionProvider, bindings, mojo, interfaces) => { | 11 ], (faceDetection, faceDetectionProvider, bindings, connection, mojo, interfac
es) => { |
| 11 | 12 |
| 12 class MockFaceDetectionProvider { | 13 class MockFaceDetectionProvider { |
| 13 constructor() { | 14 constructor() { |
| 14 this.bindingSet_ = new bindings.BindingSet( | |
| 15 faceDetectionProvider.FaceDetectionProvider); | |
| 16 | |
| 17 interfaces.addInterfaceOverrideForTesting( | 15 interfaces.addInterfaceOverrideForTesting( |
| 18 faceDetectionProvider.FaceDetectionProvider.name, | 16 faceDetectionProvider.FaceDetectionProvider.name, |
| 19 handle => this.bindingSet_.addBinding(this, handle)); | 17 pipe => this.bindToPipe(pipe)); |
| 18 } |
| 19 |
| 20 bindToPipe(pipe) { |
| 21 this.stub_ = connection.bindHandleToStub( |
| 22 pipe, faceDetectionProvider.FaceDetectionProvider); |
| 23 bindings.StubBindings(this.stub_).delegate = this; |
| 20 } | 24 } |
| 21 | 25 |
| 22 createFaceDetection(request, options) { | 26 createFaceDetection(request, options) { |
| 23 this.mock_service_ = new MockFaceDetection(request, options); | 27 this.mock_service_ = new MockFaceDetection(options); |
| 28 this.mock_service_.stub_ = connection.bindHandleToStub( |
| 29 request.handle, faceDetection.FaceDetection); |
| 30 bindings.StubBindings(this.mock_service_.stub_).delegate = |
| 31 this.mock_service_; |
| 24 } | 32 } |
| 25 | 33 |
| 26 getFrameData() { | 34 getFrameData() { |
| 27 return this.mock_service_.buffer_data_; | 35 return this.mock_service_.buffer_data_; |
| 28 } | 36 } |
| 29 | 37 |
| 30 getMaxDetectedFaces() { | 38 getMaxDetectedFaces() { |
| 31 return this.mock_service_.maxDetectedFaces_; | 39 return this.mock_service_.maxDetectedFaces_; |
| 32 } | 40 } |
| 33 | 41 |
| 34 getFastMode () { | 42 getFastMode () { |
| 35 return this.mock_service_.fastMode_; | 43 return this.mock_service_.fastMode_; |
| 36 } | 44 } |
| 37 } | 45 } |
| 38 | 46 |
| 39 class MockFaceDetection { | 47 class MockFaceDetection { |
| 40 constructor(request, options) { | 48 constructor(options) { |
| 41 this.maxDetectedFaces_ = options.max_detected_faces; | 49 this.maxDetectedFaces_ = options.max_detected_faces; |
| 42 this.fastMode_ = options.fast_mode; | 50 this.fastMode_ = options.fast_mode; |
| 43 this.binding_ = new bindings.Binding(faceDetection.FaceDetection, this, | |
| 44 request); | |
| 45 } | 51 } |
| 46 | 52 |
| 47 detect(frame_data, width, height) { | 53 detect(frame_data, width, height) { |
| 48 let receivedStruct = mojo.mapBuffer(frame_data, 0, width*height*4, 0); | 54 let receivedStruct = mojo.mapBuffer(frame_data, 0, width*height*4, 0); |
| 49 this.buffer_data_ = new Uint32Array(receivedStruct.buffer); | 55 this.buffer_data_ = new Uint32Array(receivedStruct.buffer); |
| 50 return Promise.resolve({ | 56 return Promise.resolve({ |
| 51 result: { | 57 result: { |
| 52 bounding_boxes: [ | 58 bounding_boxes: [ |
| 53 { x : 1.0, y: 1.0, width: 100.0, height: 100.0 }, | 59 { x : 1.0, y: 1.0, width: 100.0, height: 100.0 }, |
| 54 { x : 2.0, y: 2.0, width: 200.0, height: 200.0 }, | 60 { x : 2.0, y: 2.0, width: 200.0, height: 200.0 }, |
| 55 { x : 3.0, y: 3.0, width: 300.0, height: 300.0 }, | 61 { x : 3.0, y: 3.0, width: 300.0, height: 300.0 }, |
| 56 ] | 62 ] |
| 57 } | 63 } |
| 58 }); | 64 }); |
| 59 mojo.unmapBuffer(receivedStruct.buffer); | 65 mojo.unmapBuffer(receivedStruct.buffer); |
| 60 } | 66 } |
| 61 } | 67 } |
| 62 return new MockFaceDetectionProvider(); | 68 return new MockFaceDetectionProvider(); |
| 63 }); | 69 }); |
| OLD | NEW |