1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/aboutmemory/tests/test_aboutmemory5.xul Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,162 @@ 1.4 +<?xml version="1.0"?> 1.5 +<?xml-stylesheet type="text/css" href="chrome://global/skin"?> 1.6 +<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?> 1.7 +<window title="about:memory" 1.8 + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> 1.9 + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> 1.10 + <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script> 1.11 + 1.12 + <!-- This file tests the saving and loading of memory reports to/from file in 1.13 + about:memory in the presence of child processes. It is also notable 1.14 + for being an about:memory test that uses the real reporters, rather 1.15 + than fake deterministic ones, and so tends to show up problems in the 1.16 + real reporters (like bogus negative values). --> 1.17 + 1.18 + <!-- test results are displayed in the html:body --> 1.19 + <body xmlns="http://www.w3.org/1999/xhtml"></body> 1.20 + 1.21 + <iframe id="amFrame" height="400" src="about:memory"></iframe> 1.22 + 1.23 + <script type="application/javascript"> 1.24 + <![CDATA[ 1.25 + "use strict"; 1.26 + 1.27 + const Cc = Components.classes; 1.28 + const Ci = Components.interfaces; 1.29 + let mgr = Cc["@mozilla.org/memory-reporter-manager;1"]. 1.30 + getService(Ci.nsIMemoryReporterManager); 1.31 + 1.32 + let numRemotes = 3; 1.33 + let numReady = 0; 1.34 + 1.35 + // Create some remote processes, and set up message-passing so that 1.36 + // we know when each child is fully initialized. 1.37 + let remotes = []; 1.38 + 1.39 + let prefs = [ 1.40 + ["dom.ipc.processCount", 3], // Allow up to 3 child processes 1.41 + ["memory.system_memory_reporter", true] // Test SystemMemoryReporter 1.42 + ]; 1.43 + 1.44 + SpecialPowers.pushPrefEnv({"set": prefs}, function() { 1.45 + for (let i = 0; i < numRemotes; i++) { 1.46 + let w = remotes[i] = window.open("remote.xul", "", "chrome"); 1.47 + 1.48 + w.addEventListener("load", function loadHandler() { 1.49 + w.removeEventListener("load", loadHandler); 1.50 + let remoteBrowser = w.document.getElementById("remote"); 1.51 + let mm = remoteBrowser.messageManager; 1.52 + mm.addMessageListener("test:ready", function readyHandler() { 1.53 + mm.removeMessageListener("test:ready", readyHandler); 1.54 + numReady++; 1.55 + if (numReady == numRemotes) { 1.56 + // All the remote processes are ready. 1.57 + SimpleTest.waitForFocus(onFocus); 1.58 + } 1.59 + }); 1.60 + mm.loadFrameScript("data:," + encodeURI("sendAsyncMessage('test:ready');"), true); 1.61 + }); 1.62 + } 1.63 + }); 1.64 + 1.65 + // Load the given file into the frame, then copy+paste the entire frame and 1.66 + // check that the cut text matches what we expect. 1.67 + function onFocus() { 1.68 + let frame = document.getElementById("amFrame"); 1.69 + frame.focus(); 1.70 + 1.71 + function getFilePath(aFilename) { 1.72 + let file = Cc["@mozilla.org/file/directory_service;1"] 1.73 + .getService(Components.interfaces.nsIProperties) 1.74 + .get("CurWorkD", Components.interfaces.nsIFile); 1.75 + file.append("chrome"); 1.76 + file.append("toolkit"); 1.77 + file.append("components"); 1.78 + file.append("aboutmemory"); 1.79 + file.append("tests"); 1.80 + file.append(aFilename); 1.81 + return file.path; 1.82 + } 1.83 + 1.84 + let filePath = getFilePath("memory-reports-dumped.json.gz"); 1.85 + 1.86 + let e = document.createEvent('Event'); 1.87 + e.initEvent('change', true, true); 1.88 + 1.89 + let dumper = Cc["@mozilla.org/memory-info-dumper;1"]. 1.90 + getService(Ci.nsIMemoryInfoDumper); 1.91 + dumper.dumpMemoryReportsToNamedFile(filePath, loadAndCheck, null); 1.92 + 1.93 + function loadAndCheck() { 1.94 + // Load the file. 1.95 + let fileInput1 = 1.96 + frame.contentWindow.document.getElementById("fileInput1"); 1.97 + fileInput1.value = filePath; // this works because it's a chrome test 1.98 + fileInput1.dispatchEvent(e); 1.99 + 1.100 + // Initialize the clipboard contents. 1.101 + SpecialPowers.clipboardCopyString("initial clipboard value"); 1.102 + 1.103 + let numFailures = 0, maxFailures = 30; 1.104 + 1.105 + copyPasteAndCheck(); 1.106 + 1.107 + // Because the file load is async, we don't know when it will finish and 1.108 + // the output will show up. So we poll. 1.109 + function copyPasteAndCheck() { 1.110 + // Copy and paste frame contents, and filter out non-deterministic 1.111 + // differences. 1.112 + synthesizeKey("A", {accelKey: true}); 1.113 + synthesizeKey("C", {accelKey: true}); 1.114 + let actual = SpecialPowers.getClipboardData("text/unicode"); 1.115 + 1.116 + // If we have more than 1000 chars, we've probably successfully 1.117 + // copy+pasted. 1.118 + if (actual.length > 1000) { 1.119 + 1.120 + let good = true; 1.121 + 1.122 + if (actual.match("End of System")) { 1.123 + let m1 = actual.match("anonymous") && 1.124 + actual.match("shared-libraries"); 1.125 + ok(m1, "system-wide reporter") 1.126 + good = good && !!m1; 1.127 + } 1.128 + 1.129 + // Note: Match "vsize" but not "vsize-max-contiguous". 1.130 + let vsizes = actual.match(/vsize[^-]/g); 1.131 + let endOfBrowsers = actual.match(/End of Browser/g); 1.132 + let m2 = (vsizes.length == 4 && endOfBrowsers.length == 3); 1.133 + ok(m2, "three child processes present in loaded data"); 1.134 + good = good && !!m2; 1.135 + 1.136 + if (!good) { 1.137 + dump("*******ACTUAL*******\n"); 1.138 + dump(actual); 1.139 + dump("********************\n"); 1.140 + } 1.141 + 1.142 + // Close the remote processes. 1.143 + for (let i = 0; i < numRemotes; i++) { 1.144 + remotes[i].close(); 1.145 + } 1.146 + 1.147 + SimpleTest.finish(); 1.148 + 1.149 + } else { 1.150 + numFailures++; 1.151 + if (numFailures === maxFailures) { 1.152 + ok(false, "not enough chars in pasted output"); 1.153 + SimpleTest.finish(); 1.154 + } else { 1.155 + setTimeout(copyPasteAndCheck, 100); 1.156 + } 1.157 + } 1.158 + } 1.159 + } 1.160 + } 1.161 + 1.162 + SimpleTest.waitForExplicitFinish(); 1.163 + ]]> 1.164 + </script> 1.165 +</window>