| OLD | NEW |
| (Empty) |
| 1 <!doctype html> | |
| 2 <html> | |
| 3 <head> | |
| 4 <title>Test audiocontext suspend/resume</title> | |
| 5 <script src="resources/compatibility.js"></script> | |
| 6 <script src="resources/audio-testing.js"></script> | |
| 7 <script src="../resources/js-test.js"></script> | |
| 8 </head> | |
| 9 | |
| 10 <body> | |
| 11 <script> | |
| 12 description("Test suspend/resume for an AudioContext"); | |
| 13 | |
| 14 var context; | |
| 15 var osc; | |
| 16 var p1; | |
| 17 var p2; | |
| 18 | |
| 19 var sampleRate = 44100; | |
| 20 var durationInSeconds = 1; | |
| 21 | |
| 22 function passed () { | |
| 23 testPassed("Context resumed correctly."); | |
| 24 } | |
| 25 | |
| 26 function failed () { | |
| 27 testFailed("Context did not resume!."); | |
| 28 } | |
| 29 | |
| 30 function resolvedResumeWhenReleased () { | |
| 31 testFailed("resume() on a released context not rejected"); | |
| 32 finishJSTest(); | |
| 33 } | |
| 34 | |
| 35 function rejectedResumeWhenReleased () { | |
| 36 testPassed("resume() on a released context rejected as expected"); | |
| 37 finishJSTest(); | |
| 38 } | |
| 39 | |
| 40 function checkResult (event) { | |
| 41 // We don't care about the actual result of the offline rendering. | |
| 42 shouldBeEqualToString("context.state", "released"); | |
| 43 shouldThrow("context.suspend()"); | |
| 44 context.resume().then(resolvedResumeWhenReleased, rejectedResumeWhenRele
ased); | |
| 45 } | |
| 46 | |
| 47 function runTest() { | |
| 48 window.jsTestIsAsync = true; | |
| 49 // Test suspend/resume. Ideally this test is best with a online AudioCo
ntext, but content | |
| 50 // shell doesn't really have a working online AudioContext. Hence, use a
n | |
| 51 // OfflineAudioContext. Not all possible scenarios can be easily checked
with an offline | |
| 52 // context instead of an online context. | |
| 53 | |
| 54 // Create an audio context with an oscillator. | |
| 55 context = new OfflineAudioContext(1, durationInSeconds * sampleRate, sam
pleRate); | |
| 56 osc = context.createOscillator(); | |
| 57 osc.connect(context.destination); | |
| 58 | |
| 59 // Verify the state. | |
| 60 shouldBeEqualToString("context.state", "paused"); | |
| 61 | |
| 62 // Multiple calls to suspend() should not be a problem. But these curren
tly do nothing with | |
| 63 // an OfflineAudioContext. | |
| 64 shouldNotThrow("context.suspend()"); | |
| 65 shouldNotThrow("context.suspend()"); | |
| 66 | |
| 67 // Multiple calls to resume should not be a problem. But these currently
do nothing with an | |
| 68 // OfflineAudioContext. | |
| 69 shouldNotThrow("p1 = context.resume()"); | |
| 70 shouldBeType(p1, Promise); | |
| 71 p1.then(passed, failed); | |
| 72 shouldNotThrow("p2 = context.resume()"); | |
| 73 shouldBeType(p2, Promise); | |
| 74 if (p1 === p2) | |
| 75 testFailed("Promises from resume should not be equal."); | |
| 76 else | |
| 77 testPassed("Promises from resume are not equal."); | |
| 78 p2.then(passed, failed); | |
| 79 | |
| 80 // Resume doesn't actually resume an offline context | |
| 81 shouldBeEqualToString("context.state", "paused"); | |
| 82 | |
| 83 // Render the offline context. | |
| 84 osc.start(); | |
| 85 context.oncomplete = checkResult; | |
| 86 context.startRendering(); | |
| 87 } | |
| 88 | |
| 89 runTest(); | |
| 90 successfullyParsed = true; | |
| 91 </script> | |
| 92 </body> | |
| 93 </html> | |
| OLD | NEW |