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