tenfourfox/dom/tests/mochitest/geolocation/test_mozsettings.html
Cameron Kaiser c9b2922b70 hello FPR
2017-04-19 00:56:45 -07:00

93 lines
3.3 KiB
HTML

<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=478911
-->
<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=777594">Mozilla Bug 777594</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
SimpleTest.waitForExplicitFinish();
SimpleTest.requestFlakyTimeout("untriaged");
var timeToWaitMs = 1000;
resume_geolocationProvider(function() {
force_prompt(true, test1);
});
SpecialPowers.importInMainProcess("resource://gre/modules/SettingsRequestManager.jsm");
function test1() {
//This pushPermissions call is after pushPrefEnv call and pushPrefEnv calls follow after this
SpecialPowers.pushPermissions([{'type': 'settings-read', 'allow': true, 'context': document},
{'type': 'settings-write', 'allow': true, 'context': document},
{'type': 'settings-api-write', 'allow': true, 'context': document},
{'type': 'settings-api-read', 'allow': true, 'context': document}
], test2);
}
function test2() {
ok(navigator.geolocation, "get geolocation object");
toggleGeolocationSetting(false, function() {
ok(true, "turned off geolocation via mozSettings");
setTimeout(function() {
navigator.geolocation.getCurrentPosition(successCallbackAfterMozsettingOff,
failureCallbackAfterMozsettingOff);
}, timeToWaitMs); // need to wait a bit for all of these async callbacks to finish
});
}
function successCallbackAfterMozsettingOff(position) {
ok(false, "Success callback should not have been called after setting geolocation.enabled to false.");
toggleGeolocationSetting(true, function() {
ok(true, "turned on geolocation via mozSettings");
setTimeout(function() {
navigator.geolocation.getCurrentPosition(successCallbackAfterMozsettingOn,
failureCallbackAfterMozsettingOn);
}, timeToWaitMs); // need to wait a bit for all of these async callbacks to finish
});
}
function failureCallbackAfterMozsettingOff(error) {
ok(true, "Geolocation didn't work after setting geolocation.enabled to false.");
toggleGeolocationSetting(true, function() {
ok(true, "turned on geolocation via mozSettings");
setTimeout(function() {
navigator.geolocation.getCurrentPosition(successCallbackAfterMozsettingOn,
failureCallbackAfterMozsettingOn);
}, timeToWaitMs); // need to wait a bit for all of these async callbacks to finish
});
}
function successCallbackAfterMozsettingOn(position) {
ok(true, "Geolocation worked after setting geolocation.enabled to true.");
SimpleTest.finish();
}
function failureCallbackAfterMozsettingOn(error) {
ok(false, "Geolocation didn't work after setting geolocation.enabled to true.");
SimpleTest.finish();
}
</script>
</pre>
</body>
</html>