OLD | NEW |
1 <!doctype html> | 1 <!DOCTYPE html> |
2 <html> | 2 <html> |
3 <head> | 3 <head> |
| 4 <title> |
| 5 offlineaudiocontext-suspend-resume-eventhandler.html |
| 6 </title> |
4 <script src="../../resources/testharness.js"></script> | 7 <script src="../../resources/testharness.js"></script> |
5 <script src="../../resources/testharnessreport.js"></script> | 8 <script src="../../resources/testharnessreport.js"></script> |
6 <script src="../resources/audit-util.js"></script> | 9 <script src="../resources/audit-util.js"></script> |
7 <script src="../resources/audit.js"></script> | 10 <script src="../resources/audit.js"></script> |
8 </head> | 11 </head> |
| 12 <body> |
| 13 <script id="layout-test-code"> |
| 14 let audit = Audit.createTaskRunner(); |
9 | 15 |
10 <body> | 16 let context; |
11 <script> | 17 let renderQuantum = 128; |
12 var audit = Audit.createTaskRunner(); | |
13 | |
14 var context; | |
15 var renderQuantum = 128; | |
16 | 18 |
17 // The sample rate is multiple of the rendering quantum, so suspension | 19 // The sample rate is multiple of the rendering quantum, so suspension |
18 // times in the test will fall on the render quantum boundary. Although | 20 // times in the test will fall on the render quantum boundary. Although |
19 // this is not necessary, it is easier to understand the test. | 21 // this is not necessary, it is easier to understand the test. |
20 var sampleRate = renderQuantum * 100; | 22 let sampleRate = renderQuantum * 100; |
21 | 23 |
22 var renderDuration = 2; | 24 let renderDuration = 2; |
23 var scheduledSuspendTime = 0; | 25 let scheduledSuspendTime = 0; |
24 | 26 |
25 // With the sample rate setting above, this ensures suspension time fall | 27 // With the sample rate setting above, this ensures suspension time fall |
26 // in to the render quantum boundary. | 28 // in to the render quantum boundary. |
27 var suspendInterval = 0.25; | 29 let suspendInterval = 0.25; |
28 | 30 |
29 audit.define({ | 31 audit.define( |
30 label: 'test', | 32 { |
31 description: 'Test event handler from resume() and suspend()' | 33 label: 'test', |
32 }, (task, should) => { | 34 description: 'Test event handler from resume() and suspend()' |
33 context = | 35 }, |
34 new OfflineAudioContext(1, sampleRate * renderDuration, sampleRate); | 36 (task, should) => { |
| 37 context = new OfflineAudioContext( |
| 38 1, sampleRate * renderDuration, sampleRate); |
35 | 39 |
36 context.onstatechange = function() { | 40 context.onstatechange = function() { |
37 if (context.state === 'suspended' && | 41 if (context.state === 'suspended' && |
38 context.currentTime === scheduledSuspendTime) { | 42 context.currentTime === scheduledSuspendTime) { |
| 43 should( |
| 44 context.state === 'suspended' && |
| 45 context.currentTime === scheduledSuspendTime, |
| 46 'onstatechange event handler: context is suspended at ' + |
| 47 scheduledSuspendTime + ' second(s)') |
| 48 .beTrue(); |
| 49 scheduledSuspendTime = context.currentTime + suspendInterval; |
| 50 |
| 51 // Scheduling a suspend before the render duration should pass. |
| 52 if (scheduledSuspendTime < renderDuration) { |
| 53 should( |
| 54 () => context.suspend(scheduledSuspendTime), |
| 55 'Scheduling a new suspend at ' + scheduledSuspendTime + |
| 56 ' second(s)') |
| 57 .notThrow(); |
| 58 ; |
| 59 } |
| 60 |
| 61 // Scheduling a suspend exactly at the render duration should be |
| 62 // rejected. |
| 63 if (scheduledSuspendTime === renderDuration) { |
| 64 should( |
| 65 context.suspend(scheduledSuspendTime), |
| 66 'Scheduling at ' + renderDuration + ' seconds') |
| 67 .beRejected(); |
| 68 } |
| 69 |
| 70 context.resume(); |
| 71 } |
| 72 }; |
| 73 |
| 74 // This test is for verifying all the event handlers on OAC and that |
| 75 // is why 'oncomplete' is used here. |
| 76 context.oncomplete = function() { |
| 77 should(context.state, 'oncomplete event handler: context.state') |
| 78 .beEqualTo('closed'); |
| 79 task.done(); |
| 80 }; |
| 81 |
| 82 // Schedule the first suspension. |
39 should( | 83 should( |
40 context.state === 'suspended' && | 84 () => context.suspend(scheduledSuspendTime), |
41 context.currentTime === scheduledSuspendTime, | 85 'A new suspend has been scheduled at ' + scheduledSuspendTime + |
42 'onstatechange event handler: context is suspended at ' + | 86 ' second(s)') |
43 scheduledSuspendTime + ' second(s)') | 87 .notThrow(); |
44 .beTrue(); | 88 ; |
45 scheduledSuspendTime = context.currentTime + suspendInterval; | |
46 | 89 |
47 // Scheduling a suspend before the render duration should pass. | 90 context.startRendering(); |
48 if (scheduledSuspendTime < renderDuration) { | 91 }); |
49 should( | |
50 () => context.suspend(scheduledSuspendTime), | |
51 'Scheduling a new suspend at ' + scheduledSuspendTime + | |
52 ' second(s)') | |
53 .notThrow(); | |
54 ; | |
55 } | |
56 | |
57 // Scheduling a suspend exactly at the render duration should be | |
58 // rejected. | |
59 if (scheduledSuspendTime === renderDuration) { | |
60 should( | |
61 context.suspend(scheduledSuspendTime), | |
62 'Scheduling at ' + renderDuration + ' seconds') | |
63 .beRejected(); | |
64 } | |
65 | |
66 context.resume(); | |
67 } | |
68 }; | |
69 | |
70 // This test is for verifying all the event handlers on OAC and that is | |
71 // why 'oncomplete' is used here. | |
72 context.oncomplete = function() { | |
73 should(context.state, 'oncomplete event handler: context.state') | |
74 .beEqualTo('closed'); | |
75 task.done(); | |
76 }; | |
77 | |
78 // Schedule the first suspension. | |
79 should( | |
80 () => context.suspend(scheduledSuspendTime), | |
81 'A new suspend has been scheduled at ' + scheduledSuspendTime + | |
82 ' second(s)') | |
83 .notThrow(); | |
84 ; | |
85 | |
86 context.startRendering(); | |
87 }); | |
88 | 92 |
89 audit.run(); | 93 audit.run(); |
90 </script> | 94 </script> |
91 | |
92 </body> | 95 </body> |
93 </html> | 96 </html> |
OLD | NEW |