Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(389)

Side by Side Diff: LayoutTests/webaudio/offlineaudiocontext-suspend-resume-sequence.html

Issue 1140723003: Implement suspend() and resume() for OfflineAudioContext (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Adapting CL to AbstractAudioContext Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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/audio-testing.js"></script>
7 </head>
8
9 <body>
10 <script>
11 description('Test OfflineAudioContext.resume() and OfflineAudioContext.sus pend() with the timed sequence.');
12 window.jsTestIsAsync = true;
13
14 var context;
15
16 // The sample rate is multiple of the rendering quantum, so suspension
17 // times fall in to the render quantum boundary.
18 var renderQuantum = 128;
19
20 var sampleRate = renderQuantum * 100;
21 var renderDuration = 2;
22
23 // 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
25 // in a random order in runtime.
26 //
27 // 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
29 // verification.
30 var suspendTimes = [0.25, 0.75, 1.0, 0.5, 1.25, 0.0, 1.75];
31
32 // Sorted ascending suspend time is our expected result.
33 var expectedSuspendTimes = suspendTimes.slice(0).sort(function (a, b) {
34 return a - b;
35 });
36
37 var actualSuspendTimes = [];
38
39 context = new OfflineAudioContext(1, sampleRate * renderDuration, sampleRa te);
40
41 for (var i = 0; i < suspendTimes.length; i++) {
42
43 // Schedule suspends in a random time order, but the actual suspend
44 // must happen in ascending time order.
45 scheduleSuspend(suspendTimes[i]);
46
47 }
48
49 function scheduleSuspend(suspendTime) {
50 context.suspend(suspendTime).then(function () {
51 actualSuspendTimes.push(suspendTime);
52 context.resume();
53 })
54 }
55
56 function verifyResult() {
57
58 for (var i = 0; i < actualSuspendTimes.length; i++) {
59 var scheduledOrder = suspendTimes.indexOf(actualSuspendTimes[i])
60 var expectedOrder = expectedSuspendTimes.indexOf(actualSuspendTimes[i] )
61
62 Should('The actual resolution order of the suspend ' + scheduledOrder +
63 ' (' + suspendTimes[scheduledOrder].toFixed(2) + ' sec.)', i)
64 .beEqualTo(expectedOrder);
65 }
66 }
67
68 context.startRendering().then(function () {
69 verifyResult();
70 finishJSTest();
71 });
Raymond Toy 2015/07/15 20:59:13 Would it be nicer to write this as startRendering
hongchan 2015/07/15 23:24:22 Done.
72
73 successfullyParsed = true;
74 </script>
75
76 </body>
77 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698