browser/devtools/debugger/test/browser_dbg_variables-view-frame-with.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  * Make sure that the variables view is correctly populated in 'with' frames.
     6  */
     8 const TAB_URL = EXAMPLE_URL + "doc_with-frame.html";
    10 let gTab, gDebuggee, gPanel, gDebugger;
    11 let gVariables;
    13 function test() {
    14   initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => {
    15     gTab = aTab;
    16     gDebuggee = aDebuggee;
    17     gPanel = aPanel;
    18     gDebugger = gPanel.panelWin;
    19     gVariables = gDebugger.DebuggerView.Variables;
    21     // The first 'with' scope should be expanded by default, but the
    22     // variables haven't been fetched yet. This is how 'with' scopes work.
    23     promise.all([
    24       waitForSourceAndCaret(gPanel, ".html", 22),
    25       waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_SCOPES),
    26       waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_VARIABLES)
    27     ]).then(testFirstWithScope)
    28       .then(expandSecondWithScope)
    29       .then(testSecondWithScope)
    30       .then(expandFunctionScope)
    31       .then(testFunctionScope)
    32       .then(() => resumeDebuggerThenCloseAndFinish(gPanel))
    33       .then(null, aError => {
    34         ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
    35       });
    37     EventUtils.sendMouseEvent({ type: "click" },
    38       gDebuggee.document.querySelector("button"),
    39       gDebuggee);
    40   });
    41 }
    43 function testFirstWithScope() {
    44   let firstWithScope = gVariables.getScopeAtIndex(0);
    45   is(firstWithScope.expanded, true,
    46     "The first 'with' scope should be expanded by default.");
    47   ok(firstWithScope.target.querySelector(".name").getAttribute("value").contains("[Object]"),
    48     "The first 'with' scope should be properly identified.");
    50   let withEnums = firstWithScope._enum.childNodes;
    51   let withNonEnums = firstWithScope._nonenum.childNodes;
    53   is(withEnums.length, 3,
    54     "The first 'with' scope should contain all the created enumerable elements.");
    55   is(withNonEnums.length, 1,
    56     "The first 'with' scope should contain all the created non-enumerable elements.");
    58   is(withEnums[0].querySelector(".name").getAttribute("value"), "this",
    59     "Should have the right property name for 'this'.");
    60   is(withEnums[0].querySelector(".value").getAttribute("value"),
    61     "Window \u2192 doc_with-frame.html",
    62     "Should have the right property value for 'this'.");
    63   ok(withEnums[0].querySelector(".value").className.contains("token-other"),
    64     "Should have the right token class for 'this'.");
    66   is(withEnums[1].querySelector(".name").getAttribute("value"), "alpha",
    67     "Should have the right property name for 'alpha'.");
    68   is(withEnums[1].querySelector(".value").getAttribute("value"), "1",
    69     "Should have the right property value for 'alpha'.");
    70   ok(withEnums[1].querySelector(".value").className.contains("token-number"),
    71     "Should have the right token class for 'alpha'.");
    73   is(withEnums[2].querySelector(".name").getAttribute("value"), "beta",
    74     "Should have the right property name for 'beta'.");
    75   is(withEnums[2].querySelector(".value").getAttribute("value"), "2",
    76     "Should have the right property value for 'beta'.");
    77   ok(withEnums[2].querySelector(".value").className.contains("token-number"),
    78     "Should have the right token class for 'beta'.");
    80   is(withNonEnums[0].querySelector(".name").getAttribute("value"), "__proto__",
    81    "Should have the right property name for '__proto__'.");
    82   is(withNonEnums[0].querySelector(".value").getAttribute("value"), "Object",
    83    "Should have the right property value for '__proto__'.");
    84   ok(withNonEnums[0].querySelector(".value").className.contains("token-other"),
    85    "Should have the right token class for '__proto__'.");
    86 }
    88 function expandSecondWithScope() {
    89   let deferred = promise.defer();
    91   let secondWithScope = gVariables.getScopeAtIndex(1);
    92   is(secondWithScope.expanded, false,
    93     "The second 'with' scope should not be expanded by default.");
    95   gDebugger.once(gDebugger.EVENTS.FETCHED_VARIABLES, deferred.resolve);
    97   EventUtils.sendMouseEvent({ type: "mousedown" },
    98     secondWithScope.target.querySelector(".name"),
    99     gDebugger);
   101   return deferred.promise;
   102 }
   104 function testSecondWithScope() {
   105   let secondWithScope = gVariables.getScopeAtIndex(1);
   106   is(secondWithScope.expanded, true,
   107     "The second 'with' scope should now be expanded.");
   108   ok(secondWithScope.target.querySelector(".name").getAttribute("value").contains("[Math]"),
   109     "The second 'with' scope should be properly identified.");
   111   let withEnums = secondWithScope._enum.childNodes;
   112   let withNonEnums = secondWithScope._nonenum.childNodes;
   114   is(withEnums.length, 0,
   115     "The second 'with' scope should contain all the created enumerable elements.");
   116   isnot(withNonEnums.length, 0,
   117     "The second 'with' scope should contain all the created non-enumerable elements.");
   119   is(secondWithScope.get("E").target.querySelector(".name").getAttribute("value"), "E",
   120     "Should have the right property name for 'E'.");
   121   is(secondWithScope.get("E").target.querySelector(".value").getAttribute("value"), "2.718281828459045",
   122     "Should have the right property value for 'E'.");
   123   ok(secondWithScope.get("E").target.querySelector(".value").className.contains("token-number"),
   124     "Should have the right token class for 'E'.");
   126   is(secondWithScope.get("PI").target.querySelector(".name").getAttribute("value"), "PI",
   127     "Should have the right property name for 'PI'.");
   128   is(secondWithScope.get("PI").target.querySelector(".value").getAttribute("value"), "3.141592653589793",
   129     "Should have the right property value for 'PI'.");
   130   ok(secondWithScope.get("PI").target.querySelector(".value").className.contains("token-number"),
   131     "Should have the right token class for 'PI'.");
   133   is(secondWithScope.get("random").target.querySelector(".name").getAttribute("value"), "random",
   134     "Should have the right property name for 'random'.");
   135   is(secondWithScope.get("random").target.querySelector(".value").getAttribute("value"), "random()",
   136     "Should have the right property value for 'random'.");
   137   ok(secondWithScope.get("random").target.querySelector(".value").className.contains("token-other"),
   138     "Should have the right token class for 'random'.");
   140   is(secondWithScope.get("__proto__").target.querySelector(".name").getAttribute("value"), "__proto__",
   141     "Should have the right property name for '__proto__'.");
   142   is(secondWithScope.get("__proto__").target.querySelector(".value").getAttribute("value"), "Object",
   143     "Should have the right property value for '__proto__'.");
   144   ok(secondWithScope.get("__proto__").target.querySelector(".value").className.contains("token-other"),
   145     "Should have the right token class for '__proto__'.");
   146 }
   148 function expandFunctionScope() {
   149   let funcScope = gVariables.getScopeAtIndex(2);
   150   is(funcScope.expanded, false,
   151     "The function scope shouldn't be expanded by default, but the " +
   152     "variables have been already fetched. This is how local scopes work.");
   154   EventUtils.sendMouseEvent({ type: "mousedown" },
   155     funcScope.target.querySelector(".name"),
   156     gDebugger);
   158   return promise.resolve(null);
   159 }
   161 function testFunctionScope() {
   162   let funcScope = gVariables.getScopeAtIndex(2);
   163   is(funcScope.expanded, true,
   164     "The function scope should now be expanded.");
   165   ok(funcScope.target.querySelector(".name").getAttribute("value").contains("[test]"),
   166     "The function scope should be properly identified.");
   168   let funcEnums = funcScope._enum.childNodes;
   169   let funcNonEnums = funcScope._nonenum.childNodes;
   171   is(funcEnums.length, 6,
   172     "The function scope should contain all the created enumerable elements.");
   173   is(funcNonEnums.length, 0,
   174     "The function scope should contain all the created non-enumerable elements.");
   176   is(funcScope.get("aNumber").target.querySelector(".name").getAttribute("value"), "aNumber",
   177     "Should have the right property name for 'aNumber'.");
   178   is(funcScope.get("aNumber").target.querySelector(".value").getAttribute("value"), "10",
   179     "Should have the right property value for 'aNumber'.");
   180   ok(funcScope.get("aNumber").target.querySelector(".value").className.contains("token-number"),
   181     "Should have the right token class for 'aNumber'.");
   183   is(funcScope.get("a").target.querySelector(".name").getAttribute("value"), "a",
   184     "Should have the right property name for 'a'.");
   185   is(funcScope.get("a").target.querySelector(".value").getAttribute("value"), "314.1592653589793",
   186     "Should have the right property value for 'a'.");
   187   ok(funcScope.get("a").target.querySelector(".value").className.contains("token-number"),
   188     "Should have the right token class for 'a'.");
   190   is(funcScope.get("r").target.querySelector(".name").getAttribute("value"), "r",
   191     "Should have the right property name for 'r'.");
   192   is(funcScope.get("r").target.querySelector(".value").getAttribute("value"), "10",
   193     "Should have the right property value for 'r'.");
   194   ok(funcScope.get("r").target.querySelector(".value").className.contains("token-number"),
   195     "Should have the right token class for 'r'.");
   197   is(funcScope.get("foo").target.querySelector(".name").getAttribute("value"), "foo",
   198     "Should have the right property name for 'foo'.");
   199   is(funcScope.get("foo").target.querySelector(".value").getAttribute("value"), "6.283185307179586",
   200     "Should have the right property value for 'foo'.");
   201   ok(funcScope.get("foo").target.querySelector(".value").className.contains("token-number"),
   202     "Should have the right token class for 'foo'.");
   203 }
   205 registerCleanupFunction(function() {
   206   gTab = null;
   207   gDebuggee = null;
   208   gPanel = null;
   209   gDebugger = null;
   210   gVariables = null;
   211 });

mercurial