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: * Bug 727429: Test the debugger watch expressions. michael@0: */ michael@0: michael@0: const TAB_URL = EXAMPLE_URL + "doc_watch-expressions.html"; 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: let gTab, gDebuggee, gPanel, gDebugger; michael@0: let gEditor, gWatch, gVariables; 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: gEditor = gDebugger.DebuggerView.editor; michael@0: gWatch = gDebugger.DebuggerView.WatchExpressions; michael@0: gVariables = gDebugger.DebuggerView.Variables; michael@0: michael@0: gDebugger.DebuggerView.toggleInstrumentsPane({ visible: true, animated: false }); michael@0: michael@0: waitForSourceShown(gPanel, ".html") michael@0: .then(() => performTest()) michael@0: .then(() => closeDebuggerAndFinish(gPanel)) michael@0: .then(null, aError => { michael@0: ok(false, "Got an error: " + aError.message + "\n" + aError.stack); michael@0: }); michael@0: }); michael@0: michael@0: function performTest() { michael@0: is(gWatch.getAllStrings().length, 0, michael@0: "There should initially be no watch expressions."); michael@0: michael@0: addAndCheckExpressions(1, 0, "a"); michael@0: addAndCheckExpressions(2, 0, "b"); michael@0: addAndCheckExpressions(3, 0, "c"); michael@0: michael@0: removeAndCheckExpression(2, 1, "a"); michael@0: removeAndCheckExpression(1, 0, "a"); michael@0: michael@0: addAndCheckExpressions(2, 0, "", true); michael@0: gEditor.focus(); michael@0: is(gWatch.getAllStrings().length, 1, michael@0: "Empty watch expressions are automatically removed."); michael@0: michael@0: addAndCheckExpressions(2, 0, "a", true); michael@0: gEditor.focus(); michael@0: is(gWatch.getAllStrings().length, 1, michael@0: "Duplicate watch expressions are automatically removed."); michael@0: michael@0: addAndCheckExpressions(2, 0, "a\t", true); michael@0: addAndCheckExpressions(2, 0, "a\r", true); michael@0: addAndCheckExpressions(2, 0, "a\n", true); michael@0: gEditor.focus(); michael@0: is(gWatch.getAllStrings().length, 1, michael@0: "Duplicate watch expressions are automatically removed."); michael@0: michael@0: addAndCheckExpressions(2, 0, "\ta", true); michael@0: addAndCheckExpressions(2, 0, "\ra", true); michael@0: addAndCheckExpressions(2, 0, "\na", true); michael@0: gEditor.focus(); michael@0: is(gWatch.getAllStrings().length, 1, michael@0: "Duplicate watch expressions are automatically removed."); michael@0: michael@0: addAndCheckCustomExpression(2, 0, "bazΩΩka"); michael@0: addAndCheckCustomExpression(3, 0, "bambøøcha"); michael@0: michael@0: EventUtils.sendMouseEvent({ type: "click" }, michael@0: gWatch.getItemAtIndex(0).attachment.view.closeNode, michael@0: gDebugger); michael@0: michael@0: is(gWatch.getAllStrings().length, 2, michael@0: "Watch expressions are removed when the close button is pressed."); michael@0: is(gWatch.getAllStrings()[0], "bazΩΩka", michael@0: "The expression at index " + 0 + " should be correct (1)."); michael@0: is(gWatch.getAllStrings()[1], "a", michael@0: "The expression at index " + 1 + " should be correct (2)."); michael@0: michael@0: EventUtils.sendMouseEvent({ type: "click" }, michael@0: gWatch.getItemAtIndex(0).attachment.view.closeNode, michael@0: gDebugger); michael@0: michael@0: is(gWatch.getAllStrings().length, 1, michael@0: "Watch expressions are removed when the close button is pressed."); michael@0: is(gWatch.getAllStrings()[0], "a", michael@0: "The expression at index " + 0 + " should be correct (3)."); michael@0: michael@0: EventUtils.sendMouseEvent({ type: "click" }, michael@0: gWatch.getItemAtIndex(0).attachment.view.closeNode, michael@0: gDebugger); michael@0: michael@0: is(gWatch.getAllStrings().length, 0, michael@0: "Watch expressions are removed when the close button is pressed."); michael@0: michael@0: EventUtils.sendMouseEvent({ type: "click" }, michael@0: gWatch.widget._parent, michael@0: gDebugger); michael@0: michael@0: is(gWatch.getAllStrings().length, 1, michael@0: "Watch expressions are added when the view container is pressed."); michael@0: } michael@0: michael@0: function addAndCheckCustomExpression(aTotal, aIndex, aString, noBlur) { michael@0: addAndCheckExpressions(aTotal, aIndex, "", true); michael@0: michael@0: for (let i = 0; i < aString.length; i++) { michael@0: EventUtils.sendChar(aString[i], gDebugger); michael@0: } michael@0: michael@0: gEditor.focus(); michael@0: michael@0: let element = gWatch.getItemAtIndex(aIndex).target; michael@0: michael@0: is(gWatch.getItemAtIndex(aIndex).attachment.initialExpression, "", michael@0: "The initial expression at index " + aIndex + " should be correct (1)."); michael@0: is(gWatch.getItemForElement(element).attachment.initialExpression, "", michael@0: "The initial expression at index " + aIndex + " should be correct (2)."); michael@0: michael@0: is(gWatch.getItemAtIndex(aIndex).attachment.currentExpression, aString, michael@0: "The expression at index " + aIndex + " should be correct (1)."); michael@0: is(gWatch.getItemForElement(element).attachment.currentExpression, aString, michael@0: "The expression at index " + aIndex + " should be correct (2)."); michael@0: michael@0: is(gWatch.getString(aIndex), aString, michael@0: "The expression at index " + aIndex + " should be correct (3)."); michael@0: is(gWatch.getAllStrings()[aIndex], aString, michael@0: "The expression at index " + aIndex + " should be correct (4)."); michael@0: } michael@0: michael@0: function addAndCheckExpressions(aTotal, aIndex, aString, noBlur) { michael@0: gWatch.addExpression(aString); michael@0: michael@0: is(gWatch.getAllStrings().length, aTotal, michael@0: "There should be " + aTotal + " watch expressions available (1)."); michael@0: is(gWatch.itemCount, aTotal, michael@0: "There should be " + aTotal + " watch expressions available (2)."); michael@0: michael@0: ok(gWatch.getItemAtIndex(aIndex), michael@0: "The expression at index " + aIndex + " should be available."); michael@0: is(gWatch.getItemAtIndex(aIndex).attachment.initialExpression, aString, michael@0: "The expression at index " + aIndex + " should have an initial expression."); michael@0: michael@0: let element = gWatch.getItemAtIndex(aIndex).target; michael@0: michael@0: ok(element, michael@0: "There should be a new expression item in the view."); michael@0: ok(gWatch.getItemForElement(element), michael@0: "The watch expression item should be accessible."); michael@0: is(gWatch.getItemForElement(element), gWatch.getItemAtIndex(aIndex), michael@0: "The correct watch expression item was accessed."); michael@0: michael@0: ok(gWatch.widget.getItemAtIndex(aIndex) instanceof XULElement, michael@0: "The correct watch expression element was accessed (1)."); michael@0: is(element, gWatch.widget.getItemAtIndex(aIndex), michael@0: "The correct watch expression element was accessed (2)."); michael@0: michael@0: is(gWatch.getItemForElement(element).attachment.view.arrowNode.hidden, false, michael@0: "The arrow node should be visible."); michael@0: is(gWatch.getItemForElement(element).attachment.view.closeNode.hidden, false, michael@0: "The close button should be visible."); michael@0: is(gWatch.getItemForElement(element).attachment.view.inputNode.getAttribute("focused"), "true", michael@0: "The textbox input should be focused."); michael@0: michael@0: is(gVariables.parentNode.scrollTop, 0, michael@0: "The variables view should be scrolled to top"); michael@0: michael@0: is(gWatch.items[0], gWatch.getItemAtIndex(aIndex), michael@0: "The correct watch expression was added to the cache (1)."); michael@0: is(gWatch.items[0], gWatch.getItemForElement(element), michael@0: "The correct watch expression was added to the cache (2)."); michael@0: michael@0: if (!noBlur) { michael@0: gEditor.focus(); michael@0: michael@0: is(gWatch.getItemAtIndex(aIndex).attachment.initialExpression, aString, michael@0: "The initial expression at index " + aIndex + " should be correct (1)."); michael@0: is(gWatch.getItemForElement(element).attachment.initialExpression, aString, michael@0: "The initial expression at index " + aIndex + " should be correct (2)."); michael@0: michael@0: is(gWatch.getItemAtIndex(aIndex).attachment.currentExpression, aString, michael@0: "The expression at index " + aIndex + " should be correct (1)."); michael@0: is(gWatch.getItemForElement(element).attachment.currentExpression, aString, michael@0: "The expression at index " + aIndex + " should be correct (2)."); michael@0: michael@0: is(gWatch.getString(aIndex), aString, michael@0: "The expression at index " + aIndex + " should be correct (3)."); michael@0: is(gWatch.getAllStrings()[aIndex], aString, michael@0: "The expression at index " + aIndex + " should be correct (4)."); michael@0: } michael@0: } michael@0: michael@0: function removeAndCheckExpression(aTotal, aIndex, aString) { michael@0: gWatch.removeAt(aIndex); michael@0: michael@0: is(gWatch.getAllStrings().length, aTotal, michael@0: "There should be " + aTotal + " watch expressions available (1)."); michael@0: is(gWatch.itemCount, aTotal, michael@0: "There should be " + aTotal + " watch expressions available (2)."); michael@0: michael@0: ok(gWatch.getItemAtIndex(aIndex), michael@0: "The expression at index " + aIndex + " should still be available."); michael@0: is(gWatch.getItemAtIndex(aIndex).attachment.initialExpression, aString, michael@0: "The expression at index " + aIndex + " should still have an initial expression."); michael@0: michael@0: let element = gWatch.getItemAtIndex(aIndex).target; michael@0: michael@0: is(gWatch.getItemAtIndex(aIndex).attachment.initialExpression, aString, michael@0: "The initial expression at index " + aIndex + " should be correct (1)."); michael@0: is(gWatch.getItemForElement(element).attachment.initialExpression, aString, michael@0: "The initial expression at index " + aIndex + " should be correct (2)."); michael@0: michael@0: is(gWatch.getItemAtIndex(aIndex).attachment.currentExpression, aString, michael@0: "The expression at index " + aIndex + " should be correct (1)."); michael@0: is(gWatch.getItemForElement(element).attachment.currentExpression, aString, michael@0: "The expression at index " + aIndex + " should be correct (2)."); michael@0: michael@0: is(gWatch.getString(aIndex), aString, michael@0: "The expression at index " + aIndex + " should be correct (3)."); michael@0: is(gWatch.getAllStrings()[aIndex], aString, michael@0: "The expression at index " + aIndex + " should be correct (4)."); michael@0: } michael@0: }