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

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

Issue 2680033002: Convert OfflineAudioContext tests to testharness (Closed)
Patch Set: Reindent. Created 3 years, 10 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
1 <!doctype html> 1 <!doctype html>
2 <html> 2 <html>
3 <head> 3 <head>
4 <script src="../../resources/js-test.js"></script> 4 <script src="../../resources/testharness.js"></script>
5 <script src="../../resources/testharnessreport.js"></script>
5 <script src="../resources/audit-util.js"></script> 6 <script src="../resources/audit-util.js"></script>
6 <script src="../resources/audio-testing.js"></script> 7 <script src="../resources/audit.js"></script>
7 </head> 8 </head>
8 9
9 <body> 10 <body>
10 <script> 11 <script>
11 description('Test promise resolution of OfflineAudioContext.resume() and O fflineAudioContext.suspend().'); 12 var audit = Audit.createTaskRunner();
12 window.jsTestIsAsync = true;
13
14 var context; 13 var context;
15 14
16 // The sample rate is multiple of the rendering quantum, so suspension 15 // The sample rate is multiple of the rendering quantum, so suspension
17 // times fall in to the render quantum boundary. 16 // times fall in to the render quantum boundary.
18 var renderQuantum = 128; 17 var renderQuantum = 128;
19 18
20 var sampleRate = renderQuantum * 100; 19 var sampleRate = renderQuantum * 100;
21 var renderDuration = 2; 20 var renderDuration = 2;
22 var scheduledSuspendTime = 0; 21 var scheduledSuspendTime = 0;
23 22
24 // With the sample rate setting above, this ensures suspension time fall 23 // With the sample rate setting above, this ensures suspension time fall
25 // in to the render quantum boundary. 24 // in to the render quantum boundary.
26 var suspendInterval = 0.25; 25 var suspendInterval = 0.25;
27 26
28 context = new OfflineAudioContext(1, sampleRate * renderDuration, sampleRa te); 27 function onSuspended(should) {
29 28 if (context.state === 'suspended' &&
30 function onSuspended() { 29 context.currentTime === scheduledSuspendTime) {
31 if (context.state === 'suspended' && context.currentTime === scheduledSu spendTime) { 30 should(
32 31 context.state === 'suspended' &&
33 testPassed('suspend promise resolved: context is suspended at ' + 32 context.currentTime === scheduledSuspendTime,
34 scheduledSuspendTime + ' second(s).'); 33 'Context suspended at ' + scheduledSuspendTime + ' second(s)')
34 .beTrue();
35 35
36 scheduledSuspendTime = context.currentTime + suspendInterval; 36 scheduledSuspendTime = context.currentTime + suspendInterval;
37 37
38 // Scheduling a suspend before the render duration should pass. 38 // Scheduling a suspend before the render duration should pass.
39 if (scheduledSuspendTime < renderDuration) { 39 if (scheduledSuspendTime < renderDuration) {
40 context.suspend(scheduledSuspendTime).then(onSuspended); 40 should(
41 testPassed('A new suspend has been scheduled at ' + 41 () => context.suspend(scheduledSuspendTime)
42 scheduledSuspendTime + ' second(s).'); 42 .then(() => onSuspended(should)),
43 'Scheduling a new suspend at ' + scheduledSuspendTime +
44 ' second(s)')
45 .notThrow();
43 } 46 }
44 47
45 // Scheduling a suspend exactly at the render duration should be 48 // Scheduling a suspend exactly at the render duration should be
46 // rejected. 49 // rejected.
47 if (scheduledSuspendTime === renderDuration) { 50 if (scheduledSuspendTime === renderDuration) {
48 Should('Scheduling at ' + renderDuration + ' seconds', 51 should(
49 context.suspend(scheduledSuspendTime)).beRejected(); 52 context.suspend(scheduledSuspendTime),
53 'Scheduling at ' + renderDuration + ' seconds')
54 .beRejected();
50 } 55 }
51 56
52 context.resume(); 57 context.resume();
53 } 58 }
54 } 59 }
55 60
56 // Schedule the first suspension. 61 audit.define('test', (task, should) => {
57 context.suspend(scheduledSuspendTime).then(onSuspended); 62 task.describe('Promise resolution of resume() and suspend()');
58 testPassed('A new suspend has been scheduled at ' + scheduledSuspendTime + ' second(s).'); 63 context = new OfflineAudioContext(1, sampleRate * renderDuration,
64 sampleRate);
59 65
60 context.startRendering().then(function () { 66 // Schedule the first suspension.
61 Should('Promise context.state', context.state).beEqualTo('closed'); 67 should(() => context.suspend(scheduledSuspendTime)
62 }).then(finishJSTest); 68 .then(() =>
69 onSuspended(should)),
70 'Scheduling a new suspend at ' + scheduledSuspendTime +
71 ' second(s)')
72 .notThrow();
63 73
64 successfullyParsed = true; 74 context.startRendering().then(function () {
75 should(context.state, 'Promise context.state')
76 .beEqualTo('closed');
77 }).then(() => task.done());
78 });
79
80 audit.run();
65 </script> 81 </script>
66 82
67 </body> 83 </body>
68 </html> 84 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698