1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/debugger/test/browser_dbg_variables-view-04.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,150 @@ 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 + * Tests that grips are correctly applied to variables. 1.9 + */ 1.10 + 1.11 +const TAB_URL = EXAMPLE_URL + "doc_recursion-stack.html"; 1.12 + 1.13 +function test() { 1.14 + initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => { 1.15 + let variables = aPanel.panelWin.DebuggerView.Variables; 1.16 + let testScope = variables.addScope("test"); 1.17 + let testVar = testScope.addItem("something"); 1.18 + 1.19 + testVar.setGrip(1.618); 1.20 + 1.21 + is(testVar.target.querySelector(".value").getAttribute("value"), "1.618", 1.22 + "The grip information for the variable wasn't set correctly (1)."); 1.23 + is(testVar.target.querySelector(".variables-view-element-details.enum").childNodes.length, 0, 1.24 + "Setting the grip alone shouldn't add any new tree nodes (1)."); 1.25 + is(testVar.target.querySelector(".variables-view-element-details.nonenum").childNodes.length, 0, 1.26 + "Setting the grip alone shouldn't add any new tree nodes (2)."); 1.27 + 1.28 + testVar.setGrip({ 1.29 + type: "object", 1.30 + class: "Window" 1.31 + }); 1.32 + 1.33 + is(testVar.target.querySelector(".value").getAttribute("value"), "Window", 1.34 + "The grip information for the variable wasn't set correctly (2)."); 1.35 + is(testVar.target.querySelector(".variables-view-element-details.enum").childNodes.length, 0, 1.36 + "Setting the grip alone shouldn't add any new tree nodes (3)."); 1.37 + is(testVar.target.querySelector(".variables-view-element-details.nonenum").childNodes.length, 0, 1.38 + "Setting the grip alone shouldn't add any new tree nodes (4)."); 1.39 + 1.40 + testVar.addItems({ 1.41 + helloWorld: { 1.42 + value: "hello world", 1.43 + enumerable: true 1.44 + } 1.45 + }); 1.46 + 1.47 + is(testVar.target.querySelector(".variables-view-element-details").childNodes.length, 1, 1.48 + "A new detail node should have been added in the variable tree."); 1.49 + is(testVar.get("helloWorld").target.querySelector(".value").getAttribute("value"), "\"hello world\"", 1.50 + "The grip information for the variable wasn't set correctly (3)."); 1.51 + 1.52 + testVar.addItems({ 1.53 + helloWorld: { 1.54 + value: "hello jupiter", 1.55 + enumerable: true 1.56 + } 1.57 + }); 1.58 + 1.59 + is(testVar.target.querySelector(".variables-view-element-details").childNodes.length, 1, 1.60 + "Shouldn't be able to duplicate nodes added in the variable tree."); 1.61 + is(testVar.get("helloWorld").target.querySelector(".value").getAttribute("value"), "\"hello world\"", 1.62 + "The grip information for the variable wasn't preserved correctly (4)."); 1.63 + 1.64 + testVar.addItems({ 1.65 + someProp0: { 1.66 + value: "random string", 1.67 + enumerable: true 1.68 + }, 1.69 + someProp1: { 1.70 + value: "another string", 1.71 + enumerable: true 1.72 + } 1.73 + }); 1.74 + 1.75 + is(testVar.target.querySelector(".variables-view-element-details").childNodes.length, 3, 1.76 + "Two new detail nodes should have been added in the variable tree."); 1.77 + is(testVar.get("someProp0").target.querySelector(".value").getAttribute("value"), "\"random string\"", 1.78 + "The grip information for the variable wasn't set correctly (5)."); 1.79 + is(testVar.get("someProp1").target.querySelector(".value").getAttribute("value"), "\"another string\"", 1.80 + "The grip information for the variable wasn't set correctly (6)."); 1.81 + 1.82 + testVar.addItems({ 1.83 + someProp2: { 1.84 + value: { 1.85 + type: "null" 1.86 + }, 1.87 + enumerable: true 1.88 + }, 1.89 + someProp3: { 1.90 + value: { 1.91 + type: "undefined" 1.92 + }, 1.93 + enumerable: true 1.94 + }, 1.95 + someProp4: { 1.96 + value: { 1.97 + type: "object", 1.98 + class: "Object" 1.99 + }, 1.100 + enumerable: true 1.101 + } 1.102 + }); 1.103 + 1.104 + is(testVar.target.querySelector(".variables-view-element-details").childNodes.length, 6, 1.105 + "Three new detail nodes should have been added in the variable tree."); 1.106 + is(testVar.get("someProp2").target.querySelector(".value").getAttribute("value"), "null", 1.107 + "The grip information for the variable wasn't set correctly (7)."); 1.108 + is(testVar.get("someProp3").target.querySelector(".value").getAttribute("value"), "undefined", 1.109 + "The grip information for the variable wasn't set correctly (8)."); 1.110 + is(testVar.get("someProp4").target.querySelector(".value").getAttribute("value"), "Object", 1.111 + "The grip information for the variable wasn't set correctly (9)."); 1.112 + 1.113 + let parent = testVar.get("someProp2"); 1.114 + let child = parent.addItem("child", { 1.115 + value: { 1.116 + type: "null" 1.117 + } 1.118 + }); 1.119 + 1.120 + is(variables.getItemForNode(parent.target), parent, 1.121 + "VariablesView should have a record of the parent."); 1.122 + is(variables.getItemForNode(child.target), child, 1.123 + "VariablesView should have a record of the child."); 1.124 + is([...parent].length, 1, 1.125 + "Parent should have one child."); 1.126 + 1.127 + parent.remove(); 1.128 + 1.129 + is(variables.getItemForNode(parent.target), undefined, 1.130 + "VariablesView should not have a record of the parent anymore."); 1.131 + is(parent.target.parentNode, null, 1.132 + "Parent element should not have a parent.") 1.133 + is(variables.getItemForNode(child.target), undefined, 1.134 + "VariablesView should not have a record of the child anymore."); 1.135 + is(child.target.parentNode, null, 1.136 + "Child element should not have a parent.") 1.137 + is([...parent].length, 0, 1.138 + "Parent should have zero children."); 1.139 + 1.140 + testScope.remove(); 1.141 + 1.142 + is([...variables].length, 0, 1.143 + "VariablesView should have been emptied."); 1.144 + is(Cu.nondeterministicGetWeakMapKeys(variables._itemsByElement).length, 0, 1.145 + "VariablesView _itemsByElement map has been emptied."); 1.146 + is(variables._currHierarchy.size, 0, 1.147 + "VariablesView _currHierarchy map has been emptied."); 1.148 + is(variables._list.children.length, 0, 1.149 + "VariablesView element should have no children."); 1.150 + 1.151 + closeDebuggerAndFinish(aPanel); 1.152 + }); 1.153 +}