browser/devtools/debugger/test/browser_dbg_variables-view-override-01.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/debugger/test/browser_dbg_variables-view-override-01.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,228 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +/**
     1.8 + * Tests that VariablesView methods responsible for styling variables
     1.9 + * as overridden work properly.
    1.10 + */
    1.11 +
    1.12 +const TAB_URL = EXAMPLE_URL + "doc_scope-variable-2.html";
    1.13 +
    1.14 +function test() {
    1.15 +  Task.spawn(function() {
    1.16 +    let [tab, debuggee, panel] = yield initDebugger(TAB_URL);
    1.17 +    let win = panel.panelWin;
    1.18 +    let events = win.EVENTS;
    1.19 +    let variables = win.DebuggerView.Variables;
    1.20 +
    1.21 +    // Allow this generator function to yield first.
    1.22 +    executeSoon(() => debuggee.test());
    1.23 +    yield waitForSourceAndCaretAndScopes(panel, ".html", 23);
    1.24 +
    1.25 +    let firstScope = variables.getScopeAtIndex(0);
    1.26 +    let secondScope = variables.getScopeAtIndex(1);
    1.27 +    let thirdScope = variables.getScopeAtIndex(2);
    1.28 +    let globalScope = variables.getScopeAtIndex(3);
    1.29 +
    1.30 +    ok(firstScope, "The first scope is available.");
    1.31 +    ok(secondScope, "The second scope is available.");
    1.32 +    ok(thirdScope, "The third scope is available.");
    1.33 +    ok(globalScope, "The global scope is available.");
    1.34 +
    1.35 +    is(firstScope.name, "Function scope [secondNest]",
    1.36 +      "The first scope's name is correct.");
    1.37 +    is(secondScope.name, "Function scope [firstNest]",
    1.38 +      "The second scope's name is correct.");
    1.39 +    is(thirdScope.name, "Function scope [test]",
    1.40 +      "The third scope's name is correct.");
    1.41 +    is(globalScope.name, "Global scope [Window]",
    1.42 +      "The global scope's name is correct.");
    1.43 +
    1.44 +    is(firstScope.expanded, true,
    1.45 +      "The first scope's expansion state is correct.");
    1.46 +    is(secondScope.expanded, false,
    1.47 +      "The second scope's expansion state is correct.");
    1.48 +    is(thirdScope.expanded, false,
    1.49 +      "The third scope's expansion state is correct.");
    1.50 +    is(globalScope.expanded, false,
    1.51 +      "The global scope's expansion state is correct.");
    1.52 +
    1.53 +    is(firstScope._store.size, 3,
    1.54 +      "The first scope should have all the variables available.");
    1.55 +    is(secondScope._store.size, 0,
    1.56 +      "The second scope should have no variables available yet.");
    1.57 +    is(thirdScope._store.size, 0,
    1.58 +      "The third scope should have no variables available yet.");
    1.59 +    is(globalScope._store.size, 0,
    1.60 +      "The global scope should have no variables available yet.");
    1.61 +
    1.62 +    // Test getOwnerScopeForVariableOrProperty with simple variables.
    1.63 +
    1.64 +    let thisVar = firstScope.get("this");
    1.65 +    let thisOwner = variables.getOwnerScopeForVariableOrProperty(thisVar);
    1.66 +    is(thisOwner, firstScope,
    1.67 +      "The getOwnerScopeForVariableOrProperty method works properly (1).");
    1.68 +
    1.69 +    let someVar1 = firstScope.get("a");
    1.70 +    let someOwner1 = variables.getOwnerScopeForVariableOrProperty(someVar1);
    1.71 +    is(someOwner1, firstScope,
    1.72 +      "The getOwnerScopeForVariableOrProperty method works properly (2).");
    1.73 +
    1.74 +    // Test getOwnerScopeForVariableOrProperty with first-degree properties.
    1.75 +
    1.76 +    let argsVar1 = firstScope.get("arguments");
    1.77 +    let fetched = waitForDebuggerEvents(panel, events.FETCHED_PROPERTIES);
    1.78 +    argsVar1.expand();
    1.79 +    yield fetched;
    1.80 +
    1.81 +    let calleeProp1 = argsVar1.get("callee");
    1.82 +    let calleeOwner1 = variables.getOwnerScopeForVariableOrProperty(calleeProp1);
    1.83 +    is(calleeOwner1, firstScope,
    1.84 +      "The getOwnerScopeForVariableOrProperty method works properly (3).");
    1.85 +
    1.86 +    // Test getOwnerScopeForVariableOrProperty with second-degree properties.
    1.87 +
    1.88 +    let protoVar1 = argsVar1.get("__proto__");
    1.89 +    let fetched = waitForDebuggerEvents(panel, events.FETCHED_PROPERTIES);
    1.90 +    protoVar1.expand();
    1.91 +    yield fetched;
    1.92 +
    1.93 +    let constrProp1 = protoVar1.get("constructor");
    1.94 +    let constrOwner1 = variables.getOwnerScopeForVariableOrProperty(constrProp1);
    1.95 +    is(constrOwner1, firstScope,
    1.96 +      "The getOwnerScopeForVariableOrProperty method works properly (4).");
    1.97 +
    1.98 +    // Test getOwnerScopeForVariableOrProperty with a simple variable
    1.99 +    // from non-topmost scopes.
   1.100 +
   1.101 +    // Only need to wait for a single FETCHED_VARIABLES event, just for the
   1.102 +    // global scope, because the other local scopes already have the
   1.103 +    // arguments and variables available as evironment bindings.
   1.104 +    let fetched = waitForDebuggerEvents(panel, events.FETCHED_VARIABLES);
   1.105 +    secondScope.expand();
   1.106 +    thirdScope.expand();
   1.107 +    globalScope.expand();
   1.108 +    yield fetched;
   1.109 +
   1.110 +    let someVar2 = secondScope.get("a");
   1.111 +    let someOwner2 = variables.getOwnerScopeForVariableOrProperty(someVar2);
   1.112 +    is(someOwner2, secondScope,
   1.113 +      "The getOwnerScopeForVariableOrProperty method works properly (5).");
   1.114 +
   1.115 +    let someVar3 = thirdScope.get("a");
   1.116 +    let someOwner3 = variables.getOwnerScopeForVariableOrProperty(someVar3);
   1.117 +    is(someOwner3, thirdScope,
   1.118 +      "The getOwnerScopeForVariableOrProperty method works properly (6).");
   1.119 +
   1.120 +    // Test getOwnerScopeForVariableOrProperty with first-degree properies
   1.121 +    // from non-topmost scopes.
   1.122 +
   1.123 +    let argsVar2 = secondScope.get("arguments");
   1.124 +    let fetched = waitForDebuggerEvents(panel, events.FETCHED_PROPERTIES);
   1.125 +    argsVar2.expand();
   1.126 +    yield fetched;
   1.127 +
   1.128 +    let calleeProp2 = argsVar2.get("callee");
   1.129 +    let calleeOwner2 = variables.getOwnerScopeForVariableOrProperty(calleeProp2);
   1.130 +    is(calleeOwner2, secondScope,
   1.131 +      "The getOwnerScopeForVariableOrProperty method works properly (7).");
   1.132 +
   1.133 +    let argsVar3 = thirdScope.get("arguments");
   1.134 +    let fetched = waitForDebuggerEvents(panel, events.FETCHED_PROPERTIES);
   1.135 +    argsVar3.expand();
   1.136 +    yield fetched;
   1.137 +
   1.138 +    let calleeProp3 = argsVar3.get("callee");
   1.139 +    let calleeOwner3 = variables.getOwnerScopeForVariableOrProperty(calleeProp3);
   1.140 +    is(calleeOwner3, thirdScope,
   1.141 +      "The getOwnerScopeForVariableOrProperty method works properly (8).");
   1.142 +
   1.143 +    // Test getOwnerScopeForVariableOrProperty with second-degree properties
   1.144 +    // from non-topmost scopes.
   1.145 +
   1.146 +    let protoVar2 = argsVar2.get("__proto__");
   1.147 +    let fetched = waitForDebuggerEvents(panel, events.FETCHED_PROPERTIES);
   1.148 +    protoVar2.expand();
   1.149 +    yield fetched;
   1.150 +
   1.151 +    let constrProp2 = protoVar2.get("constructor");
   1.152 +    let constrOwner2 = variables.getOwnerScopeForVariableOrProperty(constrProp2);
   1.153 +    is(constrOwner2, secondScope,
   1.154 +      "The getOwnerScopeForVariableOrProperty method works properly (9).");
   1.155 +
   1.156 +    let protoVar3 = argsVar3.get("__proto__");
   1.157 +    let fetched = waitForDebuggerEvents(panel, events.FETCHED_PROPERTIES);
   1.158 +    protoVar3.expand();
   1.159 +    yield fetched;
   1.160 +
   1.161 +    let constrProp3 = protoVar3.get("constructor");
   1.162 +    let constrOwner3 = variables.getOwnerScopeForVariableOrProperty(constrProp3);
   1.163 +    is(constrOwner3, thirdScope,
   1.164 +      "The getOwnerScopeForVariableOrProperty method works properly (10).");
   1.165 +
   1.166 +    // Test getParentScopesForVariableOrProperty with simple variables.
   1.167 +
   1.168 +    let varOwners1 = variables.getParentScopesForVariableOrProperty(someVar1);
   1.169 +    let varOwners2 = variables.getParentScopesForVariableOrProperty(someVar2);
   1.170 +    let varOwners3 = variables.getParentScopesForVariableOrProperty(someVar3);
   1.171 +
   1.172 +    is(varOwners1.length, 0,
   1.173 +      "There should be no owner scopes for the first variable.");
   1.174 +
   1.175 +    is(varOwners2.length, 1,
   1.176 +      "There should be one owner scope for the second variable.");
   1.177 +    is(varOwners2[0], firstScope,
   1.178 +      "The only owner scope for the second variable is correct.");
   1.179 +
   1.180 +    is(varOwners3.length, 2,
   1.181 +      "There should be two owner scopes for the third variable.");
   1.182 +    is(varOwners3[0], firstScope,
   1.183 +      "The first owner scope for the third variable is correct.");
   1.184 +    is(varOwners3[1], secondScope,
   1.185 +      "The second owner scope for the third variable is correct.");
   1.186 +
   1.187 +    // Test getParentScopesForVariableOrProperty with first-degree properties.
   1.188 +
   1.189 +    let propOwners1 = variables.getParentScopesForVariableOrProperty(calleeProp1);
   1.190 +    let propOwners2 = variables.getParentScopesForVariableOrProperty(calleeProp2);
   1.191 +    let propOwners3 = variables.getParentScopesForVariableOrProperty(calleeProp3);
   1.192 +
   1.193 +    is(propOwners1.length, 0,
   1.194 +      "There should be no owner scopes for the first property.");
   1.195 +
   1.196 +    is(propOwners2.length, 1,
   1.197 +      "There should be one owner scope for the second property.");
   1.198 +    is(propOwners2[0], firstScope,
   1.199 +      "The only owner scope for the second property is correct.");
   1.200 +
   1.201 +    is(propOwners3.length, 2,
   1.202 +      "There should be two owner scopes for the third property.");
   1.203 +    is(propOwners3[0], firstScope,
   1.204 +      "The first owner scope for the third property is correct.");
   1.205 +    is(propOwners3[1], secondScope,
   1.206 +      "The second owner scope for the third property is correct.");
   1.207 +
   1.208 +    // Test getParentScopesForVariableOrProperty with second-degree properties.
   1.209 +
   1.210 +    let secPropOwners1 = variables.getParentScopesForVariableOrProperty(constrProp1);
   1.211 +    let secPropOwners2 = variables.getParentScopesForVariableOrProperty(constrProp2);
   1.212 +    let secPropOwners3 = variables.getParentScopesForVariableOrProperty(constrProp3);
   1.213 +
   1.214 +    is(secPropOwners1.length, 0,
   1.215 +      "There should be no owner scopes for the first inner property.");
   1.216 +
   1.217 +    is(secPropOwners2.length, 1,
   1.218 +      "There should be one owner scope for the second inner property.");
   1.219 +    is(secPropOwners2[0], firstScope,
   1.220 +      "The only owner scope for the second inner property is correct.");
   1.221 +
   1.222 +    is(secPropOwners3.length, 2,
   1.223 +      "There should be two owner scopes for the third inner property.");
   1.224 +    is(secPropOwners3[0], firstScope,
   1.225 +      "The first owner scope for the third inner property is correct.");
   1.226 +    is(secPropOwners3[1], secondScope,
   1.227 +      "The second owner scope for the third inner property is correct.");
   1.228 +
   1.229 +    yield resumeDebuggerThenCloseAndFinish(panel);
   1.230 +  });
   1.231 +}

mercurial