browser/devtools/debugger/test/browser_dbg_variables-view-frame-with.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

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 * Make sure that the variables view is correctly populated in 'with' frames.
michael@0 6 */
michael@0 7
michael@0 8 const TAB_URL = EXAMPLE_URL + "doc_with-frame.html";
michael@0 9
michael@0 10 let gTab, gDebuggee, gPanel, gDebugger;
michael@0 11 let gVariables;
michael@0 12
michael@0 13 function test() {
michael@0 14 initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => {
michael@0 15 gTab = aTab;
michael@0 16 gDebuggee = aDebuggee;
michael@0 17 gPanel = aPanel;
michael@0 18 gDebugger = gPanel.panelWin;
michael@0 19 gVariables = gDebugger.DebuggerView.Variables;
michael@0 20
michael@0 21 // The first 'with' scope should be expanded by default, but the
michael@0 22 // variables haven't been fetched yet. This is how 'with' scopes work.
michael@0 23 promise.all([
michael@0 24 waitForSourceAndCaret(gPanel, ".html", 22),
michael@0 25 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_SCOPES),
michael@0 26 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_VARIABLES)
michael@0 27 ]).then(testFirstWithScope)
michael@0 28 .then(expandSecondWithScope)
michael@0 29 .then(testSecondWithScope)
michael@0 30 .then(expandFunctionScope)
michael@0 31 .then(testFunctionScope)
michael@0 32 .then(() => resumeDebuggerThenCloseAndFinish(gPanel))
michael@0 33 .then(null, aError => {
michael@0 34 ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
michael@0 35 });
michael@0 36
michael@0 37 EventUtils.sendMouseEvent({ type: "click" },
michael@0 38 gDebuggee.document.querySelector("button"),
michael@0 39 gDebuggee);
michael@0 40 });
michael@0 41 }
michael@0 42
michael@0 43 function testFirstWithScope() {
michael@0 44 let firstWithScope = gVariables.getScopeAtIndex(0);
michael@0 45 is(firstWithScope.expanded, true,
michael@0 46 "The first 'with' scope should be expanded by default.");
michael@0 47 ok(firstWithScope.target.querySelector(".name").getAttribute("value").contains("[Object]"),
michael@0 48 "The first 'with' scope should be properly identified.");
michael@0 49
michael@0 50 let withEnums = firstWithScope._enum.childNodes;
michael@0 51 let withNonEnums = firstWithScope._nonenum.childNodes;
michael@0 52
michael@0 53 is(withEnums.length, 3,
michael@0 54 "The first 'with' scope should contain all the created enumerable elements.");
michael@0 55 is(withNonEnums.length, 1,
michael@0 56 "The first 'with' scope should contain all the created non-enumerable elements.");
michael@0 57
michael@0 58 is(withEnums[0].querySelector(".name").getAttribute("value"), "this",
michael@0 59 "Should have the right property name for 'this'.");
michael@0 60 is(withEnums[0].querySelector(".value").getAttribute("value"),
michael@0 61 "Window \u2192 doc_with-frame.html",
michael@0 62 "Should have the right property value for 'this'.");
michael@0 63 ok(withEnums[0].querySelector(".value").className.contains("token-other"),
michael@0 64 "Should have the right token class for 'this'.");
michael@0 65
michael@0 66 is(withEnums[1].querySelector(".name").getAttribute("value"), "alpha",
michael@0 67 "Should have the right property name for 'alpha'.");
michael@0 68 is(withEnums[1].querySelector(".value").getAttribute("value"), "1",
michael@0 69 "Should have the right property value for 'alpha'.");
michael@0 70 ok(withEnums[1].querySelector(".value").className.contains("token-number"),
michael@0 71 "Should have the right token class for 'alpha'.");
michael@0 72
michael@0 73 is(withEnums[2].querySelector(".name").getAttribute("value"), "beta",
michael@0 74 "Should have the right property name for 'beta'.");
michael@0 75 is(withEnums[2].querySelector(".value").getAttribute("value"), "2",
michael@0 76 "Should have the right property value for 'beta'.");
michael@0 77 ok(withEnums[2].querySelector(".value").className.contains("token-number"),
michael@0 78 "Should have the right token class for 'beta'.");
michael@0 79
michael@0 80 is(withNonEnums[0].querySelector(".name").getAttribute("value"), "__proto__",
michael@0 81 "Should have the right property name for '__proto__'.");
michael@0 82 is(withNonEnums[0].querySelector(".value").getAttribute("value"), "Object",
michael@0 83 "Should have the right property value for '__proto__'.");
michael@0 84 ok(withNonEnums[0].querySelector(".value").className.contains("token-other"),
michael@0 85 "Should have the right token class for '__proto__'.");
michael@0 86 }
michael@0 87
michael@0 88 function expandSecondWithScope() {
michael@0 89 let deferred = promise.defer();
michael@0 90
michael@0 91 let secondWithScope = gVariables.getScopeAtIndex(1);
michael@0 92 is(secondWithScope.expanded, false,
michael@0 93 "The second 'with' scope should not be expanded by default.");
michael@0 94
michael@0 95 gDebugger.once(gDebugger.EVENTS.FETCHED_VARIABLES, deferred.resolve);
michael@0 96
michael@0 97 EventUtils.sendMouseEvent({ type: "mousedown" },
michael@0 98 secondWithScope.target.querySelector(".name"),
michael@0 99 gDebugger);
michael@0 100
michael@0 101 return deferred.promise;
michael@0 102 }
michael@0 103
michael@0 104 function testSecondWithScope() {
michael@0 105 let secondWithScope = gVariables.getScopeAtIndex(1);
michael@0 106 is(secondWithScope.expanded, true,
michael@0 107 "The second 'with' scope should now be expanded.");
michael@0 108 ok(secondWithScope.target.querySelector(".name").getAttribute("value").contains("[Math]"),
michael@0 109 "The second 'with' scope should be properly identified.");
michael@0 110
michael@0 111 let withEnums = secondWithScope._enum.childNodes;
michael@0 112 let withNonEnums = secondWithScope._nonenum.childNodes;
michael@0 113
michael@0 114 is(withEnums.length, 0,
michael@0 115 "The second 'with' scope should contain all the created enumerable elements.");
michael@0 116 isnot(withNonEnums.length, 0,
michael@0 117 "The second 'with' scope should contain all the created non-enumerable elements.");
michael@0 118
michael@0 119 is(secondWithScope.get("E").target.querySelector(".name").getAttribute("value"), "E",
michael@0 120 "Should have the right property name for 'E'.");
michael@0 121 is(secondWithScope.get("E").target.querySelector(".value").getAttribute("value"), "2.718281828459045",
michael@0 122 "Should have the right property value for 'E'.");
michael@0 123 ok(secondWithScope.get("E").target.querySelector(".value").className.contains("token-number"),
michael@0 124 "Should have the right token class for 'E'.");
michael@0 125
michael@0 126 is(secondWithScope.get("PI").target.querySelector(".name").getAttribute("value"), "PI",
michael@0 127 "Should have the right property name for 'PI'.");
michael@0 128 is(secondWithScope.get("PI").target.querySelector(".value").getAttribute("value"), "3.141592653589793",
michael@0 129 "Should have the right property value for 'PI'.");
michael@0 130 ok(secondWithScope.get("PI").target.querySelector(".value").className.contains("token-number"),
michael@0 131 "Should have the right token class for 'PI'.");
michael@0 132
michael@0 133 is(secondWithScope.get("random").target.querySelector(".name").getAttribute("value"), "random",
michael@0 134 "Should have the right property name for 'random'.");
michael@0 135 is(secondWithScope.get("random").target.querySelector(".value").getAttribute("value"), "random()",
michael@0 136 "Should have the right property value for 'random'.");
michael@0 137 ok(secondWithScope.get("random").target.querySelector(".value").className.contains("token-other"),
michael@0 138 "Should have the right token class for 'random'.");
michael@0 139
michael@0 140 is(secondWithScope.get("__proto__").target.querySelector(".name").getAttribute("value"), "__proto__",
michael@0 141 "Should have the right property name for '__proto__'.");
michael@0 142 is(secondWithScope.get("__proto__").target.querySelector(".value").getAttribute("value"), "Object",
michael@0 143 "Should have the right property value for '__proto__'.");
michael@0 144 ok(secondWithScope.get("__proto__").target.querySelector(".value").className.contains("token-other"),
michael@0 145 "Should have the right token class for '__proto__'.");
michael@0 146 }
michael@0 147
michael@0 148 function expandFunctionScope() {
michael@0 149 let funcScope = gVariables.getScopeAtIndex(2);
michael@0 150 is(funcScope.expanded, false,
michael@0 151 "The function scope shouldn't be expanded by default, but the " +
michael@0 152 "variables have been already fetched. This is how local scopes work.");
michael@0 153
michael@0 154 EventUtils.sendMouseEvent({ type: "mousedown" },
michael@0 155 funcScope.target.querySelector(".name"),
michael@0 156 gDebugger);
michael@0 157
michael@0 158 return promise.resolve(null);
michael@0 159 }
michael@0 160
michael@0 161 function testFunctionScope() {
michael@0 162 let funcScope = gVariables.getScopeAtIndex(2);
michael@0 163 is(funcScope.expanded, true,
michael@0 164 "The function scope should now be expanded.");
michael@0 165 ok(funcScope.target.querySelector(".name").getAttribute("value").contains("[test]"),
michael@0 166 "The function scope should be properly identified.");
michael@0 167
michael@0 168 let funcEnums = funcScope._enum.childNodes;
michael@0 169 let funcNonEnums = funcScope._nonenum.childNodes;
michael@0 170
michael@0 171 is(funcEnums.length, 6,
michael@0 172 "The function scope should contain all the created enumerable elements.");
michael@0 173 is(funcNonEnums.length, 0,
michael@0 174 "The function scope should contain all the created non-enumerable elements.");
michael@0 175
michael@0 176 is(funcScope.get("aNumber").target.querySelector(".name").getAttribute("value"), "aNumber",
michael@0 177 "Should have the right property name for 'aNumber'.");
michael@0 178 is(funcScope.get("aNumber").target.querySelector(".value").getAttribute("value"), "10",
michael@0 179 "Should have the right property value for 'aNumber'.");
michael@0 180 ok(funcScope.get("aNumber").target.querySelector(".value").className.contains("token-number"),
michael@0 181 "Should have the right token class for 'aNumber'.");
michael@0 182
michael@0 183 is(funcScope.get("a").target.querySelector(".name").getAttribute("value"), "a",
michael@0 184 "Should have the right property name for 'a'.");
michael@0 185 is(funcScope.get("a").target.querySelector(".value").getAttribute("value"), "314.1592653589793",
michael@0 186 "Should have the right property value for 'a'.");
michael@0 187 ok(funcScope.get("a").target.querySelector(".value").className.contains("token-number"),
michael@0 188 "Should have the right token class for 'a'.");
michael@0 189
michael@0 190 is(funcScope.get("r").target.querySelector(".name").getAttribute("value"), "r",
michael@0 191 "Should have the right property name for 'r'.");
michael@0 192 is(funcScope.get("r").target.querySelector(".value").getAttribute("value"), "10",
michael@0 193 "Should have the right property value for 'r'.");
michael@0 194 ok(funcScope.get("r").target.querySelector(".value").className.contains("token-number"),
michael@0 195 "Should have the right token class for 'r'.");
michael@0 196
michael@0 197 is(funcScope.get("foo").target.querySelector(".name").getAttribute("value"), "foo",
michael@0 198 "Should have the right property name for 'foo'.");
michael@0 199 is(funcScope.get("foo").target.querySelector(".value").getAttribute("value"), "6.283185307179586",
michael@0 200 "Should have the right property value for 'foo'.");
michael@0 201 ok(funcScope.get("foo").target.querySelector(".value").className.contains("token-number"),
michael@0 202 "Should have the right token class for 'foo'.");
michael@0 203 }
michael@0 204
michael@0 205 registerCleanupFunction(function() {
michael@0 206 gTab = null;
michael@0 207 gDebuggee = null;
michael@0 208 gPanel = null;
michael@0 209 gDebugger = null;
michael@0 210 gVariables = null;
michael@0 211 });

mercurial