Wed, 31 Dec 2014 06:09:35 +0100
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 | * Bug 727429: Test the debugger watch expressions. |
michael@0 | 6 | */ |
michael@0 | 7 | |
michael@0 | 8 | const TAB_URL = EXAMPLE_URL + "doc_watch-expressions.html"; |
michael@0 | 9 | |
michael@0 | 10 | function test() { |
michael@0 | 11 | // Debug test slaves are a bit slow at this test. |
michael@0 | 12 | requestLongerTimeout(2); |
michael@0 | 13 | |
michael@0 | 14 | let gTab, gDebuggee, gPanel, gDebugger; |
michael@0 | 15 | let gEditor, gWatch, gVariables; |
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 | gEditor = gDebugger.DebuggerView.editor; |
michael@0 | 23 | gWatch = gDebugger.DebuggerView.WatchExpressions; |
michael@0 | 24 | gVariables = gDebugger.DebuggerView.Variables; |
michael@0 | 25 | |
michael@0 | 26 | gDebugger.DebuggerView.toggleInstrumentsPane({ visible: true, animated: false }); |
michael@0 | 27 | |
michael@0 | 28 | waitForSourceShown(gPanel, ".html") |
michael@0 | 29 | .then(() => performTest()) |
michael@0 | 30 | .then(() => closeDebuggerAndFinish(gPanel)) |
michael@0 | 31 | .then(null, aError => { |
michael@0 | 32 | ok(false, "Got an error: " + aError.message + "\n" + aError.stack); |
michael@0 | 33 | }); |
michael@0 | 34 | }); |
michael@0 | 35 | |
michael@0 | 36 | function performTest() { |
michael@0 | 37 | is(gWatch.getAllStrings().length, 0, |
michael@0 | 38 | "There should initially be no watch expressions."); |
michael@0 | 39 | |
michael@0 | 40 | addAndCheckExpressions(1, 0, "a"); |
michael@0 | 41 | addAndCheckExpressions(2, 0, "b"); |
michael@0 | 42 | addAndCheckExpressions(3, 0, "c"); |
michael@0 | 43 | |
michael@0 | 44 | removeAndCheckExpression(2, 1, "a"); |
michael@0 | 45 | removeAndCheckExpression(1, 0, "a"); |
michael@0 | 46 | |
michael@0 | 47 | addAndCheckExpressions(2, 0, "", true); |
michael@0 | 48 | gEditor.focus(); |
michael@0 | 49 | is(gWatch.getAllStrings().length, 1, |
michael@0 | 50 | "Empty watch expressions are automatically removed."); |
michael@0 | 51 | |
michael@0 | 52 | addAndCheckExpressions(2, 0, "a", true); |
michael@0 | 53 | gEditor.focus(); |
michael@0 | 54 | is(gWatch.getAllStrings().length, 1, |
michael@0 | 55 | "Duplicate watch expressions are automatically removed."); |
michael@0 | 56 | |
michael@0 | 57 | addAndCheckExpressions(2, 0, "a\t", true); |
michael@0 | 58 | addAndCheckExpressions(2, 0, "a\r", true); |
michael@0 | 59 | addAndCheckExpressions(2, 0, "a\n", true); |
michael@0 | 60 | gEditor.focus(); |
michael@0 | 61 | is(gWatch.getAllStrings().length, 1, |
michael@0 | 62 | "Duplicate watch expressions are automatically removed."); |
michael@0 | 63 | |
michael@0 | 64 | addAndCheckExpressions(2, 0, "\ta", true); |
michael@0 | 65 | addAndCheckExpressions(2, 0, "\ra", true); |
michael@0 | 66 | addAndCheckExpressions(2, 0, "\na", true); |
michael@0 | 67 | gEditor.focus(); |
michael@0 | 68 | is(gWatch.getAllStrings().length, 1, |
michael@0 | 69 | "Duplicate watch expressions are automatically removed."); |
michael@0 | 70 | |
michael@0 | 71 | addAndCheckCustomExpression(2, 0, "bazΩΩka"); |
michael@0 | 72 | addAndCheckCustomExpression(3, 0, "bambøøcha"); |
michael@0 | 73 | |
michael@0 | 74 | EventUtils.sendMouseEvent({ type: "click" }, |
michael@0 | 75 | gWatch.getItemAtIndex(0).attachment.view.closeNode, |
michael@0 | 76 | gDebugger); |
michael@0 | 77 | |
michael@0 | 78 | is(gWatch.getAllStrings().length, 2, |
michael@0 | 79 | "Watch expressions are removed when the close button is pressed."); |
michael@0 | 80 | is(gWatch.getAllStrings()[0], "bazΩΩka", |
michael@0 | 81 | "The expression at index " + 0 + " should be correct (1)."); |
michael@0 | 82 | is(gWatch.getAllStrings()[1], "a", |
michael@0 | 83 | "The expression at index " + 1 + " should be correct (2)."); |
michael@0 | 84 | |
michael@0 | 85 | EventUtils.sendMouseEvent({ type: "click" }, |
michael@0 | 86 | gWatch.getItemAtIndex(0).attachment.view.closeNode, |
michael@0 | 87 | gDebugger); |
michael@0 | 88 | |
michael@0 | 89 | is(gWatch.getAllStrings().length, 1, |
michael@0 | 90 | "Watch expressions are removed when the close button is pressed."); |
michael@0 | 91 | is(gWatch.getAllStrings()[0], "a", |
michael@0 | 92 | "The expression at index " + 0 + " should be correct (3)."); |
michael@0 | 93 | |
michael@0 | 94 | EventUtils.sendMouseEvent({ type: "click" }, |
michael@0 | 95 | gWatch.getItemAtIndex(0).attachment.view.closeNode, |
michael@0 | 96 | gDebugger); |
michael@0 | 97 | |
michael@0 | 98 | is(gWatch.getAllStrings().length, 0, |
michael@0 | 99 | "Watch expressions are removed when the close button is pressed."); |
michael@0 | 100 | |
michael@0 | 101 | EventUtils.sendMouseEvent({ type: "click" }, |
michael@0 | 102 | gWatch.widget._parent, |
michael@0 | 103 | gDebugger); |
michael@0 | 104 | |
michael@0 | 105 | is(gWatch.getAllStrings().length, 1, |
michael@0 | 106 | "Watch expressions are added when the view container is pressed."); |
michael@0 | 107 | } |
michael@0 | 108 | |
michael@0 | 109 | function addAndCheckCustomExpression(aTotal, aIndex, aString, noBlur) { |
michael@0 | 110 | addAndCheckExpressions(aTotal, aIndex, "", true); |
michael@0 | 111 | |
michael@0 | 112 | for (let i = 0; i < aString.length; i++) { |
michael@0 | 113 | EventUtils.sendChar(aString[i], gDebugger); |
michael@0 | 114 | } |
michael@0 | 115 | |
michael@0 | 116 | gEditor.focus(); |
michael@0 | 117 | |
michael@0 | 118 | let element = gWatch.getItemAtIndex(aIndex).target; |
michael@0 | 119 | |
michael@0 | 120 | is(gWatch.getItemAtIndex(aIndex).attachment.initialExpression, "", |
michael@0 | 121 | "The initial expression at index " + aIndex + " should be correct (1)."); |
michael@0 | 122 | is(gWatch.getItemForElement(element).attachment.initialExpression, "", |
michael@0 | 123 | "The initial expression at index " + aIndex + " should be correct (2)."); |
michael@0 | 124 | |
michael@0 | 125 | is(gWatch.getItemAtIndex(aIndex).attachment.currentExpression, aString, |
michael@0 | 126 | "The expression at index " + aIndex + " should be correct (1)."); |
michael@0 | 127 | is(gWatch.getItemForElement(element).attachment.currentExpression, aString, |
michael@0 | 128 | "The expression at index " + aIndex + " should be correct (2)."); |
michael@0 | 129 | |
michael@0 | 130 | is(gWatch.getString(aIndex), aString, |
michael@0 | 131 | "The expression at index " + aIndex + " should be correct (3)."); |
michael@0 | 132 | is(gWatch.getAllStrings()[aIndex], aString, |
michael@0 | 133 | "The expression at index " + aIndex + " should be correct (4)."); |
michael@0 | 134 | } |
michael@0 | 135 | |
michael@0 | 136 | function addAndCheckExpressions(aTotal, aIndex, aString, noBlur) { |
michael@0 | 137 | gWatch.addExpression(aString); |
michael@0 | 138 | |
michael@0 | 139 | is(gWatch.getAllStrings().length, aTotal, |
michael@0 | 140 | "There should be " + aTotal + " watch expressions available (1)."); |
michael@0 | 141 | is(gWatch.itemCount, aTotal, |
michael@0 | 142 | "There should be " + aTotal + " watch expressions available (2)."); |
michael@0 | 143 | |
michael@0 | 144 | ok(gWatch.getItemAtIndex(aIndex), |
michael@0 | 145 | "The expression at index " + aIndex + " should be available."); |
michael@0 | 146 | is(gWatch.getItemAtIndex(aIndex).attachment.initialExpression, aString, |
michael@0 | 147 | "The expression at index " + aIndex + " should have an initial expression."); |
michael@0 | 148 | |
michael@0 | 149 | let element = gWatch.getItemAtIndex(aIndex).target; |
michael@0 | 150 | |
michael@0 | 151 | ok(element, |
michael@0 | 152 | "There should be a new expression item in the view."); |
michael@0 | 153 | ok(gWatch.getItemForElement(element), |
michael@0 | 154 | "The watch expression item should be accessible."); |
michael@0 | 155 | is(gWatch.getItemForElement(element), gWatch.getItemAtIndex(aIndex), |
michael@0 | 156 | "The correct watch expression item was accessed."); |
michael@0 | 157 | |
michael@0 | 158 | ok(gWatch.widget.getItemAtIndex(aIndex) instanceof XULElement, |
michael@0 | 159 | "The correct watch expression element was accessed (1)."); |
michael@0 | 160 | is(element, gWatch.widget.getItemAtIndex(aIndex), |
michael@0 | 161 | "The correct watch expression element was accessed (2)."); |
michael@0 | 162 | |
michael@0 | 163 | is(gWatch.getItemForElement(element).attachment.view.arrowNode.hidden, false, |
michael@0 | 164 | "The arrow node should be visible."); |
michael@0 | 165 | is(gWatch.getItemForElement(element).attachment.view.closeNode.hidden, false, |
michael@0 | 166 | "The close button should be visible."); |
michael@0 | 167 | is(gWatch.getItemForElement(element).attachment.view.inputNode.getAttribute("focused"), "true", |
michael@0 | 168 | "The textbox input should be focused."); |
michael@0 | 169 | |
michael@0 | 170 | is(gVariables.parentNode.scrollTop, 0, |
michael@0 | 171 | "The variables view should be scrolled to top"); |
michael@0 | 172 | |
michael@0 | 173 | is(gWatch.items[0], gWatch.getItemAtIndex(aIndex), |
michael@0 | 174 | "The correct watch expression was added to the cache (1)."); |
michael@0 | 175 | is(gWatch.items[0], gWatch.getItemForElement(element), |
michael@0 | 176 | "The correct watch expression was added to the cache (2)."); |
michael@0 | 177 | |
michael@0 | 178 | if (!noBlur) { |
michael@0 | 179 | gEditor.focus(); |
michael@0 | 180 | |
michael@0 | 181 | is(gWatch.getItemAtIndex(aIndex).attachment.initialExpression, aString, |
michael@0 | 182 | "The initial expression at index " + aIndex + " should be correct (1)."); |
michael@0 | 183 | is(gWatch.getItemForElement(element).attachment.initialExpression, aString, |
michael@0 | 184 | "The initial expression at index " + aIndex + " should be correct (2)."); |
michael@0 | 185 | |
michael@0 | 186 | is(gWatch.getItemAtIndex(aIndex).attachment.currentExpression, aString, |
michael@0 | 187 | "The expression at index " + aIndex + " should be correct (1)."); |
michael@0 | 188 | is(gWatch.getItemForElement(element).attachment.currentExpression, aString, |
michael@0 | 189 | "The expression at index " + aIndex + " should be correct (2)."); |
michael@0 | 190 | |
michael@0 | 191 | is(gWatch.getString(aIndex), aString, |
michael@0 | 192 | "The expression at index " + aIndex + " should be correct (3)."); |
michael@0 | 193 | is(gWatch.getAllStrings()[aIndex], aString, |
michael@0 | 194 | "The expression at index " + aIndex + " should be correct (4)."); |
michael@0 | 195 | } |
michael@0 | 196 | } |
michael@0 | 197 | |
michael@0 | 198 | function removeAndCheckExpression(aTotal, aIndex, aString) { |
michael@0 | 199 | gWatch.removeAt(aIndex); |
michael@0 | 200 | |
michael@0 | 201 | is(gWatch.getAllStrings().length, aTotal, |
michael@0 | 202 | "There should be " + aTotal + " watch expressions available (1)."); |
michael@0 | 203 | is(gWatch.itemCount, aTotal, |
michael@0 | 204 | "There should be " + aTotal + " watch expressions available (2)."); |
michael@0 | 205 | |
michael@0 | 206 | ok(gWatch.getItemAtIndex(aIndex), |
michael@0 | 207 | "The expression at index " + aIndex + " should still be available."); |
michael@0 | 208 | is(gWatch.getItemAtIndex(aIndex).attachment.initialExpression, aString, |
michael@0 | 209 | "The expression at index " + aIndex + " should still have an initial expression."); |
michael@0 | 210 | |
michael@0 | 211 | let element = gWatch.getItemAtIndex(aIndex).target; |
michael@0 | 212 | |
michael@0 | 213 | is(gWatch.getItemAtIndex(aIndex).attachment.initialExpression, aString, |
michael@0 | 214 | "The initial expression at index " + aIndex + " should be correct (1)."); |
michael@0 | 215 | is(gWatch.getItemForElement(element).attachment.initialExpression, aString, |
michael@0 | 216 | "The initial expression at index " + aIndex + " should be correct (2)."); |
michael@0 | 217 | |
michael@0 | 218 | is(gWatch.getItemAtIndex(aIndex).attachment.currentExpression, aString, |
michael@0 | 219 | "The expression at index " + aIndex + " should be correct (1)."); |
michael@0 | 220 | is(gWatch.getItemForElement(element).attachment.currentExpression, aString, |
michael@0 | 221 | "The expression at index " + aIndex + " should be correct (2)."); |
michael@0 | 222 | |
michael@0 | 223 | is(gWatch.getString(aIndex), aString, |
michael@0 | 224 | "The expression at index " + aIndex + " should be correct (3)."); |
michael@0 | 225 | is(gWatch.getAllStrings()[aIndex], aString, |
michael@0 | 226 | "The expression at index " + aIndex + " should be correct (4)."); |
michael@0 | 227 | } |
michael@0 | 228 | } |