toolkit/components/aboutmemory/tests/test_memoryReporters2.xul

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial