michael@0: /* michael@0: * Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ michael@0: */ michael@0: michael@0: // Test the inspector links in the webconsole output for DOM Nodes actually michael@0: // open the inspector and select the right node michael@0: michael@0: const TEST_URI = "http://example.com/browser/browser/devtools/webconsole/test/test-console-output-dom-elements.html"; michael@0: michael@0: const TEST_DATA = [ michael@0: { michael@0: // The first test shouldn't be returning the body element as this is the michael@0: // default selected node, so re-selecting it won't fire the inspector-updated michael@0: // event michael@0: input: "testNode()", michael@0: output: '

' michael@0: }, michael@0: { michael@0: input: "testBodyNode()", michael@0: output: '' michael@0: }, michael@0: { michael@0: input: "testNodeInIframe()", michael@0: output: '

' michael@0: }, michael@0: { michael@0: input: "testDocumentElement()", michael@0: output: '' michael@0: } michael@0: ]; michael@0: michael@0: function test() { michael@0: Task.spawn(function*() { michael@0: let {tab} = yield loadTab(TEST_URI); michael@0: let hud = yield openConsole(tab); michael@0: let toolbox = gDevTools.getToolbox(hud.target); michael@0: michael@0: // Loading the inspector panel at first, to make it possible to listen for michael@0: // new node selections michael@0: yield toolbox.selectTool("inspector"); michael@0: let inspector = toolbox.getCurrentPanel(); michael@0: yield toolbox.selectTool("webconsole"); michael@0: michael@0: info("Iterating over the test data"); michael@0: for (let data of TEST_DATA) { michael@0: let [result] = yield jsEval(data.input, hud, {text: data.output}); michael@0: let {widget, msg} = yield getWidgetAndMessage(result); michael@0: michael@0: let inspectorIcon = msg.querySelector(".open-inspector"); michael@0: ok(inspectorIcon, "Inspector icon found in the ElementNode widget"); michael@0: michael@0: info("Clicking on the inspector icon and waiting for the inspector to be selected"); michael@0: let onInspectorSelected = toolbox.once("inspector-selected"); michael@0: let onInspectorUpdated = inspector.once("inspector-updated"); michael@0: let onNewNode = toolbox.selection.once("new-node"); michael@0: michael@0: EventUtils.synthesizeMouseAtCenter(inspectorIcon, {}, michael@0: inspectorIcon.ownerDocument.defaultView); michael@0: yield onInspectorSelected; michael@0: yield onInspectorUpdated; michael@0: yield onNewNode; michael@0: ok(true, "Inspector selected and new node got selected"); michael@0: michael@0: let rawNode = content.wrappedJSObject[data.input.replace(/\(\)/g, "")](); michael@0: is(inspector.selection.node.wrappedJSObject, rawNode, michael@0: "The current inspector selection is correct"); michael@0: michael@0: info("Switching back to the console"); michael@0: yield toolbox.selectTool("webconsole"); michael@0: } michael@0: }).then(finishTest); michael@0: } michael@0: michael@0: function jsEval(input, hud, message) { michael@0: info("Executing '" + input + "' in the web console"); michael@0: michael@0: hud.jsterm.clearOutput(); michael@0: hud.jsterm.execute(input); michael@0: michael@0: return waitForMessages({ michael@0: webconsole: hud, michael@0: messages: [message] michael@0: }); michael@0: } michael@0: michael@0: function* getWidgetAndMessage(result) { michael@0: info("Getting the output ElementNode widget"); michael@0: michael@0: let msg = [...result.matched][0]; michael@0: let widget = [...msg._messageObject.widgets][0]; michael@0: ok(widget, "ElementNode widget found in the output"); michael@0: michael@0: info("Waiting for the ElementNode widget to be linked to the inspector"); michael@0: yield widget.linkToInspector(); michael@0: michael@0: return {widget: widget, msg: msg}; michael@0: }