dom/tests/mochitest/geolocation/test_handlerSpinsEventLoop.html

branch
TOR_BUG_9701
changeset 9
a63d609f5ebe
equal deleted inserted replaced
-1:000000000000 0:23e78e269a7d
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>
10
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">
17
18 </div>
19 <pre id="test">
20 <script class="testbody" type="text/javascript">
21
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 */
27
28 SimpleTest.waitForExplicitFinish();
29
30 resume_geolocationProvider(function() {
31 force_prompt(true, test1);
32 });
33
34 function spinEventLoopAndSetTimeout() {
35 if (successCallbackCalled || errorCallbackCalled) {
36 // this should only be called once from either callback
37 return;
38 }
39
40 window.showModalDialog("javascript:window.close()");
41
42 setTimeout(function() {
43 ok(successCallbackCalled != errorCallbackCalled, "Ensure only one callback is called");
44 SimpleTest.finish();
45 }, 5);
46 }
47
48 var successCallbackCalled = false;
49 function successCallback(position) {
50 spinEventLoopAndSetTimeout();
51 successCallbackCalled = true;
52 }
53
54 var errorCallbackCalled = false;
55 function errorCallback(error) {
56 spinEventLoopAndSetTimeout();
57 errorCallbackCalled = true;
58 }
59
60 function test1() {
61 navigator.geolocation.getCurrentPosition(successCallback, errorCallback, {timeout: 1});
62 }
63 </script>
64 </pre>
65 </body>
66 </html>

mercurial