Bug 1269741 - Test. r=karlt
authorPaul Adenot <paul@paul.cx>
Wed, 04 May 2016 14:25:52 +0200
changeset 381513 cc90d9d43123ac4bf6a50b2945aebaf9df7a206d
parent 381512 fccaa8ee3ed99b39aa47aa60ba6d5879f4e16438
child 381514 7b0517746549ee534f6e8021c2d87b6672a2acfa
push id21504
push userbmo:npang@mozilla.com
push dateMon, 27 Jun 2016 18:10:09 +0000
reviewerskarlt
bugs1269741
milestone50.0a1
Bug 1269741 - Test. r=karlt MozReview-Commit-ID: 9dl3e5eTOKV
dom/media/webaudio/test/test_audioContextSuspendResumeClose.html
--- a/dom/media/webaudio/test/test_audioContextSuspendResumeClose.html
+++ b/dom/media/webaudio/test/test_audioContextSuspendResumeClose.html
@@ -5,19 +5,17 @@
   <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.requestCompleteLog();
-
-function tryToToCreateNodeOnClosedContext(ctx) {
+function tryToCreateNodeOnClosedContext(ctx) {
   ok(ctx.state, "closed", "The context is in closed state");
 
   [ { name: "createBufferSource" },
     { name: "createMediaStreamDestination",
       onOfflineAudioContext: false},
     { name: "createScriptProcessor" },
     { name: "createStereoPanner" },
     { name: "createAnalyser" },
@@ -302,17 +300,17 @@ function testAudioContext() {
     stateTracker.resume.handler = true;
     stateTracker.previous = ac.state;
     ac.onstatechange = afterClose;
 
     ac.close().then(function() {
       ok(!stateTracker.close.promise && !stateTracker.close.handler,
         "Promise should be called before the callback, and only once");
       stateTracker.close.promise = true;
-      tryToToCreateNodeOnClosedContext(ac);
+      tryToCreateNodeOnClosedContext(ac);
       tryLegalOpeerationsOnClosedContext(ac);
     });
   }
 
   function afterClose() {
     ok(stateTracker.previous == "running" &&
        ac.state == "closed",
        "AudioContext should switch to \"closed\" when the audio stream is" +
@@ -345,48 +343,67 @@ function testOfflineAudioContext() {
     ok(previousState == "running" && o.state == "closed",
         "onstatechanged handler is called when rendering finishes, " +
         "and the new state is closed");
     ok(finishedRendering, "The Promise that is resolved when the rendering is" +
                     "done should be resolved earlier than the state change.");
     previousState = o.state;
     o.onstatechange = afterRenderingFinished;
 
-    tryToToCreateNodeOnClosedContext(o);
+    tryToCreateNodeOnClosedContext(o);
     tryLegalOpeerationsOnClosedContext(o);
   }
 
   function afterRenderingFinished() {
     ok(false, "There should be no transition out of the closed state.");
   }
 
   o.onstatechange = beforeStartRendering;
 
   o.startRendering().then(function(buffer) {
     finishedRendering = true;
   });
 }
 
+function testSuspendResumeEventLoop() {
+  var ac = new AudioContext();
+  var source = ac.createBufferSource();
+  source.buffer = ac.createBuffer(1, 44100, 44100);
+  source.onended = function() {
+    ok(true, "The AudioContext did resume.");
+    finish();
+  }
+  ac.onstatechange = function() {
+    ac.onstatechange = null;
+
+    ok(ac.state == "running", "initial state is running");
+    ac.suspend();
+    source.start();
+    ac.resume();
+  }
+}
+
 var remaining = 0;
 function finish() {
   remaining--;
   if (remaining == 0) {
     SimpleTest.finish();
   }
 }
 
 
 SimpleTest.waitForExplicitFinish();
 addLoadEvent(function() {
   var tests = [
     testAudioContext,
     testOfflineAudioContext,
     testScriptProcessNodeSuspended,
     testMultiContextOutput,
-    testMultiContextInput
+    testMultiContextInput,
+    testSuspendResumeEventLoop
   ];
   remaining = tests.length;
   tests.forEach(function(f) { f() });
 });
 
 </script>
 </pre>
 </body>