Files
sousa-gecko/testing/web-platform/tests/geolocation/getCurrentPosition-success.https.html
T
Alvin Ji b69ed1d4aa Bug 2018336 [wpt PR 57947] - Geolocation: Migrate WPTs to use BiDi geolocation overrides, a=testonly
Automatic update from web-platform-tests
Geolocation: Migrate WPTs to use BiDi geolocation overrides

Migrates Geolocation WPTs from
`getCurrentPosition_permission_allow.https.html` to
`getCurrentPosition-success.https.html` to leverage BiDi geolocation
overrides.

The original `getCurrentPosition_permission_allow.https.html` was timing
out on many browsers (as seen on wpt.fyi) because it lacked the
necessary geolocation override to provide a position once permission was
granted.

Change-Id: I13d3958f897da4ec2172cb41509a40573fe25479
Bug: 347055177
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7596084
Commit-Queue: Alvin Ji <alvinji@chromium.org>
Reviewed-by: Reilly Grant <reillyg@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1588129}

--

wpt-commits: 0dc0d98fdb296e92131a6c305aae3df524ce7d2d
wpt-pr: 57947
2026-02-26 15:18:46 +00:00

89 lines
3.0 KiB
HTML

<!DOCTYPE html>
<meta charset="utf-8"/>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js?feature=bidi"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script>
const latitude = 51.478;
const longitude = -0.166;
const accuracy = 100;
promise_setup(async () => {
// Ensure permission is granted before proceeding.
await test_driver.bidi.permissions.set_permission({
descriptor: {name: "geolocation"},
state: "granted",
});
});
promise_test(async (t) => {
t.add_cleanup(async () => {
await test_driver.bidi.emulation.set_geolocation_override(
{coordinates: null});
});
await test_driver.bidi.emulation.set_geolocation_override({
coordinates: {latitude, longitude, accuracy}
});
const position = await new Promise((resolve, reject) => {
let calledAsync = false;
window.navigator.geolocation.getCurrentPosition(
t.step_func((position) => {
assert_true(
calledAsync,
"Expected callback to be called asynchronously"
);
resolve(position.coords.toJSON());
}),
reject,
{timeout: 200}
);
calledAsync = true;
});
assert_equals(position.latitude, latitude);
assert_equals(position.longitude, longitude);
assert_equals(position.accuracy, accuracy);
}, "getCurrentPosition called with success and error callbacks");
promise_test(async (t) => {
t.add_cleanup(async () => {
await test_driver.bidi.emulation.set_geolocation_override(
{coordinates: null});
});
await test_driver.bidi.emulation.set_geolocation_override({
coordinates: {latitude, longitude, accuracy}
});
const position = await new Promise((resolve, reject) => {
let calledAsync = false;
try {
navigator.geolocation.getCurrentPosition(
t.step_func((position) => {
assert_true(
calledAsync,
"Expected callback to be called asynchronously"
);
resolve(position);
}),
null
);
calledAsync = true;
} catch (err) {
reject(err);
}
});
assert_true(
position instanceof GeolocationPosition,
"Expected GeolocationPosition"
);
assert_equals(position.coords.latitude, latitude);
assert_equals(position.coords.longitude, longitude);
assert_equals(position.coords.accuracy, accuracy);
}, "Error callback is nullable for getCurrentPosition().");
</script>