browser/devtools/webconsole/test/browser_console_variables_view_highlighter.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/webconsole/test/browser_console_variables_view_highlighter.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,97 @@
     1.4 +/*
     1.5 + * Any copyright is dedicated to the Public Domain.
     1.6 + * http://creativecommons.org/publicdomain/zero/1.0/
     1.7 + */
     1.8 +
     1.9 +// Check that variables view is linked to the inspector for highlighting and
    1.10 +// selecting DOM nodes
    1.11 +
    1.12 +const TEST_URI = "http://example.com/browser/browser/devtools/webconsole/test/test-bug-952277-highlight-nodes-in-vview.html";
    1.13 +
    1.14 +let gWebConsole, gJSTerm, gVariablesView, gToolbox;
    1.15 +
    1.16 +function test()
    1.17 +{
    1.18 +  addTab(TEST_URI);
    1.19 +  browser.addEventListener("load", function onLoad() {
    1.20 +    browser.removeEventListener("load", onLoad, true);
    1.21 +    openConsole(null, consoleOpened);
    1.22 +  }, true);
    1.23 +}
    1.24 +
    1.25 +function consoleOpened(hud)
    1.26 +{
    1.27 +  gWebConsole = hud;
    1.28 +  gJSTerm = hud.jsterm;
    1.29 +  gToolbox = gDevTools.getToolbox(hud.target);
    1.30 +  gJSTerm.execute("document.querySelectorAll('p')", onQSAexecuted);
    1.31 +}
    1.32 +
    1.33 +function onQSAexecuted(msg)
    1.34 +{
    1.35 +  ok(msg, "output message found");
    1.36 +  let anchor = msg.querySelector("a");
    1.37 +  ok(anchor, "object link found");
    1.38 +
    1.39 +  gJSTerm.once("variablesview-fetched", onNodeListVviewFetched);
    1.40 +
    1.41 +  executeSoon(() =>
    1.42 +    EventUtils.synthesizeMouse(anchor, 2, 2, {}, gWebConsole.iframeWindow)
    1.43 +  );
    1.44 +}
    1.45 +
    1.46 +function onNodeListVviewFetched(aEvent, aVar)
    1.47 +{
    1.48 +  gVariablesView = aVar._variablesView;
    1.49 +  ok(gVariablesView, "variables view object");
    1.50 +
    1.51 +  // Transform the vview into an array we can filter properties from
    1.52 +  let props = [[id, prop] for([id, prop] of aVar)];
    1.53 +  // These properties are the DOM nodes ones
    1.54 +  props = props.filter(v => v[0].match(/[0-9]+/));
    1.55 +
    1.56 +  function hoverOverDomNodeVariableAndAssertHighlighter(index) {
    1.57 +    if (props[index]) {
    1.58 +      let prop = props[index][1];
    1.59 +      let valueEl = prop._valueLabel;
    1.60 +
    1.61 +      gToolbox.once("node-highlight", () => {
    1.62 +        ok(true, "The highlighter was shown on hover of the DOMNode");
    1.63 +        gToolbox.highlighterUtils.unhighlight().then(() => {
    1.64 +          clickOnDomNodeVariableAndAssertInspectorSelected(index);
    1.65 +        });
    1.66 +      });
    1.67 +
    1.68 +      // Rather than trying to emulate a mouseenter event, let's call the
    1.69 +      // variable's highlightDomNode and see if it has the desired effect
    1.70 +      prop.highlightDomNode();
    1.71 +    } else {
    1.72 +      finishUp();
    1.73 +    }
    1.74 +  }
    1.75 +
    1.76 +  function clickOnDomNodeVariableAndAssertInspectorSelected(index) {
    1.77 +    let prop = props[index][1];
    1.78 +
    1.79 +    // Make sure the inspector is initialized so we can listen to its events
    1.80 +    gToolbox.initInspector().then(() => {
    1.81 +      // Rather than trying to click on the value here, let's just call the
    1.82 +      // variable's openNodeInInspector function and see if it has the
    1.83 +      // desired effect
    1.84 +      prop.openNodeInInspector().then(() => {
    1.85 +        is(gToolbox.currentToolId, "inspector", "The toolbox switched over the inspector on DOMNode click");
    1.86 +        gToolbox.selectTool("webconsole").then(() => {
    1.87 +          hoverOverDomNodeVariableAndAssertHighlighter(index + 1);
    1.88 +        });
    1.89 +      });
    1.90 +    });
    1.91 +  }
    1.92 +
    1.93 +  hoverOverDomNodeVariableAndAssertHighlighter(0);
    1.94 +}
    1.95 +
    1.96 +function finishUp() {
    1.97 +  gWebConsole = gJSTerm = gVariablesView = gToolbox = null;
    1.98 +
    1.99 +  finishTest();
   1.100 +}

mercurial