|
1 /* |
|
2 * Any copyright is dedicated to the Public Domain. |
|
3 * http://creativecommons.org/publicdomain/zero/1.0/ |
|
4 */ |
|
5 |
|
6 // Test the inspector links in the webconsole output for DOM Nodes actually |
|
7 // open the inspector and select the right node |
|
8 |
|
9 const TEST_URI = "http://example.com/browser/browser/devtools/webconsole/test/test-console-output-dom-elements.html"; |
|
10 |
|
11 const TEST_DATA = [ |
|
12 { |
|
13 // The first test shouldn't be returning the body element as this is the |
|
14 // default selected node, so re-selecting it won't fire the inspector-updated |
|
15 // event |
|
16 input: "testNode()", |
|
17 output: '<p some-attribute="some-value">' |
|
18 }, |
|
19 { |
|
20 input: "testBodyNode()", |
|
21 output: '<body id="body-id" class="body-class">' |
|
22 }, |
|
23 { |
|
24 input: "testNodeInIframe()", |
|
25 output: '<p>' |
|
26 }, |
|
27 { |
|
28 input: "testDocumentElement()", |
|
29 output: '<html lang="en-US" dir="ltr">' |
|
30 } |
|
31 ]; |
|
32 |
|
33 function test() { |
|
34 Task.spawn(function*() { |
|
35 let {tab} = yield loadTab(TEST_URI); |
|
36 let hud = yield openConsole(tab); |
|
37 let toolbox = gDevTools.getToolbox(hud.target); |
|
38 |
|
39 // Loading the inspector panel at first, to make it possible to listen for |
|
40 // new node selections |
|
41 yield toolbox.selectTool("inspector"); |
|
42 let inspector = toolbox.getCurrentPanel(); |
|
43 yield toolbox.selectTool("webconsole"); |
|
44 |
|
45 info("Iterating over the test data"); |
|
46 for (let data of TEST_DATA) { |
|
47 let [result] = yield jsEval(data.input, hud, {text: data.output}); |
|
48 let {widget, msg} = yield getWidgetAndMessage(result); |
|
49 |
|
50 let inspectorIcon = msg.querySelector(".open-inspector"); |
|
51 ok(inspectorIcon, "Inspector icon found in the ElementNode widget"); |
|
52 |
|
53 info("Clicking on the inspector icon and waiting for the inspector to be selected"); |
|
54 let onInspectorSelected = toolbox.once("inspector-selected"); |
|
55 let onInspectorUpdated = inspector.once("inspector-updated"); |
|
56 let onNewNode = toolbox.selection.once("new-node"); |
|
57 |
|
58 EventUtils.synthesizeMouseAtCenter(inspectorIcon, {}, |
|
59 inspectorIcon.ownerDocument.defaultView); |
|
60 yield onInspectorSelected; |
|
61 yield onInspectorUpdated; |
|
62 yield onNewNode; |
|
63 ok(true, "Inspector selected and new node got selected"); |
|
64 |
|
65 let rawNode = content.wrappedJSObject[data.input.replace(/\(\)/g, "")](); |
|
66 is(inspector.selection.node.wrappedJSObject, rawNode, |
|
67 "The current inspector selection is correct"); |
|
68 |
|
69 info("Switching back to the console"); |
|
70 yield toolbox.selectTool("webconsole"); |
|
71 } |
|
72 }).then(finishTest); |
|
73 } |
|
74 |
|
75 function jsEval(input, hud, message) { |
|
76 info("Executing '" + input + "' in the web console"); |
|
77 |
|
78 hud.jsterm.clearOutput(); |
|
79 hud.jsterm.execute(input); |
|
80 |
|
81 return waitForMessages({ |
|
82 webconsole: hud, |
|
83 messages: [message] |
|
84 }); |
|
85 } |
|
86 |
|
87 function* getWidgetAndMessage(result) { |
|
88 info("Getting the output ElementNode widget"); |
|
89 |
|
90 let msg = [...result.matched][0]; |
|
91 let widget = [...msg._messageObject.widgets][0]; |
|
92 ok(widget, "ElementNode widget found in the output"); |
|
93 |
|
94 info("Waiting for the ElementNode widget to be linked to the inspector"); |
|
95 yield widget.linkToInspector(); |
|
96 |
|
97 return {widget: widget, msg: msg}; |
|
98 } |