Bug 1087944 - Test for the promise returned by OfflineAudioContext.startRendering(). r=ehsan
authorPaul Adenot <paul@paul.cx>
Wed, 19 Nov 2014 18:18:24 +0100
changeset 243912 c213f97e0eec2b0ded9fa2ccb14877b8705f95cc
parent 243911 c6be963121ae1120ffc952bc9c5c2de3e0ecbd3d
child 243913 6d64e1e46eb1efeb6e5a5bb39936d4c713f1820f
push id4489
push userraliiev@mozilla.com
push dateMon, 23 Feb 2015 15:17:55 +0000
treeherdermozilla-beta@fd7c3dc24146 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs1087944
milestone37.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 1087944 - Test for the promise returned by OfflineAudioContext.startRendering(). r=ehsan
dom/media/webaudio/test/test_OfflineAudioContext.html
--- a/dom/media/webaudio/test/test_OfflineAudioContext.html
+++ b/dom/media/webaudio/test/test_OfflineAudioContext.html
@@ -5,16 +5,35 @@
   <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">
 
+var renderedBuffer = null;
+var finished = 0;
+
+function finish() {
+  finished++;
+  if (finished == 2) {
+    SimpleTest.finish();
+  }
+}
+
+function setOrCompareRenderedBuffer(aRenderedBuffer) {
+  if (renderedBuffer) {
+    is(renderedBuffer, aRenderedBuffer, "Rendered buffers from the event and the promise should be the same");
+    finish();
+  } else {
+    renderedBuffer = aRenderedBuffer;
+  }
+}
+
 SimpleTest.waitForExplicitFinish();
 addLoadEvent(function() {
   var ctx = new OfflineAudioContext(2, 100, 22050);
   ok(ctx instanceof EventTarget, "OfflineAudioContexts must be EventTargets");
 
   var buf = ctx.createBuffer(2, 100, ctx.sampleRate);
   for (var i = 0; i < 2; ++i) {
     for (var j = 0; j < 100; ++j) {
@@ -42,26 +61,41 @@ addLoadEvent(function() {
   expectException(function() {
     new OfflineAudioContext(2, 0, 44100);
   }, DOMException.NOT_SUPPORTED_ERR);
 
   var src = ctx.createBufferSource();
   src.buffer = buf;
   src.start(0);
   src.connect(ctx.destination);
-  ctx.startRendering();
+
   ctx.addEventListener("complete", function(e) {
     ok(e instanceof OfflineAudioCompletionEvent, "Correct event received");
     is(e.renderedBuffer.numberOfChannels, 2, "Correct expected number of buffers");
+    ok(renderedBuffer != null, "The event should be fired after the promise callback.");
+    expectNoException(function() {
+      ctx.startRendering().then(function() {
+        ok(false, "Promise should not resolve when startRendering is called a second time on an OfflineAudioContext")
+        finish();
+      }).catch(function(err) {
+        ok(true, "Promise should reject when startRendering is called a second time on an OfflineAudioContext")
+        finish();
+      });
+    });
     compareBuffers(e.renderedBuffer, buf);
+    setOrCompareRenderedBuffer(e.renderedBuffer);
 
-    expectException(function() {
-      ctx.startRendering();
-    }, DOMException.INVALID_STATE_ERR);
+  }, false);
 
-    SimpleTest.finish();
-  }, false);
+  expectNoException(function() {
+    ctx.startRendering().then(function(b) {
+      is(renderedBuffer, null, "The promise callback should be called first.");
+      setOrCompareRenderedBuffer(b);
+    }).catch(function (error) {
+       ok(false, "The promise from OfflineAudioContext.startRendering should never be rejected");
+    });
+  });
 });
 
 </script>
 </pre>
 </body>
 </html>