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 the inspector links in the webconsole output for DOM Nodes actually |
michael@0 | 7 | // open the inspector and select the right node |
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 | function test() { |
michael@0 | 34 | Task.spawn(function*() { |
michael@0 | 35 | let {tab} = yield loadTab(TEST_URI); |
michael@0 | 36 | let hud = yield openConsole(tab); |
michael@0 | 37 | let toolbox = gDevTools.getToolbox(hud.target); |
michael@0 | 38 | |
michael@0 | 39 | // Loading the inspector panel at first, to make it possible to listen for |
michael@0 | 40 | // new node selections |
michael@0 | 41 | yield toolbox.selectTool("inspector"); |
michael@0 | 42 | let inspector = toolbox.getCurrentPanel(); |
michael@0 | 43 | yield toolbox.selectTool("webconsole"); |
michael@0 | 44 | |
michael@0 | 45 | info("Iterating over the test data"); |
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, msg} = yield getWidgetAndMessage(result); |
michael@0 | 49 | |
michael@0 | 50 | let inspectorIcon = msg.querySelector(".open-inspector"); |
michael@0 | 51 | ok(inspectorIcon, "Inspector icon found in the ElementNode widget"); |
michael@0 | 52 | |
michael@0 | 53 | info("Clicking on the inspector icon and waiting for the inspector to be selected"); |
michael@0 | 54 | let onInspectorSelected = toolbox.once("inspector-selected"); |
michael@0 | 55 | let onInspectorUpdated = inspector.once("inspector-updated"); |
michael@0 | 56 | let onNewNode = toolbox.selection.once("new-node"); |
michael@0 | 57 | |
michael@0 | 58 | EventUtils.synthesizeMouseAtCenter(inspectorIcon, {}, |
michael@0 | 59 | inspectorIcon.ownerDocument.defaultView); |
michael@0 | 60 | yield onInspectorSelected; |
michael@0 | 61 | yield onInspectorUpdated; |
michael@0 | 62 | yield onNewNode; |
michael@0 | 63 | ok(true, "Inspector selected and new node got selected"); |
michael@0 | 64 | |
michael@0 | 65 | let rawNode = content.wrappedJSObject[data.input.replace(/\(\)/g, "")](); |
michael@0 | 66 | is(inspector.selection.node.wrappedJSObject, rawNode, |
michael@0 | 67 | "The current inspector selection is correct"); |
michael@0 | 68 | |
michael@0 | 69 | info("Switching back to the console"); |
michael@0 | 70 | yield toolbox.selectTool("webconsole"); |
michael@0 | 71 | } |
michael@0 | 72 | }).then(finishTest); |
michael@0 | 73 | } |
michael@0 | 74 | |
michael@0 | 75 | function jsEval(input, hud, message) { |
michael@0 | 76 | info("Executing '" + input + "' in the web console"); |
michael@0 | 77 | |
michael@0 | 78 | hud.jsterm.clearOutput(); |
michael@0 | 79 | hud.jsterm.execute(input); |
michael@0 | 80 | |
michael@0 | 81 | return waitForMessages({ |
michael@0 | 82 | webconsole: hud, |
michael@0 | 83 | messages: [message] |
michael@0 | 84 | }); |
michael@0 | 85 | } |
michael@0 | 86 | |
michael@0 | 87 | function* getWidgetAndMessage(result) { |
michael@0 | 88 | info("Getting the output ElementNode widget"); |
michael@0 | 89 | |
michael@0 | 90 | let msg = [...result.matched][0]; |
michael@0 | 91 | let widget = [...msg._messageObject.widgets][0]; |
michael@0 | 92 | ok(widget, "ElementNode widget found in the output"); |
michael@0 | 93 | |
michael@0 | 94 | info("Waiting for the ElementNode widget to be linked to the inspector"); |
michael@0 | 95 | yield widget.linkToInspector(); |
michael@0 | 96 | |
michael@0 | 97 | return {widget: widget, msg: msg}; |
michael@0 | 98 | } |