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

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

Issue 2581463002: Refactor WebAudio test directory (Closed)
Patch Set: Use correct path for wav result files Created 4 years 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 <title>Test AudioContext.suspend() and AudioContext.resume()</title>
5 <script src="../resources/js-test.js"></script>
6 <script src="resources/compatibility.js"></script>
7 <script src="resources/audit-util.js"></script>
8 <script src="resources/audio-testing.js"></script>
9 </head>
10
11 <body>
12 <script>
13 description("Test suspend/resume for an (offline) AudioContext");
14 window.jsTestIsAsync = true;
15
16 var offlineContext;
17 var osc;
18 var p1;
19 var p2;
20 var p3;
21
22 var sampleRate = 44100;
23 var durationInSeconds = 1;
24
25 var audit = Audit.createTaskRunner();
26
27 // Convenience function that returns a function that calls the |passFailFunc |
28 // with the given |message|. The |passFailFunc| should be either |testPasse d|
29 // or |testFailed|.
30 function handlePromise(passFailFunc, message) {
31 return function () {
32 passFailFunc(message);
33 };
34 }
35
36 // Task: test suspend().
37 audit.defineTask('test-suspend', function (done) {
38
39 // Test suspend/resume. Ideally this test is best with a online
40 // AudioContext, but content shell doesn't really have a working online
41 // AudioContext. Hence, use an OfflineAudioContext. Not all possible
42 // scenarios can be easily checked with an offline context instead of an
43 // online context.
44
45 // Create an audio context with an oscillator.
46 shouldNotThrow("offlineContext = new OfflineAudioContext(1, durationInSeco nds * sampleRate, sampleRate)");
47 osc = offlineContext.createOscillator();
48 osc.connect(offlineContext.destination);
49
50 // Verify the state.
51 shouldBeEqualToString("offlineContext.state", "suspended");
52
53 // Multiple calls to suspend() should not be a problem. But we can't test
54 // that on an offline context. Thus, check that suspend() on an
55 // OfflineAudioContext rejects the promise.
56 shouldNotThrow("p1 = offlineContext.suspend()");
57 shouldBeType("p1", "Promise");
58 p1.then(
59 handlePromise(testFailed, "offlineContext.suspend() should have been rej ected for an offline context"),
60 function (e) {
61 if (e.name === "TypeError") {
62 testPassed(
63 "offlineContext.suspend() was correctly rejected: " + e);
64 } else {
65 testFailed(
66 "offlineContext.suspend() was correctly rejected but expected Type Error, not: " + e);
67 }
68 }
69 ).then(done);
70 });
71
72
73 // Task: test resume().
74 audit.defineTask('test-resume', function (done) {
75
76 // Multiple calls to resume should not be a problem. But we can't test
77 // that on an offline context. Thus, check that resume() on an
78 // OfflineAudioContext rejects the promise.
79 shouldNotThrow("p2 = offlineContext.resume()");
80 shouldBeType("p2", "Promise");
81
82 // Resume doesn't actually resume an offline context
83 shouldBeEqualToString("offlineContext.state", "suspended");
84 p2.then(
85 handlePromise(testFailed, "offlineContext.resume() should have been reje cted for an offline context"),
86 function (e) {
87 if (e.name === "InvalidStateError") {
88 testPassed(
89 "offlineContext.resume() was correctly rejected: " + e);
90 } else {
91 testFailed(
92 "offlineContext.resume() was correctly rejected but expected Inval idAccessError, not: " + e);
93 }
94 }
95 ).then(done);
96 });
97
98 // Task: test the state after context closed.
99 audit.defineTask('test-after-close', function (done) {
100
101 // Render the offline context.
102 osc.start();
103
104 // Test suspend/resume in tested promise pattern. We don't care about the
105 // actual result of the offline rendering.
106 shouldNotThrow("p3 = offlineContext.startRendering()");
107 p3.then(function () {
108 shouldBeEqualToString("offlineContext.state", "closed");
109
110 // suspend() should be rejected on a closed context.
111 offlineContext.suspend().then(
112 handlePromise(testFailed, "offlineContext.suspend() on a closed contex t not rejected"),
113 function (e) {
114 if (e.name === "TypeError") {
115 testPassed("offlineContext.suspend() on a closed context rejected: " + e);
116 } else {
117 testFailed("offlineContext.suspend() on a closed context rejected but expected TypeError, not: " + e);
118 }
119 }
120 ).then(function () {
121 // resume() should be rejected on closed context.
122 offlineContext.resume().then(
123 handlePromise(testFailed, "offlineContext.resume() on a closed conte xt not rejected"),
124 function (e) {
125 if (e.name === "InvalidStateError") {
126 testPassed("offlineContext.resume() on a closed context rejected : " + e);
127 } else {
128 testFailed("offlineContext.resume() on a closed context rejected but expected InvalidStateError, not: " + e);
129 }
130 }
131 ).then(done);
132 });
133
134 });
135 });
136
137 audit.defineTask('finish-test', function (done) {
138 done();
139 finishJSTest();
140 });
141
142 audit.runTasks(
143 'test-suspend',
144 'test-resume',
145 'test-after-close',
146 'finish-test'
147 );
148
149 successfullyParsed = true;
150 </script>
151 </body>
152 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698