1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/aboutmemory/tests/test_aboutmemory4.xul Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,167 @@ 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 loading of memory reports from file when specified 1.13 + in about:memory's URL (via the "file=" suffix). --> 1.14 + 1.15 + <!-- test results are displayed in the html:body --> 1.16 + <body xmlns="http://www.w3.org/1999/xhtml"></body> 1.17 + 1.18 + <!-- test code goes here --> 1.19 + <script type="application/javascript"> 1.20 + <![CDATA[ 1.21 + "use strict"; 1.22 + 1.23 + function makePathname(aFilename) { 1.24 + let file = Components.classes["@mozilla.org/file/directory_service;1"] 1.25 + .getService(Components.interfaces.nsIProperties) 1.26 + .get("CurWorkD", Components.interfaces.nsIFile); 1.27 + file.append("chrome"); 1.28 + file.append("toolkit"); 1.29 + file.append("components"); 1.30 + file.append("aboutmemory"); 1.31 + file.append("tests"); 1.32 + file.append(aFilename); 1.33 + return file.path; 1.34 + } 1.35 + 1.36 + // Load the given file into the frame, then copy+paste the entire frame and 1.37 + // check that the cut text matches what we expect. 1.38 + function test(aFilename, aExpected, aNext) { 1.39 + let frame = document.createElementNS("http://www.w3.org/1999/xhtml", "iframe") 1.40 + frame.height = 300; 1.41 + frame.src = "about:memory?file=" + makePathname(aFilename); 1.42 + document.documentElement.appendChild(frame); 1.43 + frame.focus(); 1.44 + 1.45 + // Initialize the clipboard contents. 1.46 + SpecialPowers.clipboardCopyString("initial clipboard value"); 1.47 + 1.48 + let numFailures = 0, maxFailures = 30; 1.49 + 1.50 + // Because the file load is async, we don't know when it will finish and 1.51 + // the output will show up. So we poll. 1.52 + function copyPasteAndCheck() { 1.53 + // Copy and paste frame contents, and filter out non-deterministic 1.54 + // differences. 1.55 + synthesizeKey("A", {accelKey: true}); 1.56 + synthesizeKey("C", {accelKey: true}); 1.57 + let actual = SpecialPowers.getClipboardData("text/unicode"); 1.58 + actual = actual.replace(/\(pid \d+\)/, "(pid NNN)"); 1.59 + 1.60 + if (actual === aExpected) { 1.61 + SimpleTest.ok(true, "Clipboard has the expected contents"); 1.62 + aNext(); 1.63 + } else { 1.64 + numFailures++; 1.65 + if (numFailures === maxFailures) { 1.66 + ok(false, "pasted text doesn't match"); 1.67 + dump("******EXPECTED******\n"); 1.68 + dump(aExpected); 1.69 + dump("*******ACTUAL*******\n"); 1.70 + dump(actual); 1.71 + dump("********************\n"); 1.72 + SimpleTest.finish(); 1.73 + } else { 1.74 + setTimeout(copyPasteAndCheck, 100); 1.75 + } 1.76 + } 1.77 + } 1.78 + copyPasteAndCheck(); 1.79 + } 1.80 + 1.81 + // Returns a function that chains together multiple test() calls. 1.82 + function chain(aFrameIds) { 1.83 + let x = aFrameIds.shift(); 1.84 + if (x) { 1.85 + return function() { test(x.filename, x.expected, chain(aFrameIds)); } 1.86 + } else { 1.87 + return function() { SimpleTest.finish(); }; 1.88 + } 1.89 + } 1.90 + 1.91 + // This is pretty simple output, but that's ok; this file is about testing 1.92 + // the loading of data from file. If we got this far, we're doing fine. 1.93 + let expectedGood = 1.94 +"\ 1.95 +Explicit-only process\n\ 1.96 +\n\ 1.97 +WARNING: the 'heap-allocated' memory reporter does not work for this platform and/or configuration. This means that 'heap-unclassified' is not shown and the 'explicit' tree shows less memory than it should.\n\ 1.98 +Explicit Allocations\n\ 1.99 +\n\ 1.100 +0.10 MB (100.0%) -- explicit\n\ 1.101 +└──0.10 MB (100.0%) ── a/b\n\ 1.102 +\n\ 1.103 +Other Measurements\n\ 1.104 +\n\ 1.105 +End of Explicit-only process\n\ 1.106 +Main Process (pid NNN)\n\ 1.107 +Explicit Allocations\n\ 1.108 +\n\ 1.109 +250.00 MB (100.0%) -- explicit\n\ 1.110 +├──200.00 MB (80.00%) ── heap-unclassified\n\ 1.111 +└───50.00 MB (20.00%) ── a/b\n\ 1.112 +\n\ 1.113 +Other Measurements\n\ 1.114 +\n\ 1.115 +0.00 MB (100.0%) -- compartments\n\ 1.116 +└──0.00 MB (100.0%) ── system/a\n\ 1.117 +\n\ 1.118 +0.00 MB (100.0%) -- ghost-windows\n\ 1.119 +└──0.00 MB (100.0%) ── a\n\ 1.120 +\n\ 1.121 +0.30 MB (100.0%) -- other\n\ 1.122 +├──0.20 MB (66.67%) ── a\n\ 1.123 +└──0.10 MB (33.33%) ── b\n\ 1.124 +\n\ 1.125 +0.00 MB (100.0%) -- pss\n\ 1.126 +└──0.00 MB (100.0%) ── a\n\ 1.127 +\n\ 1.128 +0.00 MB (100.0%) -- rss\n\ 1.129 +└──0.00 MB (100.0%) ── a\n\ 1.130 +\n\ 1.131 +0.00 MB (100.0%) -- size\n\ 1.132 +└──0.00 MB (100.0%) ── a\n\ 1.133 +\n\ 1.134 +0.00 MB (100.0%) -- swap\n\ 1.135 +└──0.00 MB (100.0%) ── a\n\ 1.136 +\n\ 1.137 +250.00 MB ── heap-allocated\n\ 1.138 +\n\ 1.139 +End of Main Process (pid NNN)\n\ 1.140 +Other-only process\n\ 1.141 +Other Measurements\n\ 1.142 +\n\ 1.143 +0.19 MB (100.0%) -- a\n\ 1.144 +├──0.10 MB (50.00%) ── b\n\ 1.145 +└──0.10 MB (50.00%) ── c\n\ 1.146 +\n\ 1.147 +0.48 MB ── heap-allocated\n\ 1.148 +\n\ 1.149 +End of Other-only process\n\ 1.150 +"; 1.151 + 1.152 + // This is the output for a malformed data file. 1.153 + let expectedBad = 1.154 +"\ 1.155 +Invalid memory report(s): missing 'hasMozMallocUsableSize' property"; 1.156 + 1.157 + let frames = [ 1.158 + // This loads a pre-existing file that is valid. 1.159 + { filename: "memory-reports-good.json", expected: expectedGood }, 1.160 + 1.161 + // This loads a pre-existing file that is valid. 1.162 + { filename: "memory-reports-bad.json", expected: expectedBad } 1.163 + ]; 1.164 + 1.165 + SimpleTest.waitForFocus(chain(frames)); 1.166 + 1.167 + SimpleTest.waitForExplicitFinish(); 1.168 + ]]> 1.169 + </script> 1.170 +</window>