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

Side by Side Diff: LayoutTests/webaudio/audiocontext-suspend-resume.html

Issue 945023002: Refactoring layout tests for AudioContext.suspend() and resume() (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 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 <title>Test audiocontext suspend/resume</title> 4 <title>Test AudioContext.suspend() and AudioContext.resume()</title>
5 <script src="resources/compatibility.js"></script> 5 <script src="../resources/js-test.js"></script>
6 <script src="resources/audio-testing.js"></script> 6 <script src="resources/compatibility.js"></script>
7 <script src="../resources/js-test.js"></script> 7 <script src="resources/audio-testing.js"></script>
8 </head> 8 </head>
Raymond Toy 2015/02/20 21:35:14 Unneeded indentation change?
hongchan 2015/02/20 22:20:09 We agreed to keep the indentation as shown above.
9 9
10 <body> 10 <body>
11 <script> 11 <script>
12 description("Test suspend/resume for an (offline) AudioContext"); 12 description("Test suspend/resume for an (offline) AudioContext");
13 window.jsTestIsAsync = true;
13 14
14 var context; 15 var context;
15 var osc; 16 var osc;
16 var p1; 17 var p1;
17 var p2; 18 var p2;
18 19
19 var sampleRate = 44100; 20 var sampleRate = 44100;
20 var durationInSeconds = 1; 21 var durationInSeconds = 1;
21 22
22 // Convenience function that returns a function that calls the |passFailMe thod| with the given 23 var audit = Audit.createTaskRunner();
23 // |message|. The |passFailMethod| should be either |testPassed| or |test Failed|.
24 function handlePromise(passFailMethod, message) {
25 return function () {
26 passFailMethod(message);
27 };
28 }
29 24
30 function checkResult (event) { 25 // Convenience function that returns a function that calls the |passFailFunc |
26 // with the given |message|. The |passFailFunc| should be either |testPasse d|
27 // or |testFailed|.
28 function handlePromise(passFailFunc, message) {
29 return function () {
30 passFailFunc(message);
31 };
32 }
33
34 // Task 1: test suspend().
35 audit.defineTask('test-suspend', function (done) {
36
37 // Test suspend/resume. Ideally this test is best with a online
38 // AudioContext, but content shell doesn't really have a working online
39 // AudioContext. Hence, use an OfflineAudioContext. Not all possible
40 // scenarios can be easily checked with an offline context instead of an
41 // online context.
42
43 // Create an audio context with an oscillator.
44 context = new OfflineAudioContext(1, durationInSeconds * sampleRate, sampl eRate);
45 osc = context.createOscillator();
46 osc.connect(context.destination);
47
48 // Verify the state.
49 shouldBeEqualToString("context.state", "suspended");
50
51 // Multiple calls to suspend() should not be a problem. But we can't test
52 // that on an offline context. Thus, check that suspend() on an
53 // OfflineAudioContext rejects the promise.
54 shouldNotThrow("p1 = context.suspend()");
55 shouldBeType(p1, Promise);
56 p1.then(
57 handlePromise(testFailed, "context.suspend() should have been rejected f or an offline context"),
58 handlePromise(testPassed, "context.suspend() was correctly rejected for an offline context")
59 ).then(done);
60 });
61
62
63 // Task 2: test resume().
64 audit.defineTask('test-resume', function (done) {
65
66 // Multiple calls to resume should not be a problem. But we can't test
67 // that on an offline context. Thus, check that resume() on an
68 // OfflineAudioContext rejects the promise.
69 shouldNotThrow("p2 = context.resume()");
70 shouldBeType(p2, Promise);
71
72 // Resume doesn't actually resume an offline context
73 shouldBeEqualToString("context.state", "suspended");
74
75 p2.then(
76 handlePromise(testFailed, "context.resume() should have been rejected fo r an offline context"),
77 handlePromise(testPassed, "context.resume() was correctly rejected for a n offline context")
78 ).then(done);
79 });
80
81 // Task 3: test the state after context closed.
82 audit.defineTask('test-after-close', function (done) {
83
84 // Render the offline context.
85 osc.start();
86
87 // Test suspend/resume in tested promise pattern.
88 context.startRendering().then(function () {
89
31 // We don't care about the actual result of the offline rendering. 90 // We don't care about the actual result of the offline rendering.
Raymond Toy 2015/02/20 21:35:13 This seems indented incorrectly or inconsistently.
hongchan 2015/02/20 22:20:09 I see. I naively put the comment based on the orig
32 shouldBeEqualToString("context.state", "closed"); 91 shouldBeEqualToString("context.state", "closed");
92
33 // suspend() should be rejected on a closed context. 93 // suspend() should be rejected on a closed context.
34 context.suspend() 94 context.suspend().then(
35 .then(handlePromise( 95 handlePromise(testFailed, "context.suspend() on a closed context not r ejected"),
36 testFailed, 96 handlePromise(testPassed, "context.suspend() on a closed context rejec ted as expected")
37 "context.suspend() on a closed context not rejected"), 97 ).then(function () {
38 handlePromise( 98 // resume() should be rejected on closed context.
39 testPassed, 99 context.resume().then(
40 "context.suspend() on a closed context rejected as expected")) 100 handlePromise(testFailed, "context.resume() on a closed context not rejected"),
41 .then(function () { 101 handlePromise(testPassed, "context.resume() on a closed context reje cted as expected")
42 // resume() should be rejected on closed context. 102 ).then(done);
43 return context.resume(); 103 });
44 })
45 .then(handlePromise(
46 testFailed,
47 "context.resume() on a closed context not rejected"),
48 handlePromise(
49 testPassed,
50 "context.resume() on a closed context rejected as expected"))
51 .then(finishJSTest);
52 }
53 104
54 function runOfflineContextTest() { 105 });
55 // Render the offline context. 106 });
56 osc.start();
57 context.oncomplete = checkResult;
58 context.startRendering();
59 }
60 107
61 function runResumeTest () { 108 audit.defineTask('finish-test', function (done) {
62 // Multiple calls to resume should not be a problem. But we can't test t hat on an offline 109 done();
63 // context. Thus, check that resume() on an OfflineAudioContext rejects the promise. 110 finishJSTest();
64 shouldNotThrow("p1 = context.resume()"); 111 });
65 shouldBeType(p1, Promise);
66 // Resume doesn't actually resume an offline context
67 shouldBeEqualToString("context.state", "suspended");
68
69 p1.then(handlePromise(
70 testFailed,
71 "context.resume() should have been rejected for an offline con text"),
72 handlePromise(
73 testPassed,
74 "context.resume() was correctly rejected for an offline contex t"))
75 .then(runOfflineContextTest);
76 }
77 112
78 function runTest() { 113 audit.runTasks(
79 window.jsTestIsAsync = true; 114 'test-suspend',
80 // Test suspend/resume. Ideally this test is best with a online AudioCo ntext, but content 115 'test-resume',
81 // shell doesn't really have a working online AudioContext. Hence, use a n 116 'test-after-close',
82 // OfflineAudioContext. Not all possible scenarios can be easily checked with an offline 117 'finish-test'
83 // context instead of an online context. 118 );
84 119
85 // Create an audio context with an oscillator. 120 successfullyParsed = true;
86 context = new OfflineAudioContext(1, durationInSeconds * sampleRate, sam pleRate); 121 </script>
87 osc = context.createOscillator(); 122 </body>
88 osc.connect(context.destination);
89
90 // Verify the state.
91 shouldBeEqualToString("context.state", "suspended");
92
93 // Multiple calls to suspend() should not be a problem. But we can't tes t that on an offline
94 // context. Thus, check that suspend() on an OfflineAudioContext reject s the promise.
95 shouldNotThrow("p1 = context.suspend()");
96 shouldBeType(p1, Promise);
97 p1.then(handlePromise(
98 testFailed,
99 "context.suspend() should have been rejected for an offline co ntext"),
100 handlePromise(
101 testPassed,
102 "context.suspend() was correctly rejected for an offline conte xt"))
103 .then(runResumeTest);
104 }
105
106 runTest();
107 successfullyParsed = true;
108 </script>
109 </body>
110 </html> 123 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698