Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(107)

Side by Side Diff: third_party/WebKit/LayoutTests/shapedetection/resources/mock-facedetection.js

Issue 2564163003: ShapeDetection: Add ShapeDetectionProvider (Closed)
Patch Set: Fix layout tests, rebase Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 "use strict"; 1 "use strict";
2 2
3 let mockFaceDetectionReady = define( 3 let mockFaceDetectionReady = define(
mcasas 2016/12/13 17:37:32 s/mockFaceDetectionReady/mockFaceDetectionProvider
xianglu 2016/12/13 19:17:28 Done.
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(stub, options) {
27 this.mock_service_ = new MockFaceDetection(options);
28 bindings.StubBindings(stub).delegate = this.mock_service_;
29 }
30
31 getFrameData() {
32 return this.mock_service_.buffer_data_;
33 }
34
35 getMaxDetectedFaces() {
36 return this.mock_service_.maxDetectedFaces_;
37 }
38
39 getFastMode () {
40 return this.mock_service_.fastMode_;
41 }
42 }
43
44 class MockFaceDetection {
45 constructor(options) {
46 interfaces.addInterfaceOverrideForTesting(
47 faceDetection.FaceDetection.name,
48 pipe => this.bindToPipe(pipe));
49 this.maxDetectedFaces_ = options.max_detected_faces;
50 this.fastMode_ = options.fast_mode;
51 }
52
53 bindToPipe(pipe) {
54 this.stub_ = connection.bindHandleToStub(
55 pipe, faceDetection.FaceDetection);
56 bindings.StubBindings(this.stub_).delegate = this;
57 }
58
59 detect(frame_data, width, height) {
26 let receivedStruct = mojo.mapBuffer(frame_data, 0, width*height*4, 0); 60 let receivedStruct = mojo.mapBuffer(frame_data, 0, width*height*4, 0);
27 this.buffer_data_ = new Uint32Array(receivedStruct.buffer); 61 this.buffer_data_ = new Uint32Array(receivedStruct.buffer);
28 this.maxDetectedFaces_ = options.max_detected_faces;
29 this.fastMode_ = options.fast_mode;
30 return Promise.resolve({ 62 return Promise.resolve({
31 result: { 63 result: {
32 bounding_boxes: [ 64 bounding_boxes: [
33 { x : 1.0, y: 1.0, width: 100.0, height: 100.0 }, 65 { 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 }, 66 { 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 }, 67 { x : 3.0, y: 3.0, width: 300.0, height: 300.0 },
36 ] 68 ]
37 } 69 }
38 }); 70 });
39 mojo.unmapBuffer(receivedStruct.buffer); 71 mojo.unmapBuffer(receivedStruct.buffer);
40 } 72 }
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 } 73 }
54 return new MockFaceDetection(); 74 return new MockFaceDetectionProvider();
55 }); 75 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698