tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_handlerSpinsEventLoop.html (2115B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=911595
      5 -->
      6 <head>
      7  <title>Test for spinning the event loop inside position handlers</title>
      8  <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
      9  <script src="https://example.com/tests/dom/geolocation/test/mochitest/geolocation_common.js"></script>
     10 
     11  <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" />
     12 </head>
     13 <body>
     14 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=911595">Mozilla Bug 911595</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 
     22 /* global check_geolocation, force_prompt, resume_geolocationProvider */
     23 
     24 /*
     25 * In bug 911595 , spinning the event loop from inside position
     26 * handlers could cause both success and error callbacks to be
     27 * fired for the same request if that request has a small timeout.
     28 */
     29 
     30 SimpleTest.waitForExplicitFinish();
     31 
     32 resume_geolocationProvider(function() {
     33  force_prompt(true, test1);
     34 });
     35 
     36 var successCallbackCalled = false;
     37 function successCallback(position) {
     38  successCallbackCalled = true;
     39  check_geolocation(position);
     40  while (!timeoutPassed) {
     41    SpecialPowers.spinEventLoop(window);
     42  }
     43  info("TEST-INFO | successCallback called");
     44  check();
     45 }
     46 
     47 var errorCallbackCalled = false;
     48 function errorCallback(_error) {
     49  errorCallbackCalled = true;
     50  info("TEST-INFO | errorCallback called");
     51  check();
     52 }
     53 
     54 function check() {
     55  ok(successCallbackCalled != errorCallbackCalled, "Ensure only one callback is called");
     56  SimpleTest.finish();
     57 }
     58 
     59 var timeoutPassed = false;
     60 var timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
     61 function test1() {
     62  SpecialPowers.pushPrefEnv({"set": [["geo.provider.network.timeToWaitBeforeSending", 10]]}, function() {
     63    navigator.geolocation.getCurrentPosition(successCallback, errorCallback, {timeout: 500});
     64    timer.initWithCallback(_timer => {
     65      timeoutPassed = true;
     66    }, 600, Ci.nsITimer.TYPE_ONE_SHOT);
     67  });
     68 }
     69 </script>
     70 </pre>
     71 </body>
     72 </html>