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

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, 5 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, numberOfChannels: 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 task.done();
158 });
159
160 audit.define(
161 {label: 'options-3', description: 'Valid options'},
162 (task, should) => {
163 let context;
164 let options = {
165 length: 1,
166 sampleRate: 8000,
167 };
168
169 // Verify context with valid constructor has the correct values.
170 should(
171 () => {
172 context = new OfflineAudioContext(options);
173 },
174 'c = new OfflineAudioContext' + JSON.stringify(options) + ')')
175 .notThrow();
176 should(
177 context.length,
178 'c.length')
179 .beEqualTo(options.length);
180 should(
181 context.sampleRate,
182 'c.sampleRate')
183 .beEqualTo(options.sampleRate);
184 should(
185 context.destination.channelCount,
186 'c.destination.channelCount')
187 .beEqualTo(1);
188 should(
189 context.destination.channelCountMode,
190 'c.destination.channelCountMode')
191 .beEqualTo("explicit");
192 should(
193 context.destination.channelInterpretation,
194 'c.destination.channelCountMode')
195 .beEqualTo("speakers");
196
197 options.numberOfChannels = 7;
198 should(
199 () => {
200 context = new OfflineAudioContext(options);
201 },
202 'c = new OfflineAudioContext' + JSON.stringify(options) + ')')
203 .notThrow();
204 should(
205 context.destination.channelCount,
206 'c.destination.channelCount')
207 .beEqualTo(options.numberOfChannels);
208
209 task.done();
210 });
211
212 audit.run();
213
214 </script>
215 </body>
216 </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