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 (offline) 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 // Convenience function that returns a function that calls the |passFailMe
thod| with the given |
| 23 // |message|. The |passFailMethod| should be either |testPassed| or |test
Failed|. |
| 24 function handlePromise(passFailMethod, message) { |
| 25 return function () { |
| 26 passFailMethod(message); |
| 27 }; |
| 28 } |
| 29 |
| 30 function checkResult (event) { |
| 31 // We don't care about the actual result of the offline rendering. |
| 32 shouldBeEqualToString("context.state", "closed"); |
| 33 // suspend() should be rejected on a closed context. |
| 34 context.suspend() |
| 35 .then(handlePromise( |
| 36 testFailed, |
| 37 "context.suspend() on a closed context not rejected"), |
| 38 handlePromise( |
| 39 testPassed, |
| 40 "context.suspend() on a closed context rejected as expected")) |
| 41 .then(function () { |
| 42 // resume() should be rejected on closed context. |
| 43 context.resume() |
| 44 .then(handlePromise( |
| 45 testFailed, |
| 46 "context.resume() on a closed context not rejected"
), |
| 47 handlePromise( |
| 48 testPassed, |
| 49 "context.resume() on a closed context rejected as e
xpected")) |
| 50 .then(finishJSTest) |
| 51 }); |
| 52 } |
| 53 |
| 54 function runOfflineContextTest() { |
| 55 // Render the offline context. |
| 56 osc.start(); |
| 57 context.oncomplete = checkResult; |
| 58 context.startRendering(); |
| 59 } |
| 60 |
| 61 function runResumeTest () { |
| 62 // Multiple calls to resume should not be a problem. But we can't test t
hat on an offline |
| 63 // context. Thus, check that resume() on an OfflineAudioContext rejects
the promise. |
| 64 shouldNotThrow("p1 = context.resume()"); |
| 65 shouldBeType(p1, Promise); |
| 66 // Resume doesn't actually resume an offline context |
| 67 shouldBeEqualToString("context.state", "suspended"); |
| 68 |
| 69 p1.then(handlePromise( |
| 70 testFailed, |
| 71 "context.resume() should have been rejected for an offline con
text"), |
| 72 handlePromise( |
| 73 testPassed, |
| 74 "context.resume() was correctly rejected for an offline contex
t")) |
| 75 .then(runOfflineContextTest); |
| 76 } |
| 77 |
| 78 function runTest() { |
| 79 window.jsTestIsAsync = true; |
| 80 // Test suspend/resume. Ideally this test is best with a online AudioCo
ntext, but content |
| 81 // shell doesn't really have a working online AudioContext. Hence, use a
n |
| 82 // OfflineAudioContext. Not all possible scenarios can be easily checked
with an offline |
| 83 // context instead of an online context. |
| 84 |
| 85 // Create an audio context with an oscillator. |
| 86 context = new OfflineAudioContext(1, durationInSeconds * sampleRate, sam
pleRate); |
| 87 osc = context.createOscillator(); |
| 88 osc.connect(context.destination); |
| 89 |
| 90 // Verify the state. |
| 91 shouldBeEqualToString("context.state", "suspended"); |
| 92 |
| 93 // Multiple calls to suspend() should not be a problem. But we can't tes
t that on an offline |
| 94 // context. Thus, check that suspend() on an OfflineAudioContext reject
s the promise. |
| 95 shouldNotThrow("p1 = context.suspend()"); |
| 96 shouldBeType(p1, Promise); |
| 97 p1.then(handlePromise( |
| 98 testFailed, |
| 99 "context.suspend() should have been rejected for an offline co
ntext"), |
| 100 handlePromise( |
| 101 testPassed, |
| 102 "context.suspend() was correctly rejected for an offline conte
xt")) |
| 103 .then(runResumeTest); |
| 104 } |
| 105 |
| 106 runTest(); |
| 107 successfullyParsed = true; |
| 108 </script> |
| 109 </body> |
| 110 </html> |
OLD | NEW |