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 | * Tests that creating, collpasing and expanding variables in the |
michael@0 | 6 | * variables view works as expected. |
michael@0 | 7 | */ |
michael@0 | 8 | |
michael@0 | 9 | const TAB_URL = EXAMPLE_URL + "doc_recursion-stack.html"; |
michael@0 | 10 | |
michael@0 | 11 | function test() { |
michael@0 | 12 | initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => { |
michael@0 | 13 | let variables = aPanel.panelWin.DebuggerView.Variables; |
michael@0 | 14 | let testScope = variables.addScope("test"); |
michael@0 | 15 | let testVar = testScope.addItem("something"); |
michael@0 | 16 | let duplVar = testScope.addItem("something"); |
michael@0 | 17 | |
michael@0 | 18 | info("Scope id: " + testScope.id); |
michael@0 | 19 | info("Scope name: " + testScope.name); |
michael@0 | 20 | info("Variable id: " + testVar.id); |
michael@0 | 21 | info("Variable name: " + testVar.name); |
michael@0 | 22 | |
michael@0 | 23 | ok(testScope, |
michael@0 | 24 | "Should have created a scope."); |
michael@0 | 25 | is(duplVar, null, |
michael@0 | 26 | "Shouldn't be able to duplicate variables in the same scope."); |
michael@0 | 27 | |
michael@0 | 28 | ok(testVar, |
michael@0 | 29 | "Should have created a variable."); |
michael@0 | 30 | ok(testVar.id.contains("something"), |
michael@0 | 31 | "The newly created variable should have the default id set."); |
michael@0 | 32 | is(testVar.name, "something", |
michael@0 | 33 | "The newly created variable should have the desired name set."); |
michael@0 | 34 | |
michael@0 | 35 | ok(!testVar.displayValue, |
michael@0 | 36 | "The newly created variable should not have a displayed value yet (1)."); |
michael@0 | 37 | ok(!testVar.displayValueClassName, |
michael@0 | 38 | "The newly created variable should not have a displayed value yet (2)."); |
michael@0 | 39 | |
michael@0 | 40 | ok(testVar.target, |
michael@0 | 41 | "The newly created scope should point to a target node."); |
michael@0 | 42 | ok(testVar.target.id.contains("something"), |
michael@0 | 43 | "Should have the correct variable id on the element."); |
michael@0 | 44 | |
michael@0 | 45 | is(testVar.target.querySelector(".name").getAttribute("value"), "something", |
michael@0 | 46 | "Any new variable should have the designated name."); |
michael@0 | 47 | is(testVar.target.querySelector(".variables-view-element-details.enum").childNodes.length, 0, |
michael@0 | 48 | "Any new variable should have a container with no enumerable child nodes."); |
michael@0 | 49 | is(testVar.target.querySelector(".variables-view-element-details.nonenum").childNodes.length, 0, |
michael@0 | 50 | "Any new variable should have a container with no non-enumerable child nodes."); |
michael@0 | 51 | |
michael@0 | 52 | ok(!testVar.expanded, |
michael@0 | 53 | "Any new created scope should be initially collapsed."); |
michael@0 | 54 | ok(testVar.visible, |
michael@0 | 55 | "Any new created scope should be initially visible."); |
michael@0 | 56 | |
michael@0 | 57 | let expandCallbackArg = null; |
michael@0 | 58 | let collapseCallbackArg = null; |
michael@0 | 59 | let toggleCallbackArg = null; |
michael@0 | 60 | let hideCallbackArg = null; |
michael@0 | 61 | let showCallbackArg = null; |
michael@0 | 62 | |
michael@0 | 63 | testVar.onexpand = aScope => expandCallbackArg = aScope; |
michael@0 | 64 | testVar.oncollapse = aScope => collapseCallbackArg = aScope; |
michael@0 | 65 | testVar.ontoggle = aScope => toggleCallbackArg = aScope; |
michael@0 | 66 | testVar.onhide = aScope => hideCallbackArg = aScope; |
michael@0 | 67 | testVar.onshow = aScope => showCallbackArg = aScope; |
michael@0 | 68 | |
michael@0 | 69 | testVar.expand(); |
michael@0 | 70 | ok(testVar.expanded, |
michael@0 | 71 | "The testVar shouldn't be collapsed anymore."); |
michael@0 | 72 | is(expandCallbackArg, testVar, |
michael@0 | 73 | "The expandCallback wasn't called as it should."); |
michael@0 | 74 | |
michael@0 | 75 | testVar.collapse(); |
michael@0 | 76 | ok(!testVar.expanded, |
michael@0 | 77 | "The testVar should be collapsed again."); |
michael@0 | 78 | is(collapseCallbackArg, testVar, |
michael@0 | 79 | "The collapseCallback wasn't called as it should."); |
michael@0 | 80 | |
michael@0 | 81 | testVar.expanded = true; |
michael@0 | 82 | ok(testVar.expanded, |
michael@0 | 83 | "The testVar shouldn't be collapsed anymore."); |
michael@0 | 84 | |
michael@0 | 85 | testVar.toggle(); |
michael@0 | 86 | ok(!testVar.expanded, |
michael@0 | 87 | "The testVar should be collapsed again."); |
michael@0 | 88 | is(toggleCallbackArg, testVar, |
michael@0 | 89 | "The toggleCallback wasn't called as it should."); |
michael@0 | 90 | |
michael@0 | 91 | testVar.hide(); |
michael@0 | 92 | ok(!testVar.visible, |
michael@0 | 93 | "The testVar should be invisible after hiding."); |
michael@0 | 94 | is(hideCallbackArg, testVar, |
michael@0 | 95 | "The hideCallback wasn't called as it should."); |
michael@0 | 96 | |
michael@0 | 97 | testVar.show(); |
michael@0 | 98 | ok(testVar.visible, |
michael@0 | 99 | "The testVar should be visible again."); |
michael@0 | 100 | is(showCallbackArg, testVar, |
michael@0 | 101 | "The showCallback wasn't called as it should."); |
michael@0 | 102 | |
michael@0 | 103 | testVar.visible = false; |
michael@0 | 104 | ok(!testVar.visible, |
michael@0 | 105 | "The testVar should be invisible after hiding."); |
michael@0 | 106 | ok(!testVar.expanded, |
michael@0 | 107 | "The testVar should remember it is collapsed even if it is hidden."); |
michael@0 | 108 | |
michael@0 | 109 | testVar.visible = true; |
michael@0 | 110 | ok(testVar.visible, |
michael@0 | 111 | "The testVar should be visible after reshowing."); |
michael@0 | 112 | ok(!testVar.expanded, |
michael@0 | 113 | "The testVar should remember it is collapsed after it is reshown."); |
michael@0 | 114 | |
michael@0 | 115 | EventUtils.sendMouseEvent({ type: "mousedown" }, |
michael@0 | 116 | testVar.target.querySelector(".name"), |
michael@0 | 117 | aPanel.panelWin); |
michael@0 | 118 | |
michael@0 | 119 | ok(testVar.expanded, |
michael@0 | 120 | "Clicking the testVar name should expand it."); |
michael@0 | 121 | |
michael@0 | 122 | EventUtils.sendMouseEvent({ type: "mousedown" }, |
michael@0 | 123 | testVar.target.querySelector(".name"), |
michael@0 | 124 | aPanel.panelWin); |
michael@0 | 125 | |
michael@0 | 126 | ok(!testVar.expanded, |
michael@0 | 127 | "Clicking again the testVar name should collapse it."); |
michael@0 | 128 | |
michael@0 | 129 | EventUtils.sendMouseEvent({ type: "mousedown" }, |
michael@0 | 130 | testVar.target.querySelector(".arrow"), |
michael@0 | 131 | aPanel.panelWin); |
michael@0 | 132 | |
michael@0 | 133 | ok(testVar.expanded, |
michael@0 | 134 | "Clicking the testVar arrow should expand it."); |
michael@0 | 135 | |
michael@0 | 136 | EventUtils.sendMouseEvent({ type: "mousedown" }, |
michael@0 | 137 | testVar.target.querySelector(".arrow"), |
michael@0 | 138 | aPanel.panelWin); |
michael@0 | 139 | |
michael@0 | 140 | ok(!testVar.expanded, |
michael@0 | 141 | "Clicking again the testVar arrow should collapse it."); |
michael@0 | 142 | |
michael@0 | 143 | EventUtils.sendMouseEvent({ type: "mousedown" }, |
michael@0 | 144 | testVar.target.querySelector(".title"), |
michael@0 | 145 | aPanel.panelWin); |
michael@0 | 146 | |
michael@0 | 147 | ok(testVar.expanded, |
michael@0 | 148 | "Clicking the testVar title should expand it again."); |
michael@0 | 149 | |
michael@0 | 150 | testVar.addItem("child", { |
michael@0 | 151 | value: { |
michael@0 | 152 | type: "object", |
michael@0 | 153 | class: "Object" |
michael@0 | 154 | } |
michael@0 | 155 | }); |
michael@0 | 156 | |
michael@0 | 157 | let testChild = testVar.get("child"); |
michael@0 | 158 | ok(testChild, |
michael@0 | 159 | "Should have created a child property."); |
michael@0 | 160 | ok(testChild.id.contains("child"), |
michael@0 | 161 | "The newly created property should have the default id set."); |
michael@0 | 162 | is(testChild.name, "child", |
michael@0 | 163 | "The newly created property should have the desired name set."); |
michael@0 | 164 | |
michael@0 | 165 | is(testChild.displayValue, "Object", |
michael@0 | 166 | "The newly created property should not have a displayed value yet (1)."); |
michael@0 | 167 | is(testChild.displayValueClassName, "token-other", |
michael@0 | 168 | "The newly created property should not have a displayed value yet (2)."); |
michael@0 | 169 | |
michael@0 | 170 | ok(testChild.target, |
michael@0 | 171 | "The newly created scope should point to a target node."); |
michael@0 | 172 | ok(testChild.target.id.contains("child"), |
michael@0 | 173 | "Should have the correct property id on the element."); |
michael@0 | 174 | |
michael@0 | 175 | is(testChild.target.querySelector(".name").getAttribute("value"), "child", |
michael@0 | 176 | "Any new property should have the designated name."); |
michael@0 | 177 | is(testChild.target.querySelector(".variables-view-element-details.enum").childNodes.length, 0, |
michael@0 | 178 | "Any new property should have a container with no enumerable child nodes."); |
michael@0 | 179 | is(testChild.target.querySelector(".variables-view-element-details.nonenum").childNodes.length, 0, |
michael@0 | 180 | "Any new property should have a container with no non-enumerable child nodes."); |
michael@0 | 181 | |
michael@0 | 182 | ok(!testChild.expanded, |
michael@0 | 183 | "Any new created scope should be initially collapsed."); |
michael@0 | 184 | ok(testChild.visible, |
michael@0 | 185 | "Any new created scope should be initially visible."); |
michael@0 | 186 | |
michael@0 | 187 | EventUtils.sendMouseEvent({ type: "mousedown" }, |
michael@0 | 188 | testChild.target.querySelector(".name"), |
michael@0 | 189 | aPanel.panelWin); |
michael@0 | 190 | |
michael@0 | 191 | ok(testChild.expanded, |
michael@0 | 192 | "Clicking the testChild name should expand it."); |
michael@0 | 193 | |
michael@0 | 194 | EventUtils.sendMouseEvent({ type: "mousedown" }, |
michael@0 | 195 | testChild.target.querySelector(".name"), |
michael@0 | 196 | aPanel.panelWin); |
michael@0 | 197 | |
michael@0 | 198 | ok(!testChild.expanded, |
michael@0 | 199 | "Clicking again the testChild name should collapse it."); |
michael@0 | 200 | |
michael@0 | 201 | EventUtils.sendMouseEvent({ type: "mousedown" }, |
michael@0 | 202 | testChild.target.querySelector(".arrow"), |
michael@0 | 203 | aPanel.panelWin); |
michael@0 | 204 | |
michael@0 | 205 | ok(testChild.expanded, |
michael@0 | 206 | "Clicking the testChild arrow should expand it."); |
michael@0 | 207 | |
michael@0 | 208 | EventUtils.sendMouseEvent({ type: "mousedown" }, |
michael@0 | 209 | testChild.target.querySelector(".arrow"), |
michael@0 | 210 | aPanel.panelWin); |
michael@0 | 211 | |
michael@0 | 212 | ok(!testChild.expanded, |
michael@0 | 213 | "Clicking again the testChild arrow should collapse it."); |
michael@0 | 214 | |
michael@0 | 215 | EventUtils.sendMouseEvent({ type: "mousedown" }, |
michael@0 | 216 | testChild.target.querySelector(".title"), |
michael@0 | 217 | aPanel.panelWin); |
michael@0 | 218 | |
michael@0 | 219 | closeDebuggerAndFinish(aPanel); |
michael@0 | 220 | }); |
michael@0 | 221 | } |