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

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: Removing redundant definitions of context.suspend() 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.
yhirano 2015/11/11 16:10:55 or less than or equal to the current time?
hongchan 2015/11/11 21:21:30 Here we are not testing 'less than or equal to' ca
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();
yhirano 2015/11/11 16:10:55 return needed?
hongchan 2015/11/11 21:21:30 No, Should().beResolved() is expecting the resolut
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 a running context should be resolved.
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. Resuming
105 // a context that is already running should be resolved.
106 Should('Resuming a running context', context.resume())
107 .beResolved();
108 });
109
110 // Task: Calling resume on a context that is not started should reject the promise.
111 audit.defineTask('resume-without-suspend', function (done) {
112 var context = new OfflineAudioContext(1, sampleRate * renderDuration, sa mpleRate);
113
114 Should('Resuming a context without starting it', context.resume())
115 .beRejected().then(done);
116 });
117
118 audit.defineTask('finish', function (done) {
119 finishJSTest();
120 done();
121 });
122
123 audit.runTasks(
124 'suspend-invalid-argument',
125 'suspend-in-the-past',
126 'identical-suspend-time',
127 'resume-before-suspend',
128 'resume-without-suspend',
129 'finish'
130 );
131
132 successfullyParsed = true;
133 </script>
134
135 </body>
136 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698