| OLD | NEW |
| (Empty) |
| 1 <!doctype html> | |
| 2 <html> | |
| 3 <head> | |
| 4 <title>Test statechange event</title> | |
| 5 <script src="../resources/js-test.js"></script> | |
| 6 <script src="resources/audit-util.js"/></script> | |
| 7 <script src="resources/audio-testing.js"/></script> | |
| 8 <script src="resources/compatibility.js"></script> | |
| 9 </head> | |
| 10 | |
| 11 <body> | |
| 12 <script> | |
| 13 description("Test statechange event is properly signaled") | |
| 14 | |
| 15 window.jsTestIsAsync = true; | |
| 16 | |
| 17 var secondsToRender = 2; | |
| 18 var sampleRate = 48000; | |
| 19 | |
| 20 var stateChangeCount = 0; | |
| 21 var context; | |
| 22 var contextState; | |
| 23 | |
| 24 function checkStateChange (e) { | |
| 25 contextState = e.currentTarget.state; | |
| 26 | |
| 27 switch (stateChangeCount) { | |
| 28 case 0: | |
| 29 shouldBeEqualToString("contextState", "running"); | |
| 30 break; | |
| 31 case 1: | |
| 32 shouldBeEqualToString("contextState", "closed"); | |
| 33 break; | |
| 34 default: | |
| 35 testFailed("Expected only two state changes but got " + stateChangeCou
nt); | |
| 36 } | |
| 37 ++stateChangeCount; | |
| 38 } | |
| 39 | |
| 40 function finalCheck() { | |
| 41 // Final check that we got the right number of state changes and the cor
rect final state. | |
| 42 shouldBeEqualToNumber("stateChangeCount", 2); | |
| 43 shouldBeEqualToString("context.state", "closed"); | |
| 44 finishJSTest(); | |
| 45 } | |
| 46 | |
| 47 function runTest() { | |
| 48 // Create an offline context with a source passing through a convolver.
The convolver is | |
| 49 // just to waste some time. | |
| 50 context = new OfflineAudioContext(1, secondsToRender * sampleRate, sampl
eRate); | |
| 51 var buffer = createImpulseBuffer(context, sampleRate); | |
| 52 var source = context.createBufferSource(); | |
| 53 var conv = context.createConvolver(); | |
| 54 | |
| 55 source.buffer = buffer; | |
| 56 conv.normalize = false; | |
| 57 conv.buffer = buffer; | |
| 58 | |
| 59 source.connect(conv); | |
| 60 conv.connect(context.destination); | |
| 61 | |
| 62 source.start(); | |
| 63 | |
| 64 context.onstatechange = checkStateChange; | |
| 65 | |
| 66 context.startRendering().then(function () { | |
| 67 testPassed("context finished rendering") | |
| 68 }); | |
| 69 | |
| 70 // Don't want to set an oncomplete for the context and don't want to use
the promise because | |
| 71 // the order of the state change event and resolving the promise is not
specified. Thus, | |
| 72 // just wait for a bit and then finish the test. We assume the offline
context runs faster | |
| 73 // than realtime. | |
| 74 setTimeout(finalCheck, secondsToRender * 1000); | |
| 75 } | |
| 76 | |
| 77 runTest(); | |
| 78 </script> | |
| 79 </body> | |
| 80 </html> | |
| OLD | NEW |