|
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 the webconsole output for DOM Nodes do not try |
|
7 // to highlight or select nodes once they have been detached |
|
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 const PREF = "devtools.webconsole.persistlog"; |
|
34 |
|
35 function test() { |
|
36 Services.prefs.setBoolPref(PREF, true); |
|
37 registerCleanupFunction(() => Services.prefs.clearUserPref(PREF)); |
|
38 |
|
39 Task.spawn(function*() { |
|
40 let {tab} = yield loadTab(TEST_URI); |
|
41 let hud = yield openConsole(tab); |
|
42 let toolbox = gDevTools.getToolbox(hud.target); |
|
43 |
|
44 info("Executing the test data"); |
|
45 let widgets = []; |
|
46 for (let data of TEST_DATA) { |
|
47 let [result] = yield jsEval(data.input, hud, {text: data.output}); |
|
48 let {widget} = yield getWidgetAndMessage(result); |
|
49 widgets.push(widget); |
|
50 } |
|
51 |
|
52 info("Reloading the page"); |
|
53 yield reloadPage(); |
|
54 |
|
55 info("Iterating over the ElementNode widgets"); |
|
56 for (let widget of widgets) { |
|
57 // Verify that openNodeInInspector rejects since the associated dom node |
|
58 // doesn't exist anymore |
|
59 yield widget.openNodeInInspector().then(() => { |
|
60 ok(false, "The openNodeInInspector promise resolved"); |
|
61 }, () => { |
|
62 ok(true, "The openNodeInInspector promise rejected as expected"); |
|
63 }); |
|
64 yield toolbox.selectTool("webconsole"); |
|
65 |
|
66 // Verify that highlightDomNode rejects too, for the same reason |
|
67 yield widget.highlightDomNode().then(() => { |
|
68 ok(false, "The highlightDomNode promise resolved"); |
|
69 }, () => { |
|
70 ok(true, "The highlightDomNode promise rejected as expected"); |
|
71 }); |
|
72 } |
|
73 }).then(finishTest); |
|
74 } |
|
75 |
|
76 function jsEval(input, hud, message) { |
|
77 info("Executing '" + input + "' in the web console"); |
|
78 hud.jsterm.execute(input); |
|
79 return waitForMessages({ |
|
80 webconsole: hud, |
|
81 messages: [message] |
|
82 }); |
|
83 } |
|
84 |
|
85 function* getWidgetAndMessage(result) { |
|
86 info("Getting the output ElementNode widget"); |
|
87 |
|
88 let msg = [...result.matched][0]; |
|
89 let widget = [...msg._messageObject.widgets][0]; |
|
90 ok(widget, "ElementNode widget found in the output"); |
|
91 |
|
92 info("Waiting for the ElementNode widget to be linked to the inspector"); |
|
93 yield widget.linkToInspector(); |
|
94 |
|
95 return {widget: widget, msg: msg}; |
|
96 } |
|
97 |
|
98 function reloadPage() { |
|
99 let def = promise.defer(); |
|
100 gBrowser.selectedBrowser.addEventListener("load", function onload() { |
|
101 gBrowser.selectedBrowser.removeEventListener("load", onload, true); |
|
102 def.resolve(); |
|
103 }, true); |
|
104 content.location.reload(); |
|
105 return def.promise; |
|
106 } |