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