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

Unified Diff: third_party/WebKit/LayoutTests/http/tests/resources/geolocation-mock.js

Issue 1367853002: Move GeolocationDispatcher into blink. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/LayoutTests/http/tests/resources/geolocation-mock.js
diff --git a/third_party/WebKit/LayoutTests/http/tests/resources/geolocation-mock.js b/third_party/WebKit/LayoutTests/http/tests/resources/geolocation-mock.js
new file mode 100644
index 0000000000000000000000000000000000000000..caab365fa8654502513d4cf8d5837abcdf462945
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/http/tests/resources/geolocation-mock.js
@@ -0,0 +1,138 @@
+/*
+ * geolocation-mock contains a mock implementation of GeolocationService and
+ * PermissionService.
+ */
+
+"use strict";
+
+let geolocationServiceMock = loadMojoModules(
+ 'geolocationServiceMock',
+ ['third_party/WebKit/public/platform/modules/geolocation/geolocation.mojom',
+ 'third_party/WebKit/public/platform/modules/permissions/permission.mojom',
+ 'third_party/WebKit/public/platform/modules/permissions/permission_status.mojom',
+ 'mojo/public/js/router',
+ ]).then(mojo => {
+ let [geolocation, permission, permissionStatus, router] =
+ mojo.modules;
+
+ class GeolocationServiceMock {
Michael van Ouwerkerk 2016/05/04 13:52:16 Duplicating this mock seems less than ideal. Could
Sam McNally 2016/05/05 11:50:23 I found the file of magical path hacks so we can s
+ constructor(serviceRegistry) {
+ serviceRegistry.addServiceOverrideForTesting(
+ geolocation.GeolocationService.name,
+ handle => this.connectGeolocation(handle));
+
+ serviceRegistry.addServiceOverrideForTesting(
+ permission.PermissionService.name,
+ handle => this.connectPermission(handle));
+
+ this.serviceRegistry_ = serviceRegistry;
+ this.pendingRequests_ = [];
+ this.geoposition_ = null;
+ this.pendingPermissionRequests_ = [];
+ this.allowed_ = null;
+ this.rejectPermissionConnections_ = false;
+ this.rejectGeolocationConnections_ = false;
+ }
+
+ connectGeolocation(handle) {
+ if (this.rejectGeolocationConnections_) {
+ mojo.core.close(handle);
+ return;
+ }
+ this.geolocationStub_ = new geolocation.GeolocationService.stubClass(
+ this);
+ this.geolocationRouter_ = new router.Router(handle);
+ this.geolocationRouter_.setIncomingReceiver(this.geolocationStub_);
+ }
+
+ connectPermission(handle) {
+ if (this.rejectPermissionConnections_) {
+ mojo.core.close(handle);
+ return;
+ }
+ this.permissionStub_ = new permission.PermissionService.stubClass(this);
+ this.permissionRouter_ = new router.Router(handle);
+ this.permissionRouter_.setIncomingReceiver(this.permissionStub_);
+ }
+
+ setHighAccuracy(highAccuracy) {
+ }
+
+ queryNextPosition() {
+ let result = new Promise(
+ (resolve, reject) => this.pendingRequests_.push(resolve));
+ this.runPositionCallbacks_();
+ return result;
+ }
+
+ setGeolocationPosition(latitude, longitude, accuracy, altitude,
+ altitudeAccuracy, heading, speed) {
+ this.geoposition_ = new geolocation.Geoposition();
+ this.geoposition_.latitude = latitude;
+ this.geoposition_.longitude = longitude;
+ this.geoposition_.accuracy = accuracy;
+ this.geoposition_.altitude = altitude;
+ this.geoposition_.altitude_accuracy = altitudeAccuracy;
+ this.geoposition_.heading = heading;
+ this.geoposition_.speed = speed;
+ this.geoposition_.timestamp = new Date().getTime() / 1000;
+ this.geoposition_.error_message = '';
+ this.geoposition_.valid = true;
+ this.runPositionCallbacks_();
+ }
+
+ setGeolocationPositionUnavailableError(message) {
+ this.geoposition_ = new geolocation.Geoposition();
+ this.geoposition_.valid = false;
+ this.geoposition_.error_message = message;
+ this.geoposition_.error_code =
+ geolocation.Geoposition.ErrorCode.POSITION_UNAVAILABLE;
+ this.runPositionCallbacks_();
+ }
+
+ rejectPermissionConnections() {
+ this.rejectPermissionConnections_ = true;
+ }
+
+ rejectGeolocationConnections() {
+ this.rejectGeolocationConnections_ = true;
+ }
+
+ requestPermission(permission) {
+ let result = new Promise(
+ (resolve, reject) => this.pendingPermissionRequests_.push(resolve));
+ this.runPermissionCallbacks_();
+ return result;
+ }
+
+ runPositionCallbacks_() {
+ if (!this.geoposition_ || !this.pendingRequests_.length)
+ return;
+
+ while (this.pendingRequests_.length) {
+ this.pendingRequests_.pop()({geoposition: this.geoposition_});
+ }
+ this.geoposition_ = null;
+ }
+
+ runPermissionCallbacks_() {
+ if (this.allowed_ === null || !this.pendingPermissionRequests_.length)
+ return;
+
+ while (this.pendingPermissionRequests_.length) {
+ this.pendingPermissionRequests_.pop()(
+ {status: this.allowed_ ?
+ permissionStatus.PermissionStatus.ALLOWED:
+ permissionStatus.PermissionStatus.DENIED});
+ }
+ this.allowed_ = null;
+ }
+
+ setGeolocationPermission(allowed) {
+ this.allowed_ = allowed;
+ this.runPermissionCallbacks_();
+ }
+
+ }
+ return new GeolocationServiceMock(mojo.frameServiceRegistry);
+});

Powered by Google App Engine
This is Rietveld 408576698