Bug 645325 - Part 6: Disable geolocation request cache when testing different location providers. r=garvank r?jdm draft
authorChris Peterson <cpeterson@mozilla.com>
Sat, 10 Mar 2018 00:23:07 -0800
changeset 791843 927a79cb20d7816d6961ce8899ca6b1ef4ec73b8
parent 791842 034532dd527567d8c54103b73134b259e758f306
child 791844 828caf3ed6772aa52526d192a7d2fbff940b603a
push id108905
push usercpeterson@mozilla.com
push dateSun, 06 May 2018 06:27:00 +0000
reviewersgarvank, jdm
bugs645325
milestone61.0a1
Bug 645325 - Part 6: Disable geolocation request cache when testing different location providers. r=garvank r?jdm Disable NetworkGeolocationProvider.js request cache for test cases that change the geo.wifi.uri. The cache does not remember from which location service the cached request came from and we expect different results when we change the provider URL (geo.wifi.uri). MozReview-Commit-ID: 7SbhBOkek4H
dom/tests/mochitest/geolocation/geolocation_common.js
dom/tests/mochitest/geolocation/test_worseAccuracyDoesNotBlockCallback.html
--- a/dom/tests/mochitest/geolocation/geolocation_common.js
+++ b/dom/tests/mochitest/geolocation/geolocation_common.js
@@ -1,74 +1,83 @@
 "use strict";
 
 var harness = SimpleTest.harnessParameters.testRoot == "chrome" ? "chrome" : "tests";
 var BASE_URL = "http://mochi.test:8888/" + harness + "/dom/tests/mochitest/geolocation/network_geolocation.sjs";
 
+function set_geo_wifi_uri(uri, callback)
+{
+  // Disable NetworkGeolocationProvider.js request cache because the cache
+  // does not remember from which location service it came from. We expect
+  // different results when we change the provider URL (geo.wifi.uri).
+  set_network_request_cache_enabled(false, () => {
+    SpecialPowers.pushPrefEnv({"set": [["geo.wifi.uri", uri]]}, callback);
+  });
+}
+
 function sleep(delay)
 {
     var start = Date.now();
     while (Date.now() < start + delay);
 }
 
 function force_prompt(allow, callback) {
   SpecialPowers.pushPrefEnv({"set": [["geo.prompt.testing", true], ["geo.prompt.testing.allow", allow]]}, callback);
 }
 
 function start_sending_garbage(callback)
 {
-  SpecialPowers.pushPrefEnv({"set": [["geo.wifi.uri", BASE_URL + "?action=respond-garbage"]]}, function() {
+  set_geo_wifi_uri(BASE_URL + "?action=respond-garbage", () => {
     // we need to be sure that all location data has been purged/set.
     sleep(1000);
     callback.call();
   });
 }
 
 function stop_sending_garbage(callback)
 {
-  SpecialPowers.pushPrefEnv({"set": [["geo.wifi.uri", BASE_URL + ""]]}, function() {
+  set_geo_wifi_uri(BASE_URL + "", () => {
     // we need to be sure that all location data has been purged/set.
     sleep(1000);
     callback.call();
   });
 }
 
 function stop_geolocationProvider(callback)
 {
-  SpecialPowers.pushPrefEnv({"set": [["geo.wifi.uri", BASE_URL + "?action=stop-responding"]]}, function() {
+  set_geo_wifi_uri(BASE_URL + "?action=stop-responding", () => {
     // we need to be sure that all location data has been purged/set.
     sleep(1000);
     callback.call();
   });
 }
 
 function set_network_request_cache_enabled(enabled, callback)
 {
   SpecialPowers.pushPrefEnv({"set": [["geo.wifi.debug.requestCache.enabled", enabled]]}, callback);
 }
 
 function worse_geolocationProvider(callback)
 {
-  SpecialPowers.pushPrefEnv({"set": [["geo.wifi.uri", BASE_URL + "?action=worse-accuracy"]]}, callback);
+  set_geo_wifi_uri(BASE_URL + "?action=worse-accuracy", callback);
 }
 
 function resume_geolocationProvider(callback)
 {
-  SpecialPowers.pushPrefEnv({"set": [["geo.wifi.uri", BASE_URL + ""]]}, callback);
+  set_geo_wifi_uri(BASE_URL + "", callback);
 }
 
 function delay_geolocationProvider(delay, callback)
 {
-  SpecialPowers.pushPrefEnv({"set": [["geo.wifi.uri", BASE_URL + "?delay=" + delay]]}, callback);
+  set_geo_wifi_uri(BASE_URL + "?delay=" + delay, callback);
 }
 
 function send404_geolocationProvider(callback)
 {
-  set_network_request_cache_enabled(false, function() {
-    SpecialPowers.pushPrefEnv({"set": [["geo.wifi.uri", BASE_URL + "?action=send404"]]}, callback);});
+  set_geo_wifi_uri(BASE_URL + "?action=send404", callback);
 }
 
 function check_geolocation(location)
 {
   ok(location, "Check to see if this location is non-null");
 
   const timestamp = location.timestamp;
   dump(`timestamp=$timestamp}\n`);
--- a/dom/tests/mochitest/geolocation/test_worseAccuracyDoesNotBlockCallback.html
+++ b/dom/tests/mochitest/geolocation/test_worseAccuracyDoesNotBlockCallback.html
@@ -13,35 +13,39 @@ https://bugzilla.mozilla.org/show_bug.cg
 <body>
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=494924">Mozilla Bug 494924</a>
 <p id="display"></p>
 <div id="content" style="display: none">
 
 </div>
 <pre id="test">
 <script class="testbody" type="text/javascript">
+"use strict";
 
 SimpleTest.waitForExplicitFinish();
 
 resume_geolocationProvider(function() {
   force_prompt(true, test1);
 });
 
+// The magic numbers 100 and 42 below are the accuracy results returned from the
+// mock geolocation service and defined in network_geolocation.sjs.
 function successCallback2(position) {
   check_geolocation(position);
+  is(position.coords.accuracy, 100, "worse accuracy");
   SimpleTest.finish();
 }
 
 function successCallback1(position) {
   check_geolocation(position);
+  is(position.coords.accuracy, 42, "high accuracy");
   worse_geolocationProvider(function() {
     navigator.geolocation.getCurrentPosition(successCallback2, null, { maximumAge: 0 });
   });
 }
 
 function test1() {
   navigator.geolocation.getCurrentPosition(successCallback1, null, { maximumAge: 0 });
 }
 </script>
 </pre>
 </body>
 </html>
-