browser/devtools/debugger/test/browser_dbg_closure-inspection.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 const TAB_URL = EXAMPLE_URL + "doc_closures.html";
     6 // Test that inspecting a closure works as expected.
     8 function test() {
     9   let gPanel, gTab, gDebuggee, gDebugger;
    11   initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => {
    12     gTab = aTab;
    13     gDebuggee = aDebuggee;
    14     gPanel = aPanel;
    15     gDebugger = gPanel.panelWin;
    16     gDebuggee.gRecurseLimit = 2;
    18     waitForSourceShown(gPanel, ".html")
    19       .then(testClosure)
    20       .then(() => resumeDebuggerThenCloseAndFinish(gPanel))
    21       .then(null, aError => {
    22         ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
    23       });
    24   });
    26   function testClosure() {
    27     // Spin the event loop before causing the debuggee to pause, to allow
    28     // this function to return first.
    29     executeSoon(() => {
    30       EventUtils.sendMouseEvent({ type: "click" },
    31         gDebuggee.document.querySelector("button"),
    32         gDebuggee);
    33     });
    35     return waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_SCOPES).then(() => {
    36       let gVars = gDebugger.DebuggerView.Variables;
    37       let localScope = gVars.getScopeAtIndex(0);
    38       let localNodes = localScope.target.querySelector(".variables-view-element-details").childNodes;
    40       is(localNodes[4].querySelector(".name").getAttribute("value"), "person",
    41         "Should have the right property name for |person|.");
    42       is(localNodes[4].querySelector(".value").getAttribute("value"), "Object",
    43         "Should have the right property value for |person|.");
    45       // Expand the 'person' tree node. This causes its properties to be
    46       // retrieved and displayed.
    47       let personNode = gVars.getItemForNode(localNodes[4]);
    48       let personFetched = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_PROPERTIES);
    49       personNode.expand();
    51       return personFetched.then(() => {
    52         is(personNode.expanded, true,
    53           "|person| should be expanded at this point.");
    55         is(personNode.get("getName").target.querySelector(".name")
    56            .getAttribute("value"), "getName",
    57           "Should have the right property name for 'getName' in person.");
    58         is(personNode.get("getName").target.querySelector(".value")
    59            .getAttribute("value"), "_pfactory/<.getName()",
    60           "'getName' in person should have the right value.");
    61         is(personNode.get("getFoo").target.querySelector(".name")
    62            .getAttribute("value"), "getFoo",
    63           "Should have the right property name for 'getFoo' in person.");
    64         is(personNode.get("getFoo").target.querySelector(".value")
    65            .getAttribute("value"), "_pfactory/<.getFoo()",
    66           "'getFoo' in person should have the right value.");
    68         // Expand the function nodes. This causes their properties to be
    69         // retrieved and displayed.
    70         let getFooNode = personNode.get("getFoo");
    71         let getNameNode = personNode.get("getName");
    72         let funcsFetched = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_PROPERTIES, 2);
    73         let funcClosuresFetched = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_SCOPES, 2);
    74         getFooNode.expand();
    75         getNameNode.expand();
    77         return funcsFetched.then(() => {
    78           is(getFooNode.expanded, true,
    79             "|person.getFoo| should be expanded at this point.");
    80           is(getNameNode.expanded, true,
    81             "|person.getName| should be expanded at this point.");
    83           is(getFooNode.get("<Closure>").target.querySelector(".name")
    84              .getAttribute("value"), "<Closure>",
    85             "Found the closure node for getFoo.");
    86           is(getFooNode.get("<Closure>").target.querySelector(".value")
    87              .getAttribute("value"), "",
    88             "The closure node has no value for getFoo.");
    89           is(getNameNode.get("<Closure>").target.querySelector(".name")
    90              .getAttribute("value"), "<Closure>",
    91             "Found the closure node for getName.");
    92           is(getNameNode.get("<Closure>").target.querySelector(".value")
    93              .getAttribute("value"), "",
    94             "The closure node has no value for getName.");
    96           // Expand the closure nodes. This causes their environments to be
    97           // retrieved and displayed.
    98           let getFooClosure = getFooNode.get("<Closure>");
    99           let getNameClosure = getNameNode.get("<Closure>");
   100           getFooClosure.expand();
   101           getNameClosure.expand();
   103           return funcClosuresFetched.then(() => {
   104             is(getFooClosure.expanded, true,
   105               "|person.getFoo| closure should be expanded at this point.");
   106             is(getNameClosure.expanded, true,
   107               "|person.getName| closure should be expanded at this point.");
   109             is(getFooClosure.get("Function scope [_pfactory]").target.querySelector(".name")
   110                .getAttribute("value"), "Function scope [_pfactory]",
   111               "Found the function scope node for the getFoo closure.");
   112             is(getFooClosure.get("Function scope [_pfactory]").target.querySelector(".value")
   113                .getAttribute("value"), "",
   114               "The function scope node has no value for the getFoo closure.");
   115             is(getNameClosure.get("Function scope [_pfactory]").target.querySelector(".name")
   116                .getAttribute("value"), "Function scope [_pfactory]",
   117               "Found the function scope node for the getName closure.");
   118             is(getNameClosure.get("Function scope [_pfactory]").target.querySelector(".value")
   119                .getAttribute("value"), "",
   120               "The function scope node has no value for the getName closure.");
   122             // Expand the scope nodes.
   123             let getFooInnerScope = getFooClosure.get("Function scope [_pfactory]");
   124             let getNameInnerScope = getNameClosure.get("Function scope [_pfactory]");
   125             let innerFuncsFetched = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_PROPERTIES, 2);
   126             getFooInnerScope.expand();
   127             getNameInnerScope.expand();
   129             return funcsFetched.then(() => {
   130               is(getFooInnerScope.expanded, true,
   131                 "|person.getFoo| inner scope should be expanded at this point.");
   132               is(getNameInnerScope.expanded, true,
   133                 "|person.getName| inner scope should be expanded at this point.");
   135               // Only test that each function closes over the necessary variable.
   136               // We wouldn't want future SpiderMonkey closure space
   137               // optimizations to break this test.
   138               is(getFooInnerScope.get("foo").target.querySelector(".name")
   139                  .getAttribute("value"), "foo",
   140                 "Found the foo node for the getFoo inner scope.");
   141               is(getFooInnerScope.get("foo").target.querySelector(".value")
   142                  .getAttribute("value"), "10",
   143                 "The foo node has the expected value.");
   144               is(getNameInnerScope.get("name").target.querySelector(".name")
   145                  .getAttribute("value"), "name",
   146                 "Found the name node for the getName inner scope.");
   147               is(getNameInnerScope.get("name").target.querySelector(".value")
   148                  .getAttribute("value"), '"Bob"',
   149                 "The name node has the expected value.");
   150             });
   151           });
   152         });
   153       });
   154     });
   155   }
   156 }

mercurial