| OLD | NEW |
| 1 "use strict"; | 1 "use strict"; |
| 2 | 2 |
| 3 let mockFaceDetectionReady = define( | 3 let mockFaceDetectionProviderReady = define( |
| 4 'mockFaceDetection', | 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 'mojo/public/js/bindings', | 7 'mojo/public/js/bindings', |
| 7 'mojo/public/js/connection', | 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, bindings, connection, mojo, interfaces) => { | 11 ], (faceDetection, faceDetectionProvider, bindings, connection, mojo, interfac
es) => { |
| 11 | 12 |
| 12 class MockFaceDetection { | 13 class MockFaceDetectionProvider { |
| 13 constructor() { | 14 constructor() { |
| 14 interfaces.addInterfaceOverrideForTesting( | 15 interfaces.addInterfaceOverrideForTesting( |
| 15 faceDetection.FaceDetection.name, | 16 faceDetectionProvider.FaceDetectionProvider.name, |
| 16 pipe => this.bindToPipe(pipe)); | 17 pipe => this.bindToPipe(pipe)); |
| 17 } | 18 } |
| 18 | 19 |
| 19 bindToPipe(pipe) { | 20 bindToPipe(pipe) { |
| 20 this.stub_ = connection.bindHandleToStub(pipe, | 21 this.stub_ = connection.bindHandleToStub( |
| 21 faceDetection.FaceDetection); | 22 pipe, faceDetectionProvider.FaceDetectionProvider); |
| 22 bindings.StubBindings(this.stub_).delegate = this; | 23 bindings.StubBindings(this.stub_).delegate = this; |
| 23 } | 24 } |
| 24 | 25 |
| 25 detect(frame_data, width, height, options) { | 26 createFaceDetection(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_; |
| 32 } |
| 33 |
| 34 getFrameData() { |
| 35 return this.mock_service_.buffer_data_; |
| 36 } |
| 37 |
| 38 getMaxDetectedFaces() { |
| 39 return this.mock_service_.maxDetectedFaces_; |
| 40 } |
| 41 |
| 42 getFastMode () { |
| 43 return this.mock_service_.fastMode_; |
| 44 } |
| 45 } |
| 46 |
| 47 class MockFaceDetection { |
| 48 constructor(options) { |
| 49 this.maxDetectedFaces_ = options.max_detected_faces; |
| 50 this.fastMode_ = options.fast_mode; |
| 51 } |
| 52 |
| 53 detect(frame_data, width, height) { |
| 26 let receivedStruct = mojo.mapBuffer(frame_data, 0, width*height*4, 0); | 54 let receivedStruct = mojo.mapBuffer(frame_data, 0, width*height*4, 0); |
| 27 this.buffer_data_ = new Uint32Array(receivedStruct.buffer); | 55 this.buffer_data_ = new Uint32Array(receivedStruct.buffer); |
| 28 this.maxDetectedFaces_ = options.max_detected_faces; | |
| 29 this.fastMode_ = options.fast_mode; | |
| 30 return Promise.resolve({ | 56 return Promise.resolve({ |
| 31 result: { | 57 result: { |
| 32 bounding_boxes: [ | 58 bounding_boxes: [ |
| 33 { 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 }, |
| 34 { 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 }, |
| 35 { 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 }, |
| 36 ] | 62 ] |
| 37 } | 63 } |
| 38 }); | 64 }); |
| 39 mojo.unmapBuffer(receivedStruct.buffer); | 65 mojo.unmapBuffer(receivedStruct.buffer); |
| 40 } | 66 } |
| 41 | |
| 42 getFrameData() { | |
| 43 return this.buffer_data_; | |
| 44 } | |
| 45 | |
| 46 getMaxDetectedFaces() { | |
| 47 return this.maxDetectedFaces_; | |
| 48 } | |
| 49 | |
| 50 getFastMode () { | |
| 51 return this.fastMode_; | |
| 52 } | |
| 53 } | 67 } |
| 54 return new MockFaceDetection(); | 68 return new MockFaceDetectionProvider(); |
| 55 }); | 69 }); |
| OLD | NEW |