Bug 923517 - AudioDestinationNode should work as an EventTarget, r=ehsan

This commit is contained in:
Andrea Marchesini 2013-10-03 18:40:20 -04:00
parent 5eac7c6a72
commit 8c22a53a8f
3 changed files with 33 additions and 5 deletions

View File

@ -71,19 +71,20 @@ AudioContext::AudioContext(nsPIDOMWindow* aWindow,
uint32_t aLength,
float aSampleRate)
: mSampleRate(aIsOffline ? aSampleRate : IdealAudioRate())
, mDestination(new AudioDestinationNode(MOZ_THIS_IN_INITIALIZER_LIST(),
aIsOffline, aNumberOfChannels,
aLength, aSampleRate))
, mNumberOfChannels(aNumberOfChannels)
, mIsOffline(aIsOffline)
, mIsStarted(!aIsOffline)
, mIsShutDown(false)
{
// Actually play audio
mDestination->Stream()->AddAudioOutput(&gWebAudioOutputKey);
nsDOMEventTargetHelper::BindToOwner(aWindow);
aWindow->AddAudioContext(this);
SetIsDOMBinding();
// Note: AudioDestinationNode needs an AudioContext that must already be
// bound to the window.
mDestination = new AudioDestinationNode(this, aIsOffline, aNumberOfChannels,
aLength, aSampleRate);
mDestination->Stream()->AddAudioOutput(&gWebAudioOutputKey);
}
AudioContext::~AudioContext()

View File

@ -109,3 +109,4 @@ support-files =
[test_waveShaper.html]
[test_waveShaperNoCurve.html]
[test_waveShaperZeroLengthCurve.html]
[test_audioDestinationNode.html]

View File

@ -0,0 +1,26 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Test AudioDestinationNode as EventTarget</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="webaudio.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<pre id="test">
<script class="testbody" type="text/javascript">
SimpleTest.waitForExplicitFinish();
var ac = new AudioContext()
ac.destination.addEventListener("foo", function() {
ok(true, "Event received!");
SimpleTest.finish();
}, false);
ac.destination.dispatchEvent(new CustomEvent("foo"));
</script>
</pre>
</body>
</html>