1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/debugger/test/browser_dbg_watch-expressions-01.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,228 @@ 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 + * Bug 727429: Test the debugger watch expressions. 1.9 + */ 1.10 + 1.11 +const TAB_URL = EXAMPLE_URL + "doc_watch-expressions.html"; 1.12 + 1.13 +function test() { 1.14 + // Debug test slaves are a bit slow at this test. 1.15 + requestLongerTimeout(2); 1.16 + 1.17 + let gTab, gDebuggee, gPanel, gDebugger; 1.18 + let gEditor, gWatch, gVariables; 1.19 + 1.20 + initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => { 1.21 + gTab = aTab; 1.22 + gDebuggee = aDebuggee; 1.23 + gPanel = aPanel; 1.24 + gDebugger = gPanel.panelWin; 1.25 + gEditor = gDebugger.DebuggerView.editor; 1.26 + gWatch = gDebugger.DebuggerView.WatchExpressions; 1.27 + gVariables = gDebugger.DebuggerView.Variables; 1.28 + 1.29 + gDebugger.DebuggerView.toggleInstrumentsPane({ visible: true, animated: false }); 1.30 + 1.31 + waitForSourceShown(gPanel, ".html") 1.32 + .then(() => performTest()) 1.33 + .then(() => closeDebuggerAndFinish(gPanel)) 1.34 + .then(null, aError => { 1.35 + ok(false, "Got an error: " + aError.message + "\n" + aError.stack); 1.36 + }); 1.37 + }); 1.38 + 1.39 + function performTest() { 1.40 + is(gWatch.getAllStrings().length, 0, 1.41 + "There should initially be no watch expressions."); 1.42 + 1.43 + addAndCheckExpressions(1, 0, "a"); 1.44 + addAndCheckExpressions(2, 0, "b"); 1.45 + addAndCheckExpressions(3, 0, "c"); 1.46 + 1.47 + removeAndCheckExpression(2, 1, "a"); 1.48 + removeAndCheckExpression(1, 0, "a"); 1.49 + 1.50 + addAndCheckExpressions(2, 0, "", true); 1.51 + gEditor.focus(); 1.52 + is(gWatch.getAllStrings().length, 1, 1.53 + "Empty watch expressions are automatically removed."); 1.54 + 1.55 + addAndCheckExpressions(2, 0, "a", true); 1.56 + gEditor.focus(); 1.57 + is(gWatch.getAllStrings().length, 1, 1.58 + "Duplicate watch expressions are automatically removed."); 1.59 + 1.60 + addAndCheckExpressions(2, 0, "a\t", true); 1.61 + addAndCheckExpressions(2, 0, "a\r", true); 1.62 + addAndCheckExpressions(2, 0, "a\n", true); 1.63 + gEditor.focus(); 1.64 + is(gWatch.getAllStrings().length, 1, 1.65 + "Duplicate watch expressions are automatically removed."); 1.66 + 1.67 + addAndCheckExpressions(2, 0, "\ta", true); 1.68 + addAndCheckExpressions(2, 0, "\ra", true); 1.69 + addAndCheckExpressions(2, 0, "\na", true); 1.70 + gEditor.focus(); 1.71 + is(gWatch.getAllStrings().length, 1, 1.72 + "Duplicate watch expressions are automatically removed."); 1.73 + 1.74 + addAndCheckCustomExpression(2, 0, "bazΩΩka"); 1.75 + addAndCheckCustomExpression(3, 0, "bambøøcha"); 1.76 + 1.77 + EventUtils.sendMouseEvent({ type: "click" }, 1.78 + gWatch.getItemAtIndex(0).attachment.view.closeNode, 1.79 + gDebugger); 1.80 + 1.81 + is(gWatch.getAllStrings().length, 2, 1.82 + "Watch expressions are removed when the close button is pressed."); 1.83 + is(gWatch.getAllStrings()[0], "bazΩΩka", 1.84 + "The expression at index " + 0 + " should be correct (1)."); 1.85 + is(gWatch.getAllStrings()[1], "a", 1.86 + "The expression at index " + 1 + " should be correct (2)."); 1.87 + 1.88 + EventUtils.sendMouseEvent({ type: "click" }, 1.89 + gWatch.getItemAtIndex(0).attachment.view.closeNode, 1.90 + gDebugger); 1.91 + 1.92 + is(gWatch.getAllStrings().length, 1, 1.93 + "Watch expressions are removed when the close button is pressed."); 1.94 + is(gWatch.getAllStrings()[0], "a", 1.95 + "The expression at index " + 0 + " should be correct (3)."); 1.96 + 1.97 + EventUtils.sendMouseEvent({ type: "click" }, 1.98 + gWatch.getItemAtIndex(0).attachment.view.closeNode, 1.99 + gDebugger); 1.100 + 1.101 + is(gWatch.getAllStrings().length, 0, 1.102 + "Watch expressions are removed when the close button is pressed."); 1.103 + 1.104 + EventUtils.sendMouseEvent({ type: "click" }, 1.105 + gWatch.widget._parent, 1.106 + gDebugger); 1.107 + 1.108 + is(gWatch.getAllStrings().length, 1, 1.109 + "Watch expressions are added when the view container is pressed."); 1.110 + } 1.111 + 1.112 + function addAndCheckCustomExpression(aTotal, aIndex, aString, noBlur) { 1.113 + addAndCheckExpressions(aTotal, aIndex, "", true); 1.114 + 1.115 + for (let i = 0; i < aString.length; i++) { 1.116 + EventUtils.sendChar(aString[i], gDebugger); 1.117 + } 1.118 + 1.119 + gEditor.focus(); 1.120 + 1.121 + let element = gWatch.getItemAtIndex(aIndex).target; 1.122 + 1.123 + is(gWatch.getItemAtIndex(aIndex).attachment.initialExpression, "", 1.124 + "The initial expression at index " + aIndex + " should be correct (1)."); 1.125 + is(gWatch.getItemForElement(element).attachment.initialExpression, "", 1.126 + "The initial expression at index " + aIndex + " should be correct (2)."); 1.127 + 1.128 + is(gWatch.getItemAtIndex(aIndex).attachment.currentExpression, aString, 1.129 + "The expression at index " + aIndex + " should be correct (1)."); 1.130 + is(gWatch.getItemForElement(element).attachment.currentExpression, aString, 1.131 + "The expression at index " + aIndex + " should be correct (2)."); 1.132 + 1.133 + is(gWatch.getString(aIndex), aString, 1.134 + "The expression at index " + aIndex + " should be correct (3)."); 1.135 + is(gWatch.getAllStrings()[aIndex], aString, 1.136 + "The expression at index " + aIndex + " should be correct (4)."); 1.137 + } 1.138 + 1.139 + function addAndCheckExpressions(aTotal, aIndex, aString, noBlur) { 1.140 + gWatch.addExpression(aString); 1.141 + 1.142 + is(gWatch.getAllStrings().length, aTotal, 1.143 + "There should be " + aTotal + " watch expressions available (1)."); 1.144 + is(gWatch.itemCount, aTotal, 1.145 + "There should be " + aTotal + " watch expressions available (2)."); 1.146 + 1.147 + ok(gWatch.getItemAtIndex(aIndex), 1.148 + "The expression at index " + aIndex + " should be available."); 1.149 + is(gWatch.getItemAtIndex(aIndex).attachment.initialExpression, aString, 1.150 + "The expression at index " + aIndex + " should have an initial expression."); 1.151 + 1.152 + let element = gWatch.getItemAtIndex(aIndex).target; 1.153 + 1.154 + ok(element, 1.155 + "There should be a new expression item in the view."); 1.156 + ok(gWatch.getItemForElement(element), 1.157 + "The watch expression item should be accessible."); 1.158 + is(gWatch.getItemForElement(element), gWatch.getItemAtIndex(aIndex), 1.159 + "The correct watch expression item was accessed."); 1.160 + 1.161 + ok(gWatch.widget.getItemAtIndex(aIndex) instanceof XULElement, 1.162 + "The correct watch expression element was accessed (1)."); 1.163 + is(element, gWatch.widget.getItemAtIndex(aIndex), 1.164 + "The correct watch expression element was accessed (2)."); 1.165 + 1.166 + is(gWatch.getItemForElement(element).attachment.view.arrowNode.hidden, false, 1.167 + "The arrow node should be visible."); 1.168 + is(gWatch.getItemForElement(element).attachment.view.closeNode.hidden, false, 1.169 + "The close button should be visible."); 1.170 + is(gWatch.getItemForElement(element).attachment.view.inputNode.getAttribute("focused"), "true", 1.171 + "The textbox input should be focused."); 1.172 + 1.173 + is(gVariables.parentNode.scrollTop, 0, 1.174 + "The variables view should be scrolled to top"); 1.175 + 1.176 + is(gWatch.items[0], gWatch.getItemAtIndex(aIndex), 1.177 + "The correct watch expression was added to the cache (1)."); 1.178 + is(gWatch.items[0], gWatch.getItemForElement(element), 1.179 + "The correct watch expression was added to the cache (2)."); 1.180 + 1.181 + if (!noBlur) { 1.182 + gEditor.focus(); 1.183 + 1.184 + is(gWatch.getItemAtIndex(aIndex).attachment.initialExpression, aString, 1.185 + "The initial expression at index " + aIndex + " should be correct (1)."); 1.186 + is(gWatch.getItemForElement(element).attachment.initialExpression, aString, 1.187 + "The initial expression at index " + aIndex + " should be correct (2)."); 1.188 + 1.189 + is(gWatch.getItemAtIndex(aIndex).attachment.currentExpression, aString, 1.190 + "The expression at index " + aIndex + " should be correct (1)."); 1.191 + is(gWatch.getItemForElement(element).attachment.currentExpression, aString, 1.192 + "The expression at index " + aIndex + " should be correct (2)."); 1.193 + 1.194 + is(gWatch.getString(aIndex), aString, 1.195 + "The expression at index " + aIndex + " should be correct (3)."); 1.196 + is(gWatch.getAllStrings()[aIndex], aString, 1.197 + "The expression at index " + aIndex + " should be correct (4)."); 1.198 + } 1.199 + } 1.200 + 1.201 + function removeAndCheckExpression(aTotal, aIndex, aString) { 1.202 + gWatch.removeAt(aIndex); 1.203 + 1.204 + is(gWatch.getAllStrings().length, aTotal, 1.205 + "There should be " + aTotal + " watch expressions available (1)."); 1.206 + is(gWatch.itemCount, aTotal, 1.207 + "There should be " + aTotal + " watch expressions available (2)."); 1.208 + 1.209 + ok(gWatch.getItemAtIndex(aIndex), 1.210 + "The expression at index " + aIndex + " should still be available."); 1.211 + is(gWatch.getItemAtIndex(aIndex).attachment.initialExpression, aString, 1.212 + "The expression at index " + aIndex + " should still have an initial expression."); 1.213 + 1.214 + let element = gWatch.getItemAtIndex(aIndex).target; 1.215 + 1.216 + is(gWatch.getItemAtIndex(aIndex).attachment.initialExpression, aString, 1.217 + "The initial expression at index " + aIndex + " should be correct (1)."); 1.218 + is(gWatch.getItemForElement(element).attachment.initialExpression, aString, 1.219 + "The initial expression at index " + aIndex + " should be correct (2)."); 1.220 + 1.221 + is(gWatch.getItemAtIndex(aIndex).attachment.currentExpression, aString, 1.222 + "The expression at index " + aIndex + " should be correct (1)."); 1.223 + is(gWatch.getItemForElement(element).attachment.currentExpression, aString, 1.224 + "The expression at index " + aIndex + " should be correct (2)."); 1.225 + 1.226 + is(gWatch.getString(aIndex), aString, 1.227 + "The expression at index " + aIndex + " should be correct (3)."); 1.228 + is(gWatch.getAllStrings()[aIndex], aString, 1.229 + "The expression at index " + aIndex + " should be correct (4)."); 1.230 + } 1.231 +}