dom/tests/mochitest/geolocation/test_cachedPosition.html

Thu, 15 Jan 2015 15:55:04 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:55:04 +0100
branch
TOR_BUG_9701
changeset 9
a63d609f5ebe
permissions
-rw-r--r--

Back out 97036ab72558 which inappropriately compared turds to third parties.

     1 <!DOCTYPE HTML>
     2 <html>
     3 <!--
     4 https://bugzilla.mozilla.org/show_bug.cgi?id=850442
     5 -->
     6 <head>
     7   <title>Test for getCurrentPosition </title>
     8   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     9   <script type="text/javascript" src="geolocation_common.js"></script>
    11 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    12 </head>
    13 <body>
    14 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=850442">Mozilla Bug 850442</a>
    15 <p id="display"></p>
    16 <div id="content" style="display: none">
    18 </div>
    19 <pre id="test">
    20 <script class="testbody" type="text/javascript">
    22 SimpleTest.waitForExplicitFinish();
    24 resume_geolocationProvider(function() {
    25     force_prompt(true, function () {
    26       set_network_request_cache_enabled(false, function() {
    27         test1();
    28       });
    29     });
    30 });
    32 function done() {
    33   set_network_request_cache_enabled(true, function() {
    34     resume_geolocationProvider(function() {
    35       SimpleTest.finish();
    36     });
    37   });
    38 }
    40 function errorCallback(err) {
    41   ok(false, "error callback should not have been called");
    42   done();
    43 }
    45 function testCachedPosition() {
    46   var cached = null;
    47   navigator.geolocation.getCurrentPosition(function(pos) {
    48     // get cached position
    49     cached = pos;
    51     navigator.geolocation.getCurrentPosition(function(pos) {
    52       // force use of cached position, make sure
    53       // it's equal to what we have
    54       is(pos, cached, "position should be equal to cached position");
    55       resume_geolocationProvider(function() {
    56         navigator.geolocation.getCurrentPosition(function(pos) {
    57           // force new position, can't be the one we have
    58           isnot(pos, cached, "new position should be different from the cached");
    59           done();
    60         }, errorCallback, {maximumAge: 0});
    61       });
    62     }, errorCallback, {maximumAge: 21600000});
    63   }, errorCallback, {maximumAge: 21600000});
    64 }
    66 // ensure we have a position in cache,
    67 // and stop receiving new positions once we do so the
    68 // cache doesn't change
    69 var watchID;
    70 function test1() {
    71   watchID = navigator.geolocation.watchPosition(
    72     function(pos) {
    73       info("Stopping geolocation provider");
    74       stop_geolocationProvider(function() {});
    75     }, function(err) {
    76       is(err.code, err.TIMEOUT, "got TIMEOUT for watchPosition");
    78       // no new positions in a while,
    79       // the cache should be stable now.
    80       navigator.geolocation.clearWatch(watchID);
    81       testCachedPosition();
    82     }, {maximumAge: 0, timeout: 1000}
    83   );
    84 }
    85 </script>
    86 </pre>
    87 </body>
    88 </html>

mercurial