4 <title>Test suspend/resume
</title>
5 <style type=
"text/css">
11 font-family: monospace
;
17 <h1>Test suspend/resume
</h1>
19 <p>Press
"Start" button to start the test using a single oscillator.
</p>
20 <p>Then press
"Suspend" or
"Resume" buttons as desired.
"Suspend" should stop the audio.
21 "Resume" should resume the audio immediately.
</p>
23 <p>Some tests to run:
</p>
26 <li>Suspend/Resume Test
28 <li>Press
"Start test"; audio should be heard.
</li>
29 <li>Press
"Suspend" multiple times. The first press should stop the audio. Each
30 subsequent press should do nothing, but the console should show that each press is
31 resolved successfully.
33 <li>Press
"Resume". The first press should resume audio immediately. Each subsequent
34 press should do nothing, but the console should show that each press is resolved
37 <li>Press
"Stop test" to stop the test; audio should stop.
</li>
42 <li>Press
"Start test"; audio should be heard.
</li>
43 <li>Press
"Stop test"; audio should stop
</li>
44 <li>Press
"Suspend" or
"Resume". Each press should result in a rejected promise
45 immediately with an error that suspend or resume is invalid on a closed context.
51 <p>See
<a href=
"crbug.com/476429">issue
476429</a></p>
53 <button onclick=
"startTest()">Start test
</button>
54 <button onclick=
"stopTest()">Stop test
</button>
55 <button onclick=
"suspend()">Suspend
</button>
56 <button onclick=
"resume()">Resume
</button>
58 <header>Results
</header>
59 <div id=
"results"></div>
62 // This is loosely based on the test from isue 476429.
66 var nextSuspendID
= 0;
69 function startTest() {
71 context
= new AudioContext() || webkitAudioContext();
73 log("Neither AudioContext nor webkitAudioContext found");
77 if (!context
.suspend
|| !context
.resume
) {
78 log("AudioContext lacks suspend/resume support");
82 osc
= context
.createOscillator();
83 osc
.connect(context
.destination
);
88 var suspendID
= nextSuspendID
++;
89 log("suspend request: " + suspendID
);
92 log("suspend resolved: " + suspendID
);
94 log("suspend rejected: " + suspendID
+ "; error: " + e
);
99 var resumeID
= nextResumeID
++;
100 log("resume request: " + resumeID
);
103 log("resume resolved: " + resumeID
);
105 log("resume rejected: " + resumeID
+ "; error: " + e
);
109 function stopTest() {
115 log("Context closed.");
117 log("Unable to close context: " + e
);
122 function log(message
) {
123 console
.log(message
);
124 var results
= document
.querySelector("#results");
125 results
.textContent
+= message
+ "\n";