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

Commit

Permalink
feat(geolocation): patch the API
Browse files Browse the repository at this point in the history
fixes #113
  • Loading branch information
vicb committed May 19, 2015
1 parent 554fae0 commit cd13da1
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/patch/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var registerElementPatch = require('./register-element');
var webSocketPatch = require('./websocket');
var eventTargetPatch = require('./event-target');
var propertyDescriptorPatch = require('./property-descriptor');
var geolocationPatch = require('./geolocation');

function apply() {
fnPatch.patchSetClearFunction(global, [
Expand Down Expand Up @@ -39,6 +40,8 @@ function apply() {
definePropertyPatch.apply();

registerElementPatch.apply();

geolocationPatch.apply();
}

module.exports = {
Expand Down
16 changes: 16 additions & 0 deletions lib/patch/geolocation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict';

var utils = require('../utils');

function apply() {
if (global.navigator && global.navigator.geolocation) {
utils.patchPrototype(global.navigator.geolocation, [
'getCurrentPosition',
'watchPosition'
]);
}
}

module.exports = {
apply: apply
}
34 changes: 34 additions & 0 deletions test/patch/geolocation.spec.manual.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
'use strict';

function supportsGeolocation() {
return 'geolocation' in navigator;
}
supportsGeolocation.message = 'Geolocation';

describe('Geolocation', ifEnvSupports(supportsGeolocation, function () {
var testZone = zone.fork();

it('should work for getCurrentPosition', function(done) {
testZone.run(function() {
navigator.geolocation.getCurrentPosition(
function(pos) {
expect(window.zone).toBeDirectChildOf(testZone);
done();
}
);
});
});

it('should work for watchPosition', function(done) {
testZone.run(function() {
var watchId;
watchId = navigator.geolocation.watchPosition(
function(pos) {
expect(window.zone).toBeDirectChildOf(testZone);
navigator.geolocation.clearWatch(watchId);
done();
}
);
});
});
}));

0 comments on commit cd13da1

Please sign in to comment.