Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions geolocation/getCurrentPosition-error.https.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<!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>
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({
error: {type: "positionUnavailable"}
});

const error = await new Promise(
(resolve, reject) =>
window.navigator.geolocation.getCurrentPosition(
() => reject("Unexpected success callback"),
error => resolve({
code: error.code,
message: error.message,
PERMISSION_DENIED: error.PERMISSION_DENIED,
POSITION_UNAVAILABLE: error.POSITION_UNAVAILABLE,
TIMEOUT: error.TIMEOUT
}),
{timeout: 1000}
));

assert_equals(error.code, 2);
// The message value is not specified.
assert_not_equals(error.message, undefined);
assert_equals(error.PERMISSION_DENIED, 1);
assert_equals(error.POSITION_UNAVAILABLE, 2);
assert_equals(error.TIMEOUT, 3);
}, "Tests Geolocation error callback");
</script>
43 changes: 43 additions & 0 deletions geolocation/getCurrentPosition-success.https.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<!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>
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) =>
window.navigator.geolocation.getCurrentPosition(
position => resolve(position.coords.toJSON()),
error => reject(error),
{timeout: 200}
));

assert_equals(position.latitude, latitude);
assert_equals(position.longitude, longitude);
assert_equals(position.accuracy, accuracy);
}, "Tests Geolocation success callback");
</script>