Bug 1000264 - Test for the Promise support of AudioContext.decodeAudioData. r=ehsan
☠☠ backed out by 292ed84594c1 ☠ ☠
authorPaul Adenot <paul@paul.cx>
Wed, 22 Oct 2014 11:00:00 +0200
changeset 215533 0c9407b0e481e1718458d116050b0817aeacb905
parent 215532 c2c37b2e9fac22a76ce98221e1cf12988dc6a7a5
child 215534 87e94129e7b37f7afd0daa8d22a2bf1298898391
push id27818
push userryanvm@gmail.com
push dateThu, 13 Nov 2014 20:19:09 +0000
treeherdermozilla-central@292ed84594c1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs1000264
milestone36.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1000264 - Test for the Promise support of AudioContext.decodeAudioData. r=ehsan
dom/media/webaudio/test/mochitest.ini
dom/media/webaudio/test/test_decodeAudioDataPromise.html
--- a/dom/media/webaudio/test/mochitest.ini
+++ b/dom/media/webaudio/test/mochitest.ini
@@ -82,16 +82,17 @@ skip-if = toolkit == 'android' # bug 105
 [test_channelSplitterNodeWithVolume.html]
 [test_convolverNode.html]
 [test_convolverNode_mono_mono.html]
 [test_convolverNodeChannelCount.html]
 [test_convolverNodePassThrough.html]
 [test_convolverNodeWithGain.html]
 [test_currentTime.html]
 [test_decodeMultichannel.html]
+[test_decodeAudioDataPromise.html]
 [test_delayNode.html]
 [test_delayNodeAtMax.html]
 [test_delayNodeChannelChanges.html]
 skip-if = toolkit == 'android' # bug 1056706
 [test_delayNodeCycles.html]
 [test_delayNodePassThrough.html]
 [test_delayNodeSmallMaxDelay.html]
 [test_delayNodeTailIncrease.html]
new file mode 100644
--- /dev/null
+++ b/dom/media/webaudio/test/test_decodeAudioDataPromise.html
@@ -0,0 +1,61 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>Test the decodeAudioData API with Promise</title>
+
+  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+  <script src="webaudio.js"></script>
+</head>
+<body>
+<pre id="test">
+<script class="testbody" type="text/javascript">
+
+SimpleTest.waitForExplicitFinish();
+addLoadEvent(function() {
+
+var finished = 0;
+
+function finish() {
+  if (++finished == 2) {
+    SimpleTest.finish();
+  }
+}
+
+var ac = new AudioContext();
+// Test that a the promise is rejected with an invalid source buffer.
+expectNoException(function() {
+  var p = ac.decodeAudioData(" ");
+  ok(p instanceof Promise, "AudioContext.decodeAudioData should return a Promise");
+  p.then(function(data) {
+    ok(false, "Promise should not resolve with an invalid source buffer.");
+    finish();
+  }).catch(function() {
+    ok(true, "Promise should be rejected with an invalid source buffer.");
+    finish();
+  })
+});
+
+// Test that a the promise is resolved with a valid source buffer.
+var xhr = new XMLHttpRequest();
+xhr.open("GET", "ting-44.1k-1ch.ogg", true);
+xhr.responseType = "arraybuffer";
+xhr.onload = function() {
+  var p = ac.decodeAudioData(xhr.response);
+  ok(p instanceof Promise, "AudioContext.decodeAudioData should return a Promise");
+  p.then(function(data) {
+    ok(data instanceof AudioBuffer, "Promise should resolve, passing an AudioBuffer");
+    ok(true, "Promise should resolve with a valid source buffer.");
+    finish();
+  }).catch(function() {
+    ok(false, "Promise should not be rejected with a valid source buffer.");
+    finish();
+  });
+};
+xhr.send();
+});
+
+</script>
+</pre>
+</body>
+</html>