dom/tests/mochitest/geolocation/test_mozsettings.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/tests/mochitest/geolocation/test_mozsettings.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,87 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=478911
     1.8 +-->
     1.9 +<head>
    1.10 +  <title>Test for getCurrentPosition </title>
    1.11 +  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.12 +  <script type="text/javascript" src="geolocation_common.js"></script>
    1.13 +
    1.14 +<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    1.15 +</head>
    1.16 +<body>
    1.17 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=777594">Mozilla Bug 777594</a>
    1.18 +<p id="display"></p>
    1.19 +<div id="content" style="display: none">
    1.20 +  
    1.21 +</div>
    1.22 +<pre id="test">
    1.23 +<script class="testbody" type="text/javascript">
    1.24 +
    1.25 +SimpleTest.waitForExplicitFinish();
    1.26 +
    1.27 +resume_geolocationProvider(function() {
    1.28 +  force_prompt(true, test1);
    1.29 +});
    1.30 +
    1.31 +if (SpecialPowers.isMainProcess()) {
    1.32 +  SpecialPowers.Cu.import("resource://gre/modules/SettingsChangeNotifier.jsm");
    1.33 +}
    1.34 +
    1.35 +function test1() {
    1.36 +  //This pushPermissions call is after pushPrefEnv call and pushPrefEnv calls follow after this
    1.37 +  SpecialPowers.pushPermissions([{'type': 'settings-read', 'allow': true, 'context': document}, {'type': 'settings-write', 'allow': true, 'context': document}], test2);
    1.38 +}
    1.39 +
    1.40 +function test2() {
    1.41 +  ok(navigator.geolocation, "get geolocation object");
    1.42 +
    1.43 +  toggleGeolocationSetting(false, function() {
    1.44 +      ok(true, "turned off geolocation via mozSettings");
    1.45 +      setTimeout(function() {
    1.46 +	  navigator.geolocation.getCurrentPosition(successCallbackAfterMozsettingOff,
    1.47 +                                                   failureCallbackAfterMozsettingOff);
    1.48 +        }, 500); // need to wait a bit for all of these async callbacks to finish
    1.49 +  });
    1.50 +}
    1.51 +
    1.52 +function successCallbackAfterMozsettingOff(position) {
    1.53 +  ok(false, "Success callback should not have been called after setting geolocation.enabled to false.");
    1.54 +
    1.55 +  toggleGeolocationSetting(true, function() {
    1.56 +      ok(true, "turned on geolocation via mozSettings");
    1.57 +      setTimeout(function() {
    1.58 +         navigator.geolocation.getCurrentPosition(successCallbackAfterMozsettingOn,
    1.59 +                                                  failureCallbackAfterMozsettingOn);
    1.60 +        }, 500); // need to wait a bit for all of these async callbacks to finish
    1.61 +    });
    1.62 +}
    1.63 +
    1.64 +function failureCallbackAfterMozsettingOff(error) {
    1.65 +  ok(true, "Geolocation didn't work after setting geolocation.enabled to false.");
    1.66 +
    1.67 +  toggleGeolocationSetting(true, function() {
    1.68 +      ok(true, "turned on geolocation via mozSettings");
    1.69 +      setTimeout(function() {
    1.70 +         navigator.geolocation.getCurrentPosition(successCallbackAfterMozsettingOn,
    1.71 +                                                  failureCallbackAfterMozsettingOn);
    1.72 +        }, 500); // need to wait a bit for all of these async callbacks to finish
    1.73 +    });
    1.74 +}
    1.75 +
    1.76 +function successCallbackAfterMozsettingOn(position) {
    1.77 +  ok(true, "Geolocation worked after setting geolocation.enabled to true.");
    1.78 +  SimpleTest.finish();
    1.79 +}
    1.80 +
    1.81 +function failureCallbackAfterMozsettingOn(error) {
    1.82 +  ok(false, "Geolocation didn't work after setting geolocation.enabled to true.");
    1.83 +  SimpleTest.finish();
    1.84 +}
    1.85 +
    1.86 +</script>
    1.87 +</pre>
    1.88 +</body>
    1.89 +</html>
    1.90 +

mercurial