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

Side by Side Diff: third_party/WebKit/LayoutTests/webaudio/constructor/audionodeoptions.js

Issue 2102133002: Add constructors for WebAudio nodes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments and 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 // Test that constructor for the node with name |nodeName| handles the various
2 // possible values for channelCount, channelCountMode, and
3 // channelInterpretation.
4 function testAudioNodeOptions(context, nodeName, nodeOptions) {
5 if (nodeOptions === undefined)
6 nodeOptions = {};
7 var node;
8 var success = true;
9
10 // Test that we can set channelCount and that errors are thrown for invalid values
11 var testCount = 17;
12 if (nodeOptions.expectedChannelCount) {
13 testCount = nodeOptions.expectedChannelCount.value;
14 }
15 success = Should("new " + nodeName + "(c, {channelCount: " + testCount + "}} ",
16 function () {
17 node = new window[nodeName](
18 context,
19 Object.assign({},
20 nodeOptions.additionalOptions, {
21 channelCount: testCount
22 }));
23 }).notThrow();
24 success = Should("node.channelCount", node.channelCount)
25 .beEqualTo(testCount) && success;
26
27 if (nodeOptions.expectedChannelCount && nodeOptions.expectedChannelCount.isF ixed) {
28 // The channel count is fixed. Verify that we throw an error if we try to
29 // change it. Arbitrarily set the count to be one more than the expected
30 // value.
31 testCount = nodeOptions.expectedChannelCount.value + 1;
32 success = Should("new " + nodeName + "(c, {channelCount: " + testCount + "}}",
33 function () {
34 node = new window[nodeName](
35 context,
36 Object.assign({},
37 nodeOptions.additionalOptions, {
38 channelCount: testCount
39 }));
40 }).throw(nodeOptions.expectedChannelCount.errorType || "TypeError") && success;
41 } else {
42 // The channel count is not fixed. Try to set the count to invalid
43 // values and make sure an error is thrown.
44 var errorType = "NotSupportedError";
45
46 success = Should("new " + nodeName + "(c, {channelCount: 0}}",
47 function () {
48 node = new window[nodeName](
49 context,
50 Object.assign({},
51 nodeOptions.additionalOptions, {
52 channelCount: 0
53 }));
54 }).throw(errorType) && success;
55
56 success = Should("new " + nodeName + "(c, {channelCount: 99}}",
57 function () {
58 node = new window[nodeName](
59 context,
60 Object.assign({},
61 nodeOptions.additionalOptions, {
62 channelCount: 99
63 }));
64 }).throw(errorType) && success;
65 }
66
67 // Test channelCountMode
68 var testMode = "max";
69 if (nodeOptions && nodeOptions.expectedChannelCountMode) {
70 testMode = nodeOptions.expectedChannelCountMode.value;
71 }
72 success = Should("new " + nodeName + '(c, {channelCountMode: "' + testMode + '"}',
73 function () {
74 node = new window[nodeName](
75 context,
76 Object.assign({},
77 nodeOptions.additionalOptions, {
78 channelCountMode: testMode
79 }));
80 }).notThrow() && success;
81 success = Should("node.channelCountMode", node.channelCountMode)
82 .beEqualTo(testMode) && success;
83
84 if (nodeOptions.expectedChannelCountMode && nodeOptions.expectedChannelCount Mode.isFixed) {
85 // Channel count mode is fixed. Test setting to something else throws.
86 var testModeMap = {
87 "max": "clamped-max",
88 "clamped-max": "explicit",
89 "explicit": "max"
90 };
91 testMode = testModeMap[nodeOptions.expectedChannelCountMode.value];
92 success = Should("new " + nodeName + '(c, {channelCountMode: "' + testMo de + '"}',
93 function () {
94 node = new window[nodeName](
95 context,
96 Object.assign({},
97 nodeOptions.additionalOptions, {
98 channelCountMode: testMode
99 }));
100 }).throw(nodeOptions.expectedChannelCountMode.errorType) && success;
101 } else {
102 // Mode is not fixed. Verify that we can set the mode to all valid
103 // values, and that we throw for invalid values.
104
105 success = Should("new " + nodeName + '(c, {channelCountMode: "clamped-ma x"}',
106 function () {
107 node = new window[nodeName](
108 context,
109 Object.assign({},
110 nodeOptions.additionalOptions, {
111 channelCountMode: "clamped-max"
112 }));
113 }).notThrow() && success;
114 success = Should("node.channelCountMode", node.channelCountMode)
115 .beEqualTo("clamped-max") && success;
116
117 success = Should("new " + nodeName + '(c, {channelCountMode: "explicit"} ',
118 function () {
119 node = new window[nodeName](
120 context,
121 Object.assign({},
122 nodeOptions.additionalOptions, {
123 channelCountMode: "explicit"
124 }));
125 }).notThrow() && success;
126 success = Should("node.channelCountMode", node.channelCountMode)
127 .beEqualTo("explicit") && success;
128
129 success = Should("new " + nodeName + '(c, {channelCountMode: "foobar"}',
130 function () {
131 node = new window[nodeName](
132 context,
133 Object.assign({},
134 nodeOptions.additionalOptions, {
135 channelCountMode: "foobar"
136 }));
137 }).throw("TypeError") && success;
138 success = Should("node.channelCountMode", node.channelCountMode)
139 .beEqualTo("explicit") && success;
140 }
141
142 // Test channelInterpretation
143 success = Should("new " + nodeName + '(c, {channelInterpretation: "speakers" })',
144 function () {
145 node = new window[nodeName](
146 context,
147 Object.assign({},
148 nodeOptions.additionalOptions, {
149 channelInterpretation: "speakers"
150 }));
151 }).notThrow() && success;
152 success = Should("node.channelInterpretation", node.channelInterpretation)
153 .beEqualTo("speakers") && success;
154
155 success = Should("new " + nodeName + '(c, {channelInterpretation: "discrete" })',
156 function () {
157 node = new window[nodeName](
158 context,
159 Object.assign({},
160 nodeOptions.additionalOptions, {
161 channelInterpretation: "discrete"
162 }));
163 }).notThrow() && success;
164 success = Should("node.channelInterpretation", node.channelInterpretation)
165 .beEqualTo("discrete") && success;
166
167 success = Should("new " + nodeName + '(c, {channelInterpretation: "foobar"}) ',
168 function () {
169 node = new window[nodeName](
170 context,
171 Object.assign({},
172 nodeOptions.additionalOptions, {
173 channelInterpretation: "foobar"
174 }));
175 }).throw("TypeError") && success;
176 success = Should("node.channelInterpretation", node.channelInterpretation)
177 .beEqualTo("discrete") && success;
178
179
180 Should("AudioNodeOptions for " + nodeName, success)
181 .summarize(
182 "were correctly handled",
183 "were not correctly handled");
184 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698