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

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

Issue 2102133002: Add constructors for WebAudio nodes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 3 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
(Empty)
1 <!doctype html>
2 <html>
3 <head>
4 <title>Test Constructor: AudioBuffer</title>
5 <script src="../../resources/testharness.js"></script>
6 <script src="../../resources/testharnessreport.js"></script>
7 <script src="../resources/audio-testing.js"></script>
8 </head>
9
10 <body>
11 <script>
12 var context;
13
14 var audit = Audit.createTaskRunner();
15
16 audit.defineTask("initialize", function (taskDone) {
17 Should("context = new OfflineAudioContext(...)", function () {
18 context = new OfflineAudioContext(1, 1, 48000);
19 }).notThrow();
20
21 taskDone();
22 });
23
24 audit.defineTask("invalid constructor", function (taskDone) {
25 var node;
26 var success = true;
27
28 success = Should("new AudioBuffer()", function () {
29 node = new AudioBuffer();
30 }).throw("TypeError");
31 success = Should("new AudioBuffer(1)", function () {
32 node = new AudioBuffer(1) && success;
33 }).throw("TypeError");
34 success = Should("new AudioBuffer(context, 42)", function () {
35 node = new AudioBuffer(context, 42) && success;
36 }).throw("TypeError");
37
38 Should("Invalid constructors", success)
39 .summarize(
40 "correctly threw errors",
41 "did not throw errors in all cases");
42
43 taskDone();
44 });
45
46 audit.defineTask("required options", function (taskDone) {
47 var success = true;
48
49 success = Should("new AudioBuffer(context, {})", function () {
50 var buffer = new AudioBuffer(context, {});
51 }).throw("NotFoundError");
52
53 success = Should("new AudioBuffer(context, {numberOfChannels: 1}",
54 function () {
55 var buffer = new AudioBuffer(context, {
56 numberOfChannels: 1
57 });
58 }).throw("NotFoundError") && success;
59
60 success = Should(
61 "new AudioBuffer(context, {numberOfChannels: 1, length: 1}",
62 function () {
63 var buffer = new AudioBuffer(context, {
64 numberOfChannels: 1,
65 length: 1
66 });
67 }).notThrow() && success;
68
69 success = Should(
70 "new AudioBuffer(context, {numberOfChannels: 1, length: 1, sampleRate: 48000}",
71 function () {
72 var buffer = new AudioBuffer(context, {
73 numberOfChannels: 1,
74 length: 1,
75 sampleRate: 48000
76 });
77 }).notThrow() && success;
78
79 Should("Missing option values handled", success)
80 .summarize("correctly", "incorrectly");
81
82 taskDone();
83 });
84
85 audit.defineTask("invalid option values", function (taskDone) {
86 var success = true;
87
88 success = Should("new AudioBuffer(context, {numberOfChannels: 0})", func tion () {
89 var buffer = new AudioBuffer(context, {numberOfChannels: 0, length: 1} );
90 }).throw("NotSupportedError");
91
92 success = Should("new AudioBuffer(context, {numberOfChannels: 99})", fun ction () {
93 var buffer = new AudioBuffer(context, {numberOfChannels: 99, length: 0 });
94 }).throw("NotSupportedError") && success;
95
96 success = Should("new AudioBuffer(context, {length: 0})", function () {
97 var buffer = new AudioBuffer(context, {numberOfChannels: 1, length: 0} );
98 }).throw("NotSupportedError") && success;
99
100 success = Should("new AudioBuffer(context, {sampleRate: 100})", function () {
101 var buffer = new AudioBuffer(context, {numberOfChannels: 1, length: 1,
102 sampleRate: 100});
103 }).throw("NotSupportedError") && success;
104
105 Should("Invalid option values handled", success)
106 .summarize("correctly", "incorrectly");
107
108 taskDone();
109 });
110
111 audit.defineTask("default constructor", function (taskDone) {
112 var buffer;
113 var success = true;
114
115 success = Should(
116 "buffer = new AudioBuffer(context, {numberOfChannels: 5, length: 17})" ,
117 function () {
118 buffer = new AudioBuffer(context, {numberOfChannels: 5, length: 17}) ;
119 }).notThrow();
120
121 success = Should("buffer.numberOfChannels", buffer.numberOfChannels)
122 .beEqualTo(5) && success;
123 success = Should("buffer.length", buffer.length)
124 .beEqualTo(17) && success;
125 success = Should("buffer.sampleRate", buffer.sampleRate)
126 .beEqualTo(context.sampleRate) && success;
127
128 Should("Default constructor values set", success)
129 .summarize("correctly", "incorrectly");
130
131 taskDone();
132 });
133
134 audit.defineTask("valid constructor", function (taskDone) {
135 var buffer;
136 var success = true;
137
138 var options = {
139 numberOfChannels: 3,
140 length: 42,
141 sampleRate: 54321
142 };
143
144 var message = "new AudioBuffer(context, {";
145 message += "numberOfChannels: " + options.numberOfChannels;
146 message += ", length: " + options.length;
147 message += ", sampleRate: " + options.sampleRate;
148 message += "}";
149 success = Should(message, function () {
150 buffer = new AudioBuffer(context, options);
151 }).notThrow();
152
153 success = Should("buffer.numberOfChannels", buffer.numberOfChannels)
154 .beEqualTo(options.numberOfChannels) && success;
155
156 success = Should("buffer.length", buffer.length)
157 .beEqualTo(options.length) && success;
158
159 success = Should("buffer.sampleRate", buffer.sampleRate)
160 .beEqualTo(options.sampleRate) && success;
161
162 // Verify that we actually got the right number of channels
163 for (var k = 0; k < options.numberOfChannels; ++k) {
164 var data;
165 var message = "buffer.getChannelData(" + k + ")";
166 success = Should(message, function () {
167 data = buffer.getChannelData(k);
168 }).notThrow() && success;
169
170 success = Should(message + " length", data.length)
171 .beEqualTo(options.length) && success;
172 }
173
174 Should("buffer.getChannelData(" + options.numberOfChannels + ")",
175 function () {
176 buffer.getChannelData(options.numberOfChannels);
177 }).throw("IndexSizeError") && success;
178
179 Should("AudioBuffer constructed", success)
180 .summarize("correctly", "incorrectly");
181
182 taskDone();
183 });
184
185 audit.runTasks();
186 </script>
187 </body>
188 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698