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

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: Clarifying error messages in layout tests 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 = renderQuantum * 1.5 / sampleRate;
Raymond Toy 2015/10/21 18:22:45 1.5 * renderQuantum seems more typical and obvious
hongchan 2015/10/22 18:23:48 Done.
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 0.5 second...
80 context.suspend(renderDuration * 0.5).then(done);
Raymond Toy 2015/10/21 18:22:45 Comment and code don't quite match. It's 0.5 sec
hongchan 2015/10/22 18:23:48 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 Should('Resuming at 0 second (before the actual suspend happens)', conte xt.resume()).beRejected();
Raymond Toy 2015/10/21 18:22:45 Is there a potential race here? You've started re
hongchan 2015/10/22 18:23:48 Ack. I will make a note about it.
90 });
91
92 // Task: Calling resume on non-suspended context should reject the promise .
93 audit.defineTask('resume-without-suspend', function (done) {
94 var context = new OfflineAudioContext(1, sampleRate * renderDuration, sa mpleRate);
95
96 Should('Calling resume on context without any previous suspend', context .resume())
97 .beRejected().then(done);
98 });
99
100 audit.defineTask('finish', function (done) {
101 finishJSTest();
102 done();
103 });
104
105 audit.runTasks(
106 'suspend-invalid-argument',
Raymond Toy 2015/10/21 18:22:45 I wouldn't list the individual tasks.
hongchan 2015/10/22 18:23:48 To be honest, I prefer to keep individual tasks, s
Raymond Toy 2015/10/22 18:41:44 Ok. It goes both ways: If I add a new test, it wo
hongchan 2015/10/22 20:17:04 Acknowledged.
107 'suspend-in-the-past',
108 'identical-suspend-time',
109 'resume-before-suspend',
110 'resume-without-suspend',
111 'finish'
112 );
113
114 successfullyParsed = true;
115 </script>
116
117 </body>
118 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698