gecko/dom/tests/mochitest/geolocation/test_cachedPosition.html

84 lines
2.3 KiB
HTML

<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=850442
-->
<head>
<title>Test for getCurrentPosition </title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="geolocation_common.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=850442">Mozilla Bug 850442</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
SimpleTest.waitForExplicitFinish();
resume_geolocationProvider(function() {
force_prompt(true, test1);
});
function done() {
resume_geolocationProvider(function() {
SimpleTest.finish();
});
}
function errorCallback(err) {
ok(false, "error callback should not have been called");
done();
}
function testCachedPosition() {
var cached = null;
navigator.geolocation.getCurrentPosition(function(pos) {
// get cached position
cached = pos;
navigator.geolocation.getCurrentPosition(function(pos) {
// force use of cached position, make sure
// it's equal to what we have
is(pos, cached, "position should be equal to cached position");
resume_geolocationProvider(function() {
navigator.geolocation.getCurrentPosition(function(pos) {
// force new position, can't be the one we have
isnot(pos, cached, "new position should be different from the cached");
done();
}, errorCallback, {maximumAge: 0});
});
}, errorCallback, {maximumAge: 21600000});
}, errorCallback, {maximumAge: 21600000});
}
// ensure we have a position in cache,
// and stop receiving new positions once we do so the
// cache doesn't change
var watchID;
function test1() {
watchID = navigator.geolocation.watchPosition(
function(pos) {
info("Stopping geolocation provider");
stop_geolocationProvider(function() {});
}, function(err) {
is(err.code, err.TIMEOUT, "got TIMEOUT for watchPosition");
// no new positions in a while,
// the cache should be stable now.
navigator.geolocation.clearWatch(watchID);
testCachedPosition();
}, {maximumAge: 0, timeout: 1000}
);
}
</script>
</pre>
</body>
</html>