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

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: Addressing feedback Created 5 years, 2 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('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 var context = new OfflineAudioContext(1, sampleRate * renderDuration, sa mpleRate);
78
79 // A suspend is scheduled at the half of the render duration.
80 context.suspend(renderDuration * 0.5).then(done);
81
82 testPassed('Scheduling a suspend at 0.5 second.');
83
84 // We have to start rendering to get the time running.
85 context.startRendering();
86
87 // Then call resume() immediately after the rendering starts. This
88 // resume() will be performed before the actual suspension happens.
89 // Note that this might be racy if the rendering is so fast that it
90 // reaches to 0.5 second even before the resume here.
Raymond Toy 2015/10/21 23:14:18 Nit: "0.5 second" is wrong. Do we really need th
hongchan 2015/10/22 21:05:03 Done.
91 Should('Resuming at 0 second (before the actual suspend happens)', conte xt.resume())
92 .beRejected();
93 });
94
95 // Task: Calling resume on non-suspended context should reject the promise .
96 audit.defineTask('resume-without-suspend', function (done) {
97 var context = new OfflineAudioContext(1, sampleRate * renderDuration, sa mpleRate);
98
99 Should('Calling resume on context without any previous suspend', context .resume())
100 .beRejected().then(done);
101 });
102
103 audit.defineTask('finish', function (done) {
104 finishJSTest();
105 done();
106 });
107
108 audit.runTasks(
109 'suspend-invalid-argument',
110 'suspend-in-the-past',
111 'identical-suspend-time',
112 'resume-before-suspend',
113 'resume-without-suspend',
114 'finish'
115 );
116
117 successfullyParsed = true;
118 </script>
119
120 </body>
121 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698