diff --git a/lib/patch/browser.js b/lib/patch/browser.js index dd98202dc..643a9ecaa 100644 --- a/lib/patch/browser.js +++ b/lib/patch/browser.js @@ -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, [ @@ -39,6 +40,8 @@ function apply() { definePropertyPatch.apply(); registerElementPatch.apply(); + + geolocationPatch.apply(); } module.exports = { diff --git a/lib/patch/geolocation.js b/lib/patch/geolocation.js new file mode 100644 index 000000000..7ad3e0708 --- /dev/null +++ b/lib/patch/geolocation.js @@ -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 +} diff --git a/test/patch/geolocation.spec.manual.js b/test/patch/geolocation.spec.manual.js new file mode 100644 index 000000000..8fa3167bd --- /dev/null +++ b/test/patch/geolocation.spec.manual.js @@ -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(); + } + ); + }); + }); +}));