diff options
author | Steve Block <steveblock@google.com> | 2010-05-26 10:11:43 +0100 |
---|---|---|
committer | Steve Block <steveblock@google.com> | 2010-05-27 11:14:42 +0100 |
commit | e78cbe89e6f337f2f1fe40315be88f742b547151 (patch) | |
tree | d778000b84a04f24bbad50c7fa66244365e960e9 /LayoutTests/fast/dom/Geolocation/script-tests | |
parent | 7b582e96e4e909ed7dba1e07153d20fbddaec3f7 (diff) | |
download | external_webkit-e78cbe89e6f337f2f1fe40315be88f742b547151.zip external_webkit-e78cbe89e6f337f2f1fe40315be88f742b547151.tar.gz external_webkit-e78cbe89e6f337f2f1fe40315be88f742b547151.tar.bz2 |
Merge WebKit at r60074: Initial merge by git
Change-Id: I18a2dc5439e36c928351ea829d8fb4e39b062fc7
Diffstat (limited to 'LayoutTests/fast/dom/Geolocation/script-tests')
21 files changed, 767 insertions, 0 deletions
diff --git a/LayoutTests/fast/dom/Geolocation/script-tests/TEMPLATE.html b/LayoutTests/fast/dom/Geolocation/script-tests/TEMPLATE.html new file mode 100644 index 0000000..1951c43 --- /dev/null +++ b/LayoutTests/fast/dom/Geolocation/script-tests/TEMPLATE.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="YOUR_JS_FILE_HERE"></script> +<script src="../../js/resources/js-test-post.js"></script> +</body> +</html> diff --git a/LayoutTests/fast/dom/Geolocation/script-tests/argument-types.js b/LayoutTests/fast/dom/Geolocation/script-tests/argument-types.js new file mode 100644 index 0000000..2b559d8 --- /dev/null +++ b/LayoutTests/fast/dom/Geolocation/script-tests/argument-types.js @@ -0,0 +1,119 @@ +description("Tests the acceptable types for arguments to Geolocation methods."); + +function shouldNotThrow(expression) +{ + try { + eval(expression); + testPassed(expression + " did not throw exception."); + } catch(e) { + testFailed(expression + " should not throw exception. Threw exception " + e); + } +} + +function test(expression, expressionShouldThrow, expectedException) { + if (expressionShouldThrow) { + if (expectedException) + shouldThrow(expression, '(function() { return "' + expectedException + '"; })();'); + else + shouldThrow(expression, '(function() { return "Error: TYPE_MISMATCH_ERR: DOM Exception 17"; })();'); + } else { + shouldNotThrow(expression); + } +} + +var emptyFunction = function() {}; + +function ObjectThrowingException() {}; +ObjectThrowingException.prototype.valueOf = function() { + throw new Error('valueOf threw exception'); +} +ObjectThrowingException.prototype.__defineGetter__("enableHighAccuracy", function() { + throw new Error('enableHighAccuracy getter exception'); +}); +var objectThrowingException = new ObjectThrowingException(); + + +test('navigator.geolocation.getCurrentPosition()', true); + +test('navigator.geolocation.getCurrentPosition(undefined)', true); +test('navigator.geolocation.getCurrentPosition(null)', true); +test('navigator.geolocation.getCurrentPosition({})', true); +test('navigator.geolocation.getCurrentPosition(objectThrowingException)', true); +test('navigator.geolocation.getCurrentPosition(emptyFunction)', false); +test('navigator.geolocation.getCurrentPosition(Math.abs)', false); +test('navigator.geolocation.getCurrentPosition(true)', true); +test('navigator.geolocation.getCurrentPosition(42)', true); +test('navigator.geolocation.getCurrentPosition(Infinity)', true); +test('navigator.geolocation.getCurrentPosition(-Infinity)', true); +test('navigator.geolocation.getCurrentPosition("string")', true); + +test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined)', false); +test('navigator.geolocation.getCurrentPosition(emptyFunction, null)', false); +test('navigator.geolocation.getCurrentPosition(emptyFunction, {})', true); +test('navigator.geolocation.getCurrentPosition(emptyFunction, objectThrowingException)', true); +test('navigator.geolocation.getCurrentPosition(emptyFunction, emptyFunction)', false); +test('navigator.geolocation.getCurrentPosition(emptyFunction, Math.abs)', false); +test('navigator.geolocation.getCurrentPosition(emptyFunction, true)', true); +test('navigator.geolocation.getCurrentPosition(emptyFunction, 42)', true); +test('navigator.geolocation.getCurrentPosition(emptyFunction, Infinity)', true); +test('navigator.geolocation.getCurrentPosition(emptyFunction, -Infinity)', true); +test('navigator.geolocation.getCurrentPosition(emptyFunction, "string")', true); + +test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, undefined)', false); +test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, null)', false); +test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {})', false); +test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, objectThrowingException)', true, 'Error: enableHighAccuracy getter exception'); +test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, emptyFunction)', false); +test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, true)', false); +test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, 42)', false); +test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, Infinity)', false); +test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, -Infinity)', false); +test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, "string")', false); + +test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {dummyProperty:undefined})', false); +test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {dummyProperty:null})', false); +test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {dummyProperty:{}})', false); +test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {dummyProperty:objectThrowingException})', false); +test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {dummyProperty:emptyFunction})', false); +test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {dummyProperty:true})', false); +test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {dummyProperty:42})', false); +test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {dummyProperty:Infinity})', false); +test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {dummyProperty:-Infinity})', false); +test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {dummyProperty:"string"})', false); + +test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {enableHighAccuracy:undefined})', false); +test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {enableHighAccuracy:null})', false); +test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {enableHighAccuracy:{}})', false); +test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {enableHighAccuracy:objectThrowingException})', false); +test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {enableHighAccuracy:emptyFunction})', false); +test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {enableHighAccuracy:true})', false); +test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {enableHighAccuracy:42})', false); +test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {enableHighAccuracy:Infinity})', false); +test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {enableHighAccuracy:-Infinity})', false); +test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {enableHighAccuracy:"string"})', false); + +test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {maximumAge:undefined})', false); +test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {maximumAge:null})', false); +test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {maximumAge:{}})', false); +test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {maximumAge:objectThrowingException})', true, 'Error: valueOf threw exception'); +test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {maximumAge:emptyFunction})', false); +test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {maximumAge:true})', false); +test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {maximumAge:42})', false); +test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {maximumAge:Infinity})', false); +test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {maximumAge:-Infinity})', false); +test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {maximumAge:"string"})', false); + +test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {timeout:undefined})', false); +test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {timeout:null})', false); +test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {timeout:{}})', false); +test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {timeout:objectThrowingException})', true, 'Error: valueOf threw exception'); +test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {timeout:emptyFunction})', false); +test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {timeout:true})', false); +test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {timeout:42})', false); +test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {timeout:Infinity})', false); +test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {timeout:-Infinity})', false); +test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {timeout:"string"})', false); + +window.jsTestIsAsync = false; +window.successfullyParsed = true; + diff --git a/LayoutTests/fast/dom/Geolocation/script-tests/callback-exception.js b/LayoutTests/fast/dom/Geolocation/script-tests/callback-exception.js new file mode 100644 index 0000000..7a86648 --- /dev/null +++ b/LayoutTests/fast/dom/Geolocation/script-tests/callback-exception.js @@ -0,0 +1,31 @@ +description("Tests that when an exception is thrown in the success callback, the error callback is not invoked. Note that this test throws an exception which is not caught."); + +var mockLatitude = 51.478; +var mockLongitude = -0.166; +var mockAccuracy = 100; + +window.layoutTestController.setGeolocationPermission(true); +window.layoutTestController.setMockGeolocationPosition(mockLatitude, + mockLongitude, + mockAccuracy); + +var position; +navigator.geolocation.getCurrentPosition(function(p) { + position = p + shouldBe('position.coords.latitude', 'mockLatitude'); + shouldBe('position.coords.longitude', 'mockLongitude'); + shouldBe('position.coords.accuracy', 'mockAccuracy'); + + // Yield to allow for the error callback to be invoked. The timer + // must be started before the exception is thrown. + window.setTimeout(finishJSTest, 0); + throw new Error('Exception in success callback'); +}, function(e) { + testFailed('Error callback invoked unexpectedly'); + finishJSTest(); +}); + +window.layoutTestController.waitUntilDone(); + +window.jsTestIsAsync = true; +window.successfullyParsed = true; diff --git a/LayoutTests/fast/dom/Geolocation/script-tests/enabled.js b/LayoutTests/fast/dom/Geolocation/script-tests/enabled.js new file mode 100644 index 0000000..6cb7bad --- /dev/null +++ b/LayoutTests/fast/dom/Geolocation/script-tests/enabled.js @@ -0,0 +1,18 @@ +description("Tests that the navigator.geolocation object is present."); + +function hasGeolocationProperty() +{ + for (var property in navigator) { + if (property == "geolocation") + return true; + } + return false; +} + +shouldBeTrue("typeof navigator.geolocation == 'object'"); +shouldBeTrue("hasGeolocationProperty()"); +shouldBeTrue("'geolocation' in navigator"); +shouldBeTrue("navigator.hasOwnProperty('geolocation')"); + +window.jsTestIsAsync = false; +window.successfullyParsed = true; diff --git a/LayoutTests/fast/dom/Geolocation/script-tests/error.js b/LayoutTests/fast/dom/Geolocation/script-tests/error.js new file mode 100644 index 0000000..4c818ca --- /dev/null +++ b/LayoutTests/fast/dom/Geolocation/script-tests/error.js @@ -0,0 +1,25 @@ +description("Tests Geolocation error callback using the mock service."); + +var mockCode = 0; +var mockMessage = "debug"; + +window.layoutTestController.setMockGeolocationError(mockCode, mockMessage); + +var error; +navigator.geolocation.getCurrentPosition(function(p) { + testFailed('Success callback invoked unexpectedly'); + finishJSTest(); +}, function(e) { + error = e + shouldBe('error.code', 'mockCode'); + shouldBe('error.message', 'mockMessage'); + shouldBe('error.UNKNOWN_ERROR', 'undefined'); + shouldBe('error.PERMISSION_DENIED', '1'); + shouldBe('error.POSITION_UNAVAILABLE', '2'); + shouldBe('error.TIMEOUT', '3'); + finishJSTest(); +}); +window.layoutTestController.waitUntilDone(); + +window.jsTestIsAsync = true; +window.successfullyParsed = true; diff --git a/LayoutTests/fast/dom/Geolocation/script-tests/maximum-age.js b/LayoutTests/fast/dom/Geolocation/script-tests/maximum-age.js new file mode 100644 index 0000000..207fb64 --- /dev/null +++ b/LayoutTests/fast/dom/Geolocation/script-tests/maximum-age.js @@ -0,0 +1,80 @@ +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'); + finishJSTest(); +}); + +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'); + finishJSTest(); + }); +} + +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'); + finishJSTest(); + }, {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'); + finishJSTest(); + }, function(e) { + checkError(e); + finishJSTest(); + }); +} + +window.layoutTestController.waitUntilDone(); + +window.jsTestIsAsync = true; +window.successfullyParsed = true; diff --git a/LayoutTests/fast/dom/Geolocation/script-tests/notimer-after-unload.js b/LayoutTests/fast/dom/Geolocation/script-tests/notimer-after-unload.js new file mode 100644 index 0000000..278e027 --- /dev/null +++ b/LayoutTests/fast/dom/Geolocation/script-tests/notimer-after-unload.js @@ -0,0 +1,21 @@ +description("Tests that no timers will trigger for navigator.geolocation object after onunload."); + +if (window.layoutTestController) layoutTestController.setGeolocationPermission(true); + +document.body.onload = function() { + location = "data:text/html,You should have seen one unload alert appear.<script>window.setTimeout('if (window.layoutTestController) layoutTestController.notifyDone();', 100);</" + "script>"; +} + +document.body.onunload = function() { + navigator.geolocation.getCurrentPosition( + function(p) {alert('FAIL: Unexpected Geolocation success callback.');}, + function(e) {alert('FAIL: Unexpected Geolocation error callback.' + e.code + e.message);}, + {timeout: 0, maximumAge:0} + ); + alert("unload-called"); +} + +window.jsTestIsAsync = true; +window.successfullyParsed = true; + +if (window.layoutTestController) layoutTestController.waitUntilDone(); diff --git a/LayoutTests/fast/dom/Geolocation/script-tests/ongoing-request-leak.js b/LayoutTests/fast/dom/Geolocation/script-tests/ongoing-request-leak.js new file mode 100644 index 0000000..08e6b21 --- /dev/null +++ b/LayoutTests/fast/dom/Geolocation/script-tests/ongoing-request-leak.js @@ -0,0 +1,13 @@ +description("Exercises a condition where the DOMWindow may leak if Geolocation requests are ongoing when the page is navigated away or closed. The page should reoload."); + +if (window.layoutTestController) layoutTestController.setGeolocationPermission(true); +if (window.layoutTestController) layoutTestController.setMockGeolocationPosition(51.478, -0.166, 100.0); + +navigator.geolocation.watchPosition(function() {}, null); + +document.body.onload = function() { + location = "data:text/html,Exercises a condition where the DOMWindow may leak if Geolocation requests are ongoing when the page is navigated away or closed. Complete.<script>if (window.layoutTestController) layoutTestController.notifyDone();</" + "script>"; +} + +window.jsTestIsAsync = true; +window.successfullyParsed = true; diff --git a/LayoutTests/fast/dom/Geolocation/script-tests/permission-denied-already-clear-watch.js b/LayoutTests/fast/dom/Geolocation/script-tests/permission-denied-already-clear-watch.js new file mode 100644 index 0000000..410f042 --- /dev/null +++ b/LayoutTests/fast/dom/Geolocation/script-tests/permission-denied-already-clear-watch.js @@ -0,0 +1,37 @@ +description("Tests that when Geolocation permission has been denied prior to a call to watchPosition, and the watch is cleared in the error callback, there is no crash. This a regression test for https://bugs.webkit.org/show_bug.cgi?id=32111."); + +// Prime the Geolocation instance by denying permission. +window.layoutTestController.setGeolocationPermission(false); +window.layoutTestController.setMockGeolocationPosition(51.478, -0.166, 100); + +var error; +navigator.geolocation.getCurrentPosition(function(p) { + testFailed('Success callback invoked unexpectedly'); + finishJSTest(); +}, function(e) { + error = e + shouldBe('error.code', 'error.PERMISSION_DENIED'); + shouldBe('error.message', '"User denied Geolocation"'); + debug(''); + continueTest(); +}); + +function continueTest() +{ + // Make another request, with permission already denied. + var watchId = navigator.geolocation.watchPosition(function(p) { + testFailed('Success callback invoked unexpectedly'); + finishJSTest(); + }, function(e) { + error = e + shouldBe('error.code', 'error.PERMISSION_DENIED'); + shouldBe('error.message', '"User denied Geolocation"'); + navigator.geolocation.clearWatch(watchId); + window.setTimeout(finishJSTest, 0); + }); +} + +window.layoutTestController.waitUntilDone(); + +window.jsTestIsAsync = true; +window.successfullyParsed = true; diff --git a/LayoutTests/fast/dom/Geolocation/script-tests/permission-denied-already-error.js b/LayoutTests/fast/dom/Geolocation/script-tests/permission-denied-already-error.js new file mode 100644 index 0000000..9cea5ba --- /dev/null +++ b/LayoutTests/fast/dom/Geolocation/script-tests/permission-denied-already-error.js @@ -0,0 +1,37 @@ +description("Tests that when Geolocation permission has been denied prior to a call to a Geolocation method, the error callback is invoked with code PERMISSION_DENIED, when the Geolocation service encounters an error."); + +// Prime the Geolocation instance by denying permission. +window.layoutTestController.setGeolocationPermission(false); +window.layoutTestController.setMockGeolocationPosition(51.478, -0.166, 100); + +var error; +navigator.geolocation.getCurrentPosition(function(p) { + testFailed('Success callback invoked unexpectedly'); + finishJSTest(); +}, function(e) { + error = e + shouldBe('error.code', 'error.PERMISSION_DENIED'); + shouldBe('error.message', '"User denied Geolocation"'); + debug(''); + continueTest(); +}); + +function continueTest() +{ + // Make another request, with permission already denied. + window.layoutTestController.setMockGeolocationError(0, 'test'); + + navigator.geolocation.getCurrentPosition(function(p) { + testFailed('Success callback invoked unexpectedly'); + finishJSTest(); + }, function(e) { + error = e + shouldBe('error.code', 'error.PERMISSION_DENIED'); + shouldBe('error.message', '"User denied Geolocation"'); + finishJSTest(); + }); +} +window.layoutTestController.waitUntilDone(); + +window.jsTestIsAsync = true; +window.successfullyParsed = true; diff --git a/LayoutTests/fast/dom/Geolocation/script-tests/permission-denied-already-success.js b/LayoutTests/fast/dom/Geolocation/script-tests/permission-denied-already-success.js new file mode 100644 index 0000000..fdc74e6 --- /dev/null +++ b/LayoutTests/fast/dom/Geolocation/script-tests/permission-denied-already-success.js @@ -0,0 +1,35 @@ +description("Tests that when Geolocation permission has been denied prior to a call to a Geolocation method, the error callback is invoked with code PERMISSION_DENIED, when the Geolocation service has a good position."); + +// Prime the Geolocation instance by denying permission. +window.layoutTestController.setGeolocationPermission(false); +window.layoutTestController.setMockGeolocationPosition(51.478, -0.166, 100); + +var error; +navigator.geolocation.getCurrentPosition(function(p) { + testFailed('Success callback invoked unexpectedly'); + finishJSTest(); +}, function(e) { + error = e + shouldBe('error.code', 'error.PERMISSION_DENIED'); + shouldBe('error.message', '"User denied Geolocation"'); + debug(''); + continueTest(); +}); + +function continueTest() +{ + // Make another request, with permission already denied. + navigator.geolocation.getCurrentPosition(function(p) { + testFailed('Success callback invoked unexpectedly'); + finishJSTest(); + }, function(e) { + error = e + shouldBe('error.code', 'error.PERMISSION_DENIED'); + shouldBe('error.message', '"User denied Geolocation"'); + finishJSTest(); + }); +} +window.layoutTestController.waitUntilDone(); + +window.jsTestIsAsync = true; +window.successfullyParsed = true; diff --git a/LayoutTests/fast/dom/Geolocation/script-tests/permission-denied-stops-watches.js b/LayoutTests/fast/dom/Geolocation/script-tests/permission-denied-stops-watches.js new file mode 100644 index 0000000..244deda --- /dev/null +++ b/LayoutTests/fast/dom/Geolocation/script-tests/permission-denied-stops-watches.js @@ -0,0 +1,33 @@ +description("Tests that when Geolocation permission is denied, watches are stopped, as well as one-shots."); + +// Configure the mock Geolocation service to report a position to cause permission +// to be requested, then deny it. +window.layoutTestController.setGeolocationPermission(false); +window.layoutTestController.setMockGeolocationPosition(51.478, -0.166, 100.0); + +var error; +var errorCallbackInvoked = false; +navigator.geolocation.watchPosition(function(p) { + testFailed('Success callback invoked unexpectedly'); + finishJSTest(); +}, function(e) { + if (errorCallbackInvoked) { + testFailed('Error callback invoked unexpectedly : ' + error.message); + finishJSTest(); + } + errorCallbackInvoked = true; + + error = e + shouldBe('error.code', 'error.PERMISSION_DENIED'); + shouldBe('error.message', '"User denied Geolocation"'); + + // Update the mock Geolocation service to report a new position, then + // yield to allow a chance for the success callback to be invoked. + window.layoutTestController.setMockGeolocationPosition(55.478, -0.166, 100); + window.setTimeout(finishJSTest, 0); +}); + +window.layoutTestController.waitUntilDone(); + +window.jsTestIsAsync = true; +window.successfullyParsed = true; diff --git a/LayoutTests/fast/dom/Geolocation/script-tests/permission-denied.js b/LayoutTests/fast/dom/Geolocation/script-tests/permission-denied.js new file mode 100644 index 0000000..aafcaf1 --- /dev/null +++ b/LayoutTests/fast/dom/Geolocation/script-tests/permission-denied.js @@ -0,0 +1,19 @@ +description("Tests Geolocation when permission is denied, using the mock service."); + +window.layoutTestController.setGeolocationPermission(false); +window.layoutTestController.setMockGeolocationPosition(51.478, -0.166, 100); + +var error; +navigator.geolocation.getCurrentPosition(function(p) { + testFailed('Success callback invoked unexpectedly'); + finishJSTest(); +}, function(e) { + error = e + shouldBe('error.code', 'error.PERMISSION_DENIED'); + shouldBe('error.message', '"User denied Geolocation"'); + finishJSTest(); +}); +window.layoutTestController.waitUntilDone(); + +window.jsTestIsAsync = true; +window.successfullyParsed = true; diff --git a/LayoutTests/fast/dom/Geolocation/script-tests/position-string.js b/LayoutTests/fast/dom/Geolocation/script-tests/position-string.js new file mode 100644 index 0000000..d4931ee --- /dev/null +++ b/LayoutTests/fast/dom/Geolocation/script-tests/position-string.js @@ -0,0 +1,29 @@ +description("Tests formatting of position.toString()."); + +var mockLatitude = 51.478; +var mockLongitude = -0.166; +var mockAccuracy = 100.0; + +window.layoutTestController.setGeolocationPermission(true); +window.layoutTestController.setMockGeolocationPosition(mockLatitude, + mockLongitude, + mockAccuracy); + +var position; +navigator.geolocation.getCurrentPosition(function(p) { + // shouldBe can't use local variables yet. + position = p + shouldBe('position.coords.latitude', 'mockLatitude'); + shouldBe('position.coords.longitude', 'mockLongitude'); + shouldBe('position.coords.accuracy', 'mockAccuracy'); + shouldBe('position.toString()', '"[object Geoposition]"'); + shouldBe('position.coords.toString()', '"[object Coordinates]"'); + finishJSTest(); +}, function(e) { + testFailed('Error callback invoked unexpectedly'); + finishJSTest(); +}); +window.layoutTestController.waitUntilDone(); + +window.jsTestIsAsync = true; +window.successfullyParsed = true; diff --git a/LayoutTests/fast/dom/Geolocation/script-tests/reentrant-error.js b/LayoutTests/fast/dom/Geolocation/script-tests/reentrant-error.js new file mode 100644 index 0000000..e3361de --- /dev/null +++ b/LayoutTests/fast/dom/Geolocation/script-tests/reentrant-error.js @@ -0,0 +1,46 @@ +description("Tests that reentrant calls to Geolocation methods from the error callback are OK."); + +var mockCode = 0; +var mockMessage = 'test'; + +window.layoutTestController.setMockGeolocationError(mockCode, mockMessage); + +var error; +var errorCallbackInvoked = false; +navigator.geolocation.getCurrentPosition(function(p) { + testFailed('Success callback invoked unexpectedly'); + finishJSTest(); +}, function(e) { + if (errorCallbackInvoked) { + testFailed('Error callback invoked unexpectedly'); + finishJSTest(); + } + errorCallbackInvoked = true; + + error = e; + shouldBe('error.code', 'mockCode'); + shouldBe('error.message', 'mockMessage'); + debug(''); + continueTest(); +}); + +function continueTest() { + mockCode += 1; + mockMessage += ' repeat'; + + window.layoutTestController.setMockGeolocationError(mockCode, mockMessage); + + navigator.geolocation.getCurrentPosition(function(p) { + testFailed('Success callback invoked unexpectedly'); + finishJSTest(); + }, function(e) { + error = e; + shouldBe('error.code', 'mockCode'); + shouldBe('error.message', 'mockMessage'); + finishJSTest(); + }); +} +window.layoutTestController.waitUntilDone(); + +window.jsTestIsAsync = true; +window.successfullyParsed = true; diff --git a/LayoutTests/fast/dom/Geolocation/script-tests/reentrant-success.js b/LayoutTests/fast/dom/Geolocation/script-tests/reentrant-success.js new file mode 100644 index 0000000..4b83ea7 --- /dev/null +++ b/LayoutTests/fast/dom/Geolocation/script-tests/reentrant-success.js @@ -0,0 +1,51 @@ +description("Tests that reentrant calls to Geolocation methods from the success callback are OK."); + +var mockLatitude = 51.478; +var mockLongitude = -0.166; +var mockAccuracy = 100.0; + +window.layoutTestController.setGeolocationPermission(true); +window.layoutTestController.setMockGeolocationPosition(mockLatitude, + mockLongitude, + mockAccuracy); + +var position; +var successCallbackInvoked = false; +navigator.geolocation.getCurrentPosition(function(p) { + if (successCallbackInvoked) { + testFailed('Success callback invoked unexpectedly'); + finishJSTest(); + } + successCallbackInvoked = true; + + position = p; + shouldBe('position.coords.latitude', 'mockLatitude'); + shouldBe('position.coords.longitude', 'mockLongitude'); + shouldBe('position.coords.accuracy', 'mockAccuracy'); + debug(''); + continueTest(); +}, function(e) { + testFailed('Error callback invoked unexpectedly'); + finishJSTest(); +}); + +function continueTest() { + window.layoutTestController.setMockGeolocationPosition(++mockLatitude, + ++mockLongitude, + ++mockAccuracy); + + navigator.geolocation.getCurrentPosition(function(p) { + position = p; + shouldBe('position.coords.latitude', 'mockLatitude'); + shouldBe('position.coords.longitude', 'mockLongitude'); + shouldBe('position.coords.accuracy', 'mockAccuracy'); + finishJSTest(); + }, function(e) { + testFailed('Error callback invoked unexpectedly'); + finishJSTest(); + }); +} +window.layoutTestController.waitUntilDone(); + +window.jsTestIsAsync = true; +window.successfullyParsed = true; diff --git a/LayoutTests/fast/dom/Geolocation/script-tests/success.js b/LayoutTests/fast/dom/Geolocation/script-tests/success.js new file mode 100644 index 0000000..acb6b8d --- /dev/null +++ b/LayoutTests/fast/dom/Geolocation/script-tests/success.js @@ -0,0 +1,26 @@ +description("Tests Geolocation success callback using the mock service."); + +var mockLatitude = 51.478; +var mockLongitude = -0.166; +var mockAccuracy = 100; + +window.layoutTestController.setGeolocationPermission(true); +window.layoutTestController.setMockGeolocationPosition(mockLatitude, + mockLongitude, + mockAccuracy); + +var position; +navigator.geolocation.getCurrentPosition(function(p) { + position = p + shouldBe('position.coords.latitude', 'mockLatitude'); + shouldBe('position.coords.longitude', 'mockLongitude'); + shouldBe('position.coords.accuracy', 'mockAccuracy'); + finishJSTest(); +}, function(e) { + testFailed('Error callback invoked unexpectedly'); + finishJSTest(); +}); +window.layoutTestController.waitUntilDone(); + +window.jsTestIsAsync = true; +window.successfullyParsed = true; diff --git a/LayoutTests/fast/dom/Geolocation/script-tests/timeout-clear-watch.js b/LayoutTests/fast/dom/Geolocation/script-tests/timeout-clear-watch.js new file mode 100644 index 0000000..63e0569 --- /dev/null +++ b/LayoutTests/fast/dom/Geolocation/script-tests/timeout-clear-watch.js @@ -0,0 +1,22 @@ +description("Tests that when a watch times out and is cleared from the error callback, there is no crash. This a regression test for https://bugs.webkit.org/show_bug.cgi?id=32111."); + +window.layoutTestController.setMockGeolocationPosition(51.478, -0.166, 100.0); + +var error; +var watchId = navigator.geolocation.watchPosition(function() { + testFailed('Success callback invoked unexpectedly'); + finishJSTest(); +}, function(e) { + error = e + shouldBe('error.code', 'error.TIMEOUT'); + shouldBe('error.message', '"Timeout expired"'); + navigator.geolocation.clearWatch(watchId); + window.setTimeout(finishJSTest, 0); +}, { + timeout: 0 +}); + +window.layoutTestController.waitUntilDone(); + +window.jsTestIsAsync = true; +window.successfullyParsed = true; diff --git a/LayoutTests/fast/dom/Geolocation/script-tests/timeout-zero.js b/LayoutTests/fast/dom/Geolocation/script-tests/timeout-zero.js new file mode 100644 index 0000000..9867084 --- /dev/null +++ b/LayoutTests/fast/dom/Geolocation/script-tests/timeout-zero.js @@ -0,0 +1,20 @@ +description("Tests that when timeout is zero (and maximumAge is too), the error callback is called immediately with code TIMEOUT."); + +layoutTestController.setMockGeolocationPosition(51.478, -0.166, 100.0); + +var error; +navigator.geolocation.getCurrentPosition(function(p) { + testFailed('Success callback invoked unexpectedly'); + finishJSTest(); +}, function(e) { + error = e + shouldBe('error.code', 'error.TIMEOUT'); + shouldBe('error.message', '"Timeout expired"'); + finishJSTest(); +}, { + timeout: 0 +}); +window.layoutTestController.waitUntilDone(); + +window.jsTestIsAsync = true; +window.successfullyParsed = true; diff --git a/LayoutTests/fast/dom/Geolocation/script-tests/timeout.js b/LayoutTests/fast/dom/Geolocation/script-tests/timeout.js new file mode 100644 index 0000000..49cab29 --- /dev/null +++ b/LayoutTests/fast/dom/Geolocation/script-tests/timeout.js @@ -0,0 +1,28 @@ +description("Tests that when timeout is non-zero, the success callback is called as expected."); + +var mockLatitude = 51.478; +var mockLongitude = -0.166; +var mockAccuracy = 100.0; + +window.layoutTestController.setGeolocationPermission(true); +window.layoutTestController.setMockGeolocationPosition(mockLatitude, + mockLongitude, + mockAccuracy); + +var position; +navigator.geolocation.getCurrentPosition(function(p) { + position = p; + shouldBe('position.coords.latitude', 'mockLatitude'); + shouldBe('position.coords.longitude', 'mockLongitude'); + shouldBe('position.coords.accuracy', 'mockAccuracy'); + finishJSTest(); +}, function(e) { + testFailed('Error callback invoked unexpectedly'); + finishJSTest(); +}, { + timeout: 1000 +}); +window.layoutTestController.waitUntilDone(); + +window.jsTestIsAsync = true; +window.successfullyParsed = true; diff --git a/LayoutTests/fast/dom/Geolocation/script-tests/watch.js b/LayoutTests/fast/dom/Geolocation/script-tests/watch.js new file mode 100644 index 0000000..8249f2e --- /dev/null +++ b/LayoutTests/fast/dom/Geolocation/script-tests/watch.js @@ -0,0 +1,64 @@ +description("Tests that watchPosition correctly reports position updates and errors from the Geolocation service."); + +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) { + position = p; + shouldBe('position.coords.latitude', 'mockLatitude'); + shouldBe('position.coords.longitude', 'mockLongitude'); + shouldBe('position.coords.accuracy', 'mockAccuracy'); + debug(''); +} + +function checkError(e) { + error = e; + shouldBe('error.code', 'mockCode'); + shouldBe('error.message', 'mockMessage'); + debug(''); +} + +window.layoutTestController.setGeolocationPermission(true); +window.layoutTestController.setMockGeolocationPosition(mockLatitude, mockLongitude, mockAccuracy); + +var state = 0; +navigator.geolocation.watchPosition(function(p) { + switch (state++) { + case 0: + checkPosition(p); + window.layoutTestController.setMockGeolocationPosition(++mockLatitude, ++mockLongitude, ++mockAccuracy); + break; + case 1: + checkPosition(p); + window.layoutTestController.setMockGeolocationError(mockCode, mockMessage); + break; + case 3: + checkPosition(p); + finishJSTest(); + break; + default: + testFailed('Success callback invoked unexpectedly'); + finishJSTest(); + } +}, function(e) { + switch (state++) { + case 2: + checkError(e); + window.layoutTestController.setMockGeolocationPosition(++mockLatitude, ++mockLongitude, ++mockAccuracy); + break; + default: + testFailed('Error callback invoked unexpectedly'); + finishJSTest(); + } +}); +window.layoutTestController.waitUntilDone(); + +window.jsTestIsAsync = true; +window.successfullyParsed = true; |