Chromium Code Reviews| 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 task.describe('Test event handler from resume() and suspend()'); | |
| 30 context = new OfflineAudioContext(1, sampleRate * renderDuration, sample Rate); | 31 context = new OfflineAudioContext(1, sampleRate * renderDuration, sample Rate); |
| 31 | 32 |
| 32 context.onstatechange = function () { | 33 context.onstatechange = function () { |
| 33 if (context.state === 'suspended' && context.currentTime === scheduled SuspendTime) { | 34 if (context.state === 'suspended' && context.currentTime === scheduled SuspendTime) { |
| 34 | 35 |
| 35 testPassed('onstatechange event handler: context is suspended at ' + | 36 should(context.state === 'suspended' && context.currentTime === |
| 36 scheduledSuspendTime + ' second(s).'); | 37 scheduledSuspendTime, |
|
hongchan
2017/02/07 18:38:43
Is this the result from clang-format? This is weir
Raymond Toy
2017/02/07 19:11:09
Bad indentation from js-beautify because I didn't
| |
| 38 'onstatechange event handler: context is suspended at ' + | |
| 39 scheduledSuspendTime + ' second(s)') | |
| 40 .beTrue(); | |
| 37 | 41 |
| 38 scheduledSuspendTime = context.currentTime + suspendInterval; | 42 scheduledSuspendTime = context.currentTime + suspendInterval; |
| 39 | 43 |
| 40 // Scheduling a suspend before the render duration should pass. | 44 // Scheduling a suspend before the render duration should pass. |
| 41 if (scheduledSuspendTime < renderDuration) { | 45 if (scheduledSuspendTime < renderDuration) { |
| 42 context.suspend(scheduledSuspendTime); | 46 should(() => context.suspend(scheduledSuspendTime), |
| 43 testPassed('A new suspend has been scheduled at ' + | 47 'Scheduling a new suspend at ' + scheduledSuspendTime + |
| 44 scheduledSuspendTime + ' second(s).'); | 48 ' second(s)') |
| 49 .notThrow();; | |
| 45 } | 50 } |
| 46 | 51 |
| 47 // Scheduling a suspend exactly at the render duration should be | 52 // Scheduling a suspend exactly at the render duration should be |
| 48 // rejected. | 53 // rejected. |
| 49 if (scheduledSuspendTime === renderDuration) { | 54 if (scheduledSuspendTime === renderDuration) { |
| 50 Should('Scheduling at ' + renderDuration + ' seconds', | 55 should(context.suspend(scheduledSuspendTime), |
| 51 context.suspend(scheduledSuspendTime)).beRejected(); | 56 'Scheduling at ' + renderDuration + ' seconds') |
| 57 .beRejected(); | |
| 52 } | 58 } |
| 53 | 59 |
| 54 context.resume(); | 60 context.resume(); |
| 55 } | 61 } |
| 56 }; | 62 }; |
| 57 | 63 |
| 58 // This test is for verifying all the event handlers on OAC and that is | 64 // This test is for verifying all the event handlers on OAC and that is |
| 59 // why 'oncomplete' is used here. | 65 // why 'oncomplete' is used here. |
| 60 context.oncomplete = function () { | 66 context.oncomplete = function () { |
| 61 Should('oncomplete event handler: context.state', context.state).beEqu alTo('closed'); | 67 should(context.state, 'oncomplete event handler: context.state').beEqu alTo('closed'); |
|
hongchan
2017/02/07 18:38:43
Needs to be wrapped at 80.
Raymond Toy
2017/02/07 19:11:09
Done.
| |
| 62 finishJSTest(); | 68 task.done(); |
| 63 }; | 69 }; |
| 64 | 70 |
| 65 // Schedule the first suspension. | 71 // Schedule the first suspension. |
| 66 context.suspend(scheduledSuspendTime); | 72 should(() => context.suspend(scheduledSuspendTime), |
| 67 testPassed('A new suspend has been scheduled at ' + scheduledSuspendTime + ' second(s).'); | 73 'A new suspend has been scheduled at ' + scheduledSuspendTime + |
| 74 ' second(s)') | |
| 75 .notThrow();; | |
| 68 | 76 |
| 69 context.startRendering(); | 77 context.startRendering(); |
| 70 } | 78 }); |
| 71 | 79 |
| 72 runTest(); | 80 audit.run(); |
| 73 successfullyParsed = true; | |
| 74 </script> | 81 </script> |
| 75 | 82 |
| 76 </body> | 83 </body> |
| 77 </html> | 84 </html> |
| OLD | NEW |