|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 /** |
|
5 * Test AudioNode#getParam() / AudioNode#setParam() |
|
6 */ |
|
7 |
|
8 function spawnTest () { |
|
9 let [target, debuggee, front] = yield initBackend(SIMPLE_CONTEXT_URL); |
|
10 let [_, [destNode, oscNode, gainNode]] = yield Promise.all([ |
|
11 front.setup({ reload: true }), |
|
12 get3(front, "create-node") |
|
13 ]); |
|
14 |
|
15 let freq = yield oscNode.getParam("frequency"); |
|
16 info(typeof freq); |
|
17 ise(freq, 440, "AudioNode:getParam correctly fetches AudioParam"); |
|
18 |
|
19 let type = yield oscNode.getParam("type"); |
|
20 ise(type, "sine", "AudioNode:getParam correctly fetches non-AudioParam"); |
|
21 |
|
22 let type = yield oscNode.getParam("not-a-valid-param"); |
|
23 is(type, undefined, "AudioNode:getParam correctly returns false for invalid param"); |
|
24 |
|
25 let resSuccess = yield oscNode.setParam("frequency", 220); |
|
26 let freq = yield oscNode.getParam("frequency"); |
|
27 ise(freq, 220, "AudioNode:setParam correctly sets a `number` AudioParam"); |
|
28 is(resSuccess, undefined, "AudioNode:setParam returns undefined for correctly set AudioParam"); |
|
29 |
|
30 resSuccess = yield oscNode.setParam("type", "square"); |
|
31 let type = yield oscNode.getParam("type"); |
|
32 ise(type, "square", "AudioNode:setParam correctly sets a `string` non-AudioParam"); |
|
33 is(resSuccess, undefined, "AudioNode:setParam returns undefined for correctly set AudioParam"); |
|
34 |
|
35 resSuccess = yield oscNode.setParam("type", "\"triangle\""); |
|
36 type = yield oscNode.getParam("type"); |
|
37 ise(type, "triangle", "AudioNode:setParam correctly removes quotes in `string` non-AudioParam"); |
|
38 |
|
39 try { |
|
40 yield oscNode.setParam("frequency", "hello"); |
|
41 ok(false, "setParam with invalid types should throw"); |
|
42 } catch (e) { |
|
43 ok(/is not a finite floating-point/.test(e.message), "AudioNode:setParam returns error with correct message when attempting an invalid assignment"); |
|
44 is(e.type, "TypeError", "AudioNode:setParam returns error with correct type when attempting an invalid assignment"); |
|
45 freq = yield oscNode.getParam("frequency"); |
|
46 ise(freq, 220, "AudioNode:setParam does not modify value when an error occurs"); |
|
47 } |
|
48 |
|
49 yield removeTab(target.tab); |
|
50 finish(); |
|
51 } |