Bug 1283563 - Don't reset timeout for oneshot geolocation request. r=jdm

MozReview-Commit-ID: 4EkPD54Xu7f
This commit is contained in:
Kan-Ru Chen 2016-09-23 16:49:23 +08:00
parent 423f5ce8c1
commit 6ca2f575d0
4 changed files with 30 additions and 22 deletions

View File

@ -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!");
}

View File

@ -0,0 +1,6 @@
[DEFAULT]
support-files =
geolocation_common.js
network_geolocation.sjs
[test_handlerSpinsEventLoop.html]

View File

@ -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]

View File

@ -5,10 +5,10 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=911595
-->
<head>
<title>Test for spinning the event loop inside position handlers</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="geolocation_common.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" />
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=911595 ">Mozilla Bug 911595</a>
@ -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);
});
}
</script>
</pre>