gecko/toolkit/components/aboutmemory/tests/chrome/test_aboutmemory.xul

361 lines
13 KiB
Plaintext
Raw Normal View History

<?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 type="application/javascript" src="chrome://mochikit/content/MochiKit/packed.js"/>
<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>
<!-- 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[
const Cc = Components.classes;
const Ci = Components.interfaces;
var 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 = [];
var dummy = 0;
while (e.hasMoreElements()) {
var r = e.getNext().QueryInterface(Ci.nsIMemoryReporter);
// Get the |amount| field, even though we don't use it, just to test
// that the reporter doesn't crash or anything.
dummy += r.amount;
mgr.unregisterReporter(r);
realReporters.push(r);
}
e = mgr.enumerateMultiReporters();
var realMultiReporters = [];
var dummy = 0;
while (e.hasMoreElements()) {
var r = e.getNext().QueryInterface(Ci.nsIMemoryMultiReporter);
// Call collectReports, even though we don't use its results, just to
// test that the multi-reporter doesn't crash or anything.
r.collectReports(function(){}, null);
mgr.unregisterMultiReporter(r);
realMultiReporters.push(r);
}
// Setup various fake-but-deterministic reporters.
const KB = 1024;
const MB = KB * KB;
const kUnknown = -1;
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 f2(aProcess, aPath, aKind, aUnits, aAmount) {
return {
process: aProcess,
path: aPath,
kind: aKind,
units: aUnits,
description: "(description)",
amount: aAmount
};
}
function f(aProcess, aPath, aKind, aAmount) {
return f2(aProcess, aPath, aKind, BYTES, aAmount);
}
var fakeReporters = [
f("", "heap-allocated", OTHER, 500 * MB),
f("", "heap-unallocated", OTHER, 100 * MB),
f("", "explicit/a", HEAP, 222 * MB),
f("", "explicit/b/a", HEAP, 85 * MB),
f("", "explicit/b/b", HEAP, 75 * MB),
f("", "explicit/b/c/a", HEAP, 70 * MB),
f("", "explicit/b/c/b", HEAP, 2 * MB), // omitted
f("", "explicit/c", NONHEAP, 100 * MB),
f("", "explicit/c/d", NONHEAP, 13 * MB), // subsumed by parent
f("", "explicit/g", HEAP, 1 * MB), // internal, dup: merge
f("", "explicit/g/a", HEAP, 6 * MB),
f("", "explicit/g/b", HEAP, 5 * MB),
f("", "other1", OTHER, 111 * MB),
f2("", "other4", OTHER, COUNT, 888),
f2("", "unknown-unit", OTHER, /*bogus unit*/999, 999)
];
var fakeMultiReporters = [
{ collectReports: function(cbObj, closure) {
function f(p, k, u, a) { cbObj.callback("", p, k, u, a, "(desc)", closure); }
f("explicit/c/d", NONHEAP, BYTES, 10 * MB), // dup, subsumed by parent
f("explicit/cc", NONHEAP, BYTES, 13 * MB);
f("explicit/cc", NONHEAP, BYTES, 10 * MB); // dup
f("explicit/d", NONHEAP, BYTES, 499 * KB); // omitted
f("explicit/e", NONHEAP, BYTES, 100 * KB); // omitted
f("explicit/f/g/h/i", HEAP, BYTES, 20 * MB);
}
},
{ collectReports: function(cbObj, closure) {
function f(p, k, u, a) { cbObj.callback("", p, k, u, a, "(desc)", closure); }
f("explicit/g", HEAP, BYTES, 14 * MB); // internal
f("other2", OTHER, BYTES, 222 * MB);
f("other3", OTHER, COUNT, 777);
}
}
];
for (var i = 0; i < fakeReporters.length; i++) {
mgr.registerReporter(fakeReporters[i]);
}
for (var i = 0; i < fakeMultiReporters.length; i++) {
mgr.registerMultiReporter(fakeMultiReporters[i]);
}
// mgr.explicit sums "heap-allocated" and all the appropriate NONHEAP ones:
// - "explicit/c", "explicit/cc" x 2, "explicit/d", "explicit/e"
// - but *not* "explicit/c/d" x 2
// Check explicit now before we add the fake reporters for the fake 2nd
// and subsequent processes.
is(mgr.explicit, 500*MB + (100 + 13 + 10)*MB + 599*KB, "mgr.explicit");
// Access mgr.resident just to make sure it doesn't crash. We can't check
// its actual value because it's non-deterministic.
dummy = mgr.resident;
var fakeReporters2 = [
f("2nd", "heap-allocated", OTHER, 1000 * MB),
f("2nd", "heap-unallocated",OTHER, 100 * MB),
f("2nd", "explicit/a/b/c", HEAP, 498 * MB),
f("2nd", "explicit/a/b/c", HEAP, 1 * MB), // dup: merge
f("2nd", "explicit/flip\\the\\backslashes",
HEAP, 200 * MB),
f("2nd", "explicit/compartment(this-will-be-truncated-in-non-verbose-mode-abcdefghijklmnopqrstuvwxyz)",
HEAP, 200 * MB),
// The escaping of compartment names must prevent this script from running.
f("2nd", "danger<script>window.alert(1)</script>",
OTHER, 666 * MB),
f("2nd", "other1", OTHER, 111 * MB),
// kUnknown should be handled gracefully for "heap-allocated", non-leaf
// reporters, leaf-reporters, and "other" reporters.
f("3rd", "heap-allocated", OTHER, kUnknown),
f("3rd", "explicit/a", HEAP, kUnknown),
f("3rd", "explicit/a/b", HEAP, 333 * MB),
f("3rd", "explicit/a/c", HEAP, 444 * MB),
f("3rd", "explicit/a/d", HEAP, kUnknown),
f("3rd", "explicit/b", NONHEAP, kUnknown),
f("3rd", "other1", OTHER, kUnknown)
];
for (var i = 0; i < fakeReporters2.length; i++) {
mgr.registerReporter(fakeReporters2[i]);
}
fakeReporters = fakeReporters.concat(fakeReporters2);
]]>
</script>
<iframe id="amFrame" height="300" src="about:memory"></iframe>
<iframe id="amvFrame" height="300" src="about:memory?verbose"></iframe>
<script type="application/javascript">
<![CDATA[
var amExpectedText =
"\
Main Process\n\
\n\
Explicit Allocations\n\
623.58 MB (100.0%) -- explicit\n\
├──232.00 MB (37.20%) -- b\n\
│ ├───85.00 MB (13.63%) -- a\n\
│ ├───75.00 MB (12.03%) -- b\n\
│ └───72.00 MB (11.55%) -- c\n\
│ ├──70.00 MB (11.23%) -- a\n\
│ └───2.00 MB (00.32%) -- (1 omitted)\n\
├──222.00 MB (35.60%) -- a\n\
├──100.00 MB (16.04%) -- c\n\
│ ├───77.00 MB (12.35%) -- other\n\
│ └───23.00 MB (03.69%) -- d\n\
├───23.00 MB (03.69%) -- cc\n\
├───20.00 MB (03.21%) -- f\n\
│ └──20.00 MB (03.21%) -- g\n\
│ └──20.00 MB (03.21%) -- h\n\
│ └──20.00 MB (03.21%) -- i\n\
├───15.00 MB (02.41%) -- g\n\
│ ├───6.00 MB (00.96%) -- a\n\
│ ├───5.00 MB (00.80%) -- b\n\
│ └───4.00 MB (00.64%) -- other\n\
├───11.00 MB (01.76%) -- heap-unclassified\n\
└────0.58 MB (00.09%) -- (2 omitted)\n\
\n\
Other Measurements\n\
500.00 MB -- heap-allocated\n\
222.00 MB -- other2\n\
111.00 MB -- other1\n\
100.00 MB -- heap-unallocated\n\
777 -- other3\n\
888 -- other4\n\
(???) -- unknown-unit\n\
\n\
2nd Process\n\
\n\
Explicit Allocations\n\
1,000.00 MB (100.0%) -- explicit\n\
├────499.00 MB (49.90%) -- a\n\
│ └──499.00 MB (49.90%) -- b\n\
│ └──499.00 MB (49.90%) -- c\n\
├────200.00 MB (20.00%) -- flip/the/backslashes\n\
├────200.00 MB (20.00%) -- compartment(this-will-be-truncated-in-non-verbose-mo...)\n\
└────101.00 MB (10.10%) -- heap-unclassified\n\
\n\
Other Measurements\n\
1,000.00 MB -- heap-allocated\n\
666.00 MB -- danger<script>window.alert(1)</script>\n\
111.00 MB -- other1\n\
100.00 MB -- heap-unallocated\n\
\n\
3rd Process\n\
\n\
Explicit Allocations\n\
777.00 MB (100.0%) -- explicit\n\
├──777.00 MB (100.0%) -- a [*]\n\
│ ├──444.00 MB (57.14%) -- c\n\
│ ├──333.00 MB (42.86%) -- b\n\
│ └────0.00 MB (00.00%) -- (1 omitted)\n\
└────0.00 MB (00.00%) -- (2 omitted)\n\
\n\
Other Measurements\n\
0.00 MB -- heap-allocated [*]\n\
0.00 MB -- other1 [*]\n\
\n\
";
var amvExpectedText =
"\
Main Process\n\
\n\
Explicit Allocations\n\
653,876,224 B (100.0%) -- explicit\n\
├──243,269,632 B (37.20%) -- b\n\
│ ├───89,128,960 B (13.63%) -- a\n\
│ ├───78,643,200 B (12.03%) -- b\n\
│ └───75,497,472 B (11.55%) -- c\n\
│ ├──73,400,320 B (11.23%) -- a\n\
│ └───2,097,152 B (00.32%) -- b\n\
├──232,783,872 B (35.60%) -- a\n\
├──104,857,600 B (16.04%) -- c\n\
│ ├───80,740,352 B (12.35%) -- other\n\
│ └───24,117,248 B (03.69%) -- d\n\
├───24,117,248 B (03.69%) -- cc\n\
├───20,971,520 B (03.21%) -- f\n\
│ └──20,971,520 B (03.21%) -- g\n\
│ └──20,971,520 B (03.21%) -- h\n\
│ └──20,971,520 B (03.21%) -- i\n\
├───15,728,640 B (02.41%) -- g\n\
│ ├───6,291,456 B (00.96%) -- a\n\
│ ├───5,242,880 B (00.80%) -- b\n\
│ └───4,194,304 B (00.64%) -- other\n\
├───11,534,336 B (01.76%) -- heap-unclassified\n\
├──────510,976 B (00.08%) -- d\n\
└──────102,400 B (00.02%) -- e\n\
\n\
Other Measurements\n\
524,288,000 B -- heap-allocated\n\
232,783,872 B -- other2\n\
116,391,936 B -- other1\n\
104,857,600 B -- heap-unallocated\n\
777 -- other3\n\
888 -- other4\n\
(???) -- unknown-unit\n\
\n\
2nd Process\n\
\n\
Explicit Allocations\n\
1,048,576,000 B (100.0%) -- explicit\n\
├────523,239,424 B (49.90%) -- a\n\
│ └──523,239,424 B (49.90%) -- b\n\
│ └──523,239,424 B (49.90%) -- c\n\
├────209,715,200 B (20.00%) -- flip/the/backslashes\n\
├────209,715,200 B (20.00%) -- compartment(this-will-be-truncated-in-non-verbose-mode-abcdefghijklmnopqrstuvwxyz)\n\
└────105,906,176 B (10.10%) -- heap-unclassified\n\
\n\
Other Measurements\n\
1,048,576,000 B -- heap-allocated\n\
698,351,616 B -- danger<script>window.alert(1)</script>\n\
116,391,936 B -- other1\n\
104,857,600 B -- heap-unallocated\n\
\n\
3rd Process\n\
\n\
Explicit Allocations\n\
814,743,552 B (100.0%) -- explicit\n\
├──814,743,552 B (100.0%) -- a [*]\n\
│ ├──465,567,744 B (57.14%) -- c\n\
│ ├──349,175,808 B (42.86%) -- b\n\
│ └────────────0 B (00.00%) -- d [*]\n\
├────────────0 B (00.00%) -- b [*]\n\
└────────────0 B (00.00%) -- heap-unclassified [*]\n\
\n\
Other Measurements\n\
0 B -- heap-allocated [*]\n\
0 B -- other1 [*]\n\
\n\
"
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(aFrame, aExpectedText, aNext) {
document.querySelector("#" + aFrame).focus();
SimpleTest.waitForClipboard(aExpectedText,
function() {
synthesizeKey("A", {accelKey: true});
synthesizeKey("C", {accelKey: true});
},
aNext,
function() {
ok(false, "pasted text doesn't match for " + aFrame);
finish();
}
);
}
addLoadEvent(function() {
test(
"amFrame",
amExpectedText,
function() {
test(
"amvFrame",
amvExpectedText,
function() {
finish()
}
)
}
);
});
SimpleTest.waitForExplicitFinish();
]]>
</script>
</window>