Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* |
michael@0 | 2 | * Any copyright is dedicated to the Public Domain. |
michael@0 | 3 | * http://creativecommons.org/publicdomain/zero/1.0/ |
michael@0 | 4 | */ |
michael@0 | 5 | |
michael@0 | 6 | // Test that inspector links in the webconsole output for DOM Nodes do not try |
michael@0 | 7 | // to highlight or select nodes once they have been detached |
michael@0 | 8 | |
michael@0 | 9 | const TEST_URI = "http://example.com/browser/browser/devtools/webconsole/test/test-console-output-dom-elements.html"; |
michael@0 | 10 | |
michael@0 | 11 | const TEST_DATA = [ |
michael@0 | 12 | { |
michael@0 | 13 | // The first test shouldn't be returning the body element as this is the |
michael@0 | 14 | // default selected node, so re-selecting it won't fire the inspector-updated |
michael@0 | 15 | // event |
michael@0 | 16 | input: "testNode()", |
michael@0 | 17 | output: '<p some-attribute="some-value">' |
michael@0 | 18 | }, |
michael@0 | 19 | { |
michael@0 | 20 | input: "testBodyNode()", |
michael@0 | 21 | output: '<body id="body-id" class="body-class">' |
michael@0 | 22 | }, |
michael@0 | 23 | { |
michael@0 | 24 | input: "testNodeInIframe()", |
michael@0 | 25 | output: '<p>' |
michael@0 | 26 | }, |
michael@0 | 27 | { |
michael@0 | 28 | input: "testDocumentElement()", |
michael@0 | 29 | output: '<html lang="en-US" dir="ltr">' |
michael@0 | 30 | } |
michael@0 | 31 | ]; |
michael@0 | 32 | |
michael@0 | 33 | const PREF = "devtools.webconsole.persistlog"; |
michael@0 | 34 | |
michael@0 | 35 | function test() { |
michael@0 | 36 | Services.prefs.setBoolPref(PREF, true); |
michael@0 | 37 | registerCleanupFunction(() => Services.prefs.clearUserPref(PREF)); |
michael@0 | 38 | |
michael@0 | 39 | Task.spawn(function*() { |
michael@0 | 40 | let {tab} = yield loadTab(TEST_URI); |
michael@0 | 41 | let hud = yield openConsole(tab); |
michael@0 | 42 | let toolbox = gDevTools.getToolbox(hud.target); |
michael@0 | 43 | |
michael@0 | 44 | info("Executing the test data"); |
michael@0 | 45 | let widgets = []; |
michael@0 | 46 | for (let data of TEST_DATA) { |
michael@0 | 47 | let [result] = yield jsEval(data.input, hud, {text: data.output}); |
michael@0 | 48 | let {widget} = yield getWidgetAndMessage(result); |
michael@0 | 49 | widgets.push(widget); |
michael@0 | 50 | } |
michael@0 | 51 | |
michael@0 | 52 | info("Reloading the page"); |
michael@0 | 53 | yield reloadPage(); |
michael@0 | 54 | |
michael@0 | 55 | info("Iterating over the ElementNode widgets"); |
michael@0 | 56 | for (let widget of widgets) { |
michael@0 | 57 | // Verify that openNodeInInspector rejects since the associated dom node |
michael@0 | 58 | // doesn't exist anymore |
michael@0 | 59 | yield widget.openNodeInInspector().then(() => { |
michael@0 | 60 | ok(false, "The openNodeInInspector promise resolved"); |
michael@0 | 61 | }, () => { |
michael@0 | 62 | ok(true, "The openNodeInInspector promise rejected as expected"); |
michael@0 | 63 | }); |
michael@0 | 64 | yield toolbox.selectTool("webconsole"); |
michael@0 | 65 | |
michael@0 | 66 | // Verify that highlightDomNode rejects too, for the same reason |
michael@0 | 67 | yield widget.highlightDomNode().then(() => { |
michael@0 | 68 | ok(false, "The highlightDomNode promise resolved"); |
michael@0 | 69 | }, () => { |
michael@0 | 70 | ok(true, "The highlightDomNode promise rejected as expected"); |
michael@0 | 71 | }); |
michael@0 | 72 | } |
michael@0 | 73 | }).then(finishTest); |
michael@0 | 74 | } |
michael@0 | 75 | |
michael@0 | 76 | function jsEval(input, hud, message) { |
michael@0 | 77 | info("Executing '" + input + "' in the web console"); |
michael@0 | 78 | hud.jsterm.execute(input); |
michael@0 | 79 | return waitForMessages({ |
michael@0 | 80 | webconsole: hud, |
michael@0 | 81 | messages: [message] |
michael@0 | 82 | }); |
michael@0 | 83 | } |
michael@0 | 84 | |
michael@0 | 85 | function* getWidgetAndMessage(result) { |
michael@0 | 86 | info("Getting the output ElementNode widget"); |
michael@0 | 87 | |
michael@0 | 88 | let msg = [...result.matched][0]; |
michael@0 | 89 | let widget = [...msg._messageObject.widgets][0]; |
michael@0 | 90 | ok(widget, "ElementNode widget found in the output"); |
michael@0 | 91 | |
michael@0 | 92 | info("Waiting for the ElementNode widget to be linked to the inspector"); |
michael@0 | 93 | yield widget.linkToInspector(); |
michael@0 | 94 | |
michael@0 | 95 | return {widget: widget, msg: msg}; |
michael@0 | 96 | } |
michael@0 | 97 | |
michael@0 | 98 | function reloadPage() { |
michael@0 | 99 | let def = promise.defer(); |
michael@0 | 100 | gBrowser.selectedBrowser.addEventListener("load", function onload() { |
michael@0 | 101 | gBrowser.selectedBrowser.removeEventListener("load", onload, true); |
michael@0 | 102 | def.resolve(); |
michael@0 | 103 | }, true); |
michael@0 | 104 | content.location.reload(); |
michael@0 | 105 | return def.promise; |
michael@0 | 106 | } |