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: * Make sure that the variables view knows how to edit getters and setters. michael@0: */ michael@0: michael@0: const TAB_URL = EXAMPLE_URL + "doc_frame-parameters.html"; michael@0: michael@0: let gTab, gDebuggee, gPanel, gDebugger; michael@0: let gL10N, gEditor, gVars, gWatch; michael@0: michael@0: function test() { michael@0: // Debug test slaves are a bit slow at this test. michael@0: requestLongerTimeout(2); michael@0: michael@0: initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => { michael@0: gTab = aTab; michael@0: gDebuggee = aDebuggee; michael@0: gPanel = aPanel; michael@0: gDebugger = gPanel.panelWin; michael@0: gL10N = gDebugger.L10N; michael@0: gEditor = gDebugger.DebuggerView.editor; michael@0: gVars = gDebugger.DebuggerView.Variables; michael@0: gWatch = gDebugger.DebuggerView.WatchExpressions; michael@0: michael@0: gVars.switch = function() {}; michael@0: gVars.delete = function() {}; michael@0: michael@0: waitForSourceAndCaretAndScopes(gPanel, ".html", 24) michael@0: .then(() => addWatchExpressions()) michael@0: .then(() => testEdit("set", "this._prop = value + ' BEER CAN'", { michael@0: "myVar.prop": "xlerb BEER CAN", michael@0: "myVar.prop + 42": "xlerb BEER CAN42", michael@0: "myVar.prop = 'xlerb'": "xlerb" michael@0: })) michael@0: .then(() => testEdit("set", "{ this._prop = value + ' BEACON' }", { michael@0: "myVar.prop": "xlerb BEACON", michael@0: "myVar.prop + 42": "xlerb BEACON42", michael@0: "myVar.prop = 'xlerb'": "xlerb" michael@0: })) michael@0: .then(() => testEdit("set", "{ this._prop = value + ' BEACON;'; }", { michael@0: "myVar.prop": "xlerb BEACON;", michael@0: "myVar.prop + 42": "xlerb BEACON;42", michael@0: "myVar.prop = 'xlerb'": "xlerb" michael@0: })) michael@0: .then(() => testEdit("set", "{ return this._prop = value + ' BEACON;;'; }", { michael@0: "myVar.prop": "xlerb BEACON;;", michael@0: "myVar.prop + 42": "xlerb BEACON;;42", michael@0: "myVar.prop = 'xlerb'": "xlerb" michael@0: })) michael@0: .then(() => testEdit("set", "function(value) { this._prop = value + ' BACON' }", { michael@0: "myVar.prop": "xlerb BACON", michael@0: "myVar.prop + 42": "xlerb BACON42", michael@0: "myVar.prop = 'xlerb'": "xlerb" michael@0: })) michael@0: .then(() => testEdit("get", "'brelx BEER CAN'", { michael@0: "myVar.prop": "brelx BEER CAN", michael@0: "myVar.prop + 42": "brelx BEER CAN42", michael@0: "myVar.prop = 'xlerb'": "xlerb" michael@0: })) michael@0: .then(() => testEdit("get", "{ 'brelx BEACON' }", { michael@0: "myVar.prop": undefined, michael@0: "myVar.prop + 42": NaN, michael@0: "myVar.prop = 'xlerb'": "xlerb" michael@0: })) michael@0: .then(() => testEdit("get", "{ 'brelx BEACON;'; }", { michael@0: "myVar.prop": undefined, michael@0: "myVar.prop + 42": NaN, michael@0: "myVar.prop = 'xlerb'": "xlerb" michael@0: })) michael@0: .then(() => testEdit("get", "{ return 'brelx BEACON;;'; }", { michael@0: "myVar.prop": "brelx BEACON;;", michael@0: "myVar.prop + 42": "brelx BEACON;;42", michael@0: "myVar.prop = 'xlerb'": "xlerb" michael@0: })) michael@0: .then(() => testEdit("get", "function() { return 'brelx BACON'; }", { michael@0: "myVar.prop": "brelx BACON", michael@0: "myVar.prop + 42": "brelx BACON42", michael@0: "myVar.prop = 'xlerb'": "xlerb" michael@0: })) michael@0: .then(() => testEdit("get", "bogus", { michael@0: "myVar.prop": "ReferenceError: bogus is not defined", michael@0: "myVar.prop + 42": "ReferenceError: bogus is not defined", michael@0: "myVar.prop = 'xlerb'": "xlerb" michael@0: })) michael@0: .then(() => testEdit("set", "sugob", { michael@0: "myVar.prop": "ReferenceError: bogus is not defined", michael@0: "myVar.prop + 42": "ReferenceError: bogus is not defined", michael@0: "myVar.prop = 'xlerb'": "ReferenceError: sugob is not defined" michael@0: })) michael@0: .then(() => testEdit("get", "", { michael@0: "myVar.prop": undefined, michael@0: "myVar.prop + 42": NaN, michael@0: "myVar.prop = 'xlerb'": "ReferenceError: sugob is not defined" michael@0: })) michael@0: .then(() => testEdit("set", "", { michael@0: "myVar.prop": "xlerb", michael@0: "myVar.prop + 42": NaN, michael@0: "myVar.prop = 'xlerb'": "xlerb" michael@0: })) michael@0: .then(() => deleteWatchExpression("myVar.prop = 'xlerb'")) michael@0: .then(() => testEdit("self", "2507", { michael@0: "myVar.prop": 2507, michael@0: "myVar.prop + 42": 2549 michael@0: })) michael@0: .then(() => deleteWatchExpression("myVar.prop + 42")) michael@0: .then(() => testEdit("self", "0910", { michael@0: "myVar.prop": 910 michael@0: })) michael@0: .then(() => deleteLastWatchExpression("myVar.prop")) michael@0: .then(() => testWatchExpressionsRemoved()) michael@0: .then(() => resumeDebuggerThenCloseAndFinish(gPanel)) michael@0: .then(null, aError => { michael@0: ok(false, "Got an error: " + aError.message + "\n" + aError.stack); michael@0: }); michael@0: michael@0: EventUtils.sendMouseEvent({ type: "click" }, michael@0: gDebuggee.document.querySelector("button"), michael@0: gDebuggee); michael@0: }); michael@0: } michael@0: michael@0: function addWatchExpressions() { michael@0: return promise.resolve(null) michael@0: .then(() => { michael@0: let finished = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_WATCH_EXPRESSIONS); michael@0: gWatch.addExpression("myVar.prop"); michael@0: gEditor.focus(); michael@0: return finished; michael@0: }) michael@0: .then(() => { michael@0: let exprScope = gVars.getScopeAtIndex(0); michael@0: ok(exprScope, michael@0: "There should be a wach expressions scope in the variables view."); michael@0: is(exprScope.name, gL10N.getStr("watchExpressionsScopeLabel"), michael@0: "The scope's name should be marked as 'Watch Expressions'."); michael@0: is(exprScope._store.size, 1, michael@0: "There should be 1 evaluation available."); michael@0: michael@0: let w1 = exprScope.get("myVar.prop"); michael@0: let w2 = exprScope.get("myVar.prop + 42"); michael@0: let w3 = exprScope.get("myVar.prop = 'xlerb'"); michael@0: michael@0: ok(w1, "The first watch expression should be present in the scope."); michael@0: ok(!w2, "The second watch expression should not be present in the scope."); michael@0: ok(!w3, "The third watch expression should not be present in the scope."); michael@0: michael@0: is(w1.value, 42, "The first value is correct."); michael@0: }) michael@0: .then(() => { michael@0: let finished = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_WATCH_EXPRESSIONS); michael@0: gWatch.addExpression("myVar.prop + 42"); michael@0: gEditor.focus(); michael@0: return finished; michael@0: }) michael@0: .then(() => { michael@0: let exprScope = gVars.getScopeAtIndex(0); michael@0: ok(exprScope, michael@0: "There should be a wach expressions scope in the variables view."); michael@0: is(exprScope.name, gL10N.getStr("watchExpressionsScopeLabel"), michael@0: "The scope's name should be marked as 'Watch Expressions'."); michael@0: is(exprScope._store.size, 2, michael@0: "There should be 2 evaluations available."); michael@0: michael@0: let w1 = exprScope.get("myVar.prop"); michael@0: let w2 = exprScope.get("myVar.prop + 42"); michael@0: let w3 = exprScope.get("myVar.prop = 'xlerb'"); michael@0: michael@0: ok(w1, "The first watch expression should be present in the scope."); michael@0: ok(w2, "The second watch expression should be present in the scope."); michael@0: ok(!w3, "The third watch expression should not be present in the scope."); michael@0: michael@0: is(w1.value, "42", "The first expression value is correct."); michael@0: is(w2.value, "84", "The second expression value is correct."); michael@0: }) michael@0: .then(() => { michael@0: let finished = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_WATCH_EXPRESSIONS); michael@0: gWatch.addExpression("myVar.prop = 'xlerb'"); michael@0: gEditor.focus(); michael@0: return finished; michael@0: }) michael@0: .then(() => { michael@0: let exprScope = gVars.getScopeAtIndex(0); michael@0: ok(exprScope, michael@0: "There should be a wach expressions scope in the variables view."); michael@0: is(exprScope.name, gL10N.getStr("watchExpressionsScopeLabel"), michael@0: "The scope's name should be marked as 'Watch Expressions'."); michael@0: is(exprScope._store.size, 3, michael@0: "There should be 3 evaluations available."); michael@0: michael@0: let w1 = exprScope.get("myVar.prop"); michael@0: let w2 = exprScope.get("myVar.prop + 42"); michael@0: let w3 = exprScope.get("myVar.prop = 'xlerb'"); michael@0: michael@0: ok(w1, "The first watch expression should be present in the scope."); michael@0: ok(w2, "The second watch expression should be present in the scope."); michael@0: ok(w3, "The third watch expression should be present in the scope."); michael@0: michael@0: is(w1.value, "xlerb", "The first expression value is correct."); michael@0: is(w2.value, "xlerb42", "The second expression value is correct."); michael@0: is(w3.value, "xlerb", "The third expression value is correct."); michael@0: }); michael@0: } michael@0: michael@0: function deleteWatchExpression(aString) { michael@0: let finished = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_WATCH_EXPRESSIONS); michael@0: gWatch.deleteExpression({ name: aString }); michael@0: return finished; michael@0: } michael@0: michael@0: function deleteLastWatchExpression(aString) { michael@0: let finished = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_SCOPES); michael@0: gWatch.deleteExpression({ name: aString }); michael@0: return finished; michael@0: } michael@0: michael@0: function testEdit(aWhat, aString, aExpected) { michael@0: let localScope = gVars.getScopeAtIndex(1); michael@0: let myVar = localScope.get("myVar"); michael@0: michael@0: let finished = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_PROPERTIES).then(() => { michael@0: let propVar = myVar.get("prop"); michael@0: let getterOrSetterOrVar = aWhat != "self" ? propVar.get(aWhat) : propVar; michael@0: michael@0: let finished = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_WATCH_EXPRESSIONS).then(() => { michael@0: let exprScope = gVars.getScopeAtIndex(0); michael@0: ok(exprScope, michael@0: "There should be a wach expressions scope in the variables view."); michael@0: is(exprScope.name, gL10N.getStr("watchExpressionsScopeLabel"), michael@0: "The scope's name should be marked as 'Watch Expressions'."); michael@0: is(exprScope._store.size, Object.keys(aExpected).length, michael@0: "There should be a certain number of evaluations available."); michael@0: michael@0: function testExpression(aExpression) { michael@0: if (!aExpression) { michael@0: return; michael@0: } michael@0: let value = aExpected[aExpression.name]; michael@0: if (isNaN(value)) { michael@0: ok(isNaN(aExpression.value), michael@0: "The expression value is correct after the edit."); michael@0: } else if (value == null) { michael@0: is(aExpression.value.type, value + "", michael@0: "The expression value is correct after the edit."); michael@0: } else { michael@0: is(aExpression.value, value, michael@0: "The expression value is correct after the edit."); michael@0: } michael@0: } michael@0: michael@0: testExpression(exprScope.get(Object.keys(aExpected)[0])); michael@0: testExpression(exprScope.get(Object.keys(aExpected)[1])); michael@0: testExpression(exprScope.get(Object.keys(aExpected)[2])); michael@0: }); michael@0: michael@0: let editTarget = getterOrSetterOrVar.target; michael@0: michael@0: // Allow the target variable to get painted, so that clicking on michael@0: // its value would scroll the new textbox node into view. michael@0: executeSoon(() => { michael@0: let varValue = editTarget.querySelector(".title > .value"); michael@0: EventUtils.sendMouseEvent({ type: "mousedown" }, varValue, gDebugger); michael@0: michael@0: let varInput = editTarget.querySelector(".title > .element-value-input"); michael@0: setText(varInput, aString); michael@0: EventUtils.sendKey("RETURN", gDebugger); michael@0: }); michael@0: michael@0: return finished; michael@0: }); michael@0: michael@0: myVar.expand(); michael@0: gVars.clearHierarchy(); michael@0: michael@0: return finished; michael@0: } michael@0: michael@0: function testWatchExpressionsRemoved() { michael@0: let scope = gVars.getScopeAtIndex(0); michael@0: ok(scope, michael@0: "There should be a local scope in the variables view."); michael@0: isnot(scope.name, gL10N.getStr("watchExpressionsScopeLabel"), michael@0: "The scope's name should not be marked as 'Watch Expressions'."); michael@0: isnot(scope._store.size, 0, michael@0: "There should be some variables available."); michael@0: } michael@0: michael@0: registerCleanupFunction(function() { michael@0: gTab = null; michael@0: gDebuggee = null; michael@0: gPanel = null; michael@0: gDebugger = null; michael@0: gL10N = null; michael@0: gEditor = null; michael@0: gVars = null; michael@0: gWatch = null; michael@0: });