dom/tests/mochitest/geolocation/test_handlerSpinsEventLoop.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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 type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     9   <script type="text/javascript" src="geolocation_common.js"></script>
    11 <link rel="stylesheet" type="text/css" href="/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">
    18 </div>
    19 <pre id="test">
    20 <script class="testbody" type="text/javascript">
    22 /*
    23  * In bug 911595 , spinning the event loop from inside position
    24  * handlers could cause both success and error callbacks to be
    25  * fired for the same request if that request has a small timeout.
    26  */
    28 SimpleTest.waitForExplicitFinish();
    30 resume_geolocationProvider(function() {
    31   force_prompt(true, test1);
    32 });
    34 function spinEventLoopAndSetTimeout() {
    35   if (successCallbackCalled || errorCallbackCalled) {
    36     // this should only be called once from either callback
    37     return;
    38   }
    40   window.showModalDialog("javascript:window.close()");
    42   setTimeout(function() {
    43     ok(successCallbackCalled != errorCallbackCalled, "Ensure only one callback is called");
    44     SimpleTest.finish();
    45   }, 5);
    46 }
    48 var successCallbackCalled = false;
    49 function successCallback(position) {
    50   spinEventLoopAndSetTimeout();
    51   successCallbackCalled = true;
    52 }
    54 var errorCallbackCalled = false;
    55 function errorCallback(error) {
    56   spinEventLoopAndSetTimeout();
    57   errorCallbackCalled = true;
    58 }
    60 function test1() {
    61   navigator.geolocation.getCurrentPosition(successCallback, errorCallback, {timeout: 1});
    62 }
    63 </script>
    64 </pre>
    65 </body>
    66 </html>

mercurial