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