summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/geolocation-API
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
commit6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch)
treea68f146d7fa01f0134297619fbe7e33db084e0aa /testing/web-platform/tests/geolocation-API
parentInitial commit. (diff)
downloadthunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz
thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/geolocation-API')
-rw-r--r--testing/web-platform/tests/geolocation-API/META.yml4
-rw-r--r--testing/web-platform/tests/geolocation-API/PositionOptions.https.html93
-rw-r--r--testing/web-platform/tests/geolocation-API/clearWatch_TypeError.https.html13
-rw-r--r--testing/web-platform/tests/geolocation-API/disabled-by-permissions-policy.https.sub.html70
-rw-r--r--testing/web-platform/tests/geolocation-API/disabled-by-permissions-policy.https.sub.html.headers1
-rw-r--r--testing/web-platform/tests/geolocation-API/enabled-by-permission-policy-attribute-redirect-on-load.https.sub.html36
-rw-r--r--testing/web-platform/tests/geolocation-API/enabled-by-permission-policy-attribute.https.sub.html34
-rw-r--r--testing/web-platform/tests/geolocation-API/enabled-by-permissions-policy.https.sub.html45
-rw-r--r--testing/web-platform/tests/geolocation-API/enabled-by-permissions-policy.https.sub.html.headers1
-rw-r--r--testing/web-platform/tests/geolocation-API/enabled-on-self-origin-by-permissions-policy.https.sub.html42
-rw-r--r--testing/web-platform/tests/geolocation-API/enabled-on-self-origin-by-permissions-policy.https.sub.html.headers1
-rw-r--r--testing/web-platform/tests/geolocation-API/getCurrentPosition_TypeError.https.html61
-rw-r--r--testing/web-platform/tests/geolocation-API/getCurrentPosition_permission_allow.https.html55
-rw-r--r--testing/web-platform/tests/geolocation-API/getCurrentPosition_permission_deny.https.html29
-rw-r--r--testing/web-platform/tests/geolocation-API/idlharness.https.window.js14
-rw-r--r--testing/web-platform/tests/geolocation-API/non-fully-active.https.html106
-rw-r--r--testing/web-platform/tests/geolocation-API/non-secure-contexts.http.html82
-rw-r--r--testing/web-platform/tests/geolocation-API/permission.https.html14
-rw-r--r--testing/web-platform/tests/geolocation-API/resources/iframe.html3
-rw-r--r--testing/web-platform/tests/geolocation-API/support.js30
-rw-r--r--testing/web-platform/tests/geolocation-API/watchPosition_TypeError.https.html65
-rw-r--r--testing/web-platform/tests/geolocation-API/watchPosition_permission_deny.https.html45
22 files changed, 844 insertions, 0 deletions
diff --git a/testing/web-platform/tests/geolocation-API/META.yml b/testing/web-platform/tests/geolocation-API/META.yml
new file mode 100644
index 0000000000..e3d6c4dff8
--- /dev/null
+++ b/testing/web-platform/tests/geolocation-API/META.yml
@@ -0,0 +1,4 @@
+spec: https://w3c.github.io/geolocation-api/
+suggested_reviewers:
+ - marcoscaceres
+ - reillyeon
diff --git a/testing/web-platform/tests/geolocation-API/PositionOptions.https.html b/testing/web-platform/tests/geolocation-API/PositionOptions.https.html
new file mode 100644
index 0000000000..6b36d66d73
--- /dev/null
+++ b/testing/web-platform/tests/geolocation-API/PositionOptions.https.html
@@ -0,0 +1,93 @@
+<!DOCTYPE html>
+<meta charset="utf-8" />
+<title>Geolocation Test: PositionOptions tests</title>
+<link
+ rel="help"
+ href="http://www.w3.org/TR/geolocation-API/#position_options_interface"
+/>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="/resources/testdriver.js"></script>
+<script src="/resources/testdriver-vendor.js"></script>
+
+<script>
+ const resetPermission = () => {
+ return test_driver.set_permission({ name: "geolocation" }, "prompt");
+ };
+ const invalidValues = ["boom", 321, -Infinity, { foo: 5 }];
+
+ promise_test(async (t) => {
+ t.add_cleanup(resetPermission);
+ await test_driver.set_permission({ name: "geolocation" }, "granted");
+ for (const enableHighAccuracy of invalidValues) {
+ navigator.geolocation.getCurrentPosition(() => {}, null, {
+ enableHighAccuracy,
+ });
+ }
+ }, "Call getCurrentPosition with wrong type for enableHighAccuracy. No exception expected.");
+
+ promise_test(async (t) => {
+ t.add_cleanup(resetPermission);
+ await test_driver.set_permission({ name: "geolocation" }, "granted");
+ for (const enableHighAccuracy of invalidValues) {
+ const id = navigator.geolocation.watchPosition(() => {}, null, {
+ enableHighAccuracy,
+ });
+ navigator.geolocation.clearWatch(id);
+ }
+ }, "Call watchPosition with wrong type for enableHighAccuracy. No exception expected.");
+
+ promise_test(async (t) => {
+ t.add_cleanup(resetPermission);
+ await test_driver.set_permission({ name: "geolocation" }, "granted");
+ const error = await new Promise((resolve, reject) => {
+ navigator.geolocation.getCurrentPosition(reject, resolve, {
+ timeout: 0,
+ maxAge: 0,
+ });
+ });
+ assert_equals(error.code, GeolocationPositionError.TIMEOUT);
+ }, "Set timeout and maximumAge to 0, check that timeout error raised (getCurrentPosition)");
+
+ promise_test(async (t) => {
+ t.add_cleanup(resetPermission);
+ await test_driver.set_permission({ name: "geolocation" }, "granted");
+ let watchId;
+ const error = await new Promise((resolve, reject) => {
+ watchId = navigator.geolocation.watchPosition(reject, resolve, {
+ timeout: 0,
+ maxAge: 0,
+ });
+ });
+ assert_equals(error.code, GeolocationPositionError.TIMEOUT);
+ navigator.geolocation.clearWatch(watchId);
+ }, "Set timeout and maximumAge to 0, check that timeout error raised (watchPosition)");
+
+ promise_test(async (t) => {
+ t.add_cleanup(resetPermission);
+ await test_driver.set_permission({ name: "geolocation" }, "granted");
+ let watchId;
+ const error = await new Promise((resolve, reject) => {
+ watchId = navigator.geolocation.getCurrentPosition(reject, resolve, {
+ timeout: -100,
+ maxAge: -100,
+ });
+ });
+ assert_equals(error.code, GeolocationPositionError.TIMEOUT);
+ navigator.geolocation.clearWatch(watchId);
+ }, "Check that a negative timeout and maxAge values are clamped to 0 (getCurrentPosition)");
+
+ promise_test(async (t) => {
+ t.add_cleanup(resetPermission);
+ await test_driver.set_permission({ name: "geolocation" }, "granted");
+ let watchId;
+ const error = await new Promise((resolve, reject) => {
+ watchId = navigator.geolocation.watchPosition(reject, resolve, {
+ timeout: -100,
+ maxAge: -100,
+ });
+ });
+ assert_equals(error.code, GeolocationPositionError.TIMEOUT);
+ navigator.geolocation.clearWatch(watchId);
+ }, "Check that a negative timeout and maxAge values are clamped to 0 (watchPosition)");
+</script>
diff --git a/testing/web-platform/tests/geolocation-API/clearWatch_TypeError.https.html b/testing/web-platform/tests/geolocation-API/clearWatch_TypeError.https.html
new file mode 100644
index 0000000000..37ebeca885
--- /dev/null
+++ b/testing/web-platform/tests/geolocation-API/clearWatch_TypeError.https.html
@@ -0,0 +1,13 @@
+<!DOCTYPE html>
+<meta charset="utf-8" />
+<title>Geolocation Test: clearWatch TypeError tests</title>
+<link rel="help" href="http://www.w3.org/TR/geolocation-API/#clear-watch" />
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script>
+ for (const invalidId of [NaN, -1, 0, 1, 2147483648, Infinity, -Infinity]) {
+ test(() => {
+ navigator.geolocation.clearWatch(invalidId);
+ }, `Test that calling clearWatch with invalid watch ID (${invalidId}) does not cause an exception`);
+ }
+</script>
diff --git a/testing/web-platform/tests/geolocation-API/disabled-by-permissions-policy.https.sub.html b/testing/web-platform/tests/geolocation-API/disabled-by-permissions-policy.https.sub.html
new file mode 100644
index 0000000000..6bd3e3500b
--- /dev/null
+++ b/testing/web-platform/tests/geolocation-API/disabled-by-permissions-policy.https.sub.html
@@ -0,0 +1,70 @@
+<!DOCTYPE html>
+<meta charset="utf-8" />
+<body>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <script src="/resources/testdriver.js"></script>
+ <script src="/resources/testdriver-vendor.js"></script>
+ <script src="/permissions-policy/resources/permissions-policy.js"></script>
+ <script>
+ "use strict";
+
+ const same_origin_src =
+ "/permissions-policy/resources/permissions-policy-geolocation.html";
+ const cross_origin_src =
+ "https://{{hosts[][]}}:{{ports[https][0]}}" + same_origin_src;
+
+ promise_test(async (t) => {
+ await test_driver.set_permission(
+ { name: "geolocation" },
+ "granted"
+ );
+
+ const posError = await new Promise((resolve, reject) => {
+ navigator.geolocation.getCurrentPosition(reject, resolve);
+ });
+
+ assert_true(
+ posError instanceof GeolocationPositionError,
+ "Expected instance of GeolocationPositionError"
+ );
+
+ assert_equals(
+ posError.code,
+ GeolocationPositionError.prototype.PERMISSION_DENIED,
+ "Expected PERMISSION_DENIED"
+ );
+
+ const watchError = await new Promise((resolve, reject) => {
+ navigator.geolocation.watchPosition(reject, resolve);
+ });
+ assert_true(
+ watchError instanceof GeolocationPositionError,
+ "Expected instance of GeolocationPositionError"
+ );
+ assert_equals(
+ watchError.code,
+ GeolocationPositionError.prototype.PERMISSION_DENIED,
+ "Expected PERMISSION_DENIED"
+ );
+ }, "Permissions-Policy header geolocation=() disallows the top-level document.");
+
+ async_test((t) => {
+ test_feature_availability(
+ "geolocation",
+ t,
+ same_origin_src,
+ expect_feature_unavailable_default
+ );
+ }, "Permissions-Policy header geolocation=() disallows same-origin iframes.");
+
+ async_test((t) => {
+ test_feature_availability(
+ "geolocation",
+ t,
+ cross_origin_src,
+ expect_feature_unavailable_default
+ );
+ }, "Permissions-Policy header geolocation=() disallows cross-origin iframes.");
+ </script>
+</body>
diff --git a/testing/web-platform/tests/geolocation-API/disabled-by-permissions-policy.https.sub.html.headers b/testing/web-platform/tests/geolocation-API/disabled-by-permissions-policy.https.sub.html.headers
new file mode 100644
index 0000000000..26bfbc2496
--- /dev/null
+++ b/testing/web-platform/tests/geolocation-API/disabled-by-permissions-policy.https.sub.html.headers
@@ -0,0 +1 @@
+Permissions-Policy: geolocation=()
diff --git a/testing/web-platform/tests/geolocation-API/enabled-by-permission-policy-attribute-redirect-on-load.https.sub.html b/testing/web-platform/tests/geolocation-API/enabled-by-permission-policy-attribute-redirect-on-load.https.sub.html
new file mode 100644
index 0000000000..864fb5e761
--- /dev/null
+++ b/testing/web-platform/tests/geolocation-API/enabled-by-permission-policy-attribute-redirect-on-load.https.sub.html
@@ -0,0 +1,36 @@
+<!DOCTYPE html>
+<body>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="/permissions-policy/resources/permissions-policy.js"></script>
+<script>
+ "use strict";
+
+ const relative_path = "/permissions-policy/resources/permissions-policy-geolocation.html";
+ const base_src = "/permissions-policy/resources/redirect-on-load.html#";
+ const same_origin_src = base_src + relative_path;
+ const cross_origin_src =
+ `${base_src}https://{{hosts[][]}}:{{ports[https][0]}}${relative_path}`;
+
+ async_test(t => {
+ test_feature_availability(
+ 'geolocation',
+ t,
+ same_origin_src,
+ expect_feature_available_default,
+ "geolocation"
+ );
+ }, 'Permissions-Policy allow="geolocation" allows same-origin relocation');
+
+ async_test(t => {
+ test_feature_availability(
+ 'geolocation',
+ t,
+ cross_origin_src,
+ expect_feature_available_default,
+ "geolocation"
+ );
+ }, 'Permissions-Policy allow="geolocation" allows cross-origin relocation');
+
+</script>
+</body>
diff --git a/testing/web-platform/tests/geolocation-API/enabled-by-permission-policy-attribute.https.sub.html b/testing/web-platform/tests/geolocation-API/enabled-by-permission-policy-attribute.https.sub.html
new file mode 100644
index 0000000000..018409b829
--- /dev/null
+++ b/testing/web-platform/tests/geolocation-API/enabled-by-permission-policy-attribute.https.sub.html
@@ -0,0 +1,34 @@
+<!DOCTYPE html>
+<body>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="/permissions-policy/resources/permissions-policy.js"></script>
+<script>
+ "use strict";
+
+ const same_origin_src =
+ "/permissions-policy/resources/permissions-policy-geolocation.html";
+ const cross_origin_src =
+ "https://{{hosts[][]}}:{{ports[https][0]}}" + same_origin_src;
+
+ async_test(t => {
+ test_feature_availability(
+ "geolocation",
+ t,
+ same_origin_src,
+ expect_feature_available_default,
+ "geolocation"
+ );
+ }, 'Permissions policy "geolocation" can be enabled in same-origin iframe using allow="geolocation" attribute');
+
+ async_test(t => {
+ test_feature_availability(
+ "geolocation",
+ t,
+ cross_origin_src,
+ expect_feature_available_default,
+ "geolocation"
+ );
+ }, 'Permissions policy "geolocation" can be enabled in cross-origin iframe using allow="geolocation" attribute');
+</script>
+</body>
diff --git a/testing/web-platform/tests/geolocation-API/enabled-by-permissions-policy.https.sub.html b/testing/web-platform/tests/geolocation-API/enabled-by-permissions-policy.https.sub.html
new file mode 100644
index 0000000000..007f79ab9c
--- /dev/null
+++ b/testing/web-platform/tests/geolocation-API/enabled-by-permissions-policy.https.sub.html
@@ -0,0 +1,45 @@
+<!DOCTYPE html>
+<meta charset="utf-8" />
+<body>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <script src="/resources/testdriver.js"></script>
+ <script src="/resources/testdriver-vendor.js"></script>
+ <script src="/permissions-policy/resources/permissions-policy.js"></script>
+ <script>
+ const same_origin_src =
+ "/permissions-policy/resources/permissions-policy-geolocation.html";
+ const cross_origin_src =
+ "https://{{hosts[][]}}:{{ports[https][0]}}" + same_origin_src;
+
+ promise_test(async (t) => {
+ await test_driver.set_permission({ name: "geolocation" }, "granted");
+ const result = await new Promise((resolve, reject) => {
+ navigator.geolocation.getCurrentPosition(resolve, reject);
+ });
+
+ assert_true(
+ result instanceof GeolocationPosition,
+ "Expected a GeolocationPosition"
+ );
+ }, "Permissions-Policy header geolocation=* allows the top-level document.");
+
+ async_test((t) => {
+ test_feature_availability(
+ "geolocation",
+ t,
+ same_origin_src,
+ expect_feature_available_default
+ );
+ }, "Permissions-Policy header geolocation=* allows same-origin iframes.");
+
+ async_test((t) => {
+ test_feature_availability(
+ "geolocation",
+ t,
+ cross_origin_src,
+ expect_feature_available_default
+ );
+ }, "Permissions-Policy header geolocation=* allows cross-origin iframes.");
+ </script>
+</body>
diff --git a/testing/web-platform/tests/geolocation-API/enabled-by-permissions-policy.https.sub.html.headers b/testing/web-platform/tests/geolocation-API/enabled-by-permissions-policy.https.sub.html.headers
new file mode 100644
index 0000000000..774f4819e9
--- /dev/null
+++ b/testing/web-platform/tests/geolocation-API/enabled-by-permissions-policy.https.sub.html.headers
@@ -0,0 +1 @@
+Permissions-Policy: geolocation=*
diff --git a/testing/web-platform/tests/geolocation-API/enabled-on-self-origin-by-permissions-policy.https.sub.html b/testing/web-platform/tests/geolocation-API/enabled-on-self-origin-by-permissions-policy.https.sub.html
new file mode 100644
index 0000000000..d879c1c543
--- /dev/null
+++ b/testing/web-platform/tests/geolocation-API/enabled-on-self-origin-by-permissions-policy.https.sub.html
@@ -0,0 +1,42 @@
+<!DOCTYPE html>
+<body>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <script src="/resources/testdriver.js"></script>
+ <script src="/resources/testdriver-vendor.js"></script>
+ <script src="/permissions-policy/resources/permissions-policy.js"></script>
+
+ <script>
+ "use strict";
+
+ const same_origin_src =
+ "/permissions-policy/resources/permissions-policy-geolocation.html";
+ const cross_origin_src =
+ "https://{{hosts[][]}}:{{ports[https][0]}}" + same_origin_src;
+
+ promise_test(async (t) => {
+ await test_driver.set_permission({ name: "geolocation" }, "granted");
+ await new Promise((resolve, reject) => {
+ navigator.geolocation.getCurrentPosition(resolve, reject);
+ });
+ }, "Permissions-Policy header geolocation=(self) allows the top-level document.");
+
+ async_test((t) => {
+ test_feature_availability(
+ "geolocation",
+ t,
+ same_origin_src,
+ expect_feature_available_default
+ );
+ }, "Permissions-Policy header geolocation=(self) allows same-origin iframes.");
+
+ async_test((t) => {
+ test_feature_availability(
+ "geolocation",
+ t,
+ cross_origin_src,
+ expect_feature_unavailable_default
+ );
+ }, "Permissions-Policy header geolocation=(self) disallows cross-origin iframes.");
+ </script>
+</body>
diff --git a/testing/web-platform/tests/geolocation-API/enabled-on-self-origin-by-permissions-policy.https.sub.html.headers b/testing/web-platform/tests/geolocation-API/enabled-on-self-origin-by-permissions-policy.https.sub.html.headers
new file mode 100644
index 0000000000..9fa0a4ac9a
--- /dev/null
+++ b/testing/web-platform/tests/geolocation-API/enabled-on-self-origin-by-permissions-policy.https.sub.html.headers
@@ -0,0 +1 @@
+Permissions-Policy: geolocation=(self)
diff --git a/testing/web-platform/tests/geolocation-API/getCurrentPosition_TypeError.https.html b/testing/web-platform/tests/geolocation-API/getCurrentPosition_TypeError.https.html
new file mode 100644
index 0000000000..9da8ac1d29
--- /dev/null
+++ b/testing/web-platform/tests/geolocation-API/getCurrentPosition_TypeError.https.html
@@ -0,0 +1,61 @@
+<!DOCTYPE HTML>
+<meta charset='utf-8'>
+<title>Geolocation Test: getCurrentPosition TypeError tests</title>
+<link rel='help' href='http://www.w3.org/TR/geolocation-API/'>
+<script src='/resources/testharness.js'></script>
+<script src='/resources/testharnessreport.js'></script>
+
+<script>
+// Rewrite http://dev.w3.org/geo/api/test-suite/t.html?00027
+test(function() {
+ assert_throws_js(TypeError, function() {
+ navigator.geolocation.getCurrentPosition();
+ });
+}, 'Call getCurrentPosition without arguments, check that exception is thrown');
+
+// Rewrite http://dev.w3.org/geo/api/test-suite/t.html?00011
+test(function() {
+ assert_throws_js(TypeError, function() {
+ navigator.geolocation.getCurrentPosition(null);
+ });
+}, 'Call getCurrentPosition with null success callback, check that exception is thrown');
+
+// Rewrite http://dev.w3.org/geo/api/test-suite/t.html?00013
+test(function() {
+ assert_throws_js(TypeError, function() {
+ navigator.geolocation.getCurrentPosition(null, null);
+ });
+}, 'Call getCurrentPosition with null success and error callbacks, check that exception is thrown');
+
+// Rewrite http://dev.w3.org/geo/api/test-suite/t.html?00028
+test(function() {
+ assert_throws_js(TypeError, function() {
+ navigator.geolocation.getCurrentPosition(3);
+ });
+}, 'Call getCurrentPosition() with wrong type for first argument. Exception expected.');
+
+// Rewrite http://dev.w3.org/geo/api/test-suite/t.html?00029
+test(function() {
+ assert_throws_js(TypeError, function() {
+ navigator.geolocation.getCurrentPosition(()=>{}, 4);
+ });
+}, 'Call getCurrentPosition() with wrong type for second argument. Exception expected.');
+
+// Rewrite http://dev.w3.org/geo/api/test-suite/t.html?00030
+test(function() {
+ assert_throws_js(TypeError, function() {
+ navigator.geolocation.getCurrentPosition(()=>{}, ()=>{}, 4);
+ });
+}, 'Call getCurrentPosition() with wrong type for third argument. Exception expected.');
+
+test(function () {
+ const handleEvent = ()=>{};
+ assert_throws_js(TypeError, function () {
+ navigator.geolocation.getCurrentPosition({ handleEvent });
+ });
+
+ assert_throws_js(TypeError, function () {
+ navigator.geolocation.getCurrentPosition(()=>{}, { handleEvent });
+ });
+}, "Calling getCurrentPosition() with a legacy event handler objects.");
+</script>
diff --git a/testing/web-platform/tests/geolocation-API/getCurrentPosition_permission_allow.https.html b/testing/web-platform/tests/geolocation-API/getCurrentPosition_permission_allow.https.html
new file mode 100644
index 0000000000..c7fa970e08
--- /dev/null
+++ b/testing/web-platform/tests/geolocation-API/getCurrentPosition_permission_allow.https.html
@@ -0,0 +1,55 @@
+<!DOCTYPE html>
+<meta charset="utf-8" />
+<title>Geolocation Test: getCurrentPosition() location access</title>
+<link
+ rel="help"
+ href="https://www.w3.org/TR/geolocation/#getcurrentposition-method"
+/>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="/resources/testdriver.js"></script>
+<script src="/resources/testdriver-vendor.js"></script>
+<script>
+ promise_test(async (t) => {
+ t.add_cleanup(() => {
+ return test_driver.set_permission({ name: "geolocation" }, "prompt");
+ });
+ await test_driver.set_permission({ name: "geolocation" }, "granted");
+ const position = await new Promise((resolve, reject) => {
+ let calledAsync = false;
+ navigator.geolocation.getCurrentPosition(
+ t.step_func((position) => {
+ assert_true(
+ calledAsync,
+ "Expected callback to be called asynchronously"
+ );
+ resolve(position);
+ }),
+ reject
+ );
+ calledAsync = true;
+ });
+ assert_true(
+ position instanceof GeolocationPosition,
+ "Expected GeolocationPosition"
+ );
+ }, "User allows access, check that success callback is called.");
+
+ promise_test(async (t) => {
+ t.add_cleanup(() => {
+ return test_driver.set_permission({ name: "geolocation" }, "prompt");
+ });
+ await test_driver.set_permission({ name: "geolocation" }, "granted");
+ const position = await new Promise((resolve, reject) => {
+ try {
+ navigator.geolocation.getCurrentPosition(resolve, null);
+ } catch (err) {
+ reject(err);
+ }
+ });
+ assert_true(
+ position instanceof GeolocationPosition,
+ "Expected GeolocationPosition"
+ );
+ }, "Error callback is nullable for getCurrentPosition().");
+</script>
diff --git a/testing/web-platform/tests/geolocation-API/getCurrentPosition_permission_deny.https.html b/testing/web-platform/tests/geolocation-API/getCurrentPosition_permission_deny.https.html
new file mode 100644
index 0000000000..54bba9aeab
--- /dev/null
+++ b/testing/web-platform/tests/geolocation-API/getCurrentPosition_permission_deny.https.html
@@ -0,0 +1,29 @@
+<!DOCTYPE html>
+<meta charset="utf-8" />
+<title>Geolocation Test: getCurrentPosition location access denied</title>
+<link rel="help" href="http://www.w3.org/TR/geolocation-API/#privacy_for_uas" />
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="/resources/testdriver.js"></script>
+<script src="/resources/testdriver-vendor.js"></script>
+<script>
+ promise_test(async (t) => {
+ t.add_cleanup(() => {
+ return test_driver.set_permission({ name: "geolocation" }, "prompt");
+ });
+ await test_driver.set_permission({ name: "geolocation" }, "denied");
+ const error = await new Promise((resolve, reject) => {
+ let calledAsync = false;
+ navigator.geolocation.getCurrentPosition(reject, t.step_func((error) => {
+ assert_true(calledAsync, "Expected callback to be called asynchronously");
+ resolve(error);
+ }));
+ calledAsync = true;
+ });
+ assert_true(
+ error instanceof GeolocationPositionError,
+ "should be a GeolocationPositionError"
+ );
+ assert_equals(error.code, error.PERMISSION_DENIED);
+ }, "User denies access, check that error callback is called with correct code");
+</script>
diff --git a/testing/web-platform/tests/geolocation-API/idlharness.https.window.js b/testing/web-platform/tests/geolocation-API/idlharness.https.window.js
new file mode 100644
index 0000000000..eadd6b7a4f
--- /dev/null
+++ b/testing/web-platform/tests/geolocation-API/idlharness.https.window.js
@@ -0,0 +1,14 @@
+// META: script=/resources/WebIDLParser.js
+// META: script=/resources/idlharness.js
+// META: script=/resources/testdriver.js
+// META: script=/resources/testdriver-vendor.js
+
+// https://www.w3.org/TR/geolocation-API/
+
+window.onload = async () => {
+ idl_test(["geolocation"], ["hr-time", "html"], (idl_array) => {
+ idl_array.add_objects({
+ Geolocation: ["navigator.geolocation"],
+ });
+ });
+};
diff --git a/testing/web-platform/tests/geolocation-API/non-fully-active.https.html b/testing/web-platform/tests/geolocation-API/non-fully-active.https.html
new file mode 100644
index 0000000000..13853c0ef8
--- /dev/null
+++ b/testing/web-platform/tests/geolocation-API/non-fully-active.https.html
@@ -0,0 +1,106 @@
+<!DOCTYPE html>
+<meta charset="utf-8" />
+<title>Geolocation Test: non-fully active document</title>
+<link rel="help" href="https://github.com/w3c/geolocation-api/pull/97" />
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="/resources/testdriver.js"></script>
+<script src="/resources/testdriver-vendor.js"></script>
+<script src="support.js"></script>
+<body></body>
+<script>
+ promise_test(async (t) => {
+ t.add_cleanup(() => {
+ return test_driver.set_permission({ name: "geolocation" }, "prompt");
+ });
+ await test_driver.set_permission({ name: "geolocation" }, "granted");
+
+ // Create the iframe, wait for it to load...
+ const iframe = document.createElement("iframe");
+ iframe.src = "resources/iframe.html";
+ iframe.allow = "geolocation";
+ document.body.appendChild(iframe);
+
+ // ...wait for the iframe to load...
+ await new Promise((resolve) =>
+ iframe.addEventListener("load", resolve, { once: true })
+ );
+
+ // Steal geolocation.
+ const geo = iframe.contentWindow.navigator.geolocation;
+
+ // No longer fully active.
+ iframe.remove();
+
+ // Try to watch a position while not fully active...
+ const watchError = await new Promise((resolve, reject) => {
+ const watchId = geo.watchPosition(
+ reject, // We don't want a position
+ resolve // We want an error!
+ );
+ // Always return 0.
+ assert_equals(
+ watchId,
+ 0,
+ "watchId is 0 when document is not fully-active"
+ );
+ // And again, to make sure it's not changing
+ const watchId2 = geo.watchPosition(
+ () => {},
+ () => {}
+ );
+ assert_equals(
+ watchId2,
+ 0,
+ "watchId remains 0 when document is not fully-active"
+ );
+ });
+
+ assert_equals(
+ watchError.code,
+ GeolocationPositionError.POSITION_UNAVAILABLE,
+ "watchPosition() returns an error on non-fully-active document"
+ );
+
+ // Now try to get current position while not fully active...
+ const positionError = await new Promise((resolve, reject) => {
+ geo.getCurrentPosition(
+ reject, // We don't want a position
+ resolve // We want an error!
+ );
+ });
+ assert_equals(
+ positionError.code,
+ GeolocationPositionError.POSITION_UNAVAILABLE,
+ "getCurrentPosition() calls the errorCallback with POSITION_UNAVAILABLE"
+ );
+
+ // Re-attach, and go back to fully active.
+ document.body.appendChild(iframe);
+ iframe.contentWindow.opener = window;
+ await new Promise((resolve) =>
+ iframe.addEventListener("load", resolve, { once: true })
+ );
+
+ // And we are back to fully active.
+ let watchId;
+ let position = await new Promise((resolve, reject) => {
+ watchId = iframe.contentWindow.navigator.geolocation.watchPosition(
+ resolve,
+ reject
+ );
+ });
+ assert_true(Number.isInteger(watchId), "Expected some number for watchId");
+ assert_true(Boolean(position), "Expected a position");
+
+ // Finally, let's get the position from the reattached document.
+ position = await new Promise((resolve, reject) => {
+ iframe.contentWindow.navigator.geolocation.getCurrentPosition(
+ resolve,
+ reject
+ );
+ });
+ assert_true(Boolean(position), "Expected a position");
+ iframe.contentWindow.navigator.geolocation.clearWatch(watchId);
+ }, "non-fully active document behavior");
+</script>
diff --git a/testing/web-platform/tests/geolocation-API/non-secure-contexts.http.html b/testing/web-platform/tests/geolocation-API/non-secure-contexts.http.html
new file mode 100644
index 0000000000..d491086cf8
--- /dev/null
+++ b/testing/web-platform/tests/geolocation-API/non-secure-contexts.http.html
@@ -0,0 +1,82 @@
+<!DOCTYPE html>
+<meta charset="utf-8" />
+<title>Geolocation Test: non-secure contexts</title>
+<link rel="help" href="https://github.com/w3c/geolocation-api/pull/34" />
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script>
+ promise_test(() => {
+ return new Promise(resolve => {
+ let isAsync = true;
+ const successCallback = () => {
+ assert_unreached(
+ "successCallback must never be invoked in non-secure contexts."
+ );
+ };
+ const errorCallBack = () => {
+ isAsync = false;
+ resolve();
+ };
+ navigator.geolocation.getCurrentPosition(successCallback, errorCallBack);
+ assert_true(
+ isAsync,
+ "Expected the errorCallback to be called asynchronously."
+ );
+ });
+ }, "When in a non-secure context, getCurrentPosition()'s errorCallback is asynchronously called.");
+
+ promise_test(async () => {
+ return new Promise(resolve => {
+ let isAsync = true;
+ const successCallback = () => {
+ assert_unreached(
+ "successCallback must never be invoked in non-secure contexts."
+ );
+ };
+ const errorCallBack = () => {
+ isAsync = false;
+ resolve();
+ };
+ navigator.geolocation.watchPosition(successCallback, errorCallBack);
+ assert_true(isAsync, "errorCallback must be called asynchronously.");
+ });
+ }, "When in a non-secure context, watchPosition()'s errorCallback is asynchronously called.");
+
+ promise_test(async () => {
+ const positionErrorPromise = new Promise(errorCallBack => {
+ const successCallback = () => {
+ assert_unreached(
+ "successCallback must never be invoked in non-secure contexts."
+ );
+ };
+ navigator.geolocation.getCurrentPosition(successCallback, errorCallBack);
+ });
+ const positionError = await positionErrorPromise;
+ assert_equals(
+ positionError.code,
+ 1,
+ "Expected the value for PERMISSION_DENIED, which is 1."
+ );
+ }, "When in a non-secure context, the getCurrentPosition() errorCallBack gets a GeolocationPositionError with the correct error code.");
+
+ promise_test(async () => {
+ const positionErrorPromise = new Promise(errorCallBack => {
+ const successCallback = () => {
+ assert_unreached(
+ "successCallback must never be invoked in non-secure contexts."
+ );
+ };
+ const id = navigator.geolocation.watchPosition(
+ successCallback,
+ errorCallBack
+ );
+ assert_true(Number.isInteger(id), "Must return an identifier.");
+ });
+ const positionError = await positionErrorPromise;
+ assert_equals(
+ positionError.code,
+ 1,
+ "Expected the value for PERMISSION_DENIED, which is 1."
+ );
+ }, "When in a non-secure context, the watchPosition() errorCallBack gets a GeolocationPositionError with the correct error code.");
+</script>
diff --git a/testing/web-platform/tests/geolocation-API/permission.https.html b/testing/web-platform/tests/geolocation-API/permission.https.html
new file mode 100644
index 0000000000..4062843349
--- /dev/null
+++ b/testing/web-platform/tests/geolocation-API/permission.https.html
@@ -0,0 +1,14 @@
+<!doctype html>
+<meta charset=utf-8>
+<title>Test geolocation is a powerful feature via Permissions API</title>
+<script src=/resources/testharness.js></script>
+<script src=/resources/testharnessreport.js></script>
+
+<script>
+promise_test(async (test) => {
+ const status = await navigator.permissions.query({ name: "geolocation" });
+ assert_true(status instanceof PermissionStatus);
+ assert_equals(status.name, "geolocation", `permission's name must be "geolocation"`);
+ assert_equals(status.state, "prompt", `permission's state must be "prompt" by default`);
+}, `Query "geolocation" powerful feature`);
+</script>
diff --git a/testing/web-platform/tests/geolocation-API/resources/iframe.html b/testing/web-platform/tests/geolocation-API/resources/iframe.html
new file mode 100644
index 0000000000..25cf3d92f3
--- /dev/null
+++ b/testing/web-platform/tests/geolocation-API/resources/iframe.html
@@ -0,0 +1,3 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<h1>Just a support file</h1>
diff --git a/testing/web-platform/tests/geolocation-API/support.js b/testing/web-platform/tests/geolocation-API/support.js
new file mode 100644
index 0000000000..0f0e7f65b2
--- /dev/null
+++ b/testing/web-platform/tests/geolocation-API/support.js
@@ -0,0 +1,30 @@
+var geo;
+
+setup(function() {
+ geo = navigator.geolocation;
+});
+
+// The spec states that an implementation SHOULD acquire user permission before
+// beginning the position acquisition steps. If an implementation follows this
+// advice, set the following flag to aid debugging.
+var isUsingPreemptivePermission = false;
+
+
+var dummyFunction = function() {};
+
+var positionToString = function(pos) {
+ var c = pos.coords;
+ return '[lat: ' + c.latitude + ', lon: ' + c.longitude + ', acc: ' + c.accuracy + ']';
+};
+
+var errorToString = function(err) {
+ var codeString;
+ switch(err.code) {
+ case err.UNKNOWN_ERROR: codeString = 'UNKNOWN_ERROR'; break;
+ case err.PERMISSION_DENIED: codeString = 'PERMISSION_DENIED'; break;
+ case err.POSITION_UNAVAILABLE: codeString = 'POSITION_UNAVAILABLE'; break;
+ case err.TIMEOUT: codeString = 'TIMEOUT'; break;
+ default: codeString = 'undefined error code'; break;
+ }
+ return '[code: ' + codeString + ' (' + err.code + '), message: ' + (err.message ? err.message : '(empty)') + ']';
+};
diff --git a/testing/web-platform/tests/geolocation-API/watchPosition_TypeError.https.html b/testing/web-platform/tests/geolocation-API/watchPosition_TypeError.https.html
new file mode 100644
index 0000000000..4ae7a89037
--- /dev/null
+++ b/testing/web-platform/tests/geolocation-API/watchPosition_TypeError.https.html
@@ -0,0 +1,65 @@
+<!DOCTYPE html>
+<meta charset="utf-8" />
+<title>Geolocation Test: watchPosition TypeError tests</title>
+<link rel="help" href="http://www.w3.org/TR/geolocation-API/" />
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+
+<script>
+ // Rewrite http://dev.w3.org/geo/api/test-suite/t.html?00058
+ test(() => {
+ assert_throws_js(TypeError, () => {
+ navigator.geolocation.watchPosition();
+ });
+ }, "Call watchPosition without arguments, check that exception is thrown");
+
+ // Rewrite http://dev.w3.org/geo/api/test-suite/t.html?00015
+ test(() => {
+ assert_throws_js(TypeError, () => {
+ navigator.geolocation.watchPosition(null);
+ });
+ }, "Call watchPosition with null success callback, check that exception is thrown");
+
+ // Rewrite http://dev.w3.org/geo/api/test-suite/t.html?00017
+ test(() => {
+ assert_throws_js(TypeError, () => {
+ navigator.geolocation.watchPosition(null, null);
+ });
+ }, "Call watchPosition with null success and error callbacks, check that exception is thrown");
+
+ // Rewrite http://dev.w3.org/geo/api/test-suite/t.html?00059
+ test(() => {
+ assert_throws_js(TypeError, () => {
+ navigator.geolocation.watchPosition(3);
+ });
+ }, "Call watchPosition() with wrong type for first argument. Exception expected.");
+
+ // Rewrite http://dev.w3.org/geo/api/test-suite/t.html?00060
+ test(() => {
+ assert_throws_js(TypeError, () => {
+ navigator.geolocation.watchPosition(() => {}, 4);
+ });
+ }, "Call watchPosition() with wrong type for second argument. Exception expected.");
+
+ // Rewrite http://dev.w3.org/geo/api/test-suite/t.html?00061
+ test(() => {
+ assert_throws_js(TypeError, () => {
+ navigator.geolocation.watchPosition(
+ () => {},
+ () => {},
+ 4
+ );
+ });
+ }, "Call watchPosition() with wrong type for third argument. Exception expected.");
+
+ test(function () {
+ const handleEvent = function(){};
+ assert_throws_js(TypeError, function () {
+ navigator.geolocation.watchPosition({ handleEvent });
+ });
+
+ assert_throws_js(TypeError, function () {
+ navigator.geolocation.watchPosition(()=>{}, { handleEvent });
+ });
+ }, "Calling watchPosition() with a legacy event handler object.");
+</script>
diff --git a/testing/web-platform/tests/geolocation-API/watchPosition_permission_deny.https.html b/testing/web-platform/tests/geolocation-API/watchPosition_permission_deny.https.html
new file mode 100644
index 0000000000..d47f2b5594
--- /dev/null
+++ b/testing/web-platform/tests/geolocation-API/watchPosition_permission_deny.https.html
@@ -0,0 +1,45 @@
+<!DOCTYPE html>
+<meta charset="utf-8" />
+<title>Geolocation Test: watchPosition location access denied</title>
+<link rel="help" href="http://www.w3.org/TR/geolocation-API/#privacy_for_uas" />
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="/resources/testdriver.js"></script>
+<script src="/resources/testdriver-vendor.js"></script>
+<script>
+ const resetPermission = () => {
+ return test_driver.set_permission({ name: "geolocation" }, "prompt");
+ };
+
+ promise_test(async (t) => {
+ t.add_cleanup(resetPermission);
+ await test_driver.set_permission({ name: "geolocation" }, "denied");
+ let errorCBCalled = false;
+ let id;
+ const errorPromise = new Promise((resolve, reject) => {
+ id = navigator.geolocation.watchPosition(reject, () => {
+ errorCBCalled = true;
+ resolve();
+ });
+ });
+ assert_false(
+ errorCBCalled,
+ "error callback must not be called synchronously"
+ );
+ await errorPromise;
+ navigator.geolocation.clearWatch(id);
+ }, "Check that watchPosition returns synchronously before any callbacks are invoked.");
+
+ promise_test(async (t) => {
+ t.add_cleanup(resetPermission);
+ await test_driver.set_permission({ name: "geolocation" }, "denied");
+ const promise = new Promise((resolve, reject) => {
+ navigator.geolocation.watchPosition(reject, resolve);
+ });
+ const result = await promise;
+ assert_true(
+ result instanceof GeolocationPositionError,
+ "expected GeolocationPositionError"
+ );
+ }, "User denies access, check that error callback is called.");
+</script>