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