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 OfflineAudioContext.resume() and OfflineAudioContext.sus
pend() with the timed sequence.'); | 12 var audit = Audit.createTaskRunner(); |
12 window.jsTestIsAsync = true; | |
13 | |
14 var context; | 13 var context; |
15 | 14 |
16 // The sample rate is multiple of the rendering quantum, so suspension | 15 // The sample rate is multiple of the rendering quantum, so suspension |
17 // times fall in to the render quantum boundary. | 16 // times fall in to the render quantum boundary. |
18 var renderQuantum = 128; | 17 var renderQuantum = 128; |
19 | 18 |
20 var sampleRate = renderQuantum * 100; | 19 var sampleRate = renderQuantum * 100; |
21 var renderDuration = 2; | 20 var renderDuration = 2; |
22 | 21 |
23 // These numbers are in an arbitrary order, but not randomly generated in | 22 // These numbers are in an arbitrary order, but not randomly generated in |
24 // runtime to avoid moving pieces. However, it is safe to arrange them | 23 // runtime to avoid moving pieces. However, it is safe to arrange them |
25 // in a random order in runtime. | 24 // in a random order in runtime. |
26 // | 25 // |
27 // Also these numbers are multiple of 0.25, so they are supposed to fall | 26 // Also these numbers are multiple of 0.25, so they are supposed to fall |
28 // in the render quantum boundary for easier and more intuitive | 27 // in the render quantum boundary for easier and more intuitive |
29 // verification. | 28 // verification. |
30 var suspendTimes = [0.25, 0.75, 1.0, 0.5, 1.25, 0.0, 1.75]; | 29 var suspendTimes = [0.25, 0.75, 1.0, 0.5, 1.25, 0.0, 1.75]; |
31 | 30 |
32 // Sorted ascending suspend time is our expected result. | 31 // Sorted ascending suspend time is our expected result. |
33 var expectedSuspendTimes = suspendTimes.slice(0).sort(function (a, b) { | 32 var expectedSuspendTimes = suspendTimes.slice(0).sort(function (a, b) { |
34 return a - b; | 33 return a - b; |
35 }); | 34 }); |
36 | 35 |
37 var actualSuspendTimes = []; | 36 var actualSuspendTimes = []; |
38 | 37 |
39 context = new OfflineAudioContext(1, sampleRate * renderDuration, sampleRa
te); | 38 audit.define('test', (task, should) => { |
| 39 task.describe('resume() and suspend() with timed sequence'); |
| 40 context = new OfflineAudioContext(1, sampleRate * renderDuration, |
| 41 sampleRate); |
40 | 42 |
41 for (var i = 0; i < suspendTimes.length; i++) { | 43 for (var i = 0; i < suspendTimes.length; i++) { |
| 44 // Schedule suspends in a random time order, but the actual suspend |
| 45 // must happen in ascending time order. |
| 46 scheduleSuspend(i, suspendTimes[i], should); |
| 47 } |
42 | 48 |
43 // Schedule suspends in a random time order, but the actual suspend | 49 context.startRendering() |
44 // must happen in ascending time order. | 50 .then(buffer => verifyResult(should)) |
45 scheduleSuspend(i, suspendTimes[i]); | 51 .then(() => task.done()); |
46 | 52 |
| 53 }); |
| 54 |
| 55 audit.run(); |
| 56 |
| 57 function scheduleSuspend(index, suspendTime, should) { |
| 58 should(() => context.suspend(suspendTime) |
| 59 .then(() => { |
| 60 actualSuspendTimes.push(suspendTime); |
| 61 context.resume(); |
| 62 }), |
| 63 'Scheduling suspend #' + index + ' at ' + suspendTime + |
| 64 ' second(s)') |
| 65 .notThrow(); |
47 } | 66 } |
48 | 67 |
49 function scheduleSuspend(index, suspendTime) { | 68 function verifyResult(should) { |
50 testPassed('Scheduling suspend #' + index + ' at ' + suspendTime + ' sec
ond(s).'); | |
51 context.suspend(suspendTime).then(function () { | |
52 actualSuspendTimes.push(suspendTime); | |
53 context.resume(); | |
54 }) | |
55 } | |
56 | |
57 function verifyResult() { | |
58 | |
59 for (var i = 0; i < actualSuspendTimes.length; i++) { | 69 for (var i = 0; i < actualSuspendTimes.length; i++) { |
60 var scheduledOrder = suspendTimes.indexOf(actualSuspendTimes[i]); | 70 var scheduledOrder = suspendTimes.indexOf(actualSuspendTimes[i]); |
61 var expectedOrder = expectedSuspendTimes.indexOf(actualSuspendTimes[i]
); | 71 var expectedOrder = expectedSuspendTimes.indexOf(actualSuspendTimes[ |
| 72 i]); |
62 | 73 |
63 if (i === expectedOrder) { | 74 should(i, 'The resolution order of suspend #' + scheduledOrder + |
64 testPassed('The resolution order of suspend #' + scheduledOrder + | |
65 ' is ' + i + ' at ' + suspendTimes[scheduledOrder].toFixed(2) + | 75 ' is ' + i + ' at ' + suspendTimes[scheduledOrder].toFixed(2) + |
66 ' second(s).'); | 76 ' second(s)') |
67 } | 77 .beEqualTo(expectedOrder); |
68 } | 78 } |
69 } | 79 } |
70 | 80 |
71 context.startRendering().then(verifyResult).then(finishJSTest); | |
72 | |
73 successfullyParsed = true; | |
74 </script> | 81 </script> |
75 | 82 |
76 </body> | 83 </body> |
77 </html> | 84 </html> |
OLD | NEW |