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

86 lines
2.0 KiB
HTML
Raw Normal View History

<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=
-->
<head>
<title>Test for watchPosition </title>
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="prompt_common.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=">Mozilla Bug </a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
var numCallbacks = 5;
var callbackCounter = new Array(numCallbacks);
var watchID = new Array(numCallbacks);
function failureCallback(error)
{
ok(error.code == error.POSITION_UNAVAILABLE, "Failure was something other than position unavailable");
removePrompt();
SimpleTest.finish();
}
// define success callbacks
for(var i = 0; i < numCallbacks; i++) {
eval("function successCallback" + i + "(position) {" +
"callbackCounter[" + i + "]++;" +
"success_callback(position);" +
"}"
);
}
function registerWatches() {
for(var i = 0; i < numCallbacks; i++) {
watchID[i] = eval("navigator.geolocation.watchPosition(successCallback"
+ i + ", failureCallback, null);"
);
}
}
function clearWatches() {
for(var i = 0; i < numCallbacks; i++)
navigator.geolocation.clearWatch(watchID[i]);
}
function testAccepted() {
if(TEST_PROVIDER)
checkFlags(callbackCounter, num_pos_changes, false);
clearWatches();
removePrompt();
SimpleTest.finish();
}
/** Test for Bug **/
SimpleTest.waitForExplicitFinish();
attachPrompt();
ok(navigator.geolocation, "Ensure that the geolocation object is present");
promptOption = ACCEPT;
registerWatches();
// wait for position changes
setTimeout(testAccepted, timeout);
</script>
</pre>
</body>
</html>