michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: "use strict"; michael@0: michael@0: let {devtools} = Cu.import("resource:///modules/devtools/gDevTools.jsm", {}); michael@0: let TargetFactory = devtools.TargetFactory; michael@0: michael@0: // Import the GCLI test helper michael@0: let testDir = gTestPath.substr(0, gTestPath.lastIndexOf("/")); michael@0: Services.scriptloader.loadSubScript(testDir + "../../../commandline/test/helpers.js", this); michael@0: michael@0: gDevTools.testing = true; michael@0: SimpleTest.registerCleanupFunction(() => { michael@0: gDevTools.testing = false; michael@0: }); michael@0: michael@0: /** michael@0: * Open the toolbox, with the inspector tool visible. michael@0: * @return a promise that resolves when the inspector is ready michael@0: */ michael@0: let openInspector = Task.async(function*() { michael@0: info("Opening the inspector"); michael@0: let target = TargetFactory.forTab(gBrowser.selectedTab); michael@0: michael@0: let inspector, toolbox; michael@0: michael@0: // Checking if the toolbox and the inspector are already loaded michael@0: // The inspector-updated event should only be waited for if the inspector michael@0: // isn't loaded yet michael@0: toolbox = gDevTools.getToolbox(target); michael@0: if (toolbox) { michael@0: inspector = toolbox.getPanel("inspector"); michael@0: if (inspector) { michael@0: info("Toolbox and inspector already open"); michael@0: return { michael@0: toolbox: toolbox, michael@0: inspector: inspector michael@0: }; michael@0: } michael@0: } michael@0: michael@0: info("Opening the toolbox"); michael@0: toolbox = yield gDevTools.showToolbox(target, "inspector"); michael@0: yield waitForToolboxFrameFocus(toolbox); michael@0: inspector = toolbox.getPanel("inspector"); michael@0: michael@0: info("Waiting for the inspector to update"); michael@0: yield inspector.once("inspector-updated"); michael@0: michael@0: return { michael@0: toolbox: toolbox, michael@0: inspector: inspector michael@0: }; michael@0: }); michael@0: michael@0: /** michael@0: * Wait for the toolbox frame to receive focus after it loads michael@0: * @param {Toolbox} toolbox michael@0: * @return a promise that resolves when focus has been received michael@0: */ michael@0: function waitForToolboxFrameFocus(toolbox) { michael@0: info("Making sure that the toolbox's frame is focused"); michael@0: let def = promise.defer(); michael@0: let win = toolbox.frame.contentWindow; michael@0: waitForFocus(def.resolve, win); michael@0: return def.promise; michael@0: } michael@0: michael@0: /** michael@0: * Open the toolbox, with the inspector tool visible, and the sidebar that michael@0: * corresponds to the given id selected michael@0: * @return a promise that resolves when the inspector is ready and the sidebar michael@0: * view is visible and ready michael@0: */ michael@0: let openInspectorSideBar = Task.async(function*(id) { michael@0: let {toolbox, inspector} = yield openInspector(); michael@0: michael@0: if (!hasSideBarTab(inspector, id)) { michael@0: info("Waiting for the " + id + " sidebar to be ready"); michael@0: yield inspector.sidebar.once(id + "-ready"); michael@0: } michael@0: michael@0: info("Selecting the " + id + " sidebar"); michael@0: inspector.sidebar.select(id); michael@0: michael@0: return { michael@0: toolbox: toolbox, michael@0: inspector: inspector, michael@0: view: inspector.sidebar.getWindowForTab(id)[id].view michael@0: }; michael@0: }); michael@0: michael@0: /** michael@0: * Checks whether the inspector's sidebar corresponding to the given id already michael@0: * exists michael@0: * @param {InspectorPanel} michael@0: * @param {String} michael@0: * @return {Boolean} michael@0: */ michael@0: function hasSideBarTab(inspector, id) { michael@0: return !!inspector.sidebar.getWindowForTab(id); michael@0: } michael@0: michael@0: /** michael@0: * Open the toolbox, with the inspector tool visible, and the computed-view michael@0: * sidebar tab selected. michael@0: * @return a promise that resolves when the inspector is ready and the computed michael@0: * view is visible and ready michael@0: */ michael@0: function openComputedView() { michael@0: return openInspectorSideBar("computedview"); michael@0: } michael@0: michael@0: /** michael@0: * Open the toolbox, with the inspector tool visible, and the rule-view michael@0: * sidebar tab selected. michael@0: * @return a promise that resolves when the inspector is ready and the rule michael@0: * view is visible and ready michael@0: */ michael@0: function openRuleView() { michael@0: return openInspectorSideBar("ruleview"); michael@0: }