diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /devtools/client/performance/test/helpers/panel-utils.js | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'devtools/client/performance/test/helpers/panel-utils.js')
-rw-r--r-- | devtools/client/performance/test/helpers/panel-utils.js | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/devtools/client/performance/test/helpers/panel-utils.js b/devtools/client/performance/test/helpers/panel-utils.js new file mode 100644 index 000000000..468a86607 --- /dev/null +++ b/devtools/client/performance/test/helpers/panel-utils.js @@ -0,0 +1,106 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ +"use strict"; + +/* globals dump */ + +const { gDevTools } = require("devtools/client/framework/devtools"); +const { TargetFactory } = require("devtools/client/framework/target"); +const { addTab, removeTab } = require("devtools/client/performance/test/helpers/tab-utils"); +const { once } = require("devtools/client/performance/test/helpers/event-utils"); + +/** + * Initializes a toolbox panel in a new tab. + */ +exports.initPanelInNewTab = function* ({ tool, url, win }, options = {}) { + let tab = yield addTab({ url, win }, options); + return (yield exports.initPanelInTab({ tool, tab })); +}; + +/** + * Initializes a toolbox panel in the specified tab. + */ +exports.initPanelInTab = function* ({ tool, tab }) { + dump(`Initializing a ${tool} panel.\n`); + + let target = TargetFactory.forTab(tab); + yield target.makeRemote(); + + // Open a toolbox and wait for the connection to the performance actors + // to be opened. This is necessary because of the WebConsole's + // `profile` and `profileEnd` methods. + let toolbox = yield gDevTools.showToolbox(target, tool); + yield toolbox.initPerformance(); + + let panel = toolbox.getCurrentPanel(); + return { target, toolbox, panel }; +}; + +/** + * Initializes a performance panel in a new tab. + */ +exports.initPerformanceInNewTab = function* ({ url, win }, options = {}) { + let tab = yield addTab({ url, win }, options); + return (yield exports.initPerformanceInTab({ tab })); +}; + +/** + * Initializes a performance panel in the specified tab. + */ +exports.initPerformanceInTab = function* ({ tab }) { + return (yield exports.initPanelInTab({ + tool: "performance", + tab: tab + })); +}; + +/** + * Initializes a webconsole panel in a new tab. + * Returns a console property that allows calls to `profile` and `profileEnd`. + */ +exports.initConsoleInNewTab = function* ({ url, win }, options = {}) { + let tab = yield addTab({ url, win }, options); + return (yield exports.initConsoleInTab({ tab })); +}; + +/** + * Initializes a webconsole panel in the specified tab. + * Returns a console property that allows calls to `profile` and `profileEnd`. + */ +exports.initConsoleInTab = function* ({ tab }) { + let { target, toolbox, panel } = yield exports.initPanelInTab({ + tool: "webconsole", + tab: tab + }); + + let consoleMethod = function* (method, label, event) { + let recordingEventReceived = once(toolbox.performance, event); + if (label === undefined) { + yield panel.hud.jsterm.execute(`console.${method}()`); + } else { + yield panel.hud.jsterm.execute(`console.${method}("${label}")`); + } + yield recordingEventReceived; + }; + + let profile = function* (label) { + return yield consoleMethod("profile", label, "recording-started"); + }; + + let profileEnd = function* (label) { + return yield consoleMethod("profileEnd", label, "recording-stopped"); + }; + + return { target, toolbox, panel, console: { profile, profileEnd } }; +}; + +/** + * Tears down a toolbox panel and removes an associated tab. + */ +exports.teardownToolboxAndRemoveTab = function* (panel, options) { + dump("Destroying panel.\n"); + + let tab = panel.target.tab; + yield panel.toolbox.destroy(); + yield removeTab(tab, options); +}; |