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