michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: /** michael@0: * Test AudioNode#getParam() / AudioNode#setParam() michael@0: */ michael@0: michael@0: function spawnTest () { michael@0: let [target, debuggee, front] = yield initBackend(SIMPLE_CONTEXT_URL); michael@0: let [_, [destNode, oscNode, gainNode]] = yield Promise.all([ michael@0: front.setup({ reload: true }), michael@0: get3(front, "create-node") michael@0: ]); michael@0: michael@0: let freq = yield oscNode.getParam("frequency"); michael@0: info(typeof freq); michael@0: ise(freq, 440, "AudioNode:getParam correctly fetches AudioParam"); michael@0: michael@0: let type = yield oscNode.getParam("type"); michael@0: ise(type, "sine", "AudioNode:getParam correctly fetches non-AudioParam"); michael@0: michael@0: let type = yield oscNode.getParam("not-a-valid-param"); michael@0: is(type, undefined, "AudioNode:getParam correctly returns false for invalid param"); michael@0: michael@0: let resSuccess = yield oscNode.setParam("frequency", 220); michael@0: let freq = yield oscNode.getParam("frequency"); michael@0: ise(freq, 220, "AudioNode:setParam correctly sets a `number` AudioParam"); michael@0: is(resSuccess, undefined, "AudioNode:setParam returns undefined for correctly set AudioParam"); michael@0: michael@0: resSuccess = yield oscNode.setParam("type", "square"); michael@0: let type = yield oscNode.getParam("type"); michael@0: ise(type, "square", "AudioNode:setParam correctly sets a `string` non-AudioParam"); michael@0: is(resSuccess, undefined, "AudioNode:setParam returns undefined for correctly set AudioParam"); michael@0: michael@0: resSuccess = yield oscNode.setParam("type", "\"triangle\""); michael@0: type = yield oscNode.getParam("type"); michael@0: ise(type, "triangle", "AudioNode:setParam correctly removes quotes in `string` non-AudioParam"); michael@0: michael@0: try { michael@0: yield oscNode.setParam("frequency", "hello"); michael@0: ok(false, "setParam with invalid types should throw"); michael@0: } catch (e) { michael@0: ok(/is not a finite floating-point/.test(e.message), "AudioNode:setParam returns error with correct message when attempting an invalid assignment"); michael@0: is(e.type, "TypeError", "AudioNode:setParam returns error with correct type when attempting an invalid assignment"); michael@0: freq = yield oscNode.getParam("frequency"); michael@0: ise(freq, 220, "AudioNode:setParam does not modify value when an error occurs"); michael@0: } michael@0: michael@0: yield removeTab(target.tab); michael@0: finish(); michael@0: }