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