Bug 1006283 - Set and display proper type on AudioParams for web audio editor. r=vp
authorJordan Santell <jsantell@gmail.com>
Tue, 06 May 2014 14:03:00 -0400
changeset 181882 dfba6113cb029b923db32ccf3b54aa1d5756bdd3
parent 181881 4ed94f132f5b784cabee8ea97a72605f6935aa02
child 181883 5bbc85136202211a6f479bdd4cb965d474119607
child 181928 25e04f0991908bc4321b9b6f7f7648b848c1196e
push id43162
push userkwierso@gmail.com
push dateWed, 07 May 2014 01:07:29 +0000
treeherdermozilla-inbound@8fcfb1107b03 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvp
bugs1006283
milestone32.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1006283 - Set and display proper type on AudioParams for web audio editor. r=vp
browser/devtools/webaudioeditor/test/browser_audionode-actor-get-set-param.js
browser/devtools/webaudioeditor/test/browser_wa_params_view_edit.js
browser/devtools/webaudioeditor/test/head.js
browser/devtools/webaudioeditor/webaudioeditor-view.js
toolkit/devtools/server/actors/webaudio.js
--- a/browser/devtools/webaudioeditor/test/browser_audionode-actor-get-set-param.js
+++ b/browser/devtools/webaudioeditor/test/browser_audionode-actor-get-set-param.js
@@ -27,20 +27,16 @@ function spawnTest () {
   ise(freq, 220, "AudioNode:setParam correctly sets a `number` AudioParam");
   is(resSuccess, undefined, "AudioNode:setParam returns undefined for correctly set AudioParam");
 
   resSuccess = yield oscNode.setParam("type", "square");
   let type = yield oscNode.getParam("type");
   ise(type, "square", "AudioNode:setParam correctly sets a `string` non-AudioParam");
   is(resSuccess, undefined, "AudioNode:setParam returns undefined for correctly set AudioParam");
 
-  resSuccess = yield oscNode.setParam("type", "\"triangle\"");
-  type = yield oscNode.getParam("type");
-  ise(type, "triangle", "AudioNode:setParam correctly removes quotes in `string` non-AudioParam");
-
   try {
     yield oscNode.setParam("frequency", "hello");
     ok(false, "setParam with invalid types should throw");
   } catch (e) {
     ok(/is not a finite floating-point/.test(e.message), "AudioNode:setParam returns error with correct message when attempting an invalid assignment");
     is(e.type, "TypeError", "AudioNode:setParam returns error with correct type when attempting an invalid assignment");
     freq = yield oscNode.getParam("frequency");
     ise(freq, 220, "AudioNode:setParam does not modify value when an error occurs");
--- a/browser/devtools/webaudioeditor/test/browser_wa_params_view_edit.js
+++ b/browser/devtools/webaudioeditor/test/browser_wa_params_view_edit.js
@@ -14,29 +14,37 @@ function spawnTest() {
 
   reload(target);
 
   let [[dest, osc, gain], [[_, destID], [_, oscID], [_, gainID]]] = yield Promise.all([
     get3(gFront, "create-node"),
     get3Spread(panel.panelWin, EVENTS.UI_ADD_NODE_LIST)
   ]);
 
+  let setAndCheck = setAndCheckVariable(panel.panelWin, gVars);
 
   checkVariableView(gVars, 1, {
     "type": "\"sine\"",
     "frequency": 440,
     "detune": 0
-  });
+  }, "default loaded string");
 
   checkVariableView(gVars, 2, {
     "gain": 0
-  });
-
-  yield modifyVariableView(panel.panelWin, gVars, 1, "type", "square");
+  }, "default loaded number");
 
-  checkVariableView(gVars, 1, {
-    "type": "\"square\""
-  });
+  yield setAndCheck(1, "type", "\"square\"", "\"square\"", "sets string as string");
+
+  yield setAndCheck(2, "gain", 0.005, 0.005, "sets number as number");
 
   yield teardown(panel);
   finish();
 }
 
+function setAndCheckVariable (panelWin, gVars) {
+  return Task.async(function (varNum, prop, value, expected, desc) {
+    yield modifyVariableView(panelWin, gVars, varNum, prop, value);
+    var props = {};
+    props[prop] = expected;
+    checkVariableView(gVars, varNum, props, desc);
+  });
+}
+
--- a/browser/devtools/webaudioeditor/test/head.js
+++ b/browser/devtools/webaudioeditor/test/head.js
@@ -206,25 +206,25 @@ function waitForGraphRendered (front, no
     if (nodes === nodeCount && edges === edgeCount) {
       front.off(eventName, onGraphRendered);
       deferred.resolve();
     }
   });
   return deferred.promise;
 }
 
-function checkVariableView (view, index, hash) {
+function checkVariableView (view, index, hash, description = "") {
   let scope = view.getScopeAtIndex(index);
   let variables = Object.keys(hash);
   variables.forEach(variable => {
     let aVar = scope.get(variable);
     is(aVar.target.querySelector(".name").getAttribute("value"), variable,
       "Correct property name for " + variable);
     is(aVar.target.querySelector(".value").getAttribute("value"), hash[variable],
-      "Correct property value of " + hash[variable] + " for " + variable);
+      "Correct property value of " + hash[variable] + " for " + variable + " " + description);
   });
 }
 
 function modifyVariableView (win, view, index, prop, value) {
   let deferred = Promise.defer();
   let scope = view.getScopeAtIndex(index);
   let aVar = scope.get(prop);
   scope.expand();
--- a/browser/devtools/webaudioeditor/webaudioeditor-view.js
+++ b/browser/devtools/webaudioeditor/webaudioeditor-view.js
@@ -264,22 +264,31 @@ let WebAudioParamView = {
 
   /**
    * Executed when an audio param is changed in the UI.
    */
   _onEval: Task.async(function* (variable, value) {
     let ownerScope = variable.ownerView;
     let node = getViewNodeById(ownerScope.actorID);
     let propName = variable.name;
-    let errorMessage = yield node.actor.setParam(propName, value);
+    let error;
+
+    // Cast value to proper type
+    try {
+      value = JSON.parse(value);
+      error = yield node.actor.setParam(propName, value);
+    }
+    catch (e) {
+      error = e;
+    }
 
     // TODO figure out how to handle and display set param errors
     // and enable `test/brorwser_wa_params_view_edit_error.js`
     // Bug 994258
-    if (!errorMessage) {
+    if (!error) {
       ownerScope.get(propName).setGrip(value);
       window.emit(EVENTS.UI_SET_PARAM, node.id, propName, value);
     } else {
       window.emit(EVENTS.UI_SET_PARAM_ERROR, node.id, propName, value);
     }
   }),
 
   /**
--- a/toolkit/devtools/server/actors/webaudio.js
+++ b/toolkit/devtools/server/actors/webaudio.js
@@ -150,30 +150,25 @@ let AudioNodeActor = exports.AudioNodeAc
    */
   isSource: method(function () {
     return !!~this.type.indexOf("Source") || this.type === "OscillatorNode";
   }, {
     response: { source: RetVal("boolean") }
   }),
 
   /**
-   * Changes a param on the audio node. Responds with a `string` that's either
-   * an empty string `""` on success, or a description of the error upon
-   * param set failure.
+   * Changes a param on the audio node. Responds with either `undefined`
+   * on success, or a description of the error upon param set failure.
    *
    * @param String param
    *        Name of the AudioParam to change.
    * @param String value
    *        Value to change AudioParam to.
    */
   setParam: method(function (param, value) {
-    // Strip quotes because sometimes UIs include that for strings
-    if (typeof value === "string") {
-      value = value.replace(/[\'\"]*/g, "");
-    }
     try {
       if (isAudioParam(this.node, param))
         this.node[param].value = value;
       else
         this.node[param] = value;
       return undefined;
     } catch (e) {
       return constructError(e);