Bug 1269741 - Test. r?karlt draft
authorPaul Adenot <paul@paul.cx>
Wed, 04 May 2016 14:25:52 +0200
changeset 381461 c82fdb008ae34a1bbd31d2b6131a9b93f74b003f
parent 380596 40969d155419f72fa31e5b0e24158eb1fc10238c
child 381462 fdced9b290f98ac03004c4ce6574ed1d2cfebbd6
push id21477
push userpaul@paul.cx
push dateMon, 27 Jun 2016 09:09:41 +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,72 @@ 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 lastCurrentTime = ac.currentTime;
+  var tries = 20;
+  var equal = 10;
+  var source = ac.createBufferSource();
+  source.buffer = ac.createBuffer(1, 44100, 44100);
+  // Check the time still increases
+  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();
+    lastCurrentTime = ac.currentTime;
+  }
+}
+
 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>