diff --git a/dom/geolocation/nsGeolocation.cpp b/dom/geolocation/nsGeolocation.cpp index f5ad55552cde..487ca6a4e7f1 100644 --- a/dom/geolocation/nsGeolocation.cpp +++ b/dom/geolocation/nsGeolocation.cpp @@ -516,6 +516,8 @@ nsGeolocationRequest::GetRequester(nsIContentPermissionRequester** aRequester) void nsGeolocationRequest::SetTimeoutTimer() { + MOZ_ASSERT(!mShutdown, "set timeout after shutdown"); + StopTimeoutTimer(); if (mOptions && mOptions->mTimeout != 0 && mOptions->mTimeout != 0x7fffffff) { @@ -585,7 +587,10 @@ nsGeolocationRequest::SendLocation(nsIDOMGeoPosition* aPosition) MOZ_ASSERT(callback); callback->HandleEvent(aPosition); } - SetTimeoutTimer(); + + if (mIsWatchPositionRequest && !mShutdown) { + SetTimeoutTimer(); + } MOZ_ASSERT(mShutdown || mIsWatchPositionRequest, "non-shutdown getCurrentPosition request after callback!"); } diff --git a/dom/tests/mochitest/geolocation/chrome.ini b/dom/tests/mochitest/geolocation/chrome.ini new file mode 100644 index 000000000000..1922074f178d --- /dev/null +++ b/dom/tests/mochitest/geolocation/chrome.ini @@ -0,0 +1,6 @@ +[DEFAULT] +support-files = + geolocation_common.js + network_geolocation.sjs + +[test_handlerSpinsEventLoop.html] diff --git a/dom/tests/mochitest/geolocation/mochitest.ini b/dom/tests/mochitest/geolocation/mochitest.ini index c11e6745206d..1afcc31cb38d 100644 --- a/dom/tests/mochitest/geolocation/mochitest.ini +++ b/dom/tests/mochitest/geolocation/mochitest.ini @@ -15,7 +15,6 @@ support-files = [test_clearWatch_invalid.html] [test_errorcheck.html] [test_geolocation_is_undefined_when_pref_is_off.html] -[test_handlerSpinsEventLoop.html] [test_manyCurrentConcurrent.html] [test_manyCurrentSerial.html] [test_manyWatchConcurrent.html] diff --git a/dom/tests/mochitest/geolocation/test_handlerSpinsEventLoop.html b/dom/tests/mochitest/geolocation/test_handlerSpinsEventLoop.html index ad9814587876..becb463cc5c0 100644 --- a/dom/tests/mochitest/geolocation/test_handlerSpinsEventLoop.html +++ b/dom/tests/mochitest/geolocation/test_handlerSpinsEventLoop.html @@ -5,10 +5,10 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=911595 --> Test for spinning the event loop inside position handlers - + - + Mozilla Bug 911595 @@ -25,41 +25,39 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=911595 * fired for the same request if that request has a small timeout. */ +var { classes: Cc, interfaces: Ci, utils: Cu } = Components; + SimpleTest.waitForExplicitFinish(); -SimpleTest.requestFlakyTimeout("untriaged"); resume_geolocationProvider(function() { force_prompt(true, test1); }); -function spinEventLoopAndSetTimeout() { - if (successCallbackCalled || errorCallbackCalled) { - // this should only be called once from either callback - return; - } - - SpecialPowers.spinEventLoop(window); - - setTimeout(function() { - ok(successCallbackCalled != errorCallbackCalled, "Ensure only one callback is called"); - SimpleTest.finish(); - }, 5); -} - var successCallbackCalled = false; function successCallback(position) { - spinEventLoopAndSetTimeout(); successCallbackCalled = true; + check_geolocation(position); + while (!timeoutPassed) { + SpecialPowers.spinEventLoop(window); + } + ok(successCallbackCalled != errorCallbackCalled, "Ensure only one callback is called"); + SimpleTest.finish(); } var errorCallbackCalled = false; function errorCallback(error) { - spinEventLoopAndSetTimeout(); errorCallbackCalled = true; } +var timeoutPassed = false; +var timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer); function test1() { - navigator.geolocation.getCurrentPosition(successCallback, errorCallback, {timeout: 1}); + SpecialPowers.pushPrefEnv({"set": [["geo.wifi.timeToWaitBeforeSending", 10]]}, function() { + navigator.geolocation.getCurrentPosition(successCallback, errorCallback, {timeout: 500}); + timer.initWithCallback(timer => { + timeoutPassed = true; + }, 600, Ci.nsITimer.TYPE_ONE_SHOT); + }); }