| OLD | NEW |
| 1 /* | 1 /* |
| 2 * geolocation-mock contains a mock implementation of GeolocationService and | 2 * geolocation-mock contains a mock implementation of GeolocationService and |
| 3 * PermissionService. | 3 * PermissionService. |
| 4 */ | 4 */ |
| 5 | 5 |
| 6 "use strict"; | 6 "use strict"; |
| 7 | 7 |
| 8 let geolocationServiceMock = loadMojoModules( | 8 let geolocationServiceMock = loadMojoModules( |
| 9 'geolocationServiceMock', | 9 'geolocationServiceMock', |
| 10 ['device/geolocation/public/interfaces/geolocation.mojom', | 10 ['device/geolocation/public/interfaces/geolocation.mojom', |
| 11 'third_party/WebKit/public/platform/modules/permissions/permission.mojom', | 11 'third_party/WebKit/public/platform/modules/permissions/permission.mojom', |
| 12 'third_party/WebKit/public/platform/modules/permissions/permission_status.m
ojom', | 12 'third_party/WebKit/public/platform/modules/permissions/permission_status.m
ojom', |
| 13 'mojo/public/js/bindings', | 13 'mojo/public/js/router', |
| 14 ]).then(mojo => { | 14 ]).then(mojo => { |
| 15 let [geolocation, permission, permissionStatus, bindings] = | 15 let [geolocation, permission, permissionStatus, router] = |
| 16 mojo.modules; | 16 mojo.modules; |
| 17 | 17 |
| 18 class GeolocationServiceMock { | 18 class GeolocationServiceMock { |
| 19 constructor(interfaceProvider) { | 19 constructor(interfaceProvider) { |
| 20 interfaceProvider.addInterfaceOverrideForTesting( | 20 interfaceProvider.addInterfaceOverrideForTesting( |
| 21 geolocation.GeolocationService.name, | 21 geolocation.GeolocationService.name, |
| 22 handle => this.connectGeolocation_(handle)); | 22 handle => this.connectGeolocation_(handle)); |
| 23 | 23 |
| 24 interfaceProvider.addInterfaceOverrideForTesting( | 24 interfaceProvider.addInterfaceOverrideForTesting( |
| 25 permission.PermissionService.name, | 25 permission.PermissionService.name, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 44 /** | 44 /** |
| 45 * The status to respond to permission requests with. If set to ASK, then | 45 * The status to respond to permission requests with. If set to ASK, then |
| 46 * permission requests will block until setGeolocationPermission is called | 46 * permission requests will block until setGeolocationPermission is called |
| 47 * to allow or deny permission requests. | 47 * to allow or deny permission requests. |
| 48 * | 48 * |
| 49 * @type {!permissionStatus.PermissionStatus} | 49 * @type {!permissionStatus.PermissionStatus} |
| 50 */ | 50 */ |
| 51 this.permissionStatus_ = permissionStatus.PermissionStatus.ASK; | 51 this.permissionStatus_ = permissionStatus.PermissionStatus.ASK; |
| 52 this.rejectPermissionConnections_ = false; | 52 this.rejectPermissionConnections_ = false; |
| 53 this.rejectGeolocationConnections_ = false; | 53 this.rejectGeolocationConnections_ = false; |
| 54 | |
| 55 this.geolocationBindingSet_ = new bindings.BindingSet( | |
| 56 geolocation.GeolocationService); | |
| 57 this.permissionBindingSet_ = new bindings.BindingSet( | |
| 58 permission.PermissionService); | |
| 59 } | 54 } |
| 60 | 55 |
| 61 connectGeolocation_(handle) { | 56 connectGeolocation_(handle) { |
| 62 if (this.rejectGeolocationConnections_) { | 57 if (this.rejectGeolocationConnections_) { |
| 63 mojo.core.close(handle); | 58 mojo.core.close(handle); |
| 64 return; | 59 return; |
| 65 } | 60 } |
| 66 this.geolocationBindingSet_.addBinding(this, handle); | 61 this.geolocationStub_ = new geolocation.GeolocationService.stubClass( |
| 62 this); |
| 63 this.geolocationRouter_ = new router.Router(handle); |
| 64 this.geolocationRouter_.setIncomingReceiver(this.geolocationStub_); |
| 67 } | 65 } |
| 68 | 66 |
| 69 connectPermission_(handle) { | 67 connectPermission_(handle) { |
| 70 if (this.rejectPermissionConnections_) { | 68 if (this.rejectPermissionConnections_) { |
| 71 mojo.core.close(handle); | 69 mojo.core.close(handle); |
| 72 return; | 70 return; |
| 73 } | 71 } |
| 74 this.permissionBindingSet_.addBinding(this, handle); | 72 this.permissionStub_ = new permission.PermissionService.stubClass(this); |
| 73 this.permissionRouter_ = new router.Router(handle); |
| 74 this.permissionRouter_.setIncomingReceiver(this.permissionStub_); |
| 75 } | 75 } |
| 76 | 76 |
| 77 setHighAccuracy(highAccuracy) { | 77 setHighAccuracy(highAccuracy) { |
| 78 // FIXME: We need to add some tests regarding "high accuracy" mode. | 78 // FIXME: We need to add some tests regarding "high accuracy" mode. |
| 79 // See https://bugs.webkit.org/show_bug.cgi?id=49438 | 79 // See https://bugs.webkit.org/show_bug.cgi?id=49438 |
| 80 } | 80 } |
| 81 | 81 |
| 82 /** | 82 /** |
| 83 * A mock implementation of GeolocationService.queryNextPosition(). This | 83 * A mock implementation of GeolocationService.queryNextPosition(). This |
| 84 * returns the position set by a call to setGeolocationPosition() or | 84 * returns the position set by a call to setGeolocationPosition() or |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 setGeolocationPermission(allowed) { | 177 setGeolocationPermission(allowed) { |
| 178 this.permissionStatus_ = allowed ? | 178 this.permissionStatus_ = allowed ? |
| 179 permissionStatus.PermissionStatus.GRANTED : | 179 permissionStatus.PermissionStatus.GRANTED : |
| 180 permissionStatus.PermissionStatus.DENIED; | 180 permissionStatus.PermissionStatus.DENIED; |
| 181 this.runPermissionCallback_(); | 181 this.runPermissionCallback_(); |
| 182 } | 182 } |
| 183 | 183 |
| 184 } | 184 } |
| 185 return new GeolocationServiceMock(mojo.frameInterfaces); | 185 return new GeolocationServiceMock(mojo.frameInterfaces); |
| 186 }); | 186 }); |
| OLD | NEW |