1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/webconsole/test/browser_webconsole_closure_inspection.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,91 @@ 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 +// Check that inspecting a closure in the variables view sidebar works when 1.10 +// execution is paused. 1.11 + 1.12 +const TEST_URI = "http://example.com/browser/browser/devtools/webconsole/test/test-closures.html"; 1.13 + 1.14 +let gWebConsole, gJSTerm, gVariablesView; 1.15 + 1.16 +function test() 1.17 +{ 1.18 + registerCleanupFunction(() => { 1.19 + gWebConsole = gJSTerm = gVariablesView = null; 1.20 + }); 1.21 + 1.22 + addTab(TEST_URI); 1.23 + browser.addEventListener("load", function onLoad() { 1.24 + browser.removeEventListener("load", onLoad, true); 1.25 + openConsole(null, (hud) => { 1.26 + openDebugger().then(({ toolbox, panelWin }) => { 1.27 + let deferred = promise.defer(); 1.28 + panelWin.gThreadClient.addOneTimeListener("resumed", (aEvent, aPacket) => { 1.29 + ok(true, "Debugger resumed"); 1.30 + deferred.resolve({ toolbox: toolbox, panelWin: panelWin }); 1.31 + }); 1.32 + return deferred.promise; 1.33 + }).then(({ toolbox, panelWin }) => { 1.34 + let deferred = promise.defer(); 1.35 + panelWin.once(panelWin.EVENTS.FETCHED_SCOPES, (aEvent, aPacket) => { 1.36 + ok(true, "Scopes were fetched"); 1.37 + toolbox.selectTool("webconsole").then(() => consoleOpened(hud)); 1.38 + deferred.resolve(); 1.39 + }); 1.40 + 1.41 + let button = content.document.querySelector("button"); 1.42 + ok(button, "button element found"); 1.43 + button.click(); 1.44 + 1.45 + return deferred.promise; 1.46 + }); 1.47 + }); 1.48 + }, true); 1.49 +} 1.50 + 1.51 +function consoleOpened(hud) 1.52 +{ 1.53 + gWebConsole = hud; 1.54 + gJSTerm = hud.jsterm; 1.55 + gJSTerm.execute("window.george.getName"); 1.56 + 1.57 + waitForMessages({ 1.58 + webconsole: gWebConsole, 1.59 + messages: [{ 1.60 + text: "function _pfactory/<.getName()", 1.61 + category: CATEGORY_OUTPUT, 1.62 + objects: true, 1.63 + }], 1.64 + }).then(onExecuteGetName); 1.65 +} 1.66 + 1.67 +function onExecuteGetName(aResults) 1.68 +{ 1.69 + let clickable = aResults[0].clickableElements[0]; 1.70 + ok(clickable, "clickable object found"); 1.71 + 1.72 + gJSTerm.once("variablesview-fetched", onGetNameFetch); 1.73 + EventUtils.synthesizeMouse(clickable, 2, 2, {}, gWebConsole.iframeWindow) 1.74 +} 1.75 + 1.76 +function onGetNameFetch(aEvent, aVar) 1.77 +{ 1.78 + gVariablesView = aVar._variablesView; 1.79 + ok(gVariablesView, "variables view object"); 1.80 + 1.81 + findVariableViewProperties(aVar, [ 1.82 + { name: /_pfactory/, value: "" }, 1.83 + ], { webconsole: gWebConsole }).then(onExpandClosure); 1.84 +} 1.85 + 1.86 +function onExpandClosure(aResults) 1.87 +{ 1.88 + let prop = aResults[0].matchedProp; 1.89 + ok(prop, "matched the name property in the variables view"); 1.90 + 1.91 + gVariablesView.window.focus(); 1.92 + gJSTerm.once("sidebar-closed", finishTest); 1.93 + EventUtils.synthesizeKey("VK_ESCAPE", {}, gVariablesView.window); 1.94 +}