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 that inspector links in the webconsole output for DOM Nodes do not try michael@0: // to highlight or select nodes once they have been detached 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: const PREF = "devtools.webconsole.persistlog"; michael@0: michael@0: function test() { michael@0: Services.prefs.setBoolPref(PREF, true); michael@0: registerCleanupFunction(() => Services.prefs.clearUserPref(PREF)); michael@0: 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: info("Executing the test data"); michael@0: let widgets = []; michael@0: for (let data of TEST_DATA) { michael@0: let [result] = yield jsEval(data.input, hud, {text: data.output}); michael@0: let {widget} = yield getWidgetAndMessage(result); michael@0: widgets.push(widget); michael@0: } michael@0: michael@0: info("Reloading the page"); michael@0: yield reloadPage(); michael@0: michael@0: info("Iterating over the ElementNode widgets"); michael@0: for (let widget of widgets) { michael@0: // Verify that openNodeInInspector rejects since the associated dom node michael@0: // doesn't exist anymore michael@0: yield widget.openNodeInInspector().then(() => { michael@0: ok(false, "The openNodeInInspector promise resolved"); michael@0: }, () => { michael@0: ok(true, "The openNodeInInspector promise rejected as expected"); michael@0: }); michael@0: yield toolbox.selectTool("webconsole"); michael@0: michael@0: // Verify that highlightDomNode rejects too, for the same reason michael@0: yield widget.highlightDomNode().then(() => { michael@0: ok(false, "The highlightDomNode promise resolved"); michael@0: }, () => { michael@0: ok(true, "The highlightDomNode promise rejected as expected"); michael@0: }); 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: hud.jsterm.execute(input); 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: } michael@0: michael@0: function reloadPage() { michael@0: let def = promise.defer(); michael@0: gBrowser.selectedBrowser.addEventListener("load", function onload() { michael@0: gBrowser.selectedBrowser.removeEventListener("load", onload, true); michael@0: def.resolve(); michael@0: }, true); michael@0: content.location.reload(); michael@0: return def.promise; michael@0: }