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

Side by Side Diff: third_party/WebKit/LayoutTests/webaudio/constructor/offlineaudiocontext.html

Issue 2713793004: Add dictionary for OfflineAudioContext constructor (Closed)
Patch Set: Rebase Created 3 years, 8 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/modules/modules_idl_files.gni » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 <!doctype html>
2 <html>
3 <head>
4 <title>Test Constructor: OfflineAudioContext</title>
5 <script src="../../resources/testharness.js"></script>
6 <script src="../../resources/testharnessreport.js"></script>
7 <script src="../resources/audit.js"></script>
8 <script src="../resources/audit-util.js"></script>
9 <script src="audionodeoptions.js"></script>
10 </head>
11
12 <body>
13 <script>
14 let audit = Audit.createTaskRunner();
15
16 // Just a simple test of the 3-arg constructor; This should be
17 // well-covered by other layout tests that use the 3-arg constructor.
18 audit.define(
19 {label: 'basic', description: 'Old-style constructor'},
20 (task, should) => {
21 let context;
22
23 // First and only arg should be a dictionary.
24 should(() => {
25 new OfflineAudioContext(3);
26 }, 'new OfflineAudioContext(3)').throw();
27
28 // Constructor needs 1 or 3 args, so 2 should throw.
29 should(() => {
30 new OfflineAudioContext(3, 42);
31 }, 'new OfflineAudioContext(3, 42)').throw();
32
33 // Valid constructor
34 should(() => {
35 context = new OfflineAudioContext(3, 42, 12345);
36 }, 'context = new OfflineAudioContext(3, 42, 12345)').notThrow();
37
38 // Verify that the context was constructed correctly.
39 should(context.length, 'context.length').beEqualTo(42);
40 should(context.sampleRate, 'context.sampleRate').beEqualTo(12345);
41 should(
42 context.destination.channelCount,
43 'context.destination.channelCount')
44 .beEqualTo(3);
45 should(
46 context.destination.channelCountMode,
47 'context.destination.channelCountMode')
48 .beEqualTo('explicit');
49 should(
50 context.destination.channelInterpretation,
51 'context.destination.channelInterpretation')
52 .beEqualTo('speakers');
53 task.done();
54 });
55
56 // Test constructor throws an error if the required members of the
57 // dictionary are not given.
58 audit.define(
59 {label: 'options-1', description: 'Required options'},
60 (task, should) => {
61 let context2;
62
63 // No args should throw
64 should(() => {
65 new OfflineAudioContext();
66 }, 'new OfflineAudioContext()').throw();
67
68 // Empty OfflineAudioContextOptions should throw
69 should(() => {
70 new OfflineAudioContext({});
71 }, 'new OfflineAudioContext({})').throw();
72
73 // Invalid type should throw
74 should(() => {
75 new OfflineAudioContext(42);
76 }, 'new OfflineAudioContext(42)').throw();
77
78 let options = {length: 42};
79 // sampleRate is required.
80 should(
81 () => {
82 new OfflineAudioContext(options);
83 },
84 'new OfflineAudioContext(' + JSON.stringify(options) + ')')
85 .throw();
86
87 options = {sampleRate: 12345};
88 // length is required.
89 should(
90 () => {
91 new OfflineAudioContext(options);
92 },
93 'new OfflineAudioContext(' + JSON.stringify(options) + ')')
94 .throw();
95
96 // Valid constructor. Verify that the resulting context has the
97 // correct values.
98 options = {length: 42, sampleRate: 12345};
99 should(
100 () => {
101 context2 = new OfflineAudioContext(options);
102 },
103 'c2 = new OfflineAudioContext(' + JSON.stringify(options) + ')')
104 .notThrow();
105 should(
106 context2.destination.channelCount,
107 'c2.destination.channelCount')
108 .beEqualTo(1);
109 should(context2.length, 'c2.length').beEqualTo(options.length);
110 should(context2.sampleRate, 'c2.sampleRate')
111 .beEqualTo(options.sampleRate);
112 should(
113 context2.destination.channelCountMode,
114 'c2.destination.channelCountMode')
115 .beEqualTo('explicit');
116 should(
117 context2.destination.channelInterpretation,
118 'c2.destination.channelInterpretation')
119 .beEqualTo('speakers');
120
121 task.done();
122 });
123
124 // Constructor should throw errors for invalid values specified by
125 // OfflineAudioContextOptions.
126 audit.define(
127 {label: 'options-2', description: 'Invalid options'},
128 (task, should) => {
129 let options = {length: 42, sampleRate: 8000, channelCount: 33};
130
131 // channelCount too large.
132 should(
133 () => {
134 new OfflineAudioContext(options);
135 },
136 'new OfflineAudioContext(' + JSON.stringify(options) + ')')
137 .throw('NotSupportedError');
138
139 // length cannot be 0
140 options = {length: 0, sampleRate: 8000};
141 should(
142 () => {
143 new OfflineAudioContext(options);
144 },
145 'new OfflineAudioContext(' + JSON.stringify(options) + ')')
146 .throw('NotSupportedError');
147
148 // sampleRate outside valid range
149 options = {length: 1, sampleRate: 1};
150 should(
151 () => {
152 new OfflineAudioContext(options);
153 },
154 'new OfflineAudioContext(' + JSON.stringify(options) + ')')
155 .throw('NotSupportedError');
156
157 // Invalid channelInterpretation
158 options = {
159 length: 1,
160 sampleRate: 8000,
161 channelInterpretation: 'unknown'
162 };
163 should(
164 () => {
165 new OfflineAudioContext(options);
166 },
167 'new OfflineAudioContext(' + JSON.stringify(options) + ')')
168 .throw('TypeError');
169
170 // Invalid channelCountMode
171 options = {
172 length: 1,
173 sampleRate: 8000,
174 channelCountMode: 'unknown'
175 };
176 should(
177 () => {
178 new OfflineAudioContext(options);
179 },
180 'new OfflineAudioContext(' + JSON.stringify(options) + ')')
181 .throw('TypeError');
182
183 task.done();
184 });
185
186 audit.define(
187 {label: 'options-3', description: 'Valid options'},
188 (task, should) => {
189 let context;
190 let options = {
191 length: 1,
192 sampleRate: 8000,
193 };
194
195 // Verify context with valid constructor has the correct values.
196 should(
197 () => {
198 context = new OfflineAudioContext(options);
199 },
200 'c = new OfflineAudioContext' + JSON.stringify(options) + ')')
201 .notThrow();
202 should(
203 context.length,
204 'c.length')
205 .beEqualTo(options.length);
206 should(
207 context.sampleRate,
208 'c.sampleRate')
209 .beEqualTo(options.sampleRate);
210 should(
211 context.destination.channelCount,
212 'c.destination.channelCount')
213 .beEqualTo(1);
214 should(
215 context.destination.channelCountMode,
216 'c.destination.channelCountMode')
217 .beEqualTo("explicit");
218 should(
219 context.destination.channelInterpretation,
220 'c.destination.channelCountMode')
221 .beEqualTo("speakers");
222
223 options.channelCount = 7;
224 options.channelCountMode = 'clamped-max';
225 should(
226 () => {
227 context = new OfflineAudioContext(options);
228 },
229 'c = new OfflineAudioContext' + JSON.stringify(options) + ')')
230 .notThrow();
231 should(
232 context.destination.channelCount,
233 'c.destination.channelCount')
234 .beEqualTo(options.channelCount);
235 should(
236 context.destination.channelCountMode,
237 'c.destination.channelCountMode')
238 .beEqualTo(options.channelCountMode);
239
240 options.channelInterpretation = 'discrete';
241 should(
242 () => {
243 context = new OfflineAudioContext(options);
244 },
245 'c = new OfflineAudioContext' + JSON.stringify(options) + ')')
246 .notThrow();
247 should(
248 context.destination.channelInterpretation,
249 'c.destination.channelInterpretation')
250 .beEqualTo(options.channelInterpretation);
251
252 task.done();
253 });
254
255 audit.run();
256
257 </script>
258 </body>
259 </html>
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/modules/modules_idl_files.gni » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698