test_cachedPosition.html (2660B)
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 src="/tests/SimpleTest/SimpleTest.js"></script> 9 <script type="text/javascript" src="geolocation_common.js"></script> 10 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"> 17 18 </div> 19 <pre id="test"> 20 <script class="testbody" type="text/javascript"> 21 "use strict"; 22 23 SimpleTest.waitForExplicitFinish(); 24 25 /* 26 The request cache vs. the PositionOptions cache is confusing to the reader, to explain: 27 28 Testing uses mochitest httpd, so the network cache must be disabled in order for requests 29 to propagate to mochitest httpd. Otherwise, every request looks like a geoip request, 30 and the network request cache sees no reason to make a web request for location for geoip 31 if it has already made geoip (or better) requests. 32 33 We should investigate providing fake wifi and cell scans to the 34 network location provider, then the network cache does not need to be shut off 35 AND it will get testing coverage. 36 37 */ 38 resume_geolocationProvider(function() { 39 force_prompt(true, function () { 40 set_network_request_cache_enabled(false, test_cachedPosition) 41 }); 42 }); 43 44 function done() { 45 set_network_request_cache_enabled(true, function() { 46 resume_geolocationProvider(function() { 47 SimpleTest.finish(); 48 }); 49 }); 50 } 51 52 function errorCallback(_err) { 53 ok(false, "error callback should not have been called"); 54 done(); 55 } 56 57 function test_cachedPosition() { 58 var cached = null; 59 navigator.geolocation.getCurrentPosition(function(pos) { 60 // first call is just to warm up the cache 61 check_geolocation(pos); 62 63 navigator.geolocation.getCurrentPosition(function(pos2) { 64 check_geolocation(pos2); 65 cached = pos2; 66 67 navigator.geolocation.getCurrentPosition(function(pos3) { 68 check_geolocation(pos3); 69 is(pos3.timestamp, cached.timestamp, "position should be equal to cached position"); 70 navigator.geolocation.getCurrentPosition(function(pos4) { 71 // force new position, can't be the one we have 72 check_geolocation(pos4); 73 isnot(pos4.timestamp, cached.timestamp, "position should not be equal to cached position"); 74 done(); 75 }, errorCallback, {maximumAge: 0}); 76 }, errorCallback, {maximumAge: 21600000}); 77 }, errorCallback, {maximumAge: 21600000}); 78 }, errorCallback, {maximumAge: 21600000}); 79 } 80 </script> 81 </pre> 82 </body> 83 </html>