Skip to content

Commit

Permalink
Bug 1902601 [wpt PR 46745] - Geolocation: small cleanup of tests, a=t…
Browse files Browse the repository at this point in the history
…estonly

Automatic update from web-platform-tests
Geolocation: small cleanup of tests (#46745)

--

wpt-commits: 3334c5af355473a7416266b978198d4c586f0cfd
wpt-pr: 46745
  • Loading branch information
marcoscaceres authored and moz-wptsync-bot committed Jun 20, 2024
1 parent dc6e960 commit 5a4695c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 30 deletions.
19 changes: 4 additions & 15 deletions testing/web-platform/tests/geolocation/PositionOptions.https.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@
<script src="/resources/testdriver-vendor.js"></script>

<script>
const resetPermission = () => {
return test_driver.set_permission({ name: "geolocation" }, "prompt");
};
promise_setup(async ()=>{
await test_driver.set_permission({ name: "geolocation" }, "granted");
});

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,
Expand All @@ -27,8 +26,6 @@
}, "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,
Expand All @@ -38,8 +35,6 @@
}, "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,
Expand All @@ -50,8 +45,6 @@
}, "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, {
Expand All @@ -64,8 +57,6 @@
}, "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, {
Expand All @@ -78,8 +69,6 @@
}, "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, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@
<script src="support.js"></script>
<body></body>
<script>
promise_test(async (t) => {
t.add_cleanup(() => {
return test_driver.set_permission({ name: "geolocation" }, "prompt");
});
promise_setup(async () => {
await test_driver.set_permission({ name: "geolocation" }, "granted");
});

promise_test(async (t) => {
// Create the iframe, wait for it to load...
const iframe = document.createElement("iframe");
// ...wait for the iframe to load...
await new Promise((resolve) => {
iframe.src = "resources/iframe.html";
iframe.allow = "geolocation";
Expand Down
28 changes: 18 additions & 10 deletions testing/web-platform/tests/geolocation/permission.https.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
<!doctype html>
<meta charset=utf-8>
<!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 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`);
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"`
);
const states = ["prompt", "granted", "denied"];
assert_true(
states.includes(status.state),
`permission's state must be one of ${states.join(", ")}`
);
}, `Query "geolocation" powerful feature`);
</script>

0 comments on commit 5a4695c

Please sign in to comment.