browser/devtools/webconsole/test/browser_webconsole_output_dom_elements_03.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/webconsole/test/browser_webconsole_output_dom_elements_03.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,67 @@
     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 +// Test that inspector links in webconsole outputs for DOM Nodes highlight
    1.10 +// the actual DOM Nodes on hover
    1.11 +
    1.12 +const TEST_URI = "http://example.com/browser/browser/devtools/webconsole/test/test-console-output-dom-elements.html";
    1.13 +
    1.14 +function test() {
    1.15 +  Task.spawn(function*() {
    1.16 +    let {tab} = yield loadTab(TEST_URI);
    1.17 +    let hud = yield openConsole(tab);
    1.18 +    let toolbox = gDevTools.getToolbox(hud.target);
    1.19 +
    1.20 +    // Loading the inspector panel at first, to make it possible to listen for
    1.21 +    // new node selections
    1.22 +    yield toolbox.loadTool("inspector");
    1.23 +    let inspector = toolbox.getPanel("inspector");
    1.24 +
    1.25 +    info("Executing 'testNode()' in the web console to output a DOM Node");
    1.26 +    let [result] = yield jsEval("testNode()", hud, {
    1.27 +      text: '<p some-attribute="some-value">'
    1.28 +    });
    1.29 +
    1.30 +    let elementNodeWidget = yield getWidget(result);
    1.31 +
    1.32 +    let nodeFront = yield hoverOverWidget(elementNodeWidget, toolbox);
    1.33 +    let attrs = nodeFront.attributes;
    1.34 +    is(nodeFront.tagName, "P", "The correct node was highlighted");
    1.35 +    is(attrs[0].name, "some-attribute", "The correct node was highlighted");
    1.36 +    is(attrs[0].value, "some-value", "The correct node was highlighted");
    1.37 +  }).then(finishTest);
    1.38 +}
    1.39 +
    1.40 +function jsEval(input, hud, message) {
    1.41 +  hud.jsterm.execute(input);
    1.42 +  return waitForMessages({
    1.43 +    webconsole: hud,
    1.44 +    messages: [message]
    1.45 +  });
    1.46 +}
    1.47 +
    1.48 +function* getWidget(result) {
    1.49 +  info("Getting the output ElementNode widget");
    1.50 +
    1.51 +  let msg = [...result.matched][0];
    1.52 +  let elementNodeWidget = [...msg._messageObject.widgets][0];
    1.53 +  ok(elementNodeWidget, "ElementNode widget found in the output");
    1.54 +
    1.55 +  info("Waiting for the ElementNode widget to be linked to the inspector");
    1.56 +  yield elementNodeWidget.linkToInspector();
    1.57 +
    1.58 +  return elementNodeWidget;
    1.59 +}
    1.60 +
    1.61 +function* hoverOverWidget(widget, toolbox) {
    1.62 +  info("Hovering over the output to highlight the node");
    1.63 +
    1.64 +  let onHighlight = toolbox.once("node-highlight");
    1.65 +  EventUtils.sendMouseEvent({type: "mouseover"}, widget.element,
    1.66 +    widget.element.ownerDocument.defaultView);
    1.67 +  let nodeFront = yield onHighlight;
    1.68 +  ok(true, "The highlighter was shown on a node");
    1.69 +  return nodeFront;
    1.70 +}

mercurial