gecko-dev/testing/web-platform/tests/geolocation/tojson.https.window.js
Marcos Cáceres 0e4dcbc849 Bug 1907237 [wpt PR 47087] - Geolocation: generalize tojson.https.window.js, a=testonly
Automatic update from web-platform-tests
Geolocation: generalize tojson.https.window.js (#47087)

* Geolocation: generalize tojson.https.window.js

* remove setup desc
--

wpt-commits: 073136dbb2cba46d864f7e71ef2420c5775bb3b8
wpt-pr: 47087
2024-07-17 07:38:02 +00:00

37 lines
1.1 KiB
JavaScript

// META: script=/resources/testdriver.js
// 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 () => {
await test_driver.set_permission({ name: "geolocation" }, "granted");
});
promise_test(async (t) => {
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.");