Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
- This test gets skipped with pattern: os != 'android'
- Manifest: dom/tests/mochitest/geolocation/mochitest.toml
<!DOCTYPE HTML>
<html>
<!--
-->
<head>
<title>Test for getCurrentPosition with native location provider</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1596164">Mozilla Bug 1596164</a>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1765835">Mozilla Bug 1765835</a>
<script type="text/javascript">
"use strict";
add_task(async function test_maximumAge() {
await SpecialPowers.pushPrefEnv({
set: [["geo.provider.testing", false]],
});
await new Promise(resolve => {
navigator.geolocation.getCurrentPosition(() => {
ok(true, "can get position");
resolve();
}, () => {
ok(false, "error callback should not have been called");
resolve();
},
{ maximumAge: 10000 });
});
});
add_task(async function test_highAccuracy() {
await SpecialPowers.pushPrefEnv({
set: [["geo.provider.testing", false]],
});
const lowAccuracy = await new Promise(resolve => {
navigator.geolocation.getCurrentPosition((pos) => {
resolve(pos.coords.accuracy);
}, () => {
ok(false, "error callback should not have been called on low accuracy call");
resolve();
},
{ enableHighAccuracy: false});
});
const highAccuracy = await new Promise(resolve => {
navigator.geolocation.getCurrentPosition((pos) => {
resolve(pos.coords.accuracy);
}, () => {
ok(false, "error callback should not have been called on high accuracy call");
resolve();
},
{ enableHighAccuracy: true});
});
// Low accuracy can sometimes be the same as high accuracy
// if a location provider recently provided a value
if(highAccuracy >= lowAccuracy ){
ok(true, "accuracy is correct");
} else {
ok(false, "lower accuracy calls should not out perform high accuracy calls");
}
});
</script>
</body>
</html>