Automatic update from web-platform-tests geolocation: Convert tojson.https.window.js to use bidi Change-Id: I6c1d0610267f9a47cd6ef0630ec66235e7f27c60 Bug: 348794702 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7004945 Commit-Queue: Alvin Ji <alvinji@chromium.org> Reviewed-by: Matt Reynolds <mattreynolds@chromium.org> Cr-Commit-Position: refs/heads/main@{#1524440} -- wpt-commits: aa8321d988637aa616381fa90ce0bea7a8b76a17 wpt-pr: 55203
54 lines
1.5 KiB
JavaScript
54 lines
1.5 KiB
JavaScript
// META: script=/resources/testdriver.js?feature=bidi
|
|
// META: script=/resources/testdriver-vendor.js
|
|
"use strict";
|
|
|
|
function check_equals(original, json) {
|
|
const proto = Object.getPrototypeOf(original);
|
|
const keys = Object.keys(proto).filter(
|
|
(k) => typeof original[k] !== "function",
|
|
);
|
|
for (const key of keys) {
|
|
assert_equals(
|
|
original[key],
|
|
json[key],
|
|
`${original.constructor.name} ${key} entry does not match its toJSON value`,
|
|
);
|
|
}
|
|
}
|
|
|
|
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});
|
|
});
|
|
|
|
const latitude = 51.478;
|
|
const longitude = -0.166;
|
|
const accuracy = 100;
|
|
await test_driver.bidi.emulation.set_geolocation_override({
|
|
coordinates: {latitude, longitude, accuracy}
|
|
});
|
|
|
|
const position = await new Promise((resolve, reject) => {
|
|
navigator.geolocation.getCurrentPosition(resolve, reject);
|
|
});
|
|
|
|
const json = position.toJSON();
|
|
assert_equals(
|
|
position.timestamp,
|
|
json.timestamp,
|
|
"GeolocationPosition timestamp entry does not match its toJSON value",
|
|
);
|
|
|
|
check_equals(position.coords, json.coords);
|
|
check_equals(position.coords, position.coords.toJSON());
|
|
}, "Test toJSON() in GeolocationPosition and GeolocationCoordinates.");
|