browser/devtools/debugger/test/browser_dbg_variables-view-override-01.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 VariablesView methods responsible for styling variables
     6  * as overridden work properly.
     7  */
     9 const TAB_URL = EXAMPLE_URL + "doc_scope-variable-2.html";
    11 function test() {
    12   Task.spawn(function() {
    13     let [tab, debuggee, panel] = yield initDebugger(TAB_URL);
    14     let win = panel.panelWin;
    15     let events = win.EVENTS;
    16     let variables = win.DebuggerView.Variables;
    18     // Allow this generator function to yield first.
    19     executeSoon(() => debuggee.test());
    20     yield waitForSourceAndCaretAndScopes(panel, ".html", 23);
    22     let firstScope = variables.getScopeAtIndex(0);
    23     let secondScope = variables.getScopeAtIndex(1);
    24     let thirdScope = variables.getScopeAtIndex(2);
    25     let globalScope = variables.getScopeAtIndex(3);
    27     ok(firstScope, "The first scope is available.");
    28     ok(secondScope, "The second scope is available.");
    29     ok(thirdScope, "The third scope is available.");
    30     ok(globalScope, "The global scope is available.");
    32     is(firstScope.name, "Function scope [secondNest]",
    33       "The first scope's name is correct.");
    34     is(secondScope.name, "Function scope [firstNest]",
    35       "The second scope's name is correct.");
    36     is(thirdScope.name, "Function scope [test]",
    37       "The third scope's name is correct.");
    38     is(globalScope.name, "Global scope [Window]",
    39       "The global scope's name is correct.");
    41     is(firstScope.expanded, true,
    42       "The first scope's expansion state is correct.");
    43     is(secondScope.expanded, false,
    44       "The second scope's expansion state is correct.");
    45     is(thirdScope.expanded, false,
    46       "The third scope's expansion state is correct.");
    47     is(globalScope.expanded, false,
    48       "The global scope's expansion state is correct.");
    50     is(firstScope._store.size, 3,
    51       "The first scope should have all the variables available.");
    52     is(secondScope._store.size, 0,
    53       "The second scope should have no variables available yet.");
    54     is(thirdScope._store.size, 0,
    55       "The third scope should have no variables available yet.");
    56     is(globalScope._store.size, 0,
    57       "The global scope should have no variables available yet.");
    59     // Test getOwnerScopeForVariableOrProperty with simple variables.
    61     let thisVar = firstScope.get("this");
    62     let thisOwner = variables.getOwnerScopeForVariableOrProperty(thisVar);
    63     is(thisOwner, firstScope,
    64       "The getOwnerScopeForVariableOrProperty method works properly (1).");
    66     let someVar1 = firstScope.get("a");
    67     let someOwner1 = variables.getOwnerScopeForVariableOrProperty(someVar1);
    68     is(someOwner1, firstScope,
    69       "The getOwnerScopeForVariableOrProperty method works properly (2).");
    71     // Test getOwnerScopeForVariableOrProperty with first-degree properties.
    73     let argsVar1 = firstScope.get("arguments");
    74     let fetched = waitForDebuggerEvents(panel, events.FETCHED_PROPERTIES);
    75     argsVar1.expand();
    76     yield fetched;
    78     let calleeProp1 = argsVar1.get("callee");
    79     let calleeOwner1 = variables.getOwnerScopeForVariableOrProperty(calleeProp1);
    80     is(calleeOwner1, firstScope,
    81       "The getOwnerScopeForVariableOrProperty method works properly (3).");
    83     // Test getOwnerScopeForVariableOrProperty with second-degree properties.
    85     let protoVar1 = argsVar1.get("__proto__");
    86     let fetched = waitForDebuggerEvents(panel, events.FETCHED_PROPERTIES);
    87     protoVar1.expand();
    88     yield fetched;
    90     let constrProp1 = protoVar1.get("constructor");
    91     let constrOwner1 = variables.getOwnerScopeForVariableOrProperty(constrProp1);
    92     is(constrOwner1, firstScope,
    93       "The getOwnerScopeForVariableOrProperty method works properly (4).");
    95     // Test getOwnerScopeForVariableOrProperty with a simple variable
    96     // from non-topmost scopes.
    98     // Only need to wait for a single FETCHED_VARIABLES event, just for the
    99     // global scope, because the other local scopes already have the
   100     // arguments and variables available as evironment bindings.
   101     let fetched = waitForDebuggerEvents(panel, events.FETCHED_VARIABLES);
   102     secondScope.expand();
   103     thirdScope.expand();
   104     globalScope.expand();
   105     yield fetched;
   107     let someVar2 = secondScope.get("a");
   108     let someOwner2 = variables.getOwnerScopeForVariableOrProperty(someVar2);
   109     is(someOwner2, secondScope,
   110       "The getOwnerScopeForVariableOrProperty method works properly (5).");
   112     let someVar3 = thirdScope.get("a");
   113     let someOwner3 = variables.getOwnerScopeForVariableOrProperty(someVar3);
   114     is(someOwner3, thirdScope,
   115       "The getOwnerScopeForVariableOrProperty method works properly (6).");
   117     // Test getOwnerScopeForVariableOrProperty with first-degree properies
   118     // from non-topmost scopes.
   120     let argsVar2 = secondScope.get("arguments");
   121     let fetched = waitForDebuggerEvents(panel, events.FETCHED_PROPERTIES);
   122     argsVar2.expand();
   123     yield fetched;
   125     let calleeProp2 = argsVar2.get("callee");
   126     let calleeOwner2 = variables.getOwnerScopeForVariableOrProperty(calleeProp2);
   127     is(calleeOwner2, secondScope,
   128       "The getOwnerScopeForVariableOrProperty method works properly (7).");
   130     let argsVar3 = thirdScope.get("arguments");
   131     let fetched = waitForDebuggerEvents(panel, events.FETCHED_PROPERTIES);
   132     argsVar3.expand();
   133     yield fetched;
   135     let calleeProp3 = argsVar3.get("callee");
   136     let calleeOwner3 = variables.getOwnerScopeForVariableOrProperty(calleeProp3);
   137     is(calleeOwner3, thirdScope,
   138       "The getOwnerScopeForVariableOrProperty method works properly (8).");
   140     // Test getOwnerScopeForVariableOrProperty with second-degree properties
   141     // from non-topmost scopes.
   143     let protoVar2 = argsVar2.get("__proto__");
   144     let fetched = waitForDebuggerEvents(panel, events.FETCHED_PROPERTIES);
   145     protoVar2.expand();
   146     yield fetched;
   148     let constrProp2 = protoVar2.get("constructor");
   149     let constrOwner2 = variables.getOwnerScopeForVariableOrProperty(constrProp2);
   150     is(constrOwner2, secondScope,
   151       "The getOwnerScopeForVariableOrProperty method works properly (9).");
   153     let protoVar3 = argsVar3.get("__proto__");
   154     let fetched = waitForDebuggerEvents(panel, events.FETCHED_PROPERTIES);
   155     protoVar3.expand();
   156     yield fetched;
   158     let constrProp3 = protoVar3.get("constructor");
   159     let constrOwner3 = variables.getOwnerScopeForVariableOrProperty(constrProp3);
   160     is(constrOwner3, thirdScope,
   161       "The getOwnerScopeForVariableOrProperty method works properly (10).");
   163     // Test getParentScopesForVariableOrProperty with simple variables.
   165     let varOwners1 = variables.getParentScopesForVariableOrProperty(someVar1);
   166     let varOwners2 = variables.getParentScopesForVariableOrProperty(someVar2);
   167     let varOwners3 = variables.getParentScopesForVariableOrProperty(someVar3);
   169     is(varOwners1.length, 0,
   170       "There should be no owner scopes for the first variable.");
   172     is(varOwners2.length, 1,
   173       "There should be one owner scope for the second variable.");
   174     is(varOwners2[0], firstScope,
   175       "The only owner scope for the second variable is correct.");
   177     is(varOwners3.length, 2,
   178       "There should be two owner scopes for the third variable.");
   179     is(varOwners3[0], firstScope,
   180       "The first owner scope for the third variable is correct.");
   181     is(varOwners3[1], secondScope,
   182       "The second owner scope for the third variable is correct.");
   184     // Test getParentScopesForVariableOrProperty with first-degree properties.
   186     let propOwners1 = variables.getParentScopesForVariableOrProperty(calleeProp1);
   187     let propOwners2 = variables.getParentScopesForVariableOrProperty(calleeProp2);
   188     let propOwners3 = variables.getParentScopesForVariableOrProperty(calleeProp3);
   190     is(propOwners1.length, 0,
   191       "There should be no owner scopes for the first property.");
   193     is(propOwners2.length, 1,
   194       "There should be one owner scope for the second property.");
   195     is(propOwners2[0], firstScope,
   196       "The only owner scope for the second property is correct.");
   198     is(propOwners3.length, 2,
   199       "There should be two owner scopes for the third property.");
   200     is(propOwners3[0], firstScope,
   201       "The first owner scope for the third property is correct.");
   202     is(propOwners3[1], secondScope,
   203       "The second owner scope for the third property is correct.");
   205     // Test getParentScopesForVariableOrProperty with second-degree properties.
   207     let secPropOwners1 = variables.getParentScopesForVariableOrProperty(constrProp1);
   208     let secPropOwners2 = variables.getParentScopesForVariableOrProperty(constrProp2);
   209     let secPropOwners3 = variables.getParentScopesForVariableOrProperty(constrProp3);
   211     is(secPropOwners1.length, 0,
   212       "There should be no owner scopes for the first inner property.");
   214     is(secPropOwners2.length, 1,
   215       "There should be one owner scope for the second inner property.");
   216     is(secPropOwners2[0], firstScope,
   217       "The only owner scope for the second inner property is correct.");
   219     is(secPropOwners3.length, 2,
   220       "There should be two owner scopes for the third inner property.");
   221     is(secPropOwners3[0], firstScope,
   222       "The first owner scope for the third inner property is correct.");
   223     is(secPropOwners3[1], secondScope,
   224       "The second owner scope for the third inner property is correct.");
   226     yield resumeDebuggerThenCloseAndFinish(panel);
   227   });
   228 }

mercurial