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