diff options
-rw-r--r-- | LayoutTests/fast/dom/Geolocation/maximum-age-expected.txt | 24 | ||||
-rw-r--r-- | LayoutTests/fast/dom/Geolocation/maximum-age.html | 13 | ||||
-rw-r--r-- | LayoutTests/fast/dom/Geolocation/resources/maximum-age.js | 81 | ||||
-rw-r--r-- | WebCore/page/Geolocation.cpp | 57 | ||||
-rw-r--r-- | WebCore/page/Geolocation.h | 2 |
5 files changed, 146 insertions, 31 deletions
diff --git a/LayoutTests/fast/dom/Geolocation/maximum-age-expected.txt b/LayoutTests/fast/dom/Geolocation/maximum-age-expected.txt new file mode 100644 index 0000000..71b1980 --- /dev/null +++ b/LayoutTests/fast/dom/Geolocation/maximum-age-expected.txt @@ -0,0 +1,24 @@ +Tests that the PositionOptions.maximumAge parameter is correctly applied. + +On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". + + +PASS successfullyParsed is true + +PASS position.coords.latitude is mockLatitude +PASS position.coords.longitude is mockLongitude +PASS position.coords.accuracy is mockAccuracy + +PASS position.coords.latitude is mockLatitude +PASS position.coords.longitude is mockLongitude +PASS position.coords.accuracy is mockAccuracy + +PASS position.coords.latitude is mockLatitude +PASS position.coords.longitude is mockLongitude +PASS position.coords.accuracy is mockAccuracy + +PASS error.code is mockCode +PASS error.message is mockMessage + +TEST COMPLETE + diff --git a/LayoutTests/fast/dom/Geolocation/maximum-age.html b/LayoutTests/fast/dom/Geolocation/maximum-age.html new file mode 100644 index 0000000..2d871e0 --- /dev/null +++ b/LayoutTests/fast/dom/Geolocation/maximum-age.html @@ -0,0 +1,13 @@ +<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> +<html> +<head> +<link rel="stylesheet" href="../../js/resources/js-test-style.css"> +<script src="../../js/resources/js-test-pre.js"></script> +</head> +<body> +<p id="description"></p> +<div id="console"></div> +<script src="resources/maximum-age.js"></script> +<script src="resources/js-test-post.js"></script> +</body> +</html> diff --git a/LayoutTests/fast/dom/Geolocation/resources/maximum-age.js b/LayoutTests/fast/dom/Geolocation/resources/maximum-age.js new file mode 100644 index 0000000..f48aa0d --- /dev/null +++ b/LayoutTests/fast/dom/Geolocation/resources/maximum-age.js @@ -0,0 +1,81 @@ +description("Tests that the PositionOptions.maximumAge parameter is correctly applied."); + +var mockLatitude = 51.478; +var mockLongitude = -0.166; +var mockAccuracy = 100.0; + +var mockCode = 1; +var mockMessage = 'test'; + +var position; +var error; + +function checkPosition(p) { + debug(''); + position = p; + shouldBe('position.coords.latitude', 'mockLatitude'); + shouldBe('position.coords.longitude', 'mockLongitude'); + shouldBe('position.coords.accuracy', 'mockAccuracy'); +} + +function checkError(e) { + debug(''); + error = e; + shouldBe('error.code', 'mockCode'); + shouldBe('error.message', 'mockMessage'); +} + +window.layoutTestController.setGeolocationPermission(true); +window.layoutTestController.setMockGeolocationPosition(mockLatitude, mockLongitude, mockAccuracy); + +// Initialize the cached Position +navigator.geolocation.getCurrentPosition(function(p) { + checkPosition(p); + testZeroMaximumAge(); +}, function(e) { + testFailed('Error callback invoked unexpectedly'); + window.layoutTestController.notifyDone(); +}); + +function testZeroMaximumAge() { + // Update the position provided by the mock service. + window.layoutTestController.setMockGeolocationPosition(++mockLatitude, ++mockLongitude, ++mockAccuracy); + // The default maximumAge is zero, so we expect the updated position from the service. + navigator.geolocation.getCurrentPosition(function(p) { + checkPosition(p); + testNonZeroMaximumAge(); + }, function(e) { + testFailed('Error callback invoked unexpectedly'); + window.layoutTestController.notifyDone(); + }); +} + +function testNonZeroMaximumAge() { + // Update the mock service to report an error. + window.layoutTestController.setMockGeolocationError(mockCode, mockMessage); + // The maximumAge is non-zero, so we expect the cached position, not the error from the service. + navigator.geolocation.getCurrentPosition(function(p) { + checkPosition(p); + testZeroMaximumAgeError(); + }, function(e) { + testFailed('Error callback invoked unexpectedly'); + window.layoutTestController.notifyDone(); + }, {maximumAge: 1000}); +} + +function testZeroMaximumAgeError() { + // The default maximumAge is zero, so we expect the error from the service. + navigator.geolocation.getCurrentPosition(function(p) { + testFailed('Success callback invoked unexpectedly'); + window.layoutTestController.notifyDone(); + }, function(e) { + checkError(e); + debug('<br /><span class="pass">TEST COMPLETE</span>'); + window.layoutTestController.notifyDone(); + }); +} + +window.layoutTestController.waitUntilDone(); + +var isAsynchronous = true; +var successfullyParsed = true; diff --git a/WebCore/page/Geolocation.cpp b/WebCore/page/Geolocation.cpp index d021f7b..ad5f8d6 100644 --- a/WebCore/page/Geolocation.cpp +++ b/WebCore/page/Geolocation.cpp @@ -48,6 +48,7 @@ namespace WebCore { static const char permissionDeniedErrorMessage[] = "User denied Geolocation"; +static const char failedToStartServiceErrorMessage[] = "Failed to start Geolocation service"; #if ENABLE(CLIENT_BASED_GEOLOCATION) @@ -101,18 +102,18 @@ void Geolocation::GeoNotifier::setFatalError(PassRefPtr<PositionError> error) m_timer.startOneShot(0); } -bool Geolocation::GeoNotifier::hasZeroTimeout() const -{ - return m_options->hasTimeout() && m_options->timeout() == 0; -} - void Geolocation::GeoNotifier::setUseCachedPosition() { m_useCachedPosition = true; m_timer.startOneShot(0); } -void Geolocation::GeoNotifier::makeSuccessCallback(Geoposition* position) +bool Geolocation::GeoNotifier::hasZeroTimeout() const +{ + return m_options->hasTimeout() && m_options->timeout() == 0; +} + +void Geolocation::GeoNotifier::runSuccessCallback(Geoposition* position) { m_successCallback->handleEvent(position); } @@ -285,20 +286,16 @@ PassRefPtr<Geolocation::GeoNotifier> Geolocation::startRequest(PassRefPtr<Positi // the permission state can not change again in the lifetime of this page. if (isDenied()) notifier->setFatalError(PositionError::create(PositionError::PERMISSION_DENIED, permissionDeniedErrorMessage)); - else { - if (haveSuitableCachedPosition(notifier->m_options.get())) - notifier->setUseCachedPosition(); - else { - if (notifier->hasZeroTimeout() || startUpdating(notifier.get())) { + else if (haveSuitableCachedPosition(notifier->m_options.get())) + notifier->setUseCachedPosition(); + else if (notifier->hasZeroTimeout() || startUpdating(notifier.get())) { #if ENABLE(CLIENT_BASED_GEOLOCATION) - // Only start timer if we're not waiting for user permission. - if (!m_startRequestPermissionNotifier) + // Only start timer if we're not waiting for user permission. + if (!m_startRequestPermissionNotifier) #endif - notifier->startTimerIfNeeded(); - } else - notifier->setFatalError(PositionError::create(PositionError::POSITION_UNAVAILABLE, "Failed to start Geolocation service")); - } - } + notifier->startTimerIfNeeded(); + } else + notifier->setFatalError(PositionError::create(PositionError::POSITION_UNAVAILABLE, failedToStartServiceErrorMessage)); return notifier.release(); } @@ -313,15 +310,6 @@ void Geolocation::fatalErrorOccurred(Geolocation::GeoNotifier* notifier) stopUpdating(); } -void Geolocation::requestTimedOut(GeoNotifier* notifier) -{ - // If this is a one-shot request, stop it. - m_oneShots.remove(notifier); - - if (!hasListeners()) - stopUpdating(); -} - void Geolocation::requestUsesCachedPosition(GeoNotifier* notifier) { // This is called asynchronously, so the permissions could have been denied @@ -351,7 +339,7 @@ void Geolocation::makeCachedPositionCallbacks() GeoNotifierSet::const_iterator end = m_requestsAwaitingCachedPosition.end(); for (GeoNotifierSet::const_iterator iter = m_requestsAwaitingCachedPosition.begin(); iter != end; ++iter) { GeoNotifier* notifier = iter->get(); - notifier->makeSuccessCallback(m_positionCache->cachedPosition()); + notifier->runSuccessCallback(m_positionCache->cachedPosition()); // If this is a one-shot request, stop it. Otherwise, if the watch still // exists, start the service to get updates. @@ -361,7 +349,7 @@ void Geolocation::makeCachedPositionCallbacks() if (notifier->hasZeroTimeout() || startUpdating(notifier)) notifier->startTimerIfNeeded(); else - notifier->setFatalError(PositionError::create(PositionError::POSITION_UNAVAILABLE, "Failed to start Geolocation service")); + notifier->setFatalError(PositionError::create(PositionError::POSITION_UNAVAILABLE, failedToStartServiceErrorMessage)); } } @@ -371,13 +359,22 @@ void Geolocation::makeCachedPositionCallbacks() stopUpdating(); } +void Geolocation::requestTimedOut(GeoNotifier* notifier) +{ + // If this is a one-shot request, stop it. + m_oneShots.remove(notifier); + + if (!hasListeners()) + stopUpdating(); +} + bool Geolocation::haveSuitableCachedPosition(PositionOptions* options) { if (!m_positionCache->cachedPosition()) return false; if (!options->hasMaximumAge()) return true; - if (options->maximumAge() == 0) + if (!options->maximumAge()) return false; DOMTimeStamp currentTimeMillis = currentTime() * 1000.0; return m_positionCache->cachedPosition()->timestamp() > currentTimeMillis - options->maximumAge(); diff --git a/WebCore/page/Geolocation.h b/WebCore/page/Geolocation.h index ade4ffe..2a282b5 100644 --- a/WebCore/page/Geolocation.h +++ b/WebCore/page/Geolocation.h @@ -97,7 +97,7 @@ private: void setFatalError(PassRefPtr<PositionError>); bool hasZeroTimeout() const; void setUseCachedPosition(); - void makeSuccessCallback(Geoposition*); + void runSuccessCallback(Geoposition*); void startTimerIfNeeded(); void timerFired(Timer<GeoNotifier>*); |