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: * Tests that creating, collpasing and expanding variables in the michael@0: * variables view works as expected. michael@0: */ michael@0: michael@0: const TAB_URL = EXAMPLE_URL + "doc_recursion-stack.html"; michael@0: michael@0: function test() { michael@0: initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => { michael@0: let variables = aPanel.panelWin.DebuggerView.Variables; michael@0: let testScope = variables.addScope("test"); michael@0: let testVar = testScope.addItem("something"); michael@0: let duplVar = testScope.addItem("something"); michael@0: michael@0: info("Scope id: " + testScope.id); michael@0: info("Scope name: " + testScope.name); michael@0: info("Variable id: " + testVar.id); michael@0: info("Variable name: " + testVar.name); michael@0: michael@0: ok(testScope, michael@0: "Should have created a scope."); michael@0: is(duplVar, null, michael@0: "Shouldn't be able to duplicate variables in the same scope."); michael@0: michael@0: ok(testVar, michael@0: "Should have created a variable."); michael@0: ok(testVar.id.contains("something"), michael@0: "The newly created variable should have the default id set."); michael@0: is(testVar.name, "something", michael@0: "The newly created variable should have the desired name set."); michael@0: michael@0: ok(!testVar.displayValue, michael@0: "The newly created variable should not have a displayed value yet (1)."); michael@0: ok(!testVar.displayValueClassName, michael@0: "The newly created variable should not have a displayed value yet (2)."); michael@0: michael@0: ok(testVar.target, michael@0: "The newly created scope should point to a target node."); michael@0: ok(testVar.target.id.contains("something"), michael@0: "Should have the correct variable id on the element."); michael@0: michael@0: is(testVar.target.querySelector(".name").getAttribute("value"), "something", michael@0: "Any new variable should have the designated name."); michael@0: is(testVar.target.querySelector(".variables-view-element-details.enum").childNodes.length, 0, michael@0: "Any new variable should have a container with no enumerable child nodes."); michael@0: is(testVar.target.querySelector(".variables-view-element-details.nonenum").childNodes.length, 0, michael@0: "Any new variable should have a container with no non-enumerable child nodes."); michael@0: michael@0: ok(!testVar.expanded, michael@0: "Any new created scope should be initially collapsed."); michael@0: ok(testVar.visible, michael@0: "Any new created scope should be initially visible."); michael@0: michael@0: let expandCallbackArg = null; michael@0: let collapseCallbackArg = null; michael@0: let toggleCallbackArg = null; michael@0: let hideCallbackArg = null; michael@0: let showCallbackArg = null; michael@0: michael@0: testVar.onexpand = aScope => expandCallbackArg = aScope; michael@0: testVar.oncollapse = aScope => collapseCallbackArg = aScope; michael@0: testVar.ontoggle = aScope => toggleCallbackArg = aScope; michael@0: testVar.onhide = aScope => hideCallbackArg = aScope; michael@0: testVar.onshow = aScope => showCallbackArg = aScope; michael@0: michael@0: testVar.expand(); michael@0: ok(testVar.expanded, michael@0: "The testVar shouldn't be collapsed anymore."); michael@0: is(expandCallbackArg, testVar, michael@0: "The expandCallback wasn't called as it should."); michael@0: michael@0: testVar.collapse(); michael@0: ok(!testVar.expanded, michael@0: "The testVar should be collapsed again."); michael@0: is(collapseCallbackArg, testVar, michael@0: "The collapseCallback wasn't called as it should."); michael@0: michael@0: testVar.expanded = true; michael@0: ok(testVar.expanded, michael@0: "The testVar shouldn't be collapsed anymore."); michael@0: michael@0: testVar.toggle(); michael@0: ok(!testVar.expanded, michael@0: "The testVar should be collapsed again."); michael@0: is(toggleCallbackArg, testVar, michael@0: "The toggleCallback wasn't called as it should."); michael@0: michael@0: testVar.hide(); michael@0: ok(!testVar.visible, michael@0: "The testVar should be invisible after hiding."); michael@0: is(hideCallbackArg, testVar, michael@0: "The hideCallback wasn't called as it should."); michael@0: michael@0: testVar.show(); michael@0: ok(testVar.visible, michael@0: "The testVar should be visible again."); michael@0: is(showCallbackArg, testVar, michael@0: "The showCallback wasn't called as it should."); michael@0: michael@0: testVar.visible = false; michael@0: ok(!testVar.visible, michael@0: "The testVar should be invisible after hiding."); michael@0: ok(!testVar.expanded, michael@0: "The testVar should remember it is collapsed even if it is hidden."); michael@0: michael@0: testVar.visible = true; michael@0: ok(testVar.visible, michael@0: "The testVar should be visible after reshowing."); michael@0: ok(!testVar.expanded, michael@0: "The testVar should remember it is collapsed after it is reshown."); michael@0: michael@0: EventUtils.sendMouseEvent({ type: "mousedown" }, michael@0: testVar.target.querySelector(".name"), michael@0: aPanel.panelWin); michael@0: michael@0: ok(testVar.expanded, michael@0: "Clicking the testVar name should expand it."); michael@0: michael@0: EventUtils.sendMouseEvent({ type: "mousedown" }, michael@0: testVar.target.querySelector(".name"), michael@0: aPanel.panelWin); michael@0: michael@0: ok(!testVar.expanded, michael@0: "Clicking again the testVar name should collapse it."); michael@0: michael@0: EventUtils.sendMouseEvent({ type: "mousedown" }, michael@0: testVar.target.querySelector(".arrow"), michael@0: aPanel.panelWin); michael@0: michael@0: ok(testVar.expanded, michael@0: "Clicking the testVar arrow should expand it."); michael@0: michael@0: EventUtils.sendMouseEvent({ type: "mousedown" }, michael@0: testVar.target.querySelector(".arrow"), michael@0: aPanel.panelWin); michael@0: michael@0: ok(!testVar.expanded, michael@0: "Clicking again the testVar arrow should collapse it."); michael@0: michael@0: EventUtils.sendMouseEvent({ type: "mousedown" }, michael@0: testVar.target.querySelector(".title"), michael@0: aPanel.panelWin); michael@0: michael@0: ok(testVar.expanded, michael@0: "Clicking the testVar title should expand it again."); michael@0: michael@0: testVar.addItem("child", { michael@0: value: { michael@0: type: "object", michael@0: class: "Object" michael@0: } michael@0: }); michael@0: michael@0: let testChild = testVar.get("child"); michael@0: ok(testChild, michael@0: "Should have created a child property."); michael@0: ok(testChild.id.contains("child"), michael@0: "The newly created property should have the default id set."); michael@0: is(testChild.name, "child", michael@0: "The newly created property should have the desired name set."); michael@0: michael@0: is(testChild.displayValue, "Object", michael@0: "The newly created property should not have a displayed value yet (1)."); michael@0: is(testChild.displayValueClassName, "token-other", michael@0: "The newly created property should not have a displayed value yet (2)."); michael@0: michael@0: ok(testChild.target, michael@0: "The newly created scope should point to a target node."); michael@0: ok(testChild.target.id.contains("child"), michael@0: "Should have the correct property id on the element."); michael@0: michael@0: is(testChild.target.querySelector(".name").getAttribute("value"), "child", michael@0: "Any new property should have the designated name."); michael@0: is(testChild.target.querySelector(".variables-view-element-details.enum").childNodes.length, 0, michael@0: "Any new property should have a container with no enumerable child nodes."); michael@0: is(testChild.target.querySelector(".variables-view-element-details.nonenum").childNodes.length, 0, michael@0: "Any new property should have a container with no non-enumerable child nodes."); michael@0: michael@0: ok(!testChild.expanded, michael@0: "Any new created scope should be initially collapsed."); michael@0: ok(testChild.visible, michael@0: "Any new created scope should be initially visible."); michael@0: michael@0: EventUtils.sendMouseEvent({ type: "mousedown" }, michael@0: testChild.target.querySelector(".name"), michael@0: aPanel.panelWin); michael@0: michael@0: ok(testChild.expanded, michael@0: "Clicking the testChild name should expand it."); michael@0: michael@0: EventUtils.sendMouseEvent({ type: "mousedown" }, michael@0: testChild.target.querySelector(".name"), michael@0: aPanel.panelWin); michael@0: michael@0: ok(!testChild.expanded, michael@0: "Clicking again the testChild name should collapse it."); michael@0: michael@0: EventUtils.sendMouseEvent({ type: "mousedown" }, michael@0: testChild.target.querySelector(".arrow"), michael@0: aPanel.panelWin); michael@0: michael@0: ok(testChild.expanded, michael@0: "Clicking the testChild arrow should expand it."); michael@0: michael@0: EventUtils.sendMouseEvent({ type: "mousedown" }, michael@0: testChild.target.querySelector(".arrow"), michael@0: aPanel.panelWin); michael@0: michael@0: ok(!testChild.expanded, michael@0: "Clicking again the testChild arrow should collapse it."); michael@0: michael@0: EventUtils.sendMouseEvent({ type: "mousedown" }, michael@0: testChild.target.querySelector(".title"), michael@0: aPanel.panelWin); michael@0: michael@0: closeDebuggerAndFinish(aPanel); michael@0: }); michael@0: }