browser/devtools/webconsole/test/browser_webconsole_output_dom_elements_03.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.

michael@0 1 /*
michael@0 2 * Any copyright is dedicated to the Public Domain.
michael@0 3 * http://creativecommons.org/publicdomain/zero/1.0/
michael@0 4 */
michael@0 5
michael@0 6 // Test that inspector links in webconsole outputs for DOM Nodes highlight
michael@0 7 // the actual DOM Nodes on hover
michael@0 8
michael@0 9 const TEST_URI = "http://example.com/browser/browser/devtools/webconsole/test/test-console-output-dom-elements.html";
michael@0 10
michael@0 11 function test() {
michael@0 12 Task.spawn(function*() {
michael@0 13 let {tab} = yield loadTab(TEST_URI);
michael@0 14 let hud = yield openConsole(tab);
michael@0 15 let toolbox = gDevTools.getToolbox(hud.target);
michael@0 16
michael@0 17 // Loading the inspector panel at first, to make it possible to listen for
michael@0 18 // new node selections
michael@0 19 yield toolbox.loadTool("inspector");
michael@0 20 let inspector = toolbox.getPanel("inspector");
michael@0 21
michael@0 22 info("Executing 'testNode()' in the web console to output a DOM Node");
michael@0 23 let [result] = yield jsEval("testNode()", hud, {
michael@0 24 text: '<p some-attribute="some-value">'
michael@0 25 });
michael@0 26
michael@0 27 let elementNodeWidget = yield getWidget(result);
michael@0 28
michael@0 29 let nodeFront = yield hoverOverWidget(elementNodeWidget, toolbox);
michael@0 30 let attrs = nodeFront.attributes;
michael@0 31 is(nodeFront.tagName, "P", "The correct node was highlighted");
michael@0 32 is(attrs[0].name, "some-attribute", "The correct node was highlighted");
michael@0 33 is(attrs[0].value, "some-value", "The correct node was highlighted");
michael@0 34 }).then(finishTest);
michael@0 35 }
michael@0 36
michael@0 37 function jsEval(input, hud, message) {
michael@0 38 hud.jsterm.execute(input);
michael@0 39 return waitForMessages({
michael@0 40 webconsole: hud,
michael@0 41 messages: [message]
michael@0 42 });
michael@0 43 }
michael@0 44
michael@0 45 function* getWidget(result) {
michael@0 46 info("Getting the output ElementNode widget");
michael@0 47
michael@0 48 let msg = [...result.matched][0];
michael@0 49 let elementNodeWidget = [...msg._messageObject.widgets][0];
michael@0 50 ok(elementNodeWidget, "ElementNode widget found in the output");
michael@0 51
michael@0 52 info("Waiting for the ElementNode widget to be linked to the inspector");
michael@0 53 yield elementNodeWidget.linkToInspector();
michael@0 54
michael@0 55 return elementNodeWidget;
michael@0 56 }
michael@0 57
michael@0 58 function* hoverOverWidget(widget, toolbox) {
michael@0 59 info("Hovering over the output to highlight the node");
michael@0 60
michael@0 61 let onHighlight = toolbox.once("node-highlight");
michael@0 62 EventUtils.sendMouseEvent({type: "mouseover"}, widget.element,
michael@0 63 widget.element.ownerDocument.defaultView);
michael@0 64 let nodeFront = yield onHighlight;
michael@0 65 ok(true, "The highlighter was shown on a node");
michael@0 66 return nodeFront;
michael@0 67 }

mercurial