dom/tests/mochitest/geolocation/test_handlerSpinsEventLoop.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/tests/mochitest/geolocation/test_handlerSpinsEventLoop.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,66 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=911595
     1.8 +-->
     1.9 +<head>
    1.10 +  <title>Test for spinning the event loop inside position handlers</title>
    1.11 +  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.12 +  <script type="text/javascript" src="geolocation_common.js"></script>
    1.13 +
    1.14 +<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    1.15 +</head>
    1.16 +<body>
    1.17 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=911595 ">Mozilla Bug 911595</a>
    1.18 +<p id="display"></p>
    1.19 +<div id="content" style="display: none">
    1.20 +  
    1.21 +</div>
    1.22 +<pre id="test">
    1.23 +<script class="testbody" type="text/javascript">
    1.24 +
    1.25 +/*
    1.26 + * In bug 911595 , spinning the event loop from inside position
    1.27 + * handlers could cause both success and error callbacks to be
    1.28 + * fired for the same request if that request has a small timeout.
    1.29 + */
    1.30 +
    1.31 +SimpleTest.waitForExplicitFinish();
    1.32 +
    1.33 +resume_geolocationProvider(function() {
    1.34 +  force_prompt(true, test1);
    1.35 +});
    1.36 +
    1.37 +function spinEventLoopAndSetTimeout() {
    1.38 +  if (successCallbackCalled || errorCallbackCalled) {
    1.39 +    // this should only be called once from either callback
    1.40 +    return;
    1.41 +  }
    1.42 +
    1.43 +  window.showModalDialog("javascript:window.close()");
    1.44 +
    1.45 +  setTimeout(function() {
    1.46 +    ok(successCallbackCalled != errorCallbackCalled, "Ensure only one callback is called");
    1.47 +    SimpleTest.finish();
    1.48 +  }, 5);
    1.49 +}
    1.50 +
    1.51 +var successCallbackCalled = false;
    1.52 +function successCallback(position) {
    1.53 +  spinEventLoopAndSetTimeout();
    1.54 +  successCallbackCalled = true;
    1.55 +}
    1.56 +
    1.57 +var errorCallbackCalled = false;
    1.58 +function errorCallback(error) {
    1.59 +  spinEventLoopAndSetTimeout();
    1.60 +  errorCallbackCalled = true;
    1.61 +}
    1.62 +
    1.63 +function test1() {
    1.64 +  navigator.geolocation.getCurrentPosition(successCallback, errorCallback, {timeout: 1});
    1.65 +}
    1.66 +</script>
    1.67 +</pre>
    1.68 +</body>
    1.69 +</html>

mercurial