browser/devtools/webaudioeditor/test/browser_audionode-actor-get-set-param.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/webaudioeditor/test/browser_audionode-actor-get-set-param.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,51 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +/**
     1.8 + * Test AudioNode#getParam() / AudioNode#setParam()
     1.9 + */
    1.10 +
    1.11 +function spawnTest () {
    1.12 +  let [target, debuggee, front] = yield initBackend(SIMPLE_CONTEXT_URL);
    1.13 +  let [_, [destNode, oscNode, gainNode]] = yield Promise.all([
    1.14 +    front.setup({ reload: true }),
    1.15 +    get3(front, "create-node")
    1.16 +  ]);
    1.17 +
    1.18 +  let freq = yield oscNode.getParam("frequency");
    1.19 +  info(typeof freq);
    1.20 +  ise(freq, 440, "AudioNode:getParam correctly fetches AudioParam");
    1.21 +
    1.22 +  let type = yield oscNode.getParam("type");
    1.23 +  ise(type, "sine", "AudioNode:getParam correctly fetches non-AudioParam");
    1.24 +
    1.25 +  let type = yield oscNode.getParam("not-a-valid-param");
    1.26 +  is(type, undefined, "AudioNode:getParam correctly returns false for invalid param");
    1.27 +
    1.28 +  let resSuccess = yield oscNode.setParam("frequency", 220);
    1.29 +  let freq = yield oscNode.getParam("frequency");
    1.30 +  ise(freq, 220, "AudioNode:setParam correctly sets a `number` AudioParam");
    1.31 +  is(resSuccess, undefined, "AudioNode:setParam returns undefined for correctly set AudioParam");
    1.32 +
    1.33 +  resSuccess = yield oscNode.setParam("type", "square");
    1.34 +  let type = yield oscNode.getParam("type");
    1.35 +  ise(type, "square", "AudioNode:setParam correctly sets a `string` non-AudioParam");
    1.36 +  is(resSuccess, undefined, "AudioNode:setParam returns undefined for correctly set AudioParam");
    1.37 +
    1.38 +  resSuccess = yield oscNode.setParam("type", "\"triangle\"");
    1.39 +  type = yield oscNode.getParam("type");
    1.40 +  ise(type, "triangle", "AudioNode:setParam correctly removes quotes in `string` non-AudioParam");
    1.41 +
    1.42 +  try {
    1.43 +    yield oscNode.setParam("frequency", "hello");
    1.44 +    ok(false, "setParam with invalid types should throw");
    1.45 +  } catch (e) {
    1.46 +    ok(/is not a finite floating-point/.test(e.message), "AudioNode:setParam returns error with correct message when attempting an invalid assignment");
    1.47 +    is(e.type, "TypeError", "AudioNode:setParam returns error with correct type when attempting an invalid assignment");
    1.48 +    freq = yield oscNode.getParam("frequency");
    1.49 +    ise(freq, 220, "AudioNode:setParam does not modify value when an error occurs");
    1.50 +  }
    1.51 +
    1.52 +  yield removeTab(target.tab);
    1.53 +  finish();
    1.54 +}

mercurial