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 grips are correctly applied to variables. 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: michael@0: testVar.setGrip(1.618); michael@0: michael@0: is(testVar.target.querySelector(".value").getAttribute("value"), "1.618", michael@0: "The grip information for the variable wasn't set correctly (1)."); michael@0: is(testVar.target.querySelector(".variables-view-element-details.enum").childNodes.length, 0, michael@0: "Setting the grip alone shouldn't add any new tree nodes (1)."); michael@0: is(testVar.target.querySelector(".variables-view-element-details.nonenum").childNodes.length, 0, michael@0: "Setting the grip alone shouldn't add any new tree nodes (2)."); michael@0: michael@0: testVar.setGrip({ michael@0: type: "object", michael@0: class: "Window" michael@0: }); michael@0: michael@0: is(testVar.target.querySelector(".value").getAttribute("value"), "Window", michael@0: "The grip information for the variable wasn't set correctly (2)."); michael@0: is(testVar.target.querySelector(".variables-view-element-details.enum").childNodes.length, 0, michael@0: "Setting the grip alone shouldn't add any new tree nodes (3)."); michael@0: is(testVar.target.querySelector(".variables-view-element-details.nonenum").childNodes.length, 0, michael@0: "Setting the grip alone shouldn't add any new tree nodes (4)."); michael@0: michael@0: testVar.addItems({ michael@0: helloWorld: { michael@0: value: "hello world", michael@0: enumerable: true michael@0: } michael@0: }); michael@0: michael@0: is(testVar.target.querySelector(".variables-view-element-details").childNodes.length, 1, michael@0: "A new detail node should have been added in the variable tree."); michael@0: is(testVar.get("helloWorld").target.querySelector(".value").getAttribute("value"), "\"hello world\"", michael@0: "The grip information for the variable wasn't set correctly (3)."); michael@0: michael@0: testVar.addItems({ michael@0: helloWorld: { michael@0: value: "hello jupiter", michael@0: enumerable: true michael@0: } michael@0: }); michael@0: michael@0: is(testVar.target.querySelector(".variables-view-element-details").childNodes.length, 1, michael@0: "Shouldn't be able to duplicate nodes added in the variable tree."); michael@0: is(testVar.get("helloWorld").target.querySelector(".value").getAttribute("value"), "\"hello world\"", michael@0: "The grip information for the variable wasn't preserved correctly (4)."); michael@0: michael@0: testVar.addItems({ michael@0: someProp0: { michael@0: value: "random string", michael@0: enumerable: true michael@0: }, michael@0: someProp1: { michael@0: value: "another string", michael@0: enumerable: true michael@0: } michael@0: }); michael@0: michael@0: is(testVar.target.querySelector(".variables-view-element-details").childNodes.length, 3, michael@0: "Two new detail nodes should have been added in the variable tree."); michael@0: is(testVar.get("someProp0").target.querySelector(".value").getAttribute("value"), "\"random string\"", michael@0: "The grip information for the variable wasn't set correctly (5)."); michael@0: is(testVar.get("someProp1").target.querySelector(".value").getAttribute("value"), "\"another string\"", michael@0: "The grip information for the variable wasn't set correctly (6)."); michael@0: michael@0: testVar.addItems({ michael@0: someProp2: { michael@0: value: { michael@0: type: "null" michael@0: }, michael@0: enumerable: true michael@0: }, michael@0: someProp3: { michael@0: value: { michael@0: type: "undefined" michael@0: }, michael@0: enumerable: true michael@0: }, michael@0: someProp4: { michael@0: value: { michael@0: type: "object", michael@0: class: "Object" michael@0: }, michael@0: enumerable: true michael@0: } michael@0: }); michael@0: michael@0: is(testVar.target.querySelector(".variables-view-element-details").childNodes.length, 6, michael@0: "Three new detail nodes should have been added in the variable tree."); michael@0: is(testVar.get("someProp2").target.querySelector(".value").getAttribute("value"), "null", michael@0: "The grip information for the variable wasn't set correctly (7)."); michael@0: is(testVar.get("someProp3").target.querySelector(".value").getAttribute("value"), "undefined", michael@0: "The grip information for the variable wasn't set correctly (8)."); michael@0: is(testVar.get("someProp4").target.querySelector(".value").getAttribute("value"), "Object", michael@0: "The grip information for the variable wasn't set correctly (9)."); michael@0: michael@0: let parent = testVar.get("someProp2"); michael@0: let child = parent.addItem("child", { michael@0: value: { michael@0: type: "null" michael@0: } michael@0: }); michael@0: michael@0: is(variables.getItemForNode(parent.target), parent, michael@0: "VariablesView should have a record of the parent."); michael@0: is(variables.getItemForNode(child.target), child, michael@0: "VariablesView should have a record of the child."); michael@0: is([...parent].length, 1, michael@0: "Parent should have one child."); michael@0: michael@0: parent.remove(); michael@0: michael@0: is(variables.getItemForNode(parent.target), undefined, michael@0: "VariablesView should not have a record of the parent anymore."); michael@0: is(parent.target.parentNode, null, michael@0: "Parent element should not have a parent.") michael@0: is(variables.getItemForNode(child.target), undefined, michael@0: "VariablesView should not have a record of the child anymore."); michael@0: is(child.target.parentNode, null, michael@0: "Child element should not have a parent.") michael@0: is([...parent].length, 0, michael@0: "Parent should have zero children."); michael@0: michael@0: testScope.remove(); michael@0: michael@0: is([...variables].length, 0, michael@0: "VariablesView should have been emptied."); michael@0: is(Cu.nondeterministicGetWeakMapKeys(variables._itemsByElement).length, 0, michael@0: "VariablesView _itemsByElement map has been emptied."); michael@0: is(variables._currHierarchy.size, 0, michael@0: "VariablesView _currHierarchy map has been emptied."); michael@0: is(variables._list.children.length, 0, michael@0: "VariablesView element should have no children."); michael@0: michael@0: closeDebuggerAndFinish(aPanel); michael@0: }); michael@0: }