Bug 1041594 - Fixed a race condition in the dispatching of mozinterruptbegin/end events in AudioContext, r=ehsan

This commit is contained in:
Andrea Marchesini 2014-10-19 09:23:20 +01:00
parent f0128e23f6
commit 56036c4517
3 changed files with 18 additions and 21 deletions

View File

@ -208,7 +208,7 @@ public:
explicit DestinationNodeEngine(AudioDestinationNode* aNode)
: AudioNodeEngine(aNode)
, mVolume(1.0f)
, mLastInputMuted(true)
, mLastInputMuted(false)
{
MOZ_ASSERT(aNode);
}
@ -622,6 +622,10 @@ AudioDestinationNode::CreateAudioChannelAgent()
bool isActive = false;
docshell->GetIsActive(&isActive);
mAudioChannelAgent->SetVisibilityState(isActive);
// The AudioChannelAgent must start playing immediately in order to avoid
// race conditions with mozinterruptbegin/end events.
InputMuted(false);
}
}
@ -709,10 +713,12 @@ AudioDestinationNode::InputMuted(bool aMuted)
}
int32_t state = 0;
mAudioChannelAgent->StartPlaying(&state);
mAudioChannelAgentPlaying =
state == AudioChannelState::AUDIO_CHANNEL_STATE_NORMAL;
SetCanPlay(mAudioChannelAgentPlaying);
nsresult rv = mAudioChannelAgent->StartPlaying(&state);
if (NS_WARN_IF(NS_FAILED(rv))) {
return;
}
CanPlayChanged(state);
}
} // dom namespace

View File

@ -11,15 +11,6 @@ function whenBrowserLoaded(aBrowser, aCallback) {
}, true);
}
function whenTabRestored(aTab, aCallback) {
aTab.addEventListener("SSTabRestored", function onRestored(aEvent) {
aTab.removeEventListener("SSTabRestored", onRestored, true);
executeSoon(function executeWhenTabRestored() {
aCallback();
});
}, true);
}
function whenBrowserUnloaded(aBrowser, aCallback) {
aBrowser.addEventListener("unload", function onUnload() {
aBrowser.removeEventListener("unload", onUnload, true);
@ -73,11 +64,11 @@ function test() {
gBrowser.selectedTab = tab1;
}
let tab2 = gBrowser.duplicateTab(tab1);
let tab2 = gBrowser.addTab(testURL);
gBrowser.selectedTab = tab2;
info("Restoring the tab...");
whenTabRestored(tab2, function() { info("Tab restored."); });
info("Loading the tab...");
whenBrowserLoaded(tab2.linkedBrowser, function() { info("Tab restored."); });
}
);
});

View File

@ -50,12 +50,12 @@ function test() {
let tab2 = gBrowser.duplicateTab(tab1);
gBrowser.selectedTab = tab2;
whenTabRestored(tab2, function() {
is(doc.getElementById("mozAudioChannelTest").textContent, "READY",
"AudioContext should not be muted by the second tab.");
is(doc.getElementById("mozAudioChannelTest").textContent, "mozinterruptbegin",
"AudioContext should be muted by the second tab.");
whenBrowserUnloaded(tab2.linkedBrowser, function() {
is(doc.getElementById("mozAudioChannelTest").textContent, "READY",
"AudioContext should not be muted by the second tab.");
is(doc.getElementById("mozAudioChannelTest").textContent, "mozinterruptend",
"AudioContext should be muted by the second tab.");
gBrowser.removeTab(tab1);
finish();
});