dom/tests/mochitest/geolocation/test_cachedPosition.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/tests/mochitest/geolocation/test_cachedPosition.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,89 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=850442
     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=850442">Mozilla Bug 850442</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, function () {
    1.29 +      set_network_request_cache_enabled(false, function() {
    1.30 +        test1();
    1.31 +      });
    1.32 +    });
    1.33 +});
    1.34 +
    1.35 +function done() {
    1.36 +  set_network_request_cache_enabled(true, function() {
    1.37 +    resume_geolocationProvider(function() {
    1.38 +      SimpleTest.finish();
    1.39 +    });
    1.40 +  });
    1.41 +}
    1.42 +
    1.43 +function errorCallback(err) {
    1.44 +  ok(false, "error callback should not have been called");
    1.45 +  done();
    1.46 +}
    1.47 +
    1.48 +function testCachedPosition() {
    1.49 +  var cached = null;
    1.50 +  navigator.geolocation.getCurrentPosition(function(pos) {
    1.51 +    // get cached position
    1.52 +    cached = pos;
    1.53 +
    1.54 +    navigator.geolocation.getCurrentPosition(function(pos) {
    1.55 +      // force use of cached position, make sure
    1.56 +      // it's equal to what we have
    1.57 +      is(pos, cached, "position should be equal to cached position");
    1.58 +      resume_geolocationProvider(function() {
    1.59 +        navigator.geolocation.getCurrentPosition(function(pos) {
    1.60 +          // force new position, can't be the one we have
    1.61 +          isnot(pos, cached, "new position should be different from the cached");
    1.62 +          done();
    1.63 +        }, errorCallback, {maximumAge: 0});
    1.64 +      });
    1.65 +    }, errorCallback, {maximumAge: 21600000});
    1.66 +  }, errorCallback, {maximumAge: 21600000});
    1.67 +}
    1.68 +
    1.69 +// ensure we have a position in cache,
    1.70 +// and stop receiving new positions once we do so the
    1.71 +// cache doesn't change
    1.72 +var watchID;
    1.73 +function test1() {
    1.74 +  watchID = navigator.geolocation.watchPosition(
    1.75 +    function(pos) {
    1.76 +      info("Stopping geolocation provider");
    1.77 +      stop_geolocationProvider(function() {});
    1.78 +    }, function(err) {
    1.79 +      is(err.code, err.TIMEOUT, "got TIMEOUT for watchPosition");
    1.80 +
    1.81 +      // no new positions in a while,
    1.82 +      // the cache should be stable now.
    1.83 +      navigator.geolocation.clearWatch(watchID);
    1.84 +      testCachedPosition();
    1.85 +    }, {maximumAge: 0, timeout: 1000}
    1.86 +  );
    1.87 +}
    1.88 +</script>
    1.89 +</pre>
    1.90 +</body>
    1.91 +</html>
    1.92 +

mercurial