browser/devtools/debugger/test/browser_dbg_variables-view-04.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 * Tests that grips are correctly applied to variables.
michael@0 6 */
michael@0 7
michael@0 8 const TAB_URL = EXAMPLE_URL + "doc_recursion-stack.html";
michael@0 9
michael@0 10 function test() {
michael@0 11 initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => {
michael@0 12 let variables = aPanel.panelWin.DebuggerView.Variables;
michael@0 13 let testScope = variables.addScope("test");
michael@0 14 let testVar = testScope.addItem("something");
michael@0 15
michael@0 16 testVar.setGrip(1.618);
michael@0 17
michael@0 18 is(testVar.target.querySelector(".value").getAttribute("value"), "1.618",
michael@0 19 "The grip information for the variable wasn't set correctly (1).");
michael@0 20 is(testVar.target.querySelector(".variables-view-element-details.enum").childNodes.length, 0,
michael@0 21 "Setting the grip alone shouldn't add any new tree nodes (1).");
michael@0 22 is(testVar.target.querySelector(".variables-view-element-details.nonenum").childNodes.length, 0,
michael@0 23 "Setting the grip alone shouldn't add any new tree nodes (2).");
michael@0 24
michael@0 25 testVar.setGrip({
michael@0 26 type: "object",
michael@0 27 class: "Window"
michael@0 28 });
michael@0 29
michael@0 30 is(testVar.target.querySelector(".value").getAttribute("value"), "Window",
michael@0 31 "The grip information for the variable wasn't set correctly (2).");
michael@0 32 is(testVar.target.querySelector(".variables-view-element-details.enum").childNodes.length, 0,
michael@0 33 "Setting the grip alone shouldn't add any new tree nodes (3).");
michael@0 34 is(testVar.target.querySelector(".variables-view-element-details.nonenum").childNodes.length, 0,
michael@0 35 "Setting the grip alone shouldn't add any new tree nodes (4).");
michael@0 36
michael@0 37 testVar.addItems({
michael@0 38 helloWorld: {
michael@0 39 value: "hello world",
michael@0 40 enumerable: true
michael@0 41 }
michael@0 42 });
michael@0 43
michael@0 44 is(testVar.target.querySelector(".variables-view-element-details").childNodes.length, 1,
michael@0 45 "A new detail node should have been added in the variable tree.");
michael@0 46 is(testVar.get("helloWorld").target.querySelector(".value").getAttribute("value"), "\"hello world\"",
michael@0 47 "The grip information for the variable wasn't set correctly (3).");
michael@0 48
michael@0 49 testVar.addItems({
michael@0 50 helloWorld: {
michael@0 51 value: "hello jupiter",
michael@0 52 enumerable: true
michael@0 53 }
michael@0 54 });
michael@0 55
michael@0 56 is(testVar.target.querySelector(".variables-view-element-details").childNodes.length, 1,
michael@0 57 "Shouldn't be able to duplicate nodes added in the variable tree.");
michael@0 58 is(testVar.get("helloWorld").target.querySelector(".value").getAttribute("value"), "\"hello world\"",
michael@0 59 "The grip information for the variable wasn't preserved correctly (4).");
michael@0 60
michael@0 61 testVar.addItems({
michael@0 62 someProp0: {
michael@0 63 value: "random string",
michael@0 64 enumerable: true
michael@0 65 },
michael@0 66 someProp1: {
michael@0 67 value: "another string",
michael@0 68 enumerable: true
michael@0 69 }
michael@0 70 });
michael@0 71
michael@0 72 is(testVar.target.querySelector(".variables-view-element-details").childNodes.length, 3,
michael@0 73 "Two new detail nodes should have been added in the variable tree.");
michael@0 74 is(testVar.get("someProp0").target.querySelector(".value").getAttribute("value"), "\"random string\"",
michael@0 75 "The grip information for the variable wasn't set correctly (5).");
michael@0 76 is(testVar.get("someProp1").target.querySelector(".value").getAttribute("value"), "\"another string\"",
michael@0 77 "The grip information for the variable wasn't set correctly (6).");
michael@0 78
michael@0 79 testVar.addItems({
michael@0 80 someProp2: {
michael@0 81 value: {
michael@0 82 type: "null"
michael@0 83 },
michael@0 84 enumerable: true
michael@0 85 },
michael@0 86 someProp3: {
michael@0 87 value: {
michael@0 88 type: "undefined"
michael@0 89 },
michael@0 90 enumerable: true
michael@0 91 },
michael@0 92 someProp4: {
michael@0 93 value: {
michael@0 94 type: "object",
michael@0 95 class: "Object"
michael@0 96 },
michael@0 97 enumerable: true
michael@0 98 }
michael@0 99 });
michael@0 100
michael@0 101 is(testVar.target.querySelector(".variables-view-element-details").childNodes.length, 6,
michael@0 102 "Three new detail nodes should have been added in the variable tree.");
michael@0 103 is(testVar.get("someProp2").target.querySelector(".value").getAttribute("value"), "null",
michael@0 104 "The grip information for the variable wasn't set correctly (7).");
michael@0 105 is(testVar.get("someProp3").target.querySelector(".value").getAttribute("value"), "undefined",
michael@0 106 "The grip information for the variable wasn't set correctly (8).");
michael@0 107 is(testVar.get("someProp4").target.querySelector(".value").getAttribute("value"), "Object",
michael@0 108 "The grip information for the variable wasn't set correctly (9).");
michael@0 109
michael@0 110 let parent = testVar.get("someProp2");
michael@0 111 let child = parent.addItem("child", {
michael@0 112 value: {
michael@0 113 type: "null"
michael@0 114 }
michael@0 115 });
michael@0 116
michael@0 117 is(variables.getItemForNode(parent.target), parent,
michael@0 118 "VariablesView should have a record of the parent.");
michael@0 119 is(variables.getItemForNode(child.target), child,
michael@0 120 "VariablesView should have a record of the child.");
michael@0 121 is([...parent].length, 1,
michael@0 122 "Parent should have one child.");
michael@0 123
michael@0 124 parent.remove();
michael@0 125
michael@0 126 is(variables.getItemForNode(parent.target), undefined,
michael@0 127 "VariablesView should not have a record of the parent anymore.");
michael@0 128 is(parent.target.parentNode, null,
michael@0 129 "Parent element should not have a parent.")
michael@0 130 is(variables.getItemForNode(child.target), undefined,
michael@0 131 "VariablesView should not have a record of the child anymore.");
michael@0 132 is(child.target.parentNode, null,
michael@0 133 "Child element should not have a parent.")
michael@0 134 is([...parent].length, 0,
michael@0 135 "Parent should have zero children.");
michael@0 136
michael@0 137 testScope.remove();
michael@0 138
michael@0 139 is([...variables].length, 0,
michael@0 140 "VariablesView should have been emptied.");
michael@0 141 is(Cu.nondeterministicGetWeakMapKeys(variables._itemsByElement).length, 0,
michael@0 142 "VariablesView _itemsByElement map has been emptied.");
michael@0 143 is(variables._currHierarchy.size, 0,
michael@0 144 "VariablesView _currHierarchy map has been emptied.");
michael@0 145 is(variables._list.children.length, 0,
michael@0 146 "VariablesView element should have no children.");
michael@0 147
michael@0 148 closeDebuggerAndFinish(aPanel);
michael@0 149 });
michael@0 150 }

mercurial