Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Commit cd13da1

Browse files
committed
feat(geolocation): patch the API
fixes #113
1 parent 554fae0 commit cd13da1

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

lib/patch/browser.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ var registerElementPatch = require('./register-element');
88
var webSocketPatch = require('./websocket');
99
var eventTargetPatch = require('./event-target');
1010
var propertyDescriptorPatch = require('./property-descriptor');
11+
var geolocationPatch = require('./geolocation');
1112

1213
function apply() {
1314
fnPatch.patchSetClearFunction(global, [
@@ -39,6 +40,8 @@ function apply() {
3940
definePropertyPatch.apply();
4041

4142
registerElementPatch.apply();
43+
44+
geolocationPatch.apply();
4245
}
4346

4447
module.exports = {

lib/patch/geolocation.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'use strict';
2+
3+
var utils = require('../utils');
4+
5+
function apply() {
6+
if (global.navigator && global.navigator.geolocation) {
7+
utils.patchPrototype(global.navigator.geolocation, [
8+
'getCurrentPosition',
9+
'watchPosition'
10+
]);
11+
}
12+
}
13+
14+
module.exports = {
15+
apply: apply
16+
}

test/patch/geolocation.spec.manual.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
'use strict';
2+
3+
function supportsGeolocation() {
4+
return 'geolocation' in navigator;
5+
}
6+
supportsGeolocation.message = 'Geolocation';
7+
8+
describe('Geolocation', ifEnvSupports(supportsGeolocation, function () {
9+
var testZone = zone.fork();
10+
11+
it('should work for getCurrentPosition', function(done) {
12+
testZone.run(function() {
13+
navigator.geolocation.getCurrentPosition(
14+
function(pos) {
15+
expect(window.zone).toBeDirectChildOf(testZone);
16+
done();
17+
}
18+
);
19+
});
20+
});
21+
22+
it('should work for watchPosition', function(done) {
23+
testZone.run(function() {
24+
var watchId;
25+
watchId = navigator.geolocation.watchPosition(
26+
function(pos) {
27+
expect(window.zone).toBeDirectChildOf(testZone);
28+
navigator.geolocation.clearWatch(watchId);
29+
done();
30+
}
31+
);
32+
});
33+
});
34+
}));

0 commit comments

Comments
 (0)