browser/devtools/profiler/test/head.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* Any copyright is dedicated to the Public Domain.
michael@0 2 http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 3
michael@0 4 let temp = {};
michael@0 5
michael@0 6 const PROFILER_ENABLED = "devtools.profiler.enabled";
michael@0 7 const REMOTE_ENABLED = "devtools.debugger.remote-enabled";
michael@0 8 const SHOW_PLATFORM_DATA = "devtools.profiler.ui.show-platform-data";
michael@0 9 const PROFILE_IDLE = 0;
michael@0 10 const PROFILE_RUNNING = 1;
michael@0 11 const PROFILE_COMPLETED = 2;
michael@0 12
michael@0 13 Cu.import("resource:///modules/devtools/gDevTools.jsm", temp);
michael@0 14 let gDevTools = temp.gDevTools;
michael@0 15
michael@0 16 Cu.import("resource://gre/modules/devtools/Loader.jsm", temp);
michael@0 17 let TargetFactory = temp.devtools.TargetFactory;
michael@0 18
michael@0 19 Cu.import("resource://gre/modules/devtools/dbg-server.jsm", temp);
michael@0 20 let DebuggerServer = temp.DebuggerServer;
michael@0 21
michael@0 22 // Import the GCLI test helper
michael@0 23 let testDir = gTestPath.substr(0, gTestPath.lastIndexOf("/"));
michael@0 24 Services.scriptloader.loadSubScript(testDir + "../../../commandline/test/helpers.js", this);
michael@0 25
michael@0 26 gDevTools.testing = true;
michael@0 27 SimpleTest.registerCleanupFunction(() => {
michael@0 28 gDevTools.testing = false;
michael@0 29 });
michael@0 30
michael@0 31 registerCleanupFunction(function () {
michael@0 32 helpers = null;
michael@0 33 Services.prefs.clearUserPref(PROFILER_ENABLED);
michael@0 34 Services.prefs.clearUserPref(REMOTE_ENABLED);
michael@0 35 Services.prefs.clearUserPref(SHOW_PLATFORM_DATA);
michael@0 36 DebuggerServer.destroy();
michael@0 37
michael@0 38 // These tests use a lot of memory due to GL contexts, so force a GC to help
michael@0 39 // fragmentation.
michael@0 40 info("Forcing GC after profiler test.");
michael@0 41 Cu.forceGC();
michael@0 42 });
michael@0 43
michael@0 44 function getProfileInternals(uid) {
michael@0 45 let profile = (uid != null) ? gPanel.profiles.get(uid) : gPanel.activeProfile;
michael@0 46 let win = profile.iframe.contentWindow;
michael@0 47 let doc = win.document;
michael@0 48
michael@0 49 return [win, doc];
michael@0 50 }
michael@0 51
michael@0 52 function getSidebarItem(uid, panel=gPanel) {
michael@0 53 let profile = panel.profiles.get(uid);
michael@0 54 return panel.sidebar.getItemByProfile(profile);
michael@0 55 }
michael@0 56
michael@0 57 function sendFromProfile(uid, msg) {
michael@0 58 let [win, doc] = getProfileInternals(uid);
michael@0 59 win.parent.postMessage({ uid: uid, status: msg }, "*");
michael@0 60 }
michael@0 61
michael@0 62 function loadTab(url, callback) {
michael@0 63 let tab = gBrowser.addTab();
michael@0 64 gBrowser.selectedTab = tab;
michael@0 65 loadUrl(url, tab, callback);
michael@0 66 }
michael@0 67
michael@0 68 function loadUrl(url, tab, callback) {
michael@0 69 content.location.assign(url);
michael@0 70 let browser = gBrowser.getBrowserForTab(tab);
michael@0 71 if (browser.contentDocument.readyState === "complete") {
michael@0 72 callback(tab, browser);
michael@0 73 return;
michael@0 74 }
michael@0 75
michael@0 76 let onLoad = function onLoad() {
michael@0 77 browser.removeEventListener("load", onLoad, true);
michael@0 78 callback(tab, browser);
michael@0 79 };
michael@0 80
michael@0 81 browser.addEventListener("load", onLoad, true);
michael@0 82 }
michael@0 83
michael@0 84 function openProfiler(tab, callback) {
michael@0 85 let target = TargetFactory.forTab(tab);
michael@0 86 gDevTools.showToolbox(target, "jsprofiler").then(callback);
michael@0 87 }
michael@0 88
michael@0 89 function openConsole(tab, cb=function(){}) {
michael@0 90 // This function was borrowed from webconsole/test/head.js
michael@0 91 let target = TargetFactory.forTab(tab);
michael@0 92
michael@0 93 gDevTools.showToolbox(target, "webconsole").then(function (toolbox) {
michael@0 94 let hud = toolbox.getCurrentPanel().hud;
michael@0 95 hud.jsterm._lazyVariablesView = false;
michael@0 96 cb(hud);
michael@0 97 });
michael@0 98 }
michael@0 99
michael@0 100 function closeProfiler(tab, callback) {
michael@0 101 let target = TargetFactory.forTab(tab);
michael@0 102 let toolbox = gDevTools.getToolbox(target);
michael@0 103 toolbox.destroy().then(callback);
michael@0 104 }
michael@0 105
michael@0 106 function setUp(url, callback=function(){}) {
michael@0 107 Services.prefs.setBoolPref(PROFILER_ENABLED, true);
michael@0 108
michael@0 109 loadTab(url, function onTabLoad(tab, browser) {
michael@0 110 openProfiler(tab, function onProfilerOpen() {
michael@0 111 let target = TargetFactory.forTab(tab);
michael@0 112 let panel = gDevTools.getToolbox(target).getPanel("jsprofiler");
michael@0 113 callback(tab, browser, panel);
michael@0 114 });
michael@0 115 });
michael@0 116 }
michael@0 117
michael@0 118 function tearDown(tab, callback=function(){}) {
michael@0 119 closeProfiler(tab, function onProfilerClose() {
michael@0 120 callback();
michael@0 121
michael@0 122 while (gBrowser.tabs.length > 1) {
michael@0 123 gBrowser.removeCurrentTab();
michael@0 124 }
michael@0 125
michael@0 126 finish();
michael@0 127 });
michael@0 128 }

mercurial