summaryrefslogtreecommitdiffstats
path: root/toolkit/components/aboutmemory/tests/test_aboutmemory5.xhtml
diff options
context:
space:
mode:
Diffstat (limited to 'toolkit/components/aboutmemory/tests/test_aboutmemory5.xhtml')
-rw-r--r--toolkit/components/aboutmemory/tests/test_aboutmemory5.xhtml169
1 files changed, 169 insertions, 0 deletions
diff --git a/toolkit/components/aboutmemory/tests/test_aboutmemory5.xhtml b/toolkit/components/aboutmemory/tests/test_aboutmemory5.xhtml
new file mode 100644
index 0000000000..7b63179767
--- /dev/null
+++ b/toolkit/components/aboutmemory/tests/test_aboutmemory5.xhtml
@@ -0,0 +1,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>