dom/tests/mochitest/geolocation/test_mozsettingsWatch.html
author Ed Morley <emorley@mozilla.com>
Tue, 19 Aug 2014 09:17:06 +0100
changeset 200206 a3f9b8f4010b334e7627454c84c2630d7e8ead80
parent 200201 b01c7abafbdf9005f8d57cf5623f39189eae93fc
child 200414 9d38e890184789602fec6f25726a46cc77d2ab93
permissions -rw-r--r--
Backed out changeset b01c7abafbdf (bug 846200)

<!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();

resume_geolocationProvider(function() {
  force_prompt(true, test1);
});

if (SpecialPowers.isMainProcess()) {
  SpecialPowers.Cu.import("resource://gre/modules/SettingsChangeNotifier.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}], test2);
}

var watchId;
function test2() {
  ok(navigator.geolocation, "get geolocation object");

  toggleGeolocationSetting(false, function() {
      ok(true, "turned off geolocation via mozSettings");
      setTimeout(function() {
	      watchId = navigator.geolocation.watchPosition(successCallbackAfterMozsettingOff,
                                                           failureCallbackAfterMozsettingOff);
      }, 500); // 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.");

  navigator.geolocation.clearWatch(watchId);
  toggleGeolocationSetting(true, function() {
      ok(true, "turned on geolocation via mozSettings");
      setTimeout(function() {
          watchId = navigator.geolocation.watchPosition(successCallbackAfterMozsettingOn,
                                                        failureCallbackAfterMozsettingOn);
        }, 500); // 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.");

  navigator.geolocation.clearWatch(watchId);
  toggleGeolocationSetting(true, function() {
      ok(true, "turned on geolocation via mozSettings");
      setTimeout(function() {
          watchId = navigator.geolocation.watchPosition(successCallbackAfterMozsettingOn,
                                                        failureCallbackAfterMozsettingOn);
        }, 500); // 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.");

  navigator.geolocation.clearWatch(watchId);
  SimpleTest.finish();
}

function failureCallbackAfterMozsettingOn(error) {
  ok(false, "Geolocation didn't work after setting geolocation.enabled to true.");

  navigator.geolocation.clearWatch(watchId);
  SimpleTest.finish();
}

</script>
</pre>
</body>
</html>