@flighthq/geolocation 0.3.1-next.975.01aea94 → 0.4.0-edge.1908.751021c
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/geolocation.d.ts +5 -0
- package/dist/geolocation.d.ts.map +1 -1
- package/dist/geolocation.js +61 -24
- package/dist/geolocation.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/geolocation.test.ts +81 -0
package/dist/geolocation.d.ts
CHANGED
|
@@ -1,14 +1,19 @@
|
|
|
1
|
+
import type { BackendExplanation } from '@flighthq/types/contract';
|
|
1
2
|
import type { GeolocationBackend, GeolocationErrorReason, GeolocationPermissionState, GeolocationRequestOptions, GeoPosition, GeoPositionResult } from '@flighthq/types/contract';
|
|
2
3
|
export declare function clearGeolocationWatch(id: number): void;
|
|
3
4
|
export declare function createGeoPosition(): GeoPosition;
|
|
4
5
|
export declare function createWebGeolocationBackend(): GeolocationBackend;
|
|
6
|
+
export declare function explainGeolocationBackend(): BackendExplanation;
|
|
5
7
|
export declare function getCurrentGeoPosition(options?: Readonly<GeolocationRequestOptions>): Promise<GeoPosition | null>;
|
|
6
8
|
export declare function getCurrentGeoPositionResult(options?: Readonly<GeolocationRequestOptions>): Promise<GeoPositionResult>;
|
|
7
9
|
export declare function getGeolocationBackend(): GeolocationBackend;
|
|
8
10
|
export declare function getGeolocationPermission(): Promise<GeolocationPermissionState>;
|
|
11
|
+
export declare function installGeolocationHostBackend(backend: GeolocationBackend): void;
|
|
9
12
|
export declare function isGeolocationAvailable(): boolean;
|
|
13
|
+
export declare function observeGeolocationHostResult(operation: string, succeeded: boolean): void;
|
|
10
14
|
export declare function onGeolocationPermissionChange(listener: (state: GeolocationPermissionState) => void): () => void;
|
|
11
15
|
export declare function requestGeolocationPermission(): Promise<boolean>;
|
|
16
|
+
export declare function resetGeolocationBackendForTest(): void;
|
|
12
17
|
export declare function setGeolocationBackend(backend: GeolocationBackend | null): void;
|
|
13
18
|
export declare function watchGeolocationPosition(handler: (position: Readonly<GeoPosition>) => void, options?: Readonly<GeolocationRequestOptions>, onError?: (reason: GeolocationErrorReason) => void): number;
|
|
14
19
|
//# sourceMappingURL=geolocation.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"geolocation.d.ts","sourceRoot":"","sources":["../src/geolocation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,sBAAsB,EACtB,0BAA0B,EAC1B,yBAAyB,EACzB,WAAW,EACX,iBAAiB,EAClB,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"geolocation.d.ts","sourceRoot":"","sources":["../src/geolocation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AACnE,OAAO,KAAK,EACV,kBAAkB,EAClB,sBAAsB,EACtB,0BAA0B,EAC1B,yBAAyB,EACzB,WAAW,EACX,iBAAiB,EAClB,MAAM,0BAA0B,CAAC;AAElC,wBAAgB,qBAAqB,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAEtD;AAED,wBAAgB,iBAAiB,IAAI,WAAW,CAY/C;AAKD,wBAAgB,2BAA2B,IAAI,kBAAkB,CA4GhE;AAED,wBAAgB,yBAAyB,IAAI,kBAAkB,CAa9D;AAED,wBAAgB,qBAAqB,CAAC,OAAO,CAAC,EAAE,QAAQ,CAAC,yBAAyB,CAAC,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,CAEhH;AAED,wBAAgB,2BAA2B,CAAC,OAAO,CAAC,EAAE,QAAQ,CAAC,yBAAyB,CAAC,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAErH;AAED,wBAAgB,qBAAqB,IAAI,kBAAkB,CAE1D;AAED,wBAAgB,wBAAwB,IAAI,OAAO,CAAC,0BAA0B,CAAC,CAE9E;AAED,wBAAgB,6BAA6B,CAAC,OAAO,EAAE,kBAAkB,GAAG,IAAI,CAM/E;AAED,wBAAgB,sBAAsB,IAAI,OAAO,CAIhD;AAED,wBAAgB,4BAA4B,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,GAAG,IAAI,CAKxF;AAED,wBAAgB,6BAA6B,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,0BAA0B,KAAK,IAAI,GAAG,MAAM,IAAI,CAE/G;AAED,wBAAgB,4BAA4B,IAAI,OAAO,CAAC,OAAO,CAAC,CAE/D;AAED,wBAAgB,8BAA8B,IAAI,IAAI,CAKrD;AAED,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,kBAAkB,GAAG,IAAI,GAAG,IAAI,CAE9E;AAED,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC,WAAW,CAAC,KAAK,IAAI,EAClD,OAAO,CAAC,EAAE,QAAQ,CAAC,yBAAyB,CAAC,EAC7C,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,sBAAsB,KAAK,IAAI,GACjD,MAAM,CAER"}
|
package/dist/geolocation.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
// Cancels an active position watch. No-op when the id is unknown or the backend lacks watching.
|
|
2
1
|
export function clearGeolocationWatch(id) {
|
|
3
2
|
getGeolocationBackend().clearWatch(id);
|
|
4
3
|
}
|
|
5
|
-
// Allocates a zeroed GeoPosition; use as a scratch value or when building a backend.
|
|
6
4
|
export function createGeoPosition() {
|
|
7
5
|
return {
|
|
8
6
|
accuracy: 0,
|
|
@@ -125,29 +123,40 @@ export function createWebGeolocationBackend() {
|
|
|
125
123
|
},
|
|
126
124
|
};
|
|
127
125
|
}
|
|
128
|
-
|
|
126
|
+
export function explainGeolocationBackend() {
|
|
127
|
+
if (_custom !== null) {
|
|
128
|
+
return { conflict: _hostConflict, layer: 'custom', operation: null, viability: 'unobserved' };
|
|
129
|
+
}
|
|
130
|
+
if (_host !== null) {
|
|
131
|
+
return {
|
|
132
|
+
conflict: _hostConflict,
|
|
133
|
+
layer: 'host',
|
|
134
|
+
operation: _hostObservation !== null ? _hostObservation.operation : null,
|
|
135
|
+
viability: _hostObservation !== null ? _hostObservation.viability : 'unobserved',
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
return { conflict: false, layer: 'host-not-enabled', operation: null, viability: 'unobserved' };
|
|
139
|
+
}
|
|
129
140
|
export function getCurrentGeoPosition(options) {
|
|
130
141
|
return getGeolocationBackend().getCurrentPosition(options ?? _emptyOptions);
|
|
131
142
|
}
|
|
132
|
-
// Resolves a GeoPositionResult carrying both the position and the error reason on failure.
|
|
133
|
-
// Use when the caller needs to distinguish denied / unavailable / timeout rather than just null.
|
|
134
143
|
export function getCurrentGeoPositionResult(options) {
|
|
135
144
|
return getGeolocationBackend().getCurrentPositionResult(options ?? _emptyOptions);
|
|
136
145
|
}
|
|
137
|
-
// The active geolocation backend, or a lazily-created web default. There is always a backend.
|
|
138
146
|
export function getGeolocationBackend() {
|
|
139
|
-
|
|
140
|
-
_backend = createWebGeolocationBackend();
|
|
141
|
-
return _backend;
|
|
147
|
+
return _custom ?? _host ?? _sentinel;
|
|
142
148
|
}
|
|
143
|
-
// Resolves the current permission state without triggering a user prompt.
|
|
144
|
-
// Returns 'granted', 'denied', or 'prompt' (the user has not yet been asked).
|
|
145
|
-
// Falls back to 'prompt' when the Permissions API is absent.
|
|
146
149
|
export function getGeolocationPermission() {
|
|
147
150
|
return getGeolocationBackend().getPermission();
|
|
148
151
|
}
|
|
149
|
-
|
|
150
|
-
|
|
152
|
+
export function installGeolocationHostBackend(backend) {
|
|
153
|
+
if (_host !== null) {
|
|
154
|
+
if (_host !== backend)
|
|
155
|
+
_hostConflict = true;
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
_host = backend;
|
|
159
|
+
}
|
|
151
160
|
export function isGeolocationAvailable() {
|
|
152
161
|
if (typeof navigator === 'undefined')
|
|
153
162
|
return false;
|
|
@@ -155,29 +164,57 @@ export function isGeolocationAvailable() {
|
|
|
155
164
|
return false;
|
|
156
165
|
return typeof navigator.geolocation !== 'undefined' && navigator.geolocation !== null;
|
|
157
166
|
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
167
|
+
export function observeGeolocationHostResult(operation, succeeded) {
|
|
168
|
+
_hostObservation = {
|
|
169
|
+
operation,
|
|
170
|
+
viability: succeeded ? 'available' : 'runtime-api-unavailable',
|
|
171
|
+
};
|
|
172
|
+
}
|
|
161
173
|
export function onGeolocationPermissionChange(listener) {
|
|
162
174
|
return getGeolocationBackend().subscribePermission(listener);
|
|
163
175
|
}
|
|
164
|
-
// Requests location permission. Resolves true when granted, false when denied or unavailable.
|
|
165
176
|
export function requestGeolocationPermission() {
|
|
166
177
|
return getGeolocationBackend().requestPermission();
|
|
167
178
|
}
|
|
168
|
-
|
|
179
|
+
export function resetGeolocationBackendForTest() {
|
|
180
|
+
_custom = null;
|
|
181
|
+
_host = null;
|
|
182
|
+
_hostConflict = false;
|
|
183
|
+
_hostObservation = null;
|
|
184
|
+
}
|
|
169
185
|
export function setGeolocationBackend(backend) {
|
|
170
|
-
|
|
186
|
+
_custom = backend;
|
|
171
187
|
}
|
|
172
|
-
// Starts a position watch, invoking handler on each update. Returns the watch id, or -1 when
|
|
173
|
-
// watching is unavailable. Pair with clearGeolocationWatch.
|
|
174
|
-
// Pass onError to receive ongoing failure reasons (e.g., permission revoked mid-watch).
|
|
175
188
|
export function watchGeolocationPosition(handler, options, onError) {
|
|
176
189
|
return getGeolocationBackend().watchPosition(handler, options ?? _emptyOptions, onError);
|
|
177
190
|
}
|
|
178
|
-
let
|
|
191
|
+
let _custom = null;
|
|
192
|
+
let _host = null;
|
|
193
|
+
let _hostConflict = false;
|
|
194
|
+
let _hostObservation = null;
|
|
179
195
|
const _emptyOptions = {};
|
|
180
196
|
const _noopUnsubscribe = () => { };
|
|
197
|
+
const _sentinel = {
|
|
198
|
+
clearWatch() { },
|
|
199
|
+
getCurrentPosition() {
|
|
200
|
+
return Promise.resolve(null);
|
|
201
|
+
},
|
|
202
|
+
getCurrentPositionResult() {
|
|
203
|
+
return Promise.resolve({ position: null, reason: 'unavailable' });
|
|
204
|
+
},
|
|
205
|
+
getPermission() {
|
|
206
|
+
return Promise.resolve('prompt');
|
|
207
|
+
},
|
|
208
|
+
requestPermission() {
|
|
209
|
+
return Promise.resolve(false);
|
|
210
|
+
},
|
|
211
|
+
subscribePermission() {
|
|
212
|
+
return _noopUnsubscribe;
|
|
213
|
+
},
|
|
214
|
+
watchPosition() {
|
|
215
|
+
return -1;
|
|
216
|
+
},
|
|
217
|
+
};
|
|
181
218
|
function getWebGeolocation() {
|
|
182
219
|
if (typeof navigator === 'undefined')
|
|
183
220
|
return null;
|
package/dist/geolocation.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"geolocation.js","sourceRoot":"","sources":["../src/geolocation.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"geolocation.js","sourceRoot":"","sources":["../src/geolocation.ts"],"names":[],"mappings":"AAUA,MAAM,UAAU,qBAAqB,CAAC,EAAU;IAC9C,qBAAqB,EAAE,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;AACzC,CAAC;AAED,MAAM,UAAU,iBAAiB;IAC/B,OAAO;QACL,QAAQ,EAAE,CAAC;QACX,QAAQ,EAAE,CAAC;QACX,gBAAgB,EAAE,CAAC;QACnB,UAAU,EAAE,CAAC;QACb,OAAO,EAAE,CAAC;QACV,QAAQ,EAAE,CAAC;QACX,SAAS,EAAE,CAAC;QACZ,KAAK,EAAE,CAAC;QACR,SAAS,EAAE,CAAC;KACb,CAAC;AACJ,CAAC;AAED,gGAAgG;AAChG,oGAAoG;AACpG,qDAAqD;AACrD,MAAM,UAAU,2BAA2B;IACzC,OAAO;QACL,UAAU,CAAC,EAAE;YACX,MAAM,GAAG,GAAG,iB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AE,OAAO,CAAC,SAAS;KAC3B,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { clearGeolocationWatch, createGeoPosition, getCurrentGeoPosition, getCurrentGeoPositionResult, getGeolocationPermission, isGeolocationAvailable, onGeolocationPermissionChange, requestGeolocationPermission, watchGeolocationPosition, } from './contract';
|
|
1
|
+
export { explainGeolocationBackend, clearGeolocationWatch, createGeoPosition, getCurrentGeoPosition, getCurrentGeoPositionResult, getGeolocationPermission, isGeolocationAvailable, onGeolocationPermissionChange, requestGeolocationPermission, watchGeolocationPosition, } from './contract';
|
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,iBAAiB,EACjB,qBAAqB,EACrB,2BAA2B,EAC3B,wBAAwB,EACxB,sBAAsB,EACtB,6BAA6B,EAC7B,4BAA4B,EAC5B,wBAAwB,GACzB,MAAM,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yBAAyB,EACzB,qBAAqB,EACrB,iBAAiB,EACjB,qBAAqB,EACrB,2BAA2B,EAC3B,wBAAwB,EACxB,sBAAsB,EACtB,6BAA6B,EAC7B,4BAA4B,EAC5B,wBAAwB,GACzB,MAAM,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { clearGeolocationWatch, createGeoPosition, getCurrentGeoPosition, getCurrentGeoPositionResult, getGeolocationPermission, isGeolocationAvailable, onGeolocationPermissionChange, requestGeolocationPermission, watchGeolocationPosition, } from './contract';
|
|
1
|
+
export { explainGeolocationBackend, clearGeolocationWatch, createGeoPosition, getCurrentGeoPosition, getCurrentGeoPositionResult, getGeolocationPermission, isGeolocationAvailable, onGeolocationPermissionChange, requestGeolocationPermission, watchGeolocationPosition, } from './contract';
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,iBAAiB,EACjB,qBAAqB,EACrB,2BAA2B,EAC3B,wBAAwB,EACxB,sBAAsB,EACtB,6BAA6B,EAC7B,4BAA4B,EAC5B,wBAAwB,GACzB,MAAM,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yBAAyB,EACzB,qBAAqB,EACrB,iBAAiB,EACjB,qBAAqB,EACrB,2BAA2B,EAC3B,wBAAwB,EACxB,sBAAsB,EACtB,6BAA6B,EAC7B,4BAA4B,EAC5B,wBAAwB,GACzB,MAAM,YAAY,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flighthq/geolocation",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0-edge.1908.751021c",
|
|
4
4
|
"author": "Joshua Granick and other contributors",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"clean:dist": "tsx ../../scripts/clean-package-dist.ts"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@flighthq/types": "0.
|
|
41
|
+
"@flighthq/types": "0.4.0-edge.1908.751021c"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"typescript": "^5.3.0"
|
package/src/geolocation.test.ts
CHANGED
|
@@ -18,6 +18,10 @@ import {
|
|
|
18
18
|
requestGeolocationPermission,
|
|
19
19
|
setGeolocationBackend,
|
|
20
20
|
watchGeolocationPosition,
|
|
21
|
+
explainGeolocationBackend,
|
|
22
|
+
installGeolocationHostBackend,
|
|
23
|
+
observeGeolocationHostResult,
|
|
24
|
+
resetGeolocationBackendForTest,
|
|
21
25
|
} from './geolocation';
|
|
22
26
|
|
|
23
27
|
function fakeBackend(): GeolocationBackend & { cleared: number[]; lastWatch: number } {
|
|
@@ -157,6 +161,34 @@ describe('createWebGeolocationBackend', () => {
|
|
|
157
161
|
});
|
|
158
162
|
});
|
|
159
163
|
|
|
164
|
+
describe('explainGeolocationBackend', () => {
|
|
165
|
+
afterEach(() => resetGeolocationBackendForTest());
|
|
166
|
+
|
|
167
|
+
it('reports host-not-enabled when no backend is installed', () => {
|
|
168
|
+
resetGeolocationBackendForTest();
|
|
169
|
+
const explanation = explainGeolocationBackend();
|
|
170
|
+
expect(explanation.layer).toBe('host-not-enabled');
|
|
171
|
+
expect(explanation.conflict).toBe(false);
|
|
172
|
+
expect(explanation.viability).toBe('unobserved');
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
it('reports custom layer when a custom backend is set', () => {
|
|
176
|
+
setGeolocationBackend(fakeBackend());
|
|
177
|
+
expect(explainGeolocationBackend().layer).toBe('custom');
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
it('reports host layer when a host backend is installed', () => {
|
|
181
|
+
installGeolocationHostBackend(fakeBackend());
|
|
182
|
+
expect(explainGeolocationBackend().layer).toBe('host');
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it('reports conflict when two different host backends are installed', () => {
|
|
186
|
+
installGeolocationHostBackend(fakeBackend());
|
|
187
|
+
installGeolocationHostBackend(fakeBackend());
|
|
188
|
+
expect(explainGeolocationBackend().conflict).toBe(true);
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
|
|
160
192
|
describe('getCurrentGeoPosition', () => {
|
|
161
193
|
it('returns the backend position', async () => {
|
|
162
194
|
setGeolocationBackend(fakeBackend());
|
|
@@ -206,6 +238,25 @@ describe('getGeolocationPermission', () => {
|
|
|
206
238
|
});
|
|
207
239
|
});
|
|
208
240
|
|
|
241
|
+
describe('installGeolocationHostBackend', () => {
|
|
242
|
+
afterEach(() => resetGeolocationBackendForTest());
|
|
243
|
+
|
|
244
|
+
it('installs a host backend that getGeolocationBackend returns', () => {
|
|
245
|
+
const backend = fakeBackend();
|
|
246
|
+
installGeolocationHostBackend(backend);
|
|
247
|
+
expect(getGeolocationBackend()).toBe(backend);
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
it('is first-host-wins: a second different backend sets conflict', () => {
|
|
251
|
+
const first = fakeBackend();
|
|
252
|
+
const second = fakeBackend();
|
|
253
|
+
installGeolocationHostBackend(first);
|
|
254
|
+
installGeolocationHostBackend(second);
|
|
255
|
+
expect(getGeolocationBackend()).toBe(first);
|
|
256
|
+
expect(explainGeolocationBackend().conflict).toBe(true);
|
|
257
|
+
});
|
|
258
|
+
});
|
|
259
|
+
|
|
209
260
|
describe('isGeolocationAvailable', () => {
|
|
210
261
|
it('returns a boolean', () => {
|
|
211
262
|
expect(typeof isGeolocationAvailable()).toBe('boolean');
|
|
@@ -217,6 +268,24 @@ describe('isGeolocationAvailable', () => {
|
|
|
217
268
|
});
|
|
218
269
|
});
|
|
219
270
|
|
|
271
|
+
describe('observeGeolocationHostResult', () => {
|
|
272
|
+
afterEach(() => resetGeolocationBackendForTest());
|
|
273
|
+
|
|
274
|
+
it('records a successful observation', () => {
|
|
275
|
+
installGeolocationHostBackend(fakeBackend());
|
|
276
|
+
observeGeolocationHostResult('clearWatch', true);
|
|
277
|
+
const explanation = explainGeolocationBackend();
|
|
278
|
+
expect(explanation.operation).toBe('clearWatch');
|
|
279
|
+
expect(explanation.viability).toBe('available');
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
it('records a failed observation', () => {
|
|
283
|
+
installGeolocationHostBackend(fakeBackend());
|
|
284
|
+
observeGeolocationHostResult('clearWatch', false);
|
|
285
|
+
expect(explainGeolocationBackend().viability).toBe('runtime-api-unavailable');
|
|
286
|
+
});
|
|
287
|
+
});
|
|
288
|
+
|
|
220
289
|
describe('onGeolocationPermissionChange', () => {
|
|
221
290
|
it('returns an unsubscribe function', () => {
|
|
222
291
|
const unsubscribe = onGeolocationPermissionChange(() => {});
|
|
@@ -253,6 +322,18 @@ describe('requestGeolocationPermission', () => {
|
|
|
253
322
|
});
|
|
254
323
|
});
|
|
255
324
|
|
|
325
|
+
describe('resetGeolocationBackendForTest', () => {
|
|
326
|
+
it('clears all backend slots', () => {
|
|
327
|
+
setGeolocationBackend(fakeBackend());
|
|
328
|
+
installGeolocationHostBackend(fakeBackend());
|
|
329
|
+
observeGeolocationHostResult('clearWatch', true);
|
|
330
|
+
resetGeolocationBackendForTest();
|
|
331
|
+
expect(explainGeolocationBackend().layer).toBe('host-not-enabled');
|
|
332
|
+
expect(explainGeolocationBackend().conflict).toBe(false);
|
|
333
|
+
expect(explainGeolocationBackend().viability).toBe('unobserved');
|
|
334
|
+
});
|
|
335
|
+
});
|
|
336
|
+
|
|
256
337
|
describe('setGeolocationBackend', () => {
|
|
257
338
|
it('clears back to the web fallback when passed null', () => {
|
|
258
339
|
setGeolocationBackend(fakeBackend());
|