1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/webconsole/test/browser_webconsole_output_dom_elements_04.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,106 @@ 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 that inspector links in the webconsole output for DOM Nodes do not try 1.10 +// to highlight or select nodes once they have been detached 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 +const PREF = "devtools.webconsole.persistlog"; 1.37 + 1.38 +function test() { 1.39 + Services.prefs.setBoolPref(PREF, true); 1.40 + registerCleanupFunction(() => Services.prefs.clearUserPref(PREF)); 1.41 + 1.42 + Task.spawn(function*() { 1.43 + let {tab} = yield loadTab(TEST_URI); 1.44 + let hud = yield openConsole(tab); 1.45 + let toolbox = gDevTools.getToolbox(hud.target); 1.46 + 1.47 + info("Executing the test data"); 1.48 + let widgets = []; 1.49 + for (let data of TEST_DATA) { 1.50 + let [result] = yield jsEval(data.input, hud, {text: data.output}); 1.51 + let {widget} = yield getWidgetAndMessage(result); 1.52 + widgets.push(widget); 1.53 + } 1.54 + 1.55 + info("Reloading the page"); 1.56 + yield reloadPage(); 1.57 + 1.58 + info("Iterating over the ElementNode widgets"); 1.59 + for (let widget of widgets) { 1.60 + // Verify that openNodeInInspector rejects since the associated dom node 1.61 + // doesn't exist anymore 1.62 + yield widget.openNodeInInspector().then(() => { 1.63 + ok(false, "The openNodeInInspector promise resolved"); 1.64 + }, () => { 1.65 + ok(true, "The openNodeInInspector promise rejected as expected"); 1.66 + }); 1.67 + yield toolbox.selectTool("webconsole"); 1.68 + 1.69 + // Verify that highlightDomNode rejects too, for the same reason 1.70 + yield widget.highlightDomNode().then(() => { 1.71 + ok(false, "The highlightDomNode promise resolved"); 1.72 + }, () => { 1.73 + ok(true, "The highlightDomNode promise rejected as expected"); 1.74 + }); 1.75 + } 1.76 + }).then(finishTest); 1.77 +} 1.78 + 1.79 +function jsEval(input, hud, message) { 1.80 + info("Executing '" + input + "' in the web console"); 1.81 + hud.jsterm.execute(input); 1.82 + return waitForMessages({ 1.83 + webconsole: hud, 1.84 + messages: [message] 1.85 + }); 1.86 +} 1.87 + 1.88 +function* getWidgetAndMessage(result) { 1.89 + info("Getting the output ElementNode widget"); 1.90 + 1.91 + let msg = [...result.matched][0]; 1.92 + let widget = [...msg._messageObject.widgets][0]; 1.93 + ok(widget, "ElementNode widget found in the output"); 1.94 + 1.95 + info("Waiting for the ElementNode widget to be linked to the inspector"); 1.96 + yield widget.linkToInspector(); 1.97 + 1.98 + return {widget: widget, msg: msg}; 1.99 +} 1.100 + 1.101 +function reloadPage() { 1.102 + let def = promise.defer(); 1.103 + gBrowser.selectedBrowser.addEventListener("load", function onload() { 1.104 + gBrowser.selectedBrowser.removeEventListener("load", onload, true); 1.105 + def.resolve(); 1.106 + }, true); 1.107 + content.location.reload(); 1.108 + return def.promise; 1.109 +}