browser/devtools/debugger/test/browser_dbg_variables-view-edit-getset-01.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* Any copyright is dedicated to the Public Domain.
michael@0 2 http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 3
michael@0 4 /**
michael@0 5 * Make sure that the variables view knows how to edit getters and setters.
michael@0 6 */
michael@0 7
michael@0 8 const TAB_URL = EXAMPLE_URL + "doc_frame-parameters.html";
michael@0 9
michael@0 10 let gTab, gDebuggee, gPanel, gDebugger;
michael@0 11 let gL10N, gEditor, gVars, gWatch;
michael@0 12
michael@0 13 function test() {
michael@0 14 // Debug test slaves are a bit slow at this test.
michael@0 15 requestLongerTimeout(2);
michael@0 16
michael@0 17 initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => {
michael@0 18 gTab = aTab;
michael@0 19 gDebuggee = aDebuggee;
michael@0 20 gPanel = aPanel;
michael@0 21 gDebugger = gPanel.panelWin;
michael@0 22 gL10N = gDebugger.L10N;
michael@0 23 gEditor = gDebugger.DebuggerView.editor;
michael@0 24 gVars = gDebugger.DebuggerView.Variables;
michael@0 25 gWatch = gDebugger.DebuggerView.WatchExpressions;
michael@0 26
michael@0 27 gVars.switch = function() {};
michael@0 28 gVars.delete = function() {};
michael@0 29
michael@0 30 waitForSourceAndCaretAndScopes(gPanel, ".html", 24)
michael@0 31 .then(() => addWatchExpressions())
michael@0 32 .then(() => testEdit("set", "this._prop = value + ' BEER CAN'", {
michael@0 33 "myVar.prop": "xlerb BEER CAN",
michael@0 34 "myVar.prop + 42": "xlerb BEER CAN42",
michael@0 35 "myVar.prop = 'xlerb'": "xlerb"
michael@0 36 }))
michael@0 37 .then(() => testEdit("set", "{ this._prop = value + ' BEACON' }", {
michael@0 38 "myVar.prop": "xlerb BEACON",
michael@0 39 "myVar.prop + 42": "xlerb BEACON42",
michael@0 40 "myVar.prop = 'xlerb'": "xlerb"
michael@0 41 }))
michael@0 42 .then(() => testEdit("set", "{ this._prop = value + ' BEACON;'; }", {
michael@0 43 "myVar.prop": "xlerb BEACON;",
michael@0 44 "myVar.prop + 42": "xlerb BEACON;42",
michael@0 45 "myVar.prop = 'xlerb'": "xlerb"
michael@0 46 }))
michael@0 47 .then(() => testEdit("set", "{ return this._prop = value + ' BEACON;;'; }", {
michael@0 48 "myVar.prop": "xlerb BEACON;;",
michael@0 49 "myVar.prop + 42": "xlerb BEACON;;42",
michael@0 50 "myVar.prop = 'xlerb'": "xlerb"
michael@0 51 }))
michael@0 52 .then(() => testEdit("set", "function(value) { this._prop = value + ' BACON' }", {
michael@0 53 "myVar.prop": "xlerb BACON",
michael@0 54 "myVar.prop + 42": "xlerb BACON42",
michael@0 55 "myVar.prop = 'xlerb'": "xlerb"
michael@0 56 }))
michael@0 57 .then(() => testEdit("get", "'brelx BEER CAN'", {
michael@0 58 "myVar.prop": "brelx BEER CAN",
michael@0 59 "myVar.prop + 42": "brelx BEER CAN42",
michael@0 60 "myVar.prop = 'xlerb'": "xlerb"
michael@0 61 }))
michael@0 62 .then(() => testEdit("get", "{ 'brelx BEACON' }", {
michael@0 63 "myVar.prop": undefined,
michael@0 64 "myVar.prop + 42": NaN,
michael@0 65 "myVar.prop = 'xlerb'": "xlerb"
michael@0 66 }))
michael@0 67 .then(() => testEdit("get", "{ 'brelx BEACON;'; }", {
michael@0 68 "myVar.prop": undefined,
michael@0 69 "myVar.prop + 42": NaN,
michael@0 70 "myVar.prop = 'xlerb'": "xlerb"
michael@0 71 }))
michael@0 72 .then(() => testEdit("get", "{ return 'brelx BEACON;;'; }", {
michael@0 73 "myVar.prop": "brelx BEACON;;",
michael@0 74 "myVar.prop + 42": "brelx BEACON;;42",
michael@0 75 "myVar.prop = 'xlerb'": "xlerb"
michael@0 76 }))
michael@0 77 .then(() => testEdit("get", "function() { return 'brelx BACON'; }", {
michael@0 78 "myVar.prop": "brelx BACON",
michael@0 79 "myVar.prop + 42": "brelx BACON42",
michael@0 80 "myVar.prop = 'xlerb'": "xlerb"
michael@0 81 }))
michael@0 82 .then(() => testEdit("get", "bogus", {
michael@0 83 "myVar.prop": "ReferenceError: bogus is not defined",
michael@0 84 "myVar.prop + 42": "ReferenceError: bogus is not defined",
michael@0 85 "myVar.prop = 'xlerb'": "xlerb"
michael@0 86 }))
michael@0 87 .then(() => testEdit("set", "sugob", {
michael@0 88 "myVar.prop": "ReferenceError: bogus is not defined",
michael@0 89 "myVar.prop + 42": "ReferenceError: bogus is not defined",
michael@0 90 "myVar.prop = 'xlerb'": "ReferenceError: sugob is not defined"
michael@0 91 }))
michael@0 92 .then(() => testEdit("get", "", {
michael@0 93 "myVar.prop": undefined,
michael@0 94 "myVar.prop + 42": NaN,
michael@0 95 "myVar.prop = 'xlerb'": "ReferenceError: sugob is not defined"
michael@0 96 }))
michael@0 97 .then(() => testEdit("set", "", {
michael@0 98 "myVar.prop": "xlerb",
michael@0 99 "myVar.prop + 42": NaN,
michael@0 100 "myVar.prop = 'xlerb'": "xlerb"
michael@0 101 }))
michael@0 102 .then(() => deleteWatchExpression("myVar.prop = 'xlerb'"))
michael@0 103 .then(() => testEdit("self", "2507", {
michael@0 104 "myVar.prop": 2507,
michael@0 105 "myVar.prop + 42": 2549
michael@0 106 }))
michael@0 107 .then(() => deleteWatchExpression("myVar.prop + 42"))
michael@0 108 .then(() => testEdit("self", "0910", {
michael@0 109 "myVar.prop": 910
michael@0 110 }))
michael@0 111 .then(() => deleteLastWatchExpression("myVar.prop"))
michael@0 112 .then(() => testWatchExpressionsRemoved())
michael@0 113 .then(() => resumeDebuggerThenCloseAndFinish(gPanel))
michael@0 114 .then(null, aError => {
michael@0 115 ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
michael@0 116 });
michael@0 117
michael@0 118 EventUtils.sendMouseEvent({ type: "click" },
michael@0 119 gDebuggee.document.querySelector("button"),
michael@0 120 gDebuggee);
michael@0 121 });
michael@0 122 }
michael@0 123
michael@0 124 function addWatchExpressions() {
michael@0 125 return promise.resolve(null)
michael@0 126 .then(() => {
michael@0 127 let finished = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_WATCH_EXPRESSIONS);
michael@0 128 gWatch.addExpression("myVar.prop");
michael@0 129 gEditor.focus();
michael@0 130 return finished;
michael@0 131 })
michael@0 132 .then(() => {
michael@0 133 let exprScope = gVars.getScopeAtIndex(0);
michael@0 134 ok(exprScope,
michael@0 135 "There should be a wach expressions scope in the variables view.");
michael@0 136 is(exprScope.name, gL10N.getStr("watchExpressionsScopeLabel"),
michael@0 137 "The scope's name should be marked as 'Watch Expressions'.");
michael@0 138 is(exprScope._store.size, 1,
michael@0 139 "There should be 1 evaluation available.");
michael@0 140
michael@0 141 let w1 = exprScope.get("myVar.prop");
michael@0 142 let w2 = exprScope.get("myVar.prop + 42");
michael@0 143 let w3 = exprScope.get("myVar.prop = 'xlerb'");
michael@0 144
michael@0 145 ok(w1, "The first watch expression should be present in the scope.");
michael@0 146 ok(!w2, "The second watch expression should not be present in the scope.");
michael@0 147 ok(!w3, "The third watch expression should not be present in the scope.");
michael@0 148
michael@0 149 is(w1.value, 42, "The first value is correct.");
michael@0 150 })
michael@0 151 .then(() => {
michael@0 152 let finished = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_WATCH_EXPRESSIONS);
michael@0 153 gWatch.addExpression("myVar.prop + 42");
michael@0 154 gEditor.focus();
michael@0 155 return finished;
michael@0 156 })
michael@0 157 .then(() => {
michael@0 158 let exprScope = gVars.getScopeAtIndex(0);
michael@0 159 ok(exprScope,
michael@0 160 "There should be a wach expressions scope in the variables view.");
michael@0 161 is(exprScope.name, gL10N.getStr("watchExpressionsScopeLabel"),
michael@0 162 "The scope's name should be marked as 'Watch Expressions'.");
michael@0 163 is(exprScope._store.size, 2,
michael@0 164 "There should be 2 evaluations available.");
michael@0 165
michael@0 166 let w1 = exprScope.get("myVar.prop");
michael@0 167 let w2 = exprScope.get("myVar.prop + 42");
michael@0 168 let w3 = exprScope.get("myVar.prop = 'xlerb'");
michael@0 169
michael@0 170 ok(w1, "The first watch expression should be present in the scope.");
michael@0 171 ok(w2, "The second watch expression should be present in the scope.");
michael@0 172 ok(!w3, "The third watch expression should not be present in the scope.");
michael@0 173
michael@0 174 is(w1.value, "42", "The first expression value is correct.");
michael@0 175 is(w2.value, "84", "The second expression value is correct.");
michael@0 176 })
michael@0 177 .then(() => {
michael@0 178 let finished = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_WATCH_EXPRESSIONS);
michael@0 179 gWatch.addExpression("myVar.prop = 'xlerb'");
michael@0 180 gEditor.focus();
michael@0 181 return finished;
michael@0 182 })
michael@0 183 .then(() => {
michael@0 184 let exprScope = gVars.getScopeAtIndex(0);
michael@0 185 ok(exprScope,
michael@0 186 "There should be a wach expressions scope in the variables view.");
michael@0 187 is(exprScope.name, gL10N.getStr("watchExpressionsScopeLabel"),
michael@0 188 "The scope's name should be marked as 'Watch Expressions'.");
michael@0 189 is(exprScope._store.size, 3,
michael@0 190 "There should be 3 evaluations available.");
michael@0 191
michael@0 192 let w1 = exprScope.get("myVar.prop");
michael@0 193 let w2 = exprScope.get("myVar.prop + 42");
michael@0 194 let w3 = exprScope.get("myVar.prop = 'xlerb'");
michael@0 195
michael@0 196 ok(w1, "The first watch expression should be present in the scope.");
michael@0 197 ok(w2, "The second watch expression should be present in the scope.");
michael@0 198 ok(w3, "The third watch expression should be present in the scope.");
michael@0 199
michael@0 200 is(w1.value, "xlerb", "The first expression value is correct.");
michael@0 201 is(w2.value, "xlerb42", "The second expression value is correct.");
michael@0 202 is(w3.value, "xlerb", "The third expression value is correct.");
michael@0 203 });
michael@0 204 }
michael@0 205
michael@0 206 function deleteWatchExpression(aString) {
michael@0 207 let finished = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_WATCH_EXPRESSIONS);
michael@0 208 gWatch.deleteExpression({ name: aString });
michael@0 209 return finished;
michael@0 210 }
michael@0 211
michael@0 212 function deleteLastWatchExpression(aString) {
michael@0 213 let finished = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_SCOPES);
michael@0 214 gWatch.deleteExpression({ name: aString });
michael@0 215 return finished;
michael@0 216 }
michael@0 217
michael@0 218 function testEdit(aWhat, aString, aExpected) {
michael@0 219 let localScope = gVars.getScopeAtIndex(1);
michael@0 220 let myVar = localScope.get("myVar");
michael@0 221
michael@0 222 let finished = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_PROPERTIES).then(() => {
michael@0 223 let propVar = myVar.get("prop");
michael@0 224 let getterOrSetterOrVar = aWhat != "self" ? propVar.get(aWhat) : propVar;
michael@0 225
michael@0 226 let finished = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_WATCH_EXPRESSIONS).then(() => {
michael@0 227 let exprScope = gVars.getScopeAtIndex(0);
michael@0 228 ok(exprScope,
michael@0 229 "There should be a wach expressions scope in the variables view.");
michael@0 230 is(exprScope.name, gL10N.getStr("watchExpressionsScopeLabel"),
michael@0 231 "The scope's name should be marked as 'Watch Expressions'.");
michael@0 232 is(exprScope._store.size, Object.keys(aExpected).length,
michael@0 233 "There should be a certain number of evaluations available.");
michael@0 234
michael@0 235 function testExpression(aExpression) {
michael@0 236 if (!aExpression) {
michael@0 237 return;
michael@0 238 }
michael@0 239 let value = aExpected[aExpression.name];
michael@0 240 if (isNaN(value)) {
michael@0 241 ok(isNaN(aExpression.value),
michael@0 242 "The expression value is correct after the edit.");
michael@0 243 } else if (value == null) {
michael@0 244 is(aExpression.value.type, value + "",
michael@0 245 "The expression value is correct after the edit.");
michael@0 246 } else {
michael@0 247 is(aExpression.value, value,
michael@0 248 "The expression value is correct after the edit.");
michael@0 249 }
michael@0 250 }
michael@0 251
michael@0 252 testExpression(exprScope.get(Object.keys(aExpected)[0]));
michael@0 253 testExpression(exprScope.get(Object.keys(aExpected)[1]));
michael@0 254 testExpression(exprScope.get(Object.keys(aExpected)[2]));
michael@0 255 });
michael@0 256
michael@0 257 let editTarget = getterOrSetterOrVar.target;
michael@0 258
michael@0 259 // Allow the target variable to get painted, so that clicking on
michael@0 260 // its value would scroll the new textbox node into view.
michael@0 261 executeSoon(() => {
michael@0 262 let varValue = editTarget.querySelector(".title > .value");
michael@0 263 EventUtils.sendMouseEvent({ type: "mousedown" }, varValue, gDebugger);
michael@0 264
michael@0 265 let varInput = editTarget.querySelector(".title > .element-value-input");
michael@0 266 setText(varInput, aString);
michael@0 267 EventUtils.sendKey("RETURN", gDebugger);
michael@0 268 });
michael@0 269
michael@0 270 return finished;
michael@0 271 });
michael@0 272
michael@0 273 myVar.expand();
michael@0 274 gVars.clearHierarchy();
michael@0 275
michael@0 276 return finished;
michael@0 277 }
michael@0 278
michael@0 279 function testWatchExpressionsRemoved() {
michael@0 280 let scope = gVars.getScopeAtIndex(0);
michael@0 281 ok(scope,
michael@0 282 "There should be a local scope in the variables view.");
michael@0 283 isnot(scope.name, gL10N.getStr("watchExpressionsScopeLabel"),
michael@0 284 "The scope's name should not be marked as 'Watch Expressions'.");
michael@0 285 isnot(scope._store.size, 0,
michael@0 286 "There should be some variables available.");
michael@0 287 }
michael@0 288
michael@0 289 registerCleanupFunction(function() {
michael@0 290 gTab = null;
michael@0 291 gDebuggee = null;
michael@0 292 gPanel = null;
michael@0 293 gDebugger = null;
michael@0 294 gL10N = null;
michael@0 295 gEditor = null;
michael@0 296 gVars = null;
michael@0 297 gWatch = null;
michael@0 298 });

mercurial