gecko/toolkit/components/aboutmemory/tests/test_aboutcompartments.xul
Nicholas Nethercote d09087aa9d Bug 760352 (part 1) - Allow KIND_OTHER memory reports to be in trees. r=jlebar.
--HG--
extra : rebase_source : d28d117fbc2c91069222649741f5ef6b567b3e2a
2012-06-11 20:29:12 -07:00

252 lines
8.3 KiB
XML

<?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:compartments"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
<!-- This file uses fake memory reporters to test the presentation of
compartment memory reports in about:memory. test_memoryReporters.xul
uses the real memory reporters to test whether the memory reporters
are producing sensible results. -->
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml"></body>
<!-- test code goes here -->
<script type="application/javascript">
<![CDATA[
"use strict";
const Cc = Components.classes;
const Ci = Components.interfaces;
let mgr = Cc["@mozilla.org/memory-reporter-manager;1"].
getService(Ci.nsIMemoryReporterManager);
// Remove all the real reporters and multi-reporters; save them to
// restore at the end.
var e = mgr.enumerateReporters();
var realReporters = [];
while (e.hasMoreElements()) {
var r = e.getNext().QueryInterface(Ci.nsIMemoryReporter);
mgr.unregisterReporter(r);
realReporters.push(r);
}
e = mgr.enumerateMultiReporters();
var realMultiReporters = [];
while (e.hasMoreElements()) {
var r = e.getNext().QueryInterface(Ci.nsIMemoryMultiReporter);
mgr.unregisterMultiReporter(r);
realMultiReporters.push(r);
}
// Setup various fake-but-deterministic reporters.
const KB = 1024;
const MB = KB * KB;
const NONHEAP = Ci.nsIMemoryReporter.KIND_NONHEAP;
const HEAP = Ci.nsIMemoryReporter.KIND_HEAP;
const OTHER = Ci.nsIMemoryReporter.KIND_OTHER;
const BYTES = Ci.nsIMemoryReporter.UNITS_BYTES;
const COUNT = Ci.nsIMemoryReporter.UNITS_COUNT;
function f(aProcess, aPath, aKind, aUnits, aAmount) {
return {
process: aProcess,
path: aPath,
kind: aKind,
units: aUnits,
description: "",
amount: aAmount
};
}
var fakeReporters = [
// These should be ignored.
f("", "explicit/a", HEAP, BYTES, 222 * MB),
f("", "explicit/b/a", HEAP, BYTES, 85 * MB),
f("", "explicit/b/b", NONHEAP, BYTES, 85 * MB),
f("", "other1", OTHER, BYTES, 111 * MB),
f("", "other2", OTHER, COUNT, 888),
f("2nd", "explicit/c", HEAP, BYTES, 333 * MB),
f("2nd", "compartments/user/child-user-compartment", OTHER, COUNT, 1),
f("2nd", "compartments/system/child-system-compartment", OTHER, COUNT, 1)
];
var fakeMultiReporters = [
// These shouldn't show up.
{ name: "fake",
collectReports: function(aCbObj, aClosure) {
function f(aP, aK, aU, aA) {
aCbObj.callback("", aP, aK, aU, aA, "Desc.", aClosure);
}
f("explicit/a/d", HEAP, BYTES, 13 * MB);
f("explicit/b/c", NONHEAP, BYTES, 10 * MB);
},
explicitNonHeap: 10*MB
},
{ name: "compartments",
collectReports: function(aCbObj, aClosure) {
function f(aP) {
aCbObj.callback("", aP, OTHER, COUNT, 1, "", aClosure);
}
f("compartments/user/http:\\\\foo.com\\");
f("compartments/user/https:\\\\bar.com\\bar?baz");
f("compartments/user/https:\\\\very-long-url.com\\very-long\\oh-so-long\\really-quite-long.html?a=2&b=3&c=4&d=5&e=abcdefghijklmnopqrstuvwxyz&f=123456789123456789123456789");
// This moz-nullprincipal one is shown under "System Compartments" even
// though its path indicates it's a user compartment.
f("compartments/user/moz-nullprincipal:{7ddefdaf-34f1-473f-9b03-50a4568ccb06}");
// This should show up once with a "[3]" suffix
f("compartments/system/[System Principal]");
f("compartments/system/[System Principal]");
f("compartments/system/[System Principal]");
f("compartments/system/atoms");
},
explicitNonHeap: 0
},
{ name: "ghost-windows",
collectReports: function(aCbObj, aClosure) {
function f(aP) {
aCbObj.callback("", aP, OTHER, COUNT, 1, "", aClosure);
}
f("ghost-windows/https:\\\\very-long-url.com\\very-long\\oh-so-long\\really-quite-long.html?a=2&b=3&c=4&d=5&e=abcdefghijklmnopqrstuvwxyz&f=123456789123456789123456789");
f("ghost-windows/http:\\\\foobar.com\\foo?bar#baz");
},
explicitNonHeap: 0
},
// These shouldn't show up.
{ name: "smaps",
collectReports: function(aCbObj, aClosure) {
// The amounts are given in pages, so multiply here by 4kb.
function f(aP, aA) {
aCbObj.callback("", aP, NONHEAP, BYTES, aA * 4 * KB, "Desc.", aClosure);
}
f("smaps/vsize/a", 24);
f("smaps/swap/a", 1);
},
explicitNonHeap: 0
}
];
for (var i = 0; i < fakeReporters.length; i++) {
mgr.registerReporter(fakeReporters[i]);
}
for (var i = 0; i < fakeMultiReporters.length; i++) {
mgr.registerMultiReporter(fakeMultiReporters[i]);
}
]]>
</script>
<iframe id="acFrame" height="400" src="about:compartments"></iframe>
<!-- vary the capitalization to make sure that works -->
<iframe id="acvFrame" height="400" src="abouT:compartMENTS?veRBOse"></iframe>
<script type="application/javascript">
<![CDATA[
var acExpectedText =
"\
Main Process\n\
\n\
User Compartments\n\
http://foo.com/\n\
https://bar.com/bar?baz\n\
https://very-long-url.com/very-long/oh-so-long/really-quite-long.html?a=2&b=3&c=4&d=5&e=abcdefghijklmnopqrstuvwxyz&f=123456789123456789123456789\n\
\n\
System Compartments\n\
[System Principal] [3]\n\
atoms\n\
moz-nullprincipal:{7ddefdaf-34f1-473f-9b03-50a4568ccb06}\n\
\n\
Ghost Windows\n\
http://foobar.com/foo?bar#baz\n\
https://very-long-url.com/very-long/oh-so-long/really-quite-long.html?a=2&b=3&c=4&d=5&e=abcdefghijklmnopqrstuvwxyz&f=123456789123456789123456789\n\
\n\
2nd Process\n\
\n\
User Compartments\n\
child-user-compartment\n\
\n\
System Compartments\n\
child-system-compartment\n\
\n\
Ghost Windows\n\
\n\
";
// Verbose mode output is the same when you cut and paste.
var acvExpectedText = acExpectedText;
function finish()
{
// Unregister fake reporters and multi-reporters, re-register the real
// reporters and multi-reporters, just in case subsequent tests rely on
// them.
for (var i = 0; i < fakeReporters.length; i++) {
mgr.unregisterReporter(fakeReporters[i]);
}
for (var i = 0; i < fakeMultiReporters.length; i++) {
mgr.unregisterMultiReporter(fakeMultiReporters[i]);
}
for (var i = 0; i < realReporters.length; i++) {
mgr.registerReporter(realReporters[i]);
}
for (var i = 0; i < realMultiReporters.length; i++) {
mgr.registerMultiReporter(realMultiReporters[i]);
}
SimpleTest.finish();
}
// Cut+paste the entire page and check that the cut text matches what we
// expect. This tests the output in general and also that the cutting and
// pasting works as expected.
function test(aFrameId, aExpected, aNext) {
ok(document.title === "about:compartments", "document.title is correct");
let frame = document.getElementById(aFrameId);
SimpleTest.executeSoon(function() {
frame.focus();
SimpleTest.waitForClipboard(
function(aActual) {
mostRecentActual = aActual;
return aActual === aExpected;
},
function() {
synthesizeKey("A", {accelKey: true});
synthesizeKey("C", {accelKey: true});
},
aNext,
function() {
ok(false, "pasted text doesn't match for " + aFrameId);
dump("******EXPECTED******\n");
dump(aExpected);
dump("*******ACTUAL*******\n");
dump(mostRecentActual);
dump("********************\n");
finish();
}
);
});
}
SimpleTest.waitForFocus(function() {
test(
"acFrame",
acExpectedText,
function() {
test(
"acvFrame",
acvExpectedText,
function() {
finish()
}
)
}
);
});
SimpleTest.waitForExplicitFinish();
]]>
</script>
</window>