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

Side by Side Diff: third_party/WebKit/LayoutTests/webaudio/offlineaudiocontext-suspend-resume-basic.html

Issue 1405413004: Implement suspend() and resume() for OfflineAudioContext (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: L-G-T-M webaudio part Created 5 years, 1 month 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('Basic test for OfflineAudioContext.suspend() and OfflineAudio Context.resume().');
12 window.jsTestIsAsync = true;
13
14 var sampleRate = 44100;
15 var renderDuration = 1;
16 var renderQuantum = 128;
17
18 var audit = Audit.createTaskRunner();
19
20 // Task: Calling suspend with no argument or negative time should
21 // reject the promise.
22 audit.defineTask('suspend-invalid-argument', function (done) {
23 var context = new OfflineAudioContext(1, sampleRate * renderDuration, sa mpleRate);
24
25 Should('context.suspend()', context.suspend()).beRejected();
26 Should('context.suspend(-1.0)', context.suspend(-1.0)).beRejected();
27 Should('context.suspend(2.0)', context.suspend(2.0)).beRejected();
28
29 context.startRendering().then(done);
30 });
31
32 // Task: Scheduling a suspend in the past should be rejected.
33 audit.defineTask('suspend-in-the-past', function (done) {
34 var context = new OfflineAudioContext(1, sampleRate * renderDuration, sa mpleRate);
35
36 context.suspend(0.5).then(function () {
37
38 Should('Scheduling a suspend in the past',
39 context.suspend(context.currentTime - 0.1)).beRejected();
40
41 Should('Scheduling a suspend in the future',
42 context.suspend(context.currentTime + 0.1).then(function () {
43 context.resume();
44 })).beResolved();
45
46 context.resume();
47 });
48
49 context.startRendering().then(done);
50 });
51
52 // Task: Calling multiple suspends at the same rendering quantum should
53 // reject the promise.
54 audit.defineTask('identical-suspend-time', function (done) {
55 var context = new OfflineAudioContext(1, sampleRate * renderDuration, sa mpleRate);
56
57 // |suspendTime1| and |suspendTime2| are identical when quantized to
58 // the render quantum size.
59 var suspendTime1 = renderQuantum / sampleRate;
60 var suspendTime2 = 1.5 * renderQuantum / sampleRate;
61
62 context.suspend(suspendTime1).then(function () {
63 context.resume();
64 });
65
66 // Printing out the pass message to be more informative here.
67 testPassed('Scheduling a suspend at frame ' + suspendTime1 * sampleRate + ' was successful.');
68
69 Should('Scheduling another suspend at the same rendering quantum',
70 context.suspend(suspendTime2)).beRejected();
71
72 context.startRendering().then(done);
73 });
74
75 // Task: Resuming the context before the actual suspension happens.
76 audit.defineTask('resume-before-suspend', function (done) {
77
78 // Make the render length 5 times longer to minimize the flakiness.
79 var longRenderDuration = renderDuration * 5;
80 var context = new OfflineAudioContext(1, sampleRate * longRenderDuration , sampleRate);
81
82 // Create dummy audio graph to slow the rendering.
83 var osc = context.createOscillator();
84 var lpf = context.createBiquadFilter();
85 osc.type = 'sawtooth';
86 osc.frequency.setValueAtTime(0.1, 0.0);
87 osc.frequency.linearRampToValueAtTime(1000, longRenderDuration * 0.5);
88 osc.frequency.linearRampToValueAtTime(0.1, longRenderDuration);
89 lpf.frequency.setValueAtTime(0.1, 0.0);
90 lpf.frequency.linearRampToValueAtTime(1000, longRenderDuration * 0.5);
91 lpf.frequency.linearRampToValueAtTime(0.1, longRenderDuration);
92 osc.connect(lpf);
93 lpf.connect(context.destination);
94 osc.start();
95
96 // A suspend is scheduled at the 90% of the render duration.
97 context.suspend(longRenderDuration * 0.9).then(done);
98
99 testPassed('Scheduling a suspend at ' + longRenderDuration * 0.9 + ' sec onds.');
100
101 // We have to start rendering to get the time running.
102 context.startRendering();
103
104 // Then call resume() immediately after the rendering starts. This
105 // resume() will be performed before the actual suspension happens.
106 // Note that this might be racy/flaky if the rendering is so fast that
107 // it reaches to the suspend even before the resume here.
Raymond Toy 2015/10/22 22:11:00 Nit: "it reaches to the suspend" -> "it reaches th
hongchan 2015/10/29 20:50:05 Done.
108 Should('Resuming at 0 second (before the actual suspend happens)', conte xt.resume())
109 .beRejected();
110 });
111
112 // Task: Calling resume on a context that is not started should reject the promise.
113 audit.defineTask('resume-without-suspend', function (done) {
114 var context = new OfflineAudioContext(1, sampleRate * renderDuration, sa mpleRate);
115
116 Should('Resuming a context without starting it', context.resume())
117 .beRejected().then(done);
118 });
119
120 audit.defineTask('finish', function (done) {
121 finishJSTest();
122 done();
123 });
124
125 audit.runTasks(
126 'suspend-invalid-argument',
127 'suspend-in-the-past',
128 'identical-suspend-time',
129 'resume-before-suspend',
130 'resume-without-suspend',
131 'finish'
132 );
133
134 successfullyParsed = true;
135 </script>
136
137 </body>
138 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698