OLD | NEW |
1 "use strict"; | 1 "use strict"; |
2 | 2 |
3 let mockBarcodeDetectionReady = define( | 3 let mockBarcodeDetectionReady = define( |
4 'mockBarcodeDetection', | 4 'mockBarcodeDetection', |
5 ['services/shape_detection/public/interfaces/barcodedetection.mojom', | 5 ['services/shape_detection/public/interfaces/barcodedetection.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 ], (barcodeDetection, bindings, mojo, interfaces) => { | 8 ], (barcodeDetection, bindings, interfaces) => { |
10 | 9 |
11 class MockBarcodeDetection { | 10 class MockBarcodeDetection { |
12 constructor() { | 11 constructor() { |
13 this.bindingSet_ = new bindings.BindingSet( | 12 this.bindingSet_ = new bindings.BindingSet( |
14 barcodeDetection.BarcodeDetection); | 13 barcodeDetection.BarcodeDetection); |
15 | 14 |
16 interfaces.addInterfaceOverrideForTesting( | 15 interfaces.addInterfaceOverrideForTesting( |
17 barcodeDetection.BarcodeDetection.name, | 16 barcodeDetection.BarcodeDetection.name, |
18 handle => this.bindingSet_.addBinding(this, handle)); | 17 handle => this.bindingSet_.addBinding(this, handle)); |
19 } | 18 } |
20 | 19 |
21 detect(frame_data, width, height) { | 20 detect(frame_data, width, height) { |
22 let receivedStruct = mojo.mapBuffer(frame_data, 0, width*height*4, 0); | 21 let receivedStruct = frame_data.mapBuffer(0, width*height*4); |
23 this.buffer_data_ = new Uint32Array(receivedStruct.buffer); | 22 this.buffer_data_ = new Uint32Array(receivedStruct.buffer); |
24 return Promise.resolve({ | 23 return Promise.resolve({ |
25 results: [ | 24 results: [ |
26 { | 25 { |
27 raw_value : "cats", | 26 raw_value : "cats", |
28 bounding_box: { x: 1.0, y: 1.0, width: 100.0, height: 100.0 }, | 27 bounding_box: { x: 1.0, y: 1.0, width: 100.0, height: 100.0 }, |
29 corner_points: [ | 28 corner_points: [ |
30 { x: 1.0, y: 1.0 }, | 29 { x: 1.0, y: 1.0 }, |
31 { x: 101.0, y: 1.0 }, | 30 { x: 101.0, y: 1.0 }, |
32 { x: 101.0, y: 101.0 }, | 31 { x: 101.0, y: 101.0 }, |
33 { x: 1.0, y: 101.0 } | 32 { x: 1.0, y: 101.0 } |
34 ], | 33 ], |
35 }, | 34 }, |
36 { | 35 { |
37 raw_value : "dogs", | 36 raw_value : "dogs", |
38 bounding_box: { x: 2.0, y: 2.0, width: 50.0, height: 50.0 }, | 37 bounding_box: { x: 2.0, y: 2.0, width: 50.0, height: 50.0 }, |
39 corner_points: [ | 38 corner_points: [ |
40 { x: 2.0, y: 2.0 }, | 39 { x: 2.0, y: 2.0 }, |
41 { x: 52.0, y: 2.0 }, | 40 { x: 52.0, y: 2.0 }, |
42 { x: 52.0, y: 52.0 }, | 41 { x: 52.0, y: 52.0 }, |
43 { x: 2.0, y: 52.0 } | 42 { x: 2.0, y: 52.0 } |
44 ], | 43 ], |
45 }, | 44 }, |
46 ], | 45 ], |
47 }); | 46 }); |
48 mojo.unmapBuffer(receivedStruct.buffer); | |
49 } | 47 } |
50 | 48 |
51 getFrameData() { | 49 getFrameData() { |
52 return this.buffer_data_; | 50 return this.buffer_data_; |
53 } | 51 } |
54 } | 52 } |
55 return new MockBarcodeDetection(); | 53 return new MockBarcodeDetection(); |
56 }); | 54 }); |
OLD | NEW |