|
1 <?xml version="1.0"?> |
|
2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?> |
|
3 <?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" |
|
4 type="text/css"?> |
|
5 <window title="Memory reporters with child processes" |
|
6 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> |
|
7 <script type="application/javascript" |
|
8 src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> |
|
9 |
|
10 <!-- test results are displayed in the html:body --> |
|
11 <body xmlns="http://www.w3.org/1999/xhtml"> |
|
12 </body> |
|
13 |
|
14 <!-- test code goes here --> |
|
15 <script type="application/javascript"><![CDATA[ |
|
16 |
|
17 const Cc = Components.classes; |
|
18 const Ci = Components.interfaces; |
|
19 |
|
20 SimpleTest.waitForExplicitFinish(); |
|
21 |
|
22 let numRemotes = 3; |
|
23 let numReady = 0; |
|
24 |
|
25 // Create some remote processes, and set up message-passing so that |
|
26 // we know when each child is fully initialized. |
|
27 let remotes = []; |
|
28 SpecialPowers.pushPrefEnv({"set": [["dom.ipc.processCount", 3]]}, function() { |
|
29 for (let i = 0; i < numRemotes; i++) { |
|
30 let w = remotes[i] = window.open("remote.xul", "", "chrome"); |
|
31 |
|
32 w.addEventListener("load", function loadHandler() { |
|
33 w.removeEventListener("load", loadHandler); |
|
34 let remoteBrowser = w.document.getElementById("remote"); |
|
35 let mm = remoteBrowser.messageManager; |
|
36 mm.addMessageListener("test:ready", function readyHandler() { |
|
37 mm.removeMessageListener("test:ready", readyHandler); |
|
38 numReady++; |
|
39 if (numReady == numRemotes) { |
|
40 // All the remote processes are ready. Do memory reporting. |
|
41 doReports(); |
|
42 } |
|
43 }); |
|
44 mm.loadFrameScript("data:," + encodeURI("sendAsyncMessage('test:ready');"), true); |
|
45 }); |
|
46 } |
|
47 }); |
|
48 |
|
49 let mgr = Cc["@mozilla.org/memory-reporter-manager;1"]. |
|
50 getService(Ci.nsIMemoryReporterManager); |
|
51 |
|
52 function doReports() |
|
53 { |
|
54 let residents = {}; |
|
55 |
|
56 let handleReport = function(aProcess, aPath, aKind, aUnits, aAmount, aDesc) { |
|
57 if (aPath === "resident") { |
|
58 ok(100 * 1000 <= aAmount && aAmount <= 10 * 1000 * 1000 * 1000, |
|
59 "resident is reasonable"); |
|
60 residents[aProcess] = aAmount; |
|
61 } |
|
62 } |
|
63 |
|
64 let processReports = function() { |
|
65 // First, test a failure case: calling getReports() before the previous |
|
66 // getReports() has finished should silently abort. (And the arguments |
|
67 // won't be used.) |
|
68 mgr.getReports( |
|
69 () => ok(false, "handleReport called for nested getReports() call"), |
|
70 null, null, null |
|
71 ); |
|
72 |
|
73 // Close the remote processes. |
|
74 for (let i = 0; i < numRemotes; i++) { |
|
75 remotes[i].close(); |
|
76 } |
|
77 |
|
78 // Check the results. |
|
79 |
|
80 let processes = Object.keys(residents); |
|
81 ok(processes.length == numRemotes + 1, "correct resident count"); |
|
82 |
|
83 let numEmptyProcesses = 0, numNonEmptyProcesses = 0; |
|
84 for (let i = 0; i < processes.length; i++) { |
|
85 if (processes[i] == "") { |
|
86 numEmptyProcesses++; |
|
87 } else { |
|
88 ok(processes[i].startsWith("Browser ("), |
|
89 "correct non-empty process name prefix"); |
|
90 numNonEmptyProcesses++; |
|
91 } |
|
92 } |
|
93 ok(numEmptyProcesses == 1, "correct empty process name count"); |
|
94 ok(numNonEmptyProcesses == numRemotes, |
|
95 "correct non-empty process name count"); |
|
96 |
|
97 SimpleTest.finish(); |
|
98 } |
|
99 |
|
100 mgr.getReports(handleReport, null, processReports, null); |
|
101 } |
|
102 |
|
103 ]]></script> |
|
104 </window> |