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 | // Check that variables view is linked to the inspector for highlighting and |
michael@0 | 7 | // selecting DOM nodes |
michael@0 | 8 | |
michael@0 | 9 | const TEST_URI = "http://example.com/browser/browser/devtools/webconsole/test/test-bug-952277-highlight-nodes-in-vview.html"; |
michael@0 | 10 | |
michael@0 | 11 | let gWebConsole, gJSTerm, gVariablesView, gToolbox; |
michael@0 | 12 | |
michael@0 | 13 | function test() |
michael@0 | 14 | { |
michael@0 | 15 | addTab(TEST_URI); |
michael@0 | 16 | browser.addEventListener("load", function onLoad() { |
michael@0 | 17 | browser.removeEventListener("load", onLoad, true); |
michael@0 | 18 | openConsole(null, consoleOpened); |
michael@0 | 19 | }, true); |
michael@0 | 20 | } |
michael@0 | 21 | |
michael@0 | 22 | function consoleOpened(hud) |
michael@0 | 23 | { |
michael@0 | 24 | gWebConsole = hud; |
michael@0 | 25 | gJSTerm = hud.jsterm; |
michael@0 | 26 | gToolbox = gDevTools.getToolbox(hud.target); |
michael@0 | 27 | gJSTerm.execute("document.querySelectorAll('p')", onQSAexecuted); |
michael@0 | 28 | } |
michael@0 | 29 | |
michael@0 | 30 | function onQSAexecuted(msg) |
michael@0 | 31 | { |
michael@0 | 32 | ok(msg, "output message found"); |
michael@0 | 33 | let anchor = msg.querySelector("a"); |
michael@0 | 34 | ok(anchor, "object link found"); |
michael@0 | 35 | |
michael@0 | 36 | gJSTerm.once("variablesview-fetched", onNodeListVviewFetched); |
michael@0 | 37 | |
michael@0 | 38 | executeSoon(() => |
michael@0 | 39 | EventUtils.synthesizeMouse(anchor, 2, 2, {}, gWebConsole.iframeWindow) |
michael@0 | 40 | ); |
michael@0 | 41 | } |
michael@0 | 42 | |
michael@0 | 43 | function onNodeListVviewFetched(aEvent, aVar) |
michael@0 | 44 | { |
michael@0 | 45 | gVariablesView = aVar._variablesView; |
michael@0 | 46 | ok(gVariablesView, "variables view object"); |
michael@0 | 47 | |
michael@0 | 48 | // Transform the vview into an array we can filter properties from |
michael@0 | 49 | let props = [[id, prop] for([id, prop] of aVar)]; |
michael@0 | 50 | // These properties are the DOM nodes ones |
michael@0 | 51 | props = props.filter(v => v[0].match(/[0-9]+/)); |
michael@0 | 52 | |
michael@0 | 53 | function hoverOverDomNodeVariableAndAssertHighlighter(index) { |
michael@0 | 54 | if (props[index]) { |
michael@0 | 55 | let prop = props[index][1]; |
michael@0 | 56 | let valueEl = prop._valueLabel; |
michael@0 | 57 | |
michael@0 | 58 | gToolbox.once("node-highlight", () => { |
michael@0 | 59 | ok(true, "The highlighter was shown on hover of the DOMNode"); |
michael@0 | 60 | gToolbox.highlighterUtils.unhighlight().then(() => { |
michael@0 | 61 | clickOnDomNodeVariableAndAssertInspectorSelected(index); |
michael@0 | 62 | }); |
michael@0 | 63 | }); |
michael@0 | 64 | |
michael@0 | 65 | // Rather than trying to emulate a mouseenter event, let's call the |
michael@0 | 66 | // variable's highlightDomNode and see if it has the desired effect |
michael@0 | 67 | prop.highlightDomNode(); |
michael@0 | 68 | } else { |
michael@0 | 69 | finishUp(); |
michael@0 | 70 | } |
michael@0 | 71 | } |
michael@0 | 72 | |
michael@0 | 73 | function clickOnDomNodeVariableAndAssertInspectorSelected(index) { |
michael@0 | 74 | let prop = props[index][1]; |
michael@0 | 75 | |
michael@0 | 76 | // Make sure the inspector is initialized so we can listen to its events |
michael@0 | 77 | gToolbox.initInspector().then(() => { |
michael@0 | 78 | // Rather than trying to click on the value here, let's just call the |
michael@0 | 79 | // variable's openNodeInInspector function and see if it has the |
michael@0 | 80 | // desired effect |
michael@0 | 81 | prop.openNodeInInspector().then(() => { |
michael@0 | 82 | is(gToolbox.currentToolId, "inspector", "The toolbox switched over the inspector on DOMNode click"); |
michael@0 | 83 | gToolbox.selectTool("webconsole").then(() => { |
michael@0 | 84 | hoverOverDomNodeVariableAndAssertHighlighter(index + 1); |
michael@0 | 85 | }); |
michael@0 | 86 | }); |
michael@0 | 87 | }); |
michael@0 | 88 | } |
michael@0 | 89 | |
michael@0 | 90 | hoverOverDomNodeVariableAndAssertHighlighter(0); |
michael@0 | 91 | } |
michael@0 | 92 | |
michael@0 | 93 | function finishUp() { |
michael@0 | 94 | gWebConsole = gJSTerm = gVariablesView = gToolbox = null; |
michael@0 | 95 | |
michael@0 | 96 | finishTest(); |
michael@0 | 97 | } |