Bug 1023175 - AudioContext should have attribute EventHandler onmozinterruptend/begin in the webIDL interface, r=ehsan, r=smaug

This commit is contained in:
Andrea Marchesini 2014-06-13 07:06:14 +01:00
parent ecc5558981
commit 8597ce0a97
8 changed files with 134 additions and 2 deletions

View File

@ -1817,6 +1817,10 @@ GK_ATOM(onuserproximity, "onuserproximity")
// light sensor support
GK_ATOM(ondevicelight, "ondevicelight")
// Audio channel events
GK_ATOM(onmozinterruptbegin, "onmozinterruptbegin")
GK_ATOM(onmozinterruptend, "onmozinterruptbegin")
//---------------------------------------------------------------------------
// Special atoms
//---------------------------------------------------------------------------

View File

@ -14,6 +14,7 @@
#include "mozilla/dom/OfflineAudioContextBinding.h"
#include "mozilla/dom/OwningNonNull.h"
#include "MediaStreamGraph.h"
#include "AudioChannelService.h"
#include "AudioDestinationNode.h"
#include "AudioBufferSourceNode.h"
#include "AudioBuffer.h"
@ -131,7 +132,9 @@ AudioContext::Constructor(const GlobalObject& aGlobal,
return nullptr;
}
nsRefPtr<AudioContext> object = new AudioContext(window, false);
nsRefPtr<AudioContext> object =
new AudioContext(window, false,
AudioChannelService::GetDefaultAudioChannel());
RegisterWeakMemoryReporter(object);

View File

@ -67,7 +67,7 @@ class AudioContext MOZ_FINAL : public DOMEventTargetHelper,
{
AudioContext(nsPIDOMWindow* aParentWindow,
bool aIsOffline,
AudioChannel aChannel = AudioChannel::Normal,
AudioChannel aChannel,
uint32_t aNumberOfChannels = 0,
uint32_t aLength = 0,
float aSampleRate = 0.0f);
@ -231,6 +231,9 @@ public:
return aTime - ExtraCurrentTime();
}
IMPL_EVENT_HANDLER(mozinterruptbegin)
IMPL_EVENT_HANDLER(mozinterruptend)
private:
/**
* Returns the amount of extra time added to the current time of the

View File

@ -0,0 +1,5 @@
[DEFAULT]
support-files =
browser_mozAudioChannel.html
[browser_mozAudioChannel.js]

View File

@ -0,0 +1,31 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<meta charset="utf-8">
<title>Test for mozinterruptbegin/end in AudioContext</title>
mozAudioChannelTest = <span id="mozAudioChannelTest">FAIL</span>
<script type="application/javascript">
var ac = new AudioContext();
var buffer = ac.createBuffer(1, 2048, ac.sampleRate);
for (var i = 0; i < 2048; ++i) {
buffer.getChannelData(0)[i] = Math.sin(440 * 2 * Math.PI * i / ac.sampleRate);
}
var source = ac.createBufferSource();
source.buffer = buffer;
source.connect(ac.destination);
source.start(0);
ac.onmozinterruptbegin = function(evt) {
document.getElementById("mozAudioChannelTest").innerHTML = "mozinterruptbegin";
}
ac.addEventListener('mozinterruptend', function() {
document.getElementById("mozAudioChannelTest").innerHTML = "mozinterruptend";
}, false);
document.getElementById("mozAudioChannelTest").innerHTML = "READY";
</script>

View File

@ -0,0 +1,71 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
function whenBrowserLoaded(aBrowser, aCallback) {
aBrowser.addEventListener("load", function onLoad(event) {
if (event.target == aBrowser.contentDocument) {
aBrowser.removeEventListener("load", onLoad, true);
executeSoon(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);
executeSoon(aCallback);
}, true);
}
function test() {
waitForExplicitFinish();
let testURL = "http://mochi.test:8888/browser/" +
"content/media/webaudio/test/browser_mozAudioChannel.html";
SpecialPowers.pushPrefEnv({"set": [["media.defaultAudioChannel", "content" ],
["media.useAudioChannelService", true ]]},
function() {
let tab1 = gBrowser.addTab(testURL);
gBrowser.selectedTab = tab1;
whenBrowserLoaded(tab1.linkedBrowser, function() {
let doc = tab1.linkedBrowser.contentDocument;
is(doc.getElementById("mozAudioChannelTest").textContent, "READY",
"Test is ready to run");
SpecialPowers.pushPrefEnv({"set": [["media.defaultAudioChannel", "telephony" ]]},
function() {
let tab2 = gBrowser.duplicateTab(tab1);
gBrowser.selectedTab = tab2;
whenTabRestored(tab2, function() {
is(doc.getElementById("mozAudioChannelTest").textContent, "mozinterruptbegin",
"AudioContext has been muted by the second tab.");
whenBrowserUnloaded(tab2.linkedBrowser, function() {
is(doc.getElementById("mozAudioChannelTest").textContent, "mozinterruptend",
"AudioContext has been unmuted.");
gBrowser.removeTab(tab1);
finish();
});
gBrowser.removeTab(tab2);
gBrowser.selectedTab = tab1;
});
}
);
});
}
);
}

View File

@ -12,3 +12,7 @@ MOCHITEST_MANIFESTS += [
MOCHITEST_CHROME_MANIFESTS += [
'chrome.ini'
]
BROWSER_CHROME_MANIFESTS += [
'browser.ini'
]

View File

@ -81,3 +81,14 @@ partial interface AudioContext {
[Pref="media.useAudioChannelService", SetterThrows]
attribute AudioChannel mozAudioChannelType;
};
partial interface AudioContext {
// These 2 events are dispatched when the AudioContext object is muted by
// the AudioChannelService. It's call 'interrupt' because when this event is
// dispatched on a HTMLMediaElement, the audio stream is paused.
[Pref="media.useAudioChannelService"]
attribute EventHandler onmozinterruptbegin;
[Pref="media.useAudioChannelService"]
attribute EventHandler onmozinterruptend;
};