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.

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

mercurial