Bug 645325 - Part 6: Disable geolocation request cache when testing different location providers. r=garvank r=jdm
authorChris Peterson <cpeterson@mozilla.com>
Sat, 10 Mar 2018 00:23:07 -0800
changeset 422022 5759d2ab032b348f16f7ced9a8e266d98bc6c3a1
parent 422021 d0cd7366b1a23ba8fc9ead34f4fd4281e7383318
child 422023 8e8a87c6a518e51b42abf2d12cdfcced8003a4ce
push id104177
push usercpeterson@mozilla.com
push dateSat, 09 Jun 2018 05:16:40 +0000
treeherdermozilla-inbound@8e8a87c6a518 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgarvank, jdm
bugs645325
milestone62.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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>
-