browser/devtools/debugger/test/browser_dbg_variables-view-frame-parameters-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  * Make sure that the variables view correctly displays the properties
     6  * of objects when debugger is paused.
     7  */
     9 const TAB_URL = EXAMPLE_URL + "doc_frame-parameters.html";
    11 let gTab, gDebuggee, gPanel, gDebugger;
    12 let gVariables;
    14 function test() {
    15   // Debug test slaves are a bit slow at this test.
    16   requestLongerTimeout(2);
    18   initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => {
    19     gTab = aTab;
    20     gDebuggee = aDebuggee;
    21     gPanel = aPanel;
    22     gDebugger = gPanel.panelWin;
    23     gVariables = gDebugger.DebuggerView.Variables;
    25     waitForSourceAndCaretAndScopes(gPanel, ".html", 24)
    26       .then(initialChecks)
    27       .then(testExpandVariables)
    28       .then(() => resumeDebuggerThenCloseAndFinish(gPanel))
    29       .then(null, aError => {
    30         ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
    31       });
    33     EventUtils.sendMouseEvent({ type: "click" },
    34       gDebuggee.document.querySelector("button"),
    35       gDebuggee);
    36   });
    37 }
    39 function initialChecks() {
    40   let scopeNodes = gDebugger.document.querySelectorAll(".variables-view-scope");
    41   is(scopeNodes.length, 2,
    42     "There should be 2 scopes available.");
    44   ok(scopeNodes[0].querySelector(".name").getAttribute("value").contains("[test]"),
    45     "The local scope should be properly identified.");
    46   ok(scopeNodes[1].querySelector(".name").getAttribute("value").contains("[Window]"),
    47     "The global scope should be properly identified.");
    49   is(gVariables.getScopeAtIndex(0).target, scopeNodes[0],
    50     "getScopeAtIndex(0) didn't return the expected scope.");
    51   is(gVariables.getScopeAtIndex(1).target, scopeNodes[1],
    52     "getScopeAtIndex(1) didn't return the expected scope.");
    54   is(gVariables.getItemForNode(scopeNodes[0]).target, scopeNodes[0],
    55     "getItemForNode([0]) didn't return the expected scope.");
    56   is(gVariables.getItemForNode(scopeNodes[1]).target, scopeNodes[1],
    57     "getItemForNode([1]) didn't return the expected scope.");
    59   is(gVariables.getItemForNode(scopeNodes[0]).expanded, true,
    60     "The local scope should be expanded by default.");
    61   is(gVariables.getItemForNode(scopeNodes[1]).expanded, false,
    62     "The global scope should not be collapsed by default.");
    63 }
    65 function testExpandVariables() {
    66   let deferred = promise.defer();
    68   let localScope = gVariables.getScopeAtIndex(0);
    69   let localEnums = localScope.target.querySelector(".variables-view-element-details.enum").childNodes;
    71   let thisVar = gVariables.getItemForNode(localEnums[0]);
    72   let argsVar = gVariables.getItemForNode(localEnums[8]);
    73   let cVar = gVariables.getItemForNode(localEnums[10]);
    75   is(thisVar.target.querySelector(".name").getAttribute("value"), "this",
    76     "Should have the right property name for 'this'.");
    77   is(argsVar.target.querySelector(".name").getAttribute("value"), "arguments",
    78     "Should have the right property name for 'arguments'.");
    79   is(cVar.target.querySelector(".name").getAttribute("value"), "c",
    80     "Should have the right property name for 'c'.");
    82   is(thisVar.expanded, false,
    83     "The thisVar should not be expanded at this point.");
    84   is(argsVar.expanded, false,
    85     "The argsVar should not be expanded at this point.");
    86   is(cVar.expanded, false,
    87     "The cVar should not be expanded at this point.");
    89   waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_PROPERTIES, 3).then(() => {
    90     is(thisVar.get("window").target.querySelector(".name").getAttribute("value"), "window",
    91       "Should have the right property name for 'window'.");
    92     is(thisVar.get("window").target.querySelector(".value").getAttribute("value"),
    93       "Window \u2192 doc_frame-parameters.html",
    94       "Should have the right property value for 'window'.");
    95     ok(thisVar.get("window").target.querySelector(".value").className.contains("token-other"),
    96       "Should have the right token class for 'window'.");
    98     is(thisVar.get("document").target.querySelector(".name").getAttribute("value"), "document",
    99       "Should have the right property name for 'document'.");
   100     is(thisVar.get("document").target.querySelector(".value").getAttribute("value"),
   101       "HTMLDocument \u2192 doc_frame-parameters.html",
   102       "Should have the right property value for 'document'.");
   103     ok(thisVar.get("document").target.querySelector(".value").className.contains("token-domnode"),
   104       "Should have the right token class for 'document'.");
   106     let argsProps = argsVar.target.querySelectorAll(".variables-view-property");
   107     is(argsProps.length, 8,
   108       "The 'arguments' variable should contain 5 enumerable and 3 non-enumerable properties");
   110     is(argsProps[0].querySelector(".name").getAttribute("value"), "0",
   111       "Should have the right property name for '0'.");
   112     is(argsProps[0].querySelector(".value").getAttribute("value"), "Object",
   113       "Should have the right property value for '0'.");
   114     ok(argsProps[0].querySelector(".value").className.contains("token-other"),
   115       "Should have the right token class for '0'.");
   117     is(argsProps[1].querySelector(".name").getAttribute("value"), "1",
   118       "Should have the right property name for '1'.");
   119     is(argsProps[1].querySelector(".value").getAttribute("value"), "\"beta\"",
   120       "Should have the right property value for '1'.");
   121     ok(argsProps[1].querySelector(".value").className.contains("token-string"),
   122       "Should have the right token class for '1'.");
   124     is(argsProps[2].querySelector(".name").getAttribute("value"), "2",
   125       "Should have the right property name for '2'.");
   126     is(argsProps[2].querySelector(".value").getAttribute("value"), "3",
   127       "Should have the right property name for '2'.");
   128     ok(argsProps[2].querySelector(".value").className.contains("token-number"),
   129       "Should have the right token class for '2'.");
   131     is(argsProps[3].querySelector(".name").getAttribute("value"), "3",
   132       "Should have the right property name for '3'.");
   133     is(argsProps[3].querySelector(".value").getAttribute("value"), "false",
   134       "Should have the right property value for '3'.");
   135     ok(argsProps[3].querySelector(".value").className.contains("token-boolean"),
   136       "Should have the right token class for '3'.");
   138     is(argsProps[4].querySelector(".name").getAttribute("value"), "4",
   139       "Should have the right property name for '4'.");
   140     is(argsProps[4].querySelector(".value").getAttribute("value"), "null",
   141       "Should have the right property name for '4'.");
   142     ok(argsProps[4].querySelector(".value").className.contains("token-null"),
   143       "Should have the right token class for '4'.");
   145     is(gVariables.getItemForNode(argsProps[0]).target,
   146        argsVar.target.querySelectorAll(".variables-view-property")[0],
   147       "getItemForNode([0]) didn't return the expected property.");
   149     is(gVariables.getItemForNode(argsProps[1]).target,
   150        argsVar.target.querySelectorAll(".variables-view-property")[1],
   151       "getItemForNode([1]) didn't return the expected property.");
   153     is(gVariables.getItemForNode(argsProps[2]).target,
   154        argsVar.target.querySelectorAll(".variables-view-property")[2],
   155       "getItemForNode([2]) didn't return the expected property.");
   157     is(argsVar.find(argsProps[0]).target,
   158        argsVar.target.querySelectorAll(".variables-view-property")[0],
   159       "find([0]) didn't return the expected property.");
   161     is(argsVar.find(argsProps[1]).target,
   162        argsVar.target.querySelectorAll(".variables-view-property")[1],
   163       "find([1]) didn't return the expected property.");
   165     is(argsVar.find(argsProps[2]).target,
   166        argsVar.target.querySelectorAll(".variables-view-property")[2],
   167       "find([2]) didn't return the expected property.");
   169     let cProps = cVar.target.querySelectorAll(".variables-view-property");
   170     is(cProps.length, 7,
   171       "The 'c' variable should contain 6 enumerable and 1 non-enumerable properties");
   173     is(cProps[0].querySelector(".name").getAttribute("value"), "a",
   174       "Should have the right property name for 'a'.");
   175     is(cProps[0].querySelector(".value").getAttribute("value"), "1",
   176       "Should have the right property value for 'a'.");
   177     ok(cProps[0].querySelector(".value").className.contains("token-number"),
   178       "Should have the right token class for 'a'.");
   180     is(cProps[1].querySelector(".name").getAttribute("value"), "b",
   181       "Should have the right property name for 'b'.");
   182     is(cProps[1].querySelector(".value").getAttribute("value"), "\"beta\"",
   183       "Should have the right property value for 'b'.");
   184     ok(cProps[1].querySelector(".value").className.contains("token-string"),
   185       "Should have the right token class for 'b'.");
   187     is(cProps[2].querySelector(".name").getAttribute("value"), "c",
   188       "Should have the right property name for 'c'.");
   189     is(cProps[2].querySelector(".value").getAttribute("value"), "3",
   190       "Should have the right property value for 'c'.");
   191     ok(cProps[2].querySelector(".value").className.contains("token-number"),
   192       "Should have the right token class for 'c'.");
   194     is(cProps[3].querySelector(".name").getAttribute("value"), "d",
   195       "Should have the right property name for 'd'.");
   196     is(cProps[3].querySelector(".value").getAttribute("value"), "false",
   197       "Should have the right property value for 'd'.");
   198     ok(cProps[3].querySelector(".value").className.contains("token-boolean"),
   199       "Should have the right token class for 'd'.");
   201     is(cProps[4].querySelector(".name").getAttribute("value"), "e",
   202       "Should have the right property name for 'e'.");
   203     is(cProps[4].querySelector(".value").getAttribute("value"), "null",
   204       "Should have the right property value for 'e'.");
   205     ok(cProps[4].querySelector(".value").className.contains("token-null"),
   206       "Should have the right token class for 'e'.");
   208     is(cProps[5].querySelector(".name").getAttribute("value"), "f",
   209       "Should have the right property name for 'f'.");
   210     is(cProps[5].querySelector(".value").getAttribute("value"), "undefined",
   211       "Should have the right property value for 'f'.");
   212     ok(cProps[5].querySelector(".value").className.contains("token-undefined"),
   213       "Should have the right token class for 'f'.");
   215     is(gVariables.getItemForNode(cProps[0]).target,
   216        cVar.target.querySelectorAll(".variables-view-property")[0],
   217       "getItemForNode([0]) didn't return the expected property.");
   219     is(gVariables.getItemForNode(cProps[1]).target,
   220        cVar.target.querySelectorAll(".variables-view-property")[1],
   221       "getItemForNode([1]) didn't return the expected property.");
   223     is(gVariables.getItemForNode(cProps[2]).target,
   224        cVar.target.querySelectorAll(".variables-view-property")[2],
   225       "getItemForNode([2]) didn't return the expected property.");
   227     is(cVar.find(cProps[0]).target,
   228        cVar.target.querySelectorAll(".variables-view-property")[0],
   229       "find([0]) didn't return the expected property.");
   231     is(cVar.find(cProps[1]).target,
   232        cVar.target.querySelectorAll(".variables-view-property")[1],
   233       "find([1]) didn't return the expected property.");
   235     is(cVar.find(cProps[2]).target,
   236        cVar.target.querySelectorAll(".variables-view-property")[2],
   237       "find([2]) didn't return the expected property.");
   238   });
   240   // Expand the 'this', 'arguments' and 'c' variables view nodes. This causes
   241   // their properties to be retrieved and displayed.
   242   thisVar.expand();
   243   argsVar.expand();
   244   cVar.expand();
   246   is(thisVar.expanded, true,
   247     "The thisVar should be immediately marked as expanded.");
   248   is(argsVar.expanded, true,
   249     "The argsVar should be immediately marked as expanded.");
   250   is(cVar.expanded, true,
   251     "The cVar should be immediately marked as expanded.");
   252 }
   254 registerCleanupFunction(function() {
   255   gTab = null;
   256   gDebuggee = null;
   257   gPanel = null;
   258   gDebugger = null;
   259   gVariables = null;
   260 });

mercurial