Bug 1198386 - Wait for the AudioContext to enter the running state before calling suspend() on it; r=karlt, a=test-only
authorEhsan Akhgari <ehsan@mozilla.com>
Tue, 29 Sep 2015 09:57:01 -0400
changeset 297916 ecdf6e8d473d2315e9b44c0e0fcef86760fd0511
parent 297915 735ebc504963a025a007611bad8c9bf7f05c9ed7
child 297917 3a47df4bf8197fa89d675cd9161910423c188d7b
push id962
push userjlund@mozilla.com
push dateFri, 04 Dec 2015 23:28:54 +0000
treeherdermozilla-release@23a2d286e80f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskarlt, test-only
bugs1198386
milestone43.0a2
Bug 1198386 - Wait for the AudioContext to enter the running state before calling suspend() on it; r=karlt, a=test-only
dom/base/test/file_webaudioLoop.html
--- a/dom/base/test/file_webaudioLoop.html
+++ b/dom/base/test/file_webaudioLoop.html
@@ -1,28 +1,37 @@
 <!DOCTYPE html>
 <script>
 var ac = new AudioContext();
+var runningPromise = new Promise(resolve => {
+  ac.onstatechange = event => {
+    if (ac.state == "running") {
+      resolve();
+    }
+  };
+});
 fetch("audio.ogg").then(response => {
   return response.arrayBuffer();
 }).then(ab => {
   return ac.decodeAudioData(ab);
 }).then(ab => {
   var src = ac.createBufferSource();
   src.buffer = ab;
   src.loop = true;
   src.loopStart = 0;
   src.loopEnd = ab.duration;
   src.start();
   src.connect(ac.destination);
 });
 
 var suspendPromise;
 function suspendAC() {
-  suspendPromise = ac.suspend();
+  runningPromise.then(() => {
+    suspendPromise = ac.suspend();
+  });
 }
 
 var resumePromise;
 function resumeAC() {
   suspendPromise.then(() => {
     resumePromise = ac.resume();
   });
 }