browser/devtools/webconsole/test/browser_console_variables_view_highlighter.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 /*
     2  * Any copyright is dedicated to the Public Domain.
     3  * http://creativecommons.org/publicdomain/zero/1.0/
     4  */
     6 // Check that variables view is linked to the inspector for highlighting and
     7 // selecting DOM nodes
     9 const TEST_URI = "http://example.com/browser/browser/devtools/webconsole/test/test-bug-952277-highlight-nodes-in-vview.html";
    11 let gWebConsole, gJSTerm, gVariablesView, gToolbox;
    13 function test()
    14 {
    15   addTab(TEST_URI);
    16   browser.addEventListener("load", function onLoad() {
    17     browser.removeEventListener("load", onLoad, true);
    18     openConsole(null, consoleOpened);
    19   }, true);
    20 }
    22 function consoleOpened(hud)
    23 {
    24   gWebConsole = hud;
    25   gJSTerm = hud.jsterm;
    26   gToolbox = gDevTools.getToolbox(hud.target);
    27   gJSTerm.execute("document.querySelectorAll('p')", onQSAexecuted);
    28 }
    30 function onQSAexecuted(msg)
    31 {
    32   ok(msg, "output message found");
    33   let anchor = msg.querySelector("a");
    34   ok(anchor, "object link found");
    36   gJSTerm.once("variablesview-fetched", onNodeListVviewFetched);
    38   executeSoon(() =>
    39     EventUtils.synthesizeMouse(anchor, 2, 2, {}, gWebConsole.iframeWindow)
    40   );
    41 }
    43 function onNodeListVviewFetched(aEvent, aVar)
    44 {
    45   gVariablesView = aVar._variablesView;
    46   ok(gVariablesView, "variables view object");
    48   // Transform the vview into an array we can filter properties from
    49   let props = [[id, prop] for([id, prop] of aVar)];
    50   // These properties are the DOM nodes ones
    51   props = props.filter(v => v[0].match(/[0-9]+/));
    53   function hoverOverDomNodeVariableAndAssertHighlighter(index) {
    54     if (props[index]) {
    55       let prop = props[index][1];
    56       let valueEl = prop._valueLabel;
    58       gToolbox.once("node-highlight", () => {
    59         ok(true, "The highlighter was shown on hover of the DOMNode");
    60         gToolbox.highlighterUtils.unhighlight().then(() => {
    61           clickOnDomNodeVariableAndAssertInspectorSelected(index);
    62         });
    63       });
    65       // Rather than trying to emulate a mouseenter event, let's call the
    66       // variable's highlightDomNode and see if it has the desired effect
    67       prop.highlightDomNode();
    68     } else {
    69       finishUp();
    70     }
    71   }
    73   function clickOnDomNodeVariableAndAssertInspectorSelected(index) {
    74     let prop = props[index][1];
    76     // Make sure the inspector is initialized so we can listen to its events
    77     gToolbox.initInspector().then(() => {
    78       // Rather than trying to click on the value here, let's just call the
    79       // variable's openNodeInInspector function and see if it has the
    80       // desired effect
    81       prop.openNodeInInspector().then(() => {
    82         is(gToolbox.currentToolId, "inspector", "The toolbox switched over the inspector on DOMNode click");
    83         gToolbox.selectTool("webconsole").then(() => {
    84           hoverOverDomNodeVariableAndAssertHighlighter(index + 1);
    85         });
    86       });
    87     });
    88   }
    90   hoverOverDomNodeVariableAndAssertHighlighter(0);
    91 }
    93 function finishUp() {
    94   gWebConsole = gJSTerm = gVariablesView = gToolbox = null;
    96   finishTest();
    97 }

mercurial