michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: let temp = {}; michael@0: michael@0: const PROFILER_ENABLED = "devtools.profiler.enabled"; michael@0: const REMOTE_ENABLED = "devtools.debugger.remote-enabled"; michael@0: const SHOW_PLATFORM_DATA = "devtools.profiler.ui.show-platform-data"; michael@0: const PROFILE_IDLE = 0; michael@0: const PROFILE_RUNNING = 1; michael@0: const PROFILE_COMPLETED = 2; michael@0: michael@0: Cu.import("resource:///modules/devtools/gDevTools.jsm", temp); michael@0: let gDevTools = temp.gDevTools; michael@0: michael@0: Cu.import("resource://gre/modules/devtools/Loader.jsm", temp); michael@0: let TargetFactory = temp.devtools.TargetFactory; michael@0: michael@0: Cu.import("resource://gre/modules/devtools/dbg-server.jsm", temp); michael@0: let DebuggerServer = temp.DebuggerServer; 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: registerCleanupFunction(function () { michael@0: helpers = null; michael@0: Services.prefs.clearUserPref(PROFILER_ENABLED); michael@0: Services.prefs.clearUserPref(REMOTE_ENABLED); michael@0: Services.prefs.clearUserPref(SHOW_PLATFORM_DATA); michael@0: DebuggerServer.destroy(); michael@0: michael@0: // These tests use a lot of memory due to GL contexts, so force a GC to help michael@0: // fragmentation. michael@0: info("Forcing GC after profiler test."); michael@0: Cu.forceGC(); michael@0: }); michael@0: michael@0: function getProfileInternals(uid) { michael@0: let profile = (uid != null) ? gPanel.profiles.get(uid) : gPanel.activeProfile; michael@0: let win = profile.iframe.contentWindow; michael@0: let doc = win.document; michael@0: michael@0: return [win, doc]; michael@0: } michael@0: michael@0: function getSidebarItem(uid, panel=gPanel) { michael@0: let profile = panel.profiles.get(uid); michael@0: return panel.sidebar.getItemByProfile(profile); michael@0: } michael@0: michael@0: function sendFromProfile(uid, msg) { michael@0: let [win, doc] = getProfileInternals(uid); michael@0: win.parent.postMessage({ uid: uid, status: msg }, "*"); michael@0: } michael@0: michael@0: function loadTab(url, callback) { michael@0: let tab = gBrowser.addTab(); michael@0: gBrowser.selectedTab = tab; michael@0: loadUrl(url, tab, callback); michael@0: } michael@0: michael@0: function loadUrl(url, tab, callback) { michael@0: content.location.assign(url); michael@0: let browser = gBrowser.getBrowserForTab(tab); michael@0: if (browser.contentDocument.readyState === "complete") { michael@0: callback(tab, browser); michael@0: return; michael@0: } michael@0: michael@0: let onLoad = function onLoad() { michael@0: browser.removeEventListener("load", onLoad, true); michael@0: callback(tab, browser); michael@0: }; michael@0: michael@0: browser.addEventListener("load", onLoad, true); michael@0: } michael@0: michael@0: function openProfiler(tab, callback) { michael@0: let target = TargetFactory.forTab(tab); michael@0: gDevTools.showToolbox(target, "jsprofiler").then(callback); michael@0: } michael@0: michael@0: function openConsole(tab, cb=function(){}) { michael@0: // This function was borrowed from webconsole/test/head.js michael@0: let target = TargetFactory.forTab(tab); michael@0: michael@0: gDevTools.showToolbox(target, "webconsole").then(function (toolbox) { michael@0: let hud = toolbox.getCurrentPanel().hud; michael@0: hud.jsterm._lazyVariablesView = false; michael@0: cb(hud); michael@0: }); michael@0: } michael@0: michael@0: function closeProfiler(tab, callback) { michael@0: let target = TargetFactory.forTab(tab); michael@0: let toolbox = gDevTools.getToolbox(target); michael@0: toolbox.destroy().then(callback); michael@0: } michael@0: michael@0: function setUp(url, callback=function(){}) { michael@0: Services.prefs.setBoolPref(PROFILER_ENABLED, true); michael@0: michael@0: loadTab(url, function onTabLoad(tab, browser) { michael@0: openProfiler(tab, function onProfilerOpen() { michael@0: let target = TargetFactory.forTab(tab); michael@0: let panel = gDevTools.getToolbox(target).getPanel("jsprofiler"); michael@0: callback(tab, browser, panel); michael@0: }); michael@0: }); michael@0: } michael@0: michael@0: function tearDown(tab, callback=function(){}) { michael@0: closeProfiler(tab, function onProfilerClose() { michael@0: callback(); michael@0: michael@0: while (gBrowser.tabs.length > 1) { michael@0: gBrowser.removeCurrentTab(); michael@0: } michael@0: michael@0: finish(); michael@0: }); michael@0: }