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