Bug 645325 - Part 7: Always check location results in geolocation tests' success callbacks. r=garvank r=jdm
authorChris Peterson <cpeterson@mozilla.com>
Sat, 10 Mar 2018 02:11:09 -0800
changeset 422023 8e8a87c6a518e51b42abf2d12cdfcced8003a4ce
parent 422022 5759d2ab032b348f16f7ced9a8e266d98bc6c3a1
child 422025 e8157c8580f89ea168abb77f1b74065f9204f770
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 7: Always check location results in geolocation tests' success callbacks. r=garvank r=jdm MozReview-Commit-ID: DVQAvxfzJNx
dom/tests/mochitest/geolocation/test_cachedPosition.html
dom/tests/mochitest/geolocation/test_clearWatch.html
dom/tests/mochitest/geolocation/test_clearWatchBeforeAllowing.html
dom/tests/mochitest/geolocation/test_manyCurrentConcurrent.html
dom/tests/mochitest/geolocation/test_manyWatchConcurrent.html
dom/tests/mochitest/geolocation/test_manyWatchSerial.html
dom/tests/mochitest/geolocation/test_timerRestartWatch.html
dom/tests/mochitest/geolocation/windowTest.html
--- a/dom/tests/mochitest/geolocation/test_cachedPosition.html
+++ b/dom/tests/mochitest/geolocation/test_cachedPosition.html
@@ -13,16 +13,17 @@ https://bugzilla.mozilla.org/show_bug.cg
 <body>
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=850442">Mozilla Bug 850442</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();
 
 /*
 The request cache vs. the PositionOptions cache is confusing to the reader, to explain:
 
 Testing uses mochitest httpd, so the network cache must be disabled in order for requests
 to propagate to mochitest httpd. Otherwise, every request looks like a geoip request,
@@ -48,36 +49,35 @@ function done() {
   });
 }
 
 function errorCallback(err) {
   ok(false, "error callback should not have been called");
   done();
 }
 
-function areTimesEqual(loc1, loc2) {
-  return loc1.timestamp === loc2.timestamp;
-}
-
 function test_cachedPosition() {
    var cached = null;
    navigator.geolocation.getCurrentPosition(function(pos) {
-    // first call is just to warm up the cache
+     // first call is just to warm up the cache
+     check_geolocation(pos);
 
      navigator.geolocation.getCurrentPosition(function(pos) {
+      check_geolocation(pos);
       cached = pos;
 
       navigator.geolocation.getCurrentPosition(function(pos) {
-        ok(areTimesEqual(pos, cached), "position should be equal to cached position");
+        check_geolocation(pos);
+        is(pos.timestamp, cached.timestamp, "position should be equal to cached position");
         navigator.geolocation.getCurrentPosition(function(pos) {
           // force new position, can't be the one we have
-          ok(!areTimesEqual(pos, cached), "position should not be equal to cached position");
+          check_geolocation(pos);
+          isnot(pos.timestamp, cached.timestamp, "position should not be equal to cached position");
           done();
         }, errorCallback, {maximumAge: 0});
       }, errorCallback, {maximumAge: 21600000});
      }, errorCallback, {maximumAge: 21600000});
    }, errorCallback, {maximumAge: 21600000});
  }
 </script>
 </pre>
 </body>
 </html>
-
--- a/dom/tests/mochitest/geolocation/test_clearWatch.html
+++ b/dom/tests/mochitest/geolocation/test_clearWatch.html
@@ -13,16 +13,17 @@ https://bugzilla.mozilla.org/show_bug.cg
 <body>
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=478911">Mozilla Bug 478911</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);
 });
 
 var hasBeenCleared = false;
@@ -32,25 +33,28 @@ var firstCallback = true;
 function failureCallback(error)
 {
   ok(0, "we should not be seeing failures from this watchPosition");
 }
 
 function successCallback(position) {
   ok(true, "successCallback was called, hasBeenCleared=" + hasBeenCleared +
            ", successWasCalledAfterClear=" + successWasCalledAfterClear);
+  check_geolocation(position);
   if (hasBeenCleared == true) {
     successWasCalledAfterClear = true;
   }
   if (firstCallback) {
     SimpleTest.executeSoon(clearWatch);
     firstCallback = false;
   }
 }
 
+let watchID;
+
 function clearWatch() {
   ok(true, "clearWatch was called, hasBeenCleared=" + hasBeenCleared +
            ", successWasCalledAfterClear=" + successWasCalledAfterClear);
   navigator.geolocation.clearWatch(watchID);
   hasBeenCleared = true;
   SimpleTest.executeSoon(testAccepted);
 }
 
--- a/dom/tests/mochitest/geolocation/test_clearWatchBeforeAllowing.html
+++ b/dom/tests/mochitest/geolocation/test_clearWatchBeforeAllowing.html
@@ -14,36 +14,39 @@ https://bugzilla.mozilla.org/show_bug.cg
 <a target="_blank"
 href="https://bugzilla.mozilla.org/show_bug.cgi?id=886026">Mozilla Bug 886026</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, run_test);
 });
 
 function run_test() {
   var successCallbackCalled = false,
   errorCallbackCalled = false;
 
   var watchId = navigator.geolocation.watchPosition(
     function(pos) {
+      check_geolocation(pos);
       successCallbackCalled = true;
     }, function(err) {
-         errorCallbackCalled = true;
-       }
+      errorCallbackCalled = true;
+    }
   );
 
   navigator.geolocation.getCurrentPosition(
     function(pos) {
+      check_geolocation(pos);
       SimpleTest.executeSoon(function() {
         ok(successCallbackCalled == false,
         "getCurrentPosition : Success callback should not have been called");
 
         ok(errorCallbackCalled == false,
         "getCurrentPosition : Error callback should not have been called");
 
         SimpleTest.finish();
@@ -51,9 +54,9 @@ function run_test() {
     }
   );
 
   navigator.geolocation.clearWatch(watchId);
 }
 </script>
 </pre>
 </body>
-</html>
\ No newline at end of file
+</html>
--- a/dom/tests/mochitest/geolocation/test_manyCurrentConcurrent.html
+++ b/dom/tests/mochitest/geolocation/test_manyCurrentConcurrent.html
@@ -13,28 +13,30 @@ https://bugzilla.mozilla.org/show_bug.cg
 <body>
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=482260">Mozilla Bug 482260</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);
 });
 
 var successCallbackCalled = 0;
 var failureCallbackCalled = 0;
 const totalResults = 100;
 
 function successCallback(position) {
+  check_geolocation(position);
   successCallbackCalled++;
   testPassed();
 }
 
 function failureCallback(code) {
   failureCallbackCalled++;
   testPassed();
 }
--- a/dom/tests/mochitest/geolocation/test_manyWatchConcurrent.html
+++ b/dom/tests/mochitest/geolocation/test_manyWatchConcurrent.html
@@ -13,43 +13,46 @@ https://bugzilla.mozilla.org/show_bug.cg
 <body>
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=482260">Mozilla Bug 482260</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);
 });
 
 var successCallbackCalled = 0;
 var failureCallbackCalled = 0;
 const totalResults = 100;
 
-function successCallback(position) {
-  successCallbackCalled++;
-  testPassed();
+function test1() {
+  for (var x = 0; x < totalResults; x++) {
+    let watchID = navigator.geolocation.watchPosition(
+      position => {
+        check_geolocation(position);
+        successCallbackCalled++;
+        watchCallback(watchID);
+      },
+      error => {
+        failureCallbackCalled++;
+        watchCallback(watchID);
+      }
+    );
+  }
 }
 
-function failureCallback(code) {
-  failureCallbackCalled++;
-  testPassed();
-}
-
-function test1() {
-  for (var x = 0; x < totalResults; x++)
-    navigator.geolocation.watchPosition(successCallback, failureCallback);
-}
-
-function testPassed() {
+function watchCallback(watchID) {
+  navigator.geolocation.clearWatch(watchID);
   if (successCallbackCalled + failureCallbackCalled != totalResults)
     return;
   is(failureCallbackCalled, 0, "no failure callbacks should have been received");
   SimpleTest.finish();
 }
 
 </script>
 </pre>
--- a/dom/tests/mochitest/geolocation/test_manyWatchSerial.html
+++ b/dom/tests/mochitest/geolocation/test_manyWatchSerial.html
@@ -9,32 +9,34 @@ https://bugzilla.mozilla.org/show_bug.cg
   <script type="text/javascript" src="geolocation_common.js"></script>
 
 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
 </head>
 <body>
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=482260">Mozilla Bug 482260</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);
 });
 
 var watchID = 0;
 var completeCount = 10;
 
 
 function successCallback(position) {
+  check_geolocation(position);
 
   navigator.geolocation.clearWatch(watchID);
 
   completeCount--;
 
   if (completeCount==0) {
     ok(1, "all watchPosition successCallbacks called");
     SimpleTest.finish();
--- a/dom/tests/mochitest/geolocation/test_timerRestartWatch.html
+++ b/dom/tests/mochitest/geolocation/test_timerRestartWatch.html
@@ -9,48 +9,54 @@ https://bugzilla.mozilla.org/show_bug.cg
   <script type="text/javascript" src="geolocation_common.js"></script>
 
 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
 </head>
 <body>
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=526326">Mozilla Bug 526326</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();
 
 // ensure we are using the right testing provider
 resume_geolocationProvider(function() {
   force_prompt(true, test1);
 });
 
 var watchID;
 var times = 0;
 
 function errorCallback(err) {
-  ok(err.code == err.TIMEOUT, "ensure error is a timeout.");
+  is(err.code, err.TIMEOUT, "ensure error is a timeout.");
+
   times++;
+  isnot(times, 0, "times should be nonzero");
+  isnot(times, 4, "should not receive more than three error callbacks");
 
   // make sure we got at least 3 times errorCallback
   if (times >= 3) {
     navigator.geolocation.clearWatch(watchID);
     resume_geolocationProvider(function() {
       set_network_request_cache_enabled(true,
         function() { SimpleTest.finish(); } );
     });
   }
 }
 
 function successCallback(position) {
   ok(1, "on success");
-  // Now that we got a success callback, lets try to ensure
+  check_geolocation(position);
+
+  // Now that we got a success callback, let's try to ensure
   // that we get a timeout error.
   // The network cache is already off, now stop the sjs from reponding to requests
   stop_geolocationProvider(function(){});
 }
 
 var options = {
     maximumAge: 0,
     timeout: 1000
@@ -61,9 +67,8 @@ function test1() {
       function() {
         watchID = navigator.geolocation.watchPosition(successCallback, errorCallback, options);
       });
 }
 </script>
 </pre>
 </body>
 </html>
-
--- a/dom/tests/mochitest/geolocation/windowTest.html
+++ b/dom/tests/mochitest/geolocation/windowTest.html
@@ -9,23 +9,27 @@ https://bugzilla.mozilla.org/show_bug.cg
   <script type="text/javascript" src="geolocation_common.js"></script>
 
 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
 </head>
 <body>
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=493615">Mozilla Bug 493615</a>
 <p id="display"></p>
 <div id="content" style="display: none">
-  
+
 </div>
 <pre id="test">
 <script class="testbody" type="text/javascript">
+"use strict";
+
 var finished = false;
 
 function successCallback(position) {
+  check_geolocation(position);
+
   // watchPosition can notify more than once.
   if (finished) {
     return;
   }
   finished = true;
 
   var opener = window.opener;
   window.close();