1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
|
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
<window title="about:memory"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
<!-- This file tests the saving and loading of memory reports to/from file in
about:memory in the presence of child processes. It is also notable
for being an about:memory test that uses the real reporters, rather
than fake deterministic ones, and so tends to show up problems in the
real reporters (like bogus negative values). -->
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml"></body>
<iframe id="amFrame" height="400" src="about:memory"></iframe>
<script type="application/javascript">
<![CDATA[
"use strict";
let mgr = Cc["@mozilla.org/memory-reporter-manager;1"].
getService(Ci.nsIMemoryReporterManager);
let numRemotes = 3;
let numReady = 0;
// Create some remote processes, and set up message-passing so that
// we know when each child is fully initialized.
let remotes = [];
let prefs = [
["dom.ipc.processCount", 3], // Allow up to 3 child processes
["memory.report_concurrency", 2] // Cover more child handling cases
];
SpecialPowers.pushPrefEnv({"set": prefs}).then(function() {
for (let i = 0; i < numRemotes; i++) {
let w = remotes[i] = window.browsingContext.topChromeWindow.open("remote.xhtml", "", "chrome");
w.addEventListener("load", function loadHandler() {
let remoteBrowser = w.document.getElementById("remote");
let mm = remoteBrowser.messageManager;
mm.addMessageListener("test:ready", function readyHandler() {
mm.removeMessageListener("test:ready", readyHandler);
numReady++;
if (numReady == numRemotes) {
// All the remote processes are ready.
SimpleTest.waitForFocus(onFocus);
}
});
mm.loadFrameScript("data:," + encodeURI("sendAsyncMessage('test:ready');"), true);
});
}
});
// Load the given file into the frame, then copy+paste the entire frame and
// check that the cut text matches what we expect.
function onFocus() {
let frame = document.getElementById("amFrame");
frame.focus();
function getFilePath(aFilename) {
let file = SpecialPowers.Services.dirsvc.get("CurWorkD", Ci.nsIFile);
file.append("chrome");
file.append("toolkit");
file.append("components");
file.append("aboutmemory");
file.append("tests");
file.append(aFilename);
return file.path;
}
let filePath = getFilePath("memory-reports-dumped.json.gz");
let e = document.createEvent('Event');
e.initEvent('change', true, true);
let dumper = Cc["@mozilla.org/memory-info-dumper;1"].
getService(Ci.nsIMemoryInfoDumper);
dumper.dumpMemoryReportsToNamedFile(filePath, loadAndCheck, null,
/* anonymize = */ false,
/* minimize memory usage = */ false);
function loadAndCheck() {
// Load the file.
let fileInput1 =
frame.contentWindow.document.getElementById("fileInput1");
fileInput1.value = filePath; // this works because it's a chrome test
fileInput1.dispatchEvent(e);
// Initialize the clipboard contents.
SpecialPowers.clipboardCopyString("initial clipboard value");
let numFailures = 0, maxFailures = 30;
copyPasteAndCheck();
// Because the file load is async, we don't know when it will finish and
// the output will show up. So we poll.
function copyPasteAndCheck() {
// Copy and paste frame contents, and filter out non-deterministic
// differences.
synthesizeKey("A", {accelKey: true});
synthesizeKey("C", {accelKey: true});
let actual = SpecialPowers.getClipboardData("text/plain");
// If we have more than 1000 chars, we've probably successfully
// copy+pasted.
if (actual.length > 1000) {
let good = true;
if (actual.match("End of System")) {
let m1 = actual.match("anonymous") &&
actual.match("shared-libraries");
ok(m1, "system-wide reporter")
good = good && !!m1;
}
// Note: Match "vsize" but not "vsize-max-contiguous".
let vsizes = actual.match(/vsize[^-]/g);
let endOfBrowsers = actual.match(/End of Browser/g);
if (endOfBrowsers == null) {
endOfBrowsers = actual.match(/End of [wW]eb /g);
}
let socketProcessRunning = 0;
if (SpecialPowers.Services.io.socketProcessLaunched) {
socketProcessRunning = 1;
}
let m2 = (vsizes.length == (4 + socketProcessRunning + ChromeUtils.aliveUtilityProcesses) &&
endOfBrowsers.length == 3);
ok(m2, "three content processes present in loaded data");
good = good && !!m2;
if (!good) {
dump("*******ACTUAL*******\n");
dump(actual);
dump("********************\n");
}
// Close the remote processes.
for (let i = 0; i < numRemotes; i++) {
remotes[i].close();
}
SimpleTest.finish();
} else {
numFailures++;
if (numFailures === maxFailures) {
ok(false, "not enough chars in pasted output");
SimpleTest.finish();
} else {
setTimeout(copyPasteAndCheck, 100);
}
}
}
}
}
SimpleTest.waitForExplicitFinish();
]]>
</script>
</window>
|