1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/webconsole/test/browser_webconsole_output_dom_elements_02.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,98 @@ 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 the inspector links in the webconsole output for DOM Nodes actually 1.10 +// open the inspector and select the right node 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 +const TEST_DATA = [ 1.15 + { 1.16 + // The first test shouldn't be returning the body element as this is the 1.17 + // default selected node, so re-selecting it won't fire the inspector-updated 1.18 + // event 1.19 + input: "testNode()", 1.20 + output: '<p some-attribute="some-value">' 1.21 + }, 1.22 + { 1.23 + input: "testBodyNode()", 1.24 + output: '<body id="body-id" class="body-class">' 1.25 + }, 1.26 + { 1.27 + input: "testNodeInIframe()", 1.28 + output: '<p>' 1.29 + }, 1.30 + { 1.31 + input: "testDocumentElement()", 1.32 + output: '<html lang="en-US" dir="ltr">' 1.33 + } 1.34 +]; 1.35 + 1.36 +function test() { 1.37 + Task.spawn(function*() { 1.38 + let {tab} = yield loadTab(TEST_URI); 1.39 + let hud = yield openConsole(tab); 1.40 + let toolbox = gDevTools.getToolbox(hud.target); 1.41 + 1.42 + // Loading the inspector panel at first, to make it possible to listen for 1.43 + // new node selections 1.44 + yield toolbox.selectTool("inspector"); 1.45 + let inspector = toolbox.getCurrentPanel(); 1.46 + yield toolbox.selectTool("webconsole"); 1.47 + 1.48 + info("Iterating over the test data"); 1.49 + for (let data of TEST_DATA) { 1.50 + let [result] = yield jsEval(data.input, hud, {text: data.output}); 1.51 + let {widget, msg} = yield getWidgetAndMessage(result); 1.52 + 1.53 + let inspectorIcon = msg.querySelector(".open-inspector"); 1.54 + ok(inspectorIcon, "Inspector icon found in the ElementNode widget"); 1.55 + 1.56 + info("Clicking on the inspector icon and waiting for the inspector to be selected"); 1.57 + let onInspectorSelected = toolbox.once("inspector-selected"); 1.58 + let onInspectorUpdated = inspector.once("inspector-updated"); 1.59 + let onNewNode = toolbox.selection.once("new-node"); 1.60 + 1.61 + EventUtils.synthesizeMouseAtCenter(inspectorIcon, {}, 1.62 + inspectorIcon.ownerDocument.defaultView); 1.63 + yield onInspectorSelected; 1.64 + yield onInspectorUpdated; 1.65 + yield onNewNode; 1.66 + ok(true, "Inspector selected and new node got selected"); 1.67 + 1.68 + let rawNode = content.wrappedJSObject[data.input.replace(/\(\)/g, "")](); 1.69 + is(inspector.selection.node.wrappedJSObject, rawNode, 1.70 + "The current inspector selection is correct"); 1.71 + 1.72 + info("Switching back to the console"); 1.73 + yield toolbox.selectTool("webconsole"); 1.74 + } 1.75 + }).then(finishTest); 1.76 +} 1.77 + 1.78 +function jsEval(input, hud, message) { 1.79 + info("Executing '" + input + "' in the web console"); 1.80 + 1.81 + hud.jsterm.clearOutput(); 1.82 + hud.jsterm.execute(input); 1.83 + 1.84 + return waitForMessages({ 1.85 + webconsole: hud, 1.86 + messages: [message] 1.87 + }); 1.88 +} 1.89 + 1.90 +function* getWidgetAndMessage(result) { 1.91 + info("Getting the output ElementNode widget"); 1.92 + 1.93 + let msg = [...result.matched][0]; 1.94 + let widget = [...msg._messageObject.widgets][0]; 1.95 + ok(widget, "ElementNode widget found in the output"); 1.96 + 1.97 + info("Waiting for the ElementNode widget to be linked to the inspector"); 1.98 + yield widget.linkToInspector(); 1.99 + 1.100 + return {widget: widget, msg: msg}; 1.101 +}