| Index: third_party/WebKit/LayoutTests/fast/dom/Geolocation/maximum-age.html
|
| diff --git a/third_party/WebKit/LayoutTests/fast/dom/Geolocation/maximum-age.html b/third_party/WebKit/LayoutTests/fast/dom/Geolocation/maximum-age.html
|
| index 569d0590906b628e17939f439b5d974fdc3f5288..186dc0731ea9122c4538543446052d37f58aa5dc 100644
|
| --- a/third_party/WebKit/LayoutTests/fast/dom/Geolocation/maximum-age.html
|
| +++ b/third_party/WebKit/LayoutTests/fast/dom/Geolocation/maximum-age.html
|
| @@ -6,6 +6,124 @@
|
| <script src="resources/geolocation-mock.js"></script>
|
| </head>
|
| <body>
|
| -<script src="script-tests/maximum-age.js"></script>
|
| +<script>
|
| +description("Tests that the PositionOptions.maximumAge parameter is correctly applied.");
|
| +
|
| +var mockLatitude = 51.478;
|
| +var mockLongitude = -0.166;
|
| +var mockAccuracy = 100.0;
|
| +
|
| +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', 'error.POSITION_UNAVAILABLE');
|
| + shouldBe('error.message', 'mockMessage');
|
| +}
|
| +
|
| +geolocationServiceMock.then(mock => {
|
| + mock.setGeolocationPermission(true);
|
| + mock.setGeolocationPosition(mockLatitude, mockLongitude, mockAccuracy);
|
| +
|
| + // Initialize the cached Position
|
| + navigator.geolocation.getCurrentPosition(function(p) {
|
| + checkPosition(p);
|
| + testZeroMaximumAge();
|
| + }, function(e) {
|
| + testFailed('Error callback invoked unexpectedly');
|
| + finishJSTest();
|
| + });
|
| +
|
| + function testZeroMaximumAge() {
|
| + // Update the position provided by the mock service.
|
| + mock.setGeolocationPosition(++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');
|
| + finishJSTest();
|
| + });
|
| + }
|
| +
|
| + function testNonZeroMaximumAge() {
|
| + // Update the mock service to report an error.
|
| + mock.setGeolocationPositionUnavailableError(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);
|
| + testNegativeValueMaximumAge();
|
| + }, function(e) {
|
| + testFailed('Error callback invoked unexpectedly');
|
| + finishJSTest();
|
| + }, {maximumAge: 1000});
|
| + }
|
| +
|
| + function testNegativeValueMaximumAge() {
|
| + // Update the position provided by the mock service.
|
| + mock.setGeolocationPosition(++mockLatitude, ++mockLongitude, ++mockAccuracy);
|
| + // The maximumAge is same as zero, so we expect the updated position from the service.
|
| + navigator.geolocation.getCurrentPosition(function(p) {
|
| + checkPosition(p);
|
| + testOverSignedIntMaximumAge();
|
| + }, function(e) {
|
| + testFailed('Error callback invoked unexpectedly');
|
| + finishJSTest();
|
| + }, {maximumAge: -1000});
|
| + }
|
| +
|
| + function testOverSignedIntMaximumAge() {
|
| + // Update the mock service to report an error.
|
| + mock.setGeolocationPositionUnavailableError(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);
|
| + testOverUnsignedIntMaximumAge();
|
| + }, function(e) {
|
| + testFailed('Error callback invoked unexpectedly');
|
| + finishJSTest();
|
| + }, {maximumAge: 2147483648});
|
| + }
|
| +
|
| + function testOverUnsignedIntMaximumAge() {
|
| + // Update the mock service to report an error.
|
| + mock.setGeolocationPositionUnavailableError(mockMessage);
|
| + // The maximumAge is max-value of unsigned, 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');
|
| + finishJSTest();
|
| + }, {maximumAge: 4294967296});
|
| + }
|
| +
|
| + 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');
|
| + finishJSTest();
|
| + }, function(e) {
|
| + checkError(e);
|
| + finishJSTest();
|
| + });
|
| + }
|
| +});
|
| +
|
| +window.jsTestIsAsync = true;
|
| +</script>
|
| </body>
|
| </html>
|
|
|