OLD | NEW |
1 "use strict"; | 1 "use strict"; |
2 | 2 |
3 let mockTextDetectionReady = define( | 3 let mockTextDetectionReady = define( |
4 'mockTextDetection', | 4 'mockTextDetection', |
5 ['services/shape_detection/public/interfaces/textdetection.mojom', | 5 ['services/shape_detection/public/interfaces/textdetection.mojom', |
6 'mojo/public/js/bindings', | 6 'mojo/public/js/bindings', |
7 'mojo/public/js/core', | |
8 'content/public/renderer/interfaces', | 7 'content/public/renderer/interfaces', |
9 ], (textDetection, bindings, mojo, interfaces) => { | 8 ], (textDetection, bindings, interfaces) => { |
10 | 9 |
11 class MockTextDetection { | 10 class MockTextDetection { |
12 constructor() { | 11 constructor() { |
13 this.bindingSet_ = new bindings.BindingSet(textDetection.TextDetection); | 12 this.bindingSet_ = new bindings.BindingSet(textDetection.TextDetection); |
14 | 13 |
15 interfaces.addInterfaceOverrideForTesting( | 14 interfaces.addInterfaceOverrideForTesting( |
16 textDetection.TextDetection.name, | 15 textDetection.TextDetection.name, |
17 handle => this.bindingSet_.addBinding(this, handle)); | 16 handle => this.bindingSet_.addBinding(this, handle)); |
18 } | 17 } |
19 | 18 |
20 detect(frame_data, width, height) { | 19 detect(frame_data, width, height) { |
21 let receivedStruct = mojo.mapBuffer(frame_data, 0, width*height*4, 0); | 20 let receivedStruct = frame_data.mapBuffer(0, width*height*4); |
22 this.buffer_data_ = new Uint32Array(receivedStruct.buffer); | 21 this.buffer_data_ = new Uint32Array(receivedStruct.buffer); |
23 return Promise.resolve({ | 22 return Promise.resolve({ |
24 results: [ | 23 results: [ |
25 { | 24 { |
26 raw_value : "cats", | 25 raw_value : "cats", |
27 bounding_box: { x: 1.0, y: 1.0, width: 100.0, height: 100.0 } | 26 bounding_box: { x: 1.0, y: 1.0, width: 100.0, height: 100.0 } |
28 }, | 27 }, |
29 { | 28 { |
30 raw_value : "dogs", | 29 raw_value : "dogs", |
31 bounding_box: { x: 2.0, y: 2.0, width: 50.0, height: 50.0 } | 30 bounding_box: { x: 2.0, y: 2.0, width: 50.0, height: 50.0 } |
32 }, | 31 }, |
33 ], | 32 ], |
34 }); | 33 }); |
35 mojo.unmapBuffer(receivedStruct.buffer); | |
36 } | 34 } |
37 | 35 |
38 getFrameData() { | 36 getFrameData() { |
39 return this.buffer_data_; | 37 return this.buffer_data_; |
40 } | 38 } |
41 } | 39 } |
42 return new MockTextDetection(); | 40 return new MockTextDetection(); |
43 }); | 41 }); |
OLD | NEW |