1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/aboutmemory/tests/test_aboutmemory2.xul Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,416 @@ 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 collapsing and expanding of sub-trees in 1.13 + about:memory. --> 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 + const Cc = Components.classes; 1.24 + const Ci = Components.interfaces; 1.25 + let mgr = Cc["@mozilla.org/memory-reporter-manager;1"]. 1.26 + getService(Ci.nsIMemoryReporterManager); 1.27 + 1.28 + // Hide all the real reporters; we'll restore them at the end. 1.29 + mgr.blockRegistrationAndHideExistingReporters(); 1.30 + 1.31 + // Setup various fake-but-deterministic reporters. 1.32 + const KB = 1024; 1.33 + const MB = KB * KB; 1.34 + const HEAP = Ci.nsIMemoryReporter.KIND_HEAP; 1.35 + const OTHER = Ci.nsIMemoryReporter.KIND_OTHER; 1.36 + const BYTES = Ci.nsIMemoryReporter.UNITS_BYTES; 1.37 + 1.38 + let hiPath = "explicit/h/i"; 1.39 + let hi2Path = "explicit/h/i2"; 1.40 + let jkPath = "explicit/j/k"; 1.41 + let jk2Path = "explicit/j/k2"; 1.42 + 1.43 + let fakeReporters = [ 1.44 + { collectReports: function(aCbObj, aClosure) { 1.45 + function f(aP, aK, aA) { 1.46 + aCbObj.callback("", aP, aK, BYTES, aA, "Desc.", aClosure); 1.47 + } 1.48 + f("heap-allocated", OTHER, 250 * MB); 1.49 + f("explicit/a/b", HEAP, 50 * MB); 1.50 + f("explicit/a/c/d", HEAP, 25 * MB); 1.51 + f("explicit/a/c/e", HEAP, 15 * MB); 1.52 + f("explicit/a/f", HEAP, 30 * MB); 1.53 + f("explicit/g", HEAP, 100 * MB); 1.54 + f(hiPath, HEAP, 10 * MB); 1.55 + f(hi2Path, HEAP, 9 * MB); 1.56 + f(jkPath, HEAP, 0.5 * MB); 1.57 + f(jk2Path, HEAP, 0.3 * MB); 1.58 + f("explicit/a/l/m", HEAP, 0.1 * MB); 1.59 + f("explicit/a/l/n", HEAP, 0.1 * MB); 1.60 + } 1.61 + } 1.62 + ]; 1.63 + 1.64 + for (let i = 0; i < fakeReporters.length; i++) { 1.65 + mgr.registerStrongReporterEvenIfBlocked(fakeReporters[i]); 1.66 + } 1.67 + 1.68 + ]]> 1.69 + </script> 1.70 + 1.71 + <iframe id="amFrame" height="500" src="about:memory"></iframe> 1.72 + 1.73 + <script type="application/javascript"> 1.74 + <![CDATA[ 1.75 + function finish() 1.76 + { 1.77 + mgr.unblockRegistrationAndRestoreOriginalReporters(); 1.78 + SimpleTest.finish(); 1.79 + } 1.80 + 1.81 + // Click on the identified element, then cut+paste the entire page and 1.82 + // check that the cut text matches what we expect. 1.83 + function test(aId, aSwap, aExpected, aNext) { 1.84 + let win = document.getElementById("amFrame").contentWindow; 1.85 + if (aId) { 1.86 + let node = win.document.getElementById(aId); 1.87 + 1.88 + // Yuk: clicking a button is easy; but for tree entries we need to 1.89 + // click on a child of the span identified via |id|. 1.90 + if (node.nodeName === "button") { 1.91 + if (aSwap) { 1.92 + // We swap hipath/hi2Path and jkPath/jk2Path just before updating, to 1.93 + // test what happens when significant nodes become insignificant and 1.94 + // vice versa. 1.95 + hiPath = "explicit/j/k"; 1.96 + hi2Path = "explicit/j/k2"; 1.97 + jkPath = "explicit/h/i"; 1.98 + jk2Path = "explicit/h/i2"; 1.99 + } 1.100 + node.click(); 1.101 + } else { 1.102 + node.childNodes[0].click(); 1.103 + } 1.104 + } 1.105 + 1.106 + SimpleTest.executeSoon(function() { 1.107 + let mostRecentActual; 1.108 + document.getElementById("amFrame").focus(); 1.109 + SimpleTest.waitForClipboard( 1.110 + function(aActual) { 1.111 + mostRecentActual = aActual; 1.112 + return aActual === aExpected; 1.113 + }, 1.114 + function() { 1.115 + synthesizeKey("A", {accelKey: true}); 1.116 + synthesizeKey("C", {accelKey: true}); 1.117 + }, 1.118 + aNext, 1.119 + function() { 1.120 + ok(false, "pasted text doesn't match"); 1.121 + dump("******EXPECTED******\n"); 1.122 + dump(aExpected); 1.123 + dump("*******ACTUAL*******\n"); 1.124 + dump(mostRecentActual); 1.125 + dump("********************\n"); 1.126 + finish(); 1.127 + } 1.128 + ); 1.129 + }); 1.130 + } 1.131 + 1.132 + // Returns a function that chains together one test() call per id. 1.133 + function chain(aIds) { 1.134 + let x = aIds.shift(); 1.135 + if (x) { 1.136 + return function() { test(x.id, x.swap, x.expected, chain(aIds)); } 1.137 + } else { 1.138 + return function() { finish(); }; 1.139 + } 1.140 + } 1.141 + 1.142 + let startExpected = 1.143 +"\ 1.144 +Main Process\n\ 1.145 +Explicit Allocations\n\ 1.146 +\n\ 1.147 +250.00 MB (100.0%) -- explicit\n\ 1.148 +├──120.20 MB (48.08%) -- a\n\ 1.149 +│ ├───50.00 MB (20.00%) ── b\n\ 1.150 +│ ├───40.00 MB (16.00%) -- c\n\ 1.151 +│ │ ├──25.00 MB (10.00%) ── d\n\ 1.152 +│ │ └──15.00 MB (06.00%) ── e\n\ 1.153 +│ ├───30.00 MB (12.00%) ── f\n\ 1.154 +│ └────0.20 MB (00.08%) ++ l\n\ 1.155 +├──100.00 MB (40.00%) ── g\n\ 1.156 +├───19.00 MB (07.60%) -- h\n\ 1.157 +│ ├──10.00 MB (04.00%) ── i\n\ 1.158 +│ └───9.00 MB (03.60%) ── i2\n\ 1.159 +├───10.00 MB (04.00%) ── heap-unclassified\n\ 1.160 +└────0.80 MB (00.32%) ++ j\n\ 1.161 +\n\ 1.162 +Other Measurements\n\ 1.163 +\n\ 1.164 +250.00 MB ── heap-allocated\n\ 1.165 +\n\ 1.166 +End of Main Process\n\ 1.167 +"; 1.168 + 1.169 + let acCollapsedExpected = 1.170 +"\ 1.171 +Main Process\n\ 1.172 +Explicit Allocations\n\ 1.173 +\n\ 1.174 +250.00 MB (100.0%) -- explicit\n\ 1.175 +├──120.20 MB (48.08%) -- a\n\ 1.176 +│ ├───50.00 MB (20.00%) ── b\n\ 1.177 +│ ├───40.00 MB (16.00%) ++ c\n\ 1.178 +│ ├───30.00 MB (12.00%) ── f\n\ 1.179 +│ └────0.20 MB (00.08%) ++ l\n\ 1.180 +├──100.00 MB (40.00%) ── g\n\ 1.181 +├───19.00 MB (07.60%) -- h\n\ 1.182 +│ ├──10.00 MB (04.00%) ── i\n\ 1.183 +│ └───9.00 MB (03.60%) ── i2\n\ 1.184 +├───10.00 MB (04.00%) ── heap-unclassified\n\ 1.185 +└────0.80 MB (00.32%) ++ j\n\ 1.186 +\n\ 1.187 +Other Measurements\n\ 1.188 +\n\ 1.189 +250.00 MB ── heap-allocated\n\ 1.190 +\n\ 1.191 +End of Main Process\n\ 1.192 +"; 1.193 + 1.194 + let alExpandedExpected = 1.195 +"\ 1.196 +Main Process\n\ 1.197 +Explicit Allocations\n\ 1.198 +\n\ 1.199 +250.00 MB (100.0%) -- explicit\n\ 1.200 +├──120.20 MB (48.08%) -- a\n\ 1.201 +│ ├───50.00 MB (20.00%) ── b\n\ 1.202 +│ ├───40.00 MB (16.00%) ++ c\n\ 1.203 +│ ├───30.00 MB (12.00%) ── f\n\ 1.204 +│ └────0.20 MB (00.08%) -- l\n\ 1.205 +│ ├──0.10 MB (00.04%) ── m\n\ 1.206 +│ └──0.10 MB (00.04%) ── n\n\ 1.207 +├──100.00 MB (40.00%) ── g\n\ 1.208 +├───19.00 MB (07.60%) -- h\n\ 1.209 +│ ├──10.00 MB (04.00%) ── i\n\ 1.210 +│ └───9.00 MB (03.60%) ── i2\n\ 1.211 +├───10.00 MB (04.00%) ── heap-unclassified\n\ 1.212 +└────0.80 MB (00.32%) ++ j\n\ 1.213 +\n\ 1.214 +Other Measurements\n\ 1.215 +\n\ 1.216 +250.00 MB ── heap-allocated\n\ 1.217 +\n\ 1.218 +End of Main Process\n\ 1.219 +"; 1.220 + 1.221 + let aCollapsedExpected = 1.222 +"\ 1.223 +Main Process\n\ 1.224 +Explicit Allocations\n\ 1.225 +\n\ 1.226 +250.00 MB (100.0%) -- explicit\n\ 1.227 +├──120.20 MB (48.08%) ++ a\n\ 1.228 +├──100.00 MB (40.00%) ── g\n\ 1.229 +├───19.00 MB (07.60%) -- h\n\ 1.230 +│ ├──10.00 MB (04.00%) ── i\n\ 1.231 +│ └───9.00 MB (03.60%) ── i2\n\ 1.232 +├───10.00 MB (04.00%) ── heap-unclassified\n\ 1.233 +└────0.80 MB (00.32%) ++ j\n\ 1.234 +\n\ 1.235 +Other Measurements\n\ 1.236 +\n\ 1.237 +250.00 MB ── heap-allocated\n\ 1.238 +\n\ 1.239 +End of Main Process\n\ 1.240 +"; 1.241 + 1.242 + let hCollapsedExpected = 1.243 +"\ 1.244 +Main Process\n\ 1.245 +Explicit Allocations\n\ 1.246 +\n\ 1.247 +250.00 MB (100.0%) -- explicit\n\ 1.248 +├──120.20 MB (48.08%) ++ a\n\ 1.249 +├──100.00 MB (40.00%) ── g\n\ 1.250 +├───19.00 MB (07.60%) ++ h\n\ 1.251 +├───10.00 MB (04.00%) ── heap-unclassified\n\ 1.252 +└────0.80 MB (00.32%) ++ j\n\ 1.253 +\n\ 1.254 +Other Measurements\n\ 1.255 +\n\ 1.256 +250.00 MB ── heap-allocated\n\ 1.257 +\n\ 1.258 +End of Main Process\n\ 1.259 +"; 1.260 + 1.261 + let jExpandedExpected = 1.262 +"\ 1.263 +Main Process\n\ 1.264 +Explicit Allocations\n\ 1.265 +\n\ 1.266 +250.00 MB (100.0%) -- explicit\n\ 1.267 +├──120.20 MB (48.08%) ++ a\n\ 1.268 +├──100.00 MB (40.00%) ── g\n\ 1.269 +├───19.00 MB (07.60%) ++ h\n\ 1.270 +├───10.00 MB (04.00%) ── heap-unclassified\n\ 1.271 +└────0.80 MB (00.32%) -- j\n\ 1.272 + ├──0.50 MB (00.20%) ── k\n\ 1.273 + └──0.30 MB (00.12%) ── k2\n\ 1.274 +\n\ 1.275 +Other Measurements\n\ 1.276 +\n\ 1.277 +250.00 MB ── heap-allocated\n\ 1.278 +\n\ 1.279 +End of Main Process\n\ 1.280 +"; 1.281 + 1.282 + // The important thing here is that two values have been swapped. 1.283 + // explicit/h/i should remain collapsed, and explicit/j/k should remain 1.284 + // expanded. See bug 724863. 1.285 + let updatedExpected = 1.286 +"\ 1.287 +Main Process\n\ 1.288 +Explicit Allocations\n\ 1.289 +\n\ 1.290 +250.00 MB (100.0%) -- explicit\n\ 1.291 +├──120.20 MB (48.08%) ++ a\n\ 1.292 +├──100.00 MB (40.00%) ── g\n\ 1.293 +├───19.00 MB (07.60%) -- j\n\ 1.294 +│ ├──10.00 MB (04.00%) ── k\n\ 1.295 +│ └───9.00 MB (03.60%) ── k2\n\ 1.296 +├───10.00 MB (04.00%) ── heap-unclassified\n\ 1.297 +└────0.80 MB (00.32%) ++ h\n\ 1.298 +\n\ 1.299 +Other Measurements\n\ 1.300 +\n\ 1.301 +250.00 MB ── heap-allocated\n\ 1.302 +\n\ 1.303 +End of Main Process\n\ 1.304 +"; 1.305 + 1.306 + let aExpandedExpected = 1.307 +"\ 1.308 +Main Process\n\ 1.309 +Explicit Allocations\n\ 1.310 +\n\ 1.311 +250.00 MB (100.0%) -- explicit\n\ 1.312 +├──120.20 MB (48.08%) -- a\n\ 1.313 +│ ├───50.00 MB (20.00%) ── b\n\ 1.314 +│ ├───40.00 MB (16.00%) ++ c\n\ 1.315 +│ ├───30.00 MB (12.00%) ── f\n\ 1.316 +│ └────0.20 MB (00.08%) -- l\n\ 1.317 +│ ├──0.10 MB (00.04%) ── m\n\ 1.318 +│ └──0.10 MB (00.04%) ── n\n\ 1.319 +├──100.00 MB (40.00%) ── g\n\ 1.320 +├───19.00 MB (07.60%) -- j\n\ 1.321 +│ ├──10.00 MB (04.00%) ── k\n\ 1.322 +│ └───9.00 MB (03.60%) ── k2\n\ 1.323 +├───10.00 MB (04.00%) ── heap-unclassified\n\ 1.324 +└────0.80 MB (00.32%) ++ h\n\ 1.325 +\n\ 1.326 +Other Measurements\n\ 1.327 +\n\ 1.328 +250.00 MB ── heap-allocated\n\ 1.329 +\n\ 1.330 +End of Main Process\n\ 1.331 +"; 1.332 + 1.333 + let acExpandedExpected = 1.334 +"\ 1.335 +Main Process\n\ 1.336 +Explicit Allocations\n\ 1.337 +\n\ 1.338 +250.00 MB (100.0%) -- explicit\n\ 1.339 +├──120.20 MB (48.08%) -- a\n\ 1.340 +│ ├───50.00 MB (20.00%) ── b\n\ 1.341 +│ ├───40.00 MB (16.00%) -- c\n\ 1.342 +│ │ ├──25.00 MB (10.00%) ── d\n\ 1.343 +│ │ └──15.00 MB (06.00%) ── e\n\ 1.344 +│ ├───30.00 MB (12.00%) ── f\n\ 1.345 +│ └────0.20 MB (00.08%) -- l\n\ 1.346 +│ ├──0.10 MB (00.04%) ── m\n\ 1.347 +│ └──0.10 MB (00.04%) ── n\n\ 1.348 +├──100.00 MB (40.00%) ── g\n\ 1.349 +├───19.00 MB (07.60%) -- j\n\ 1.350 +│ ├──10.00 MB (04.00%) ── k\n\ 1.351 +│ └───9.00 MB (03.60%) ── k2\n\ 1.352 +├───10.00 MB (04.00%) ── heap-unclassified\n\ 1.353 +└────0.80 MB (00.32%) ++ h\n\ 1.354 +\n\ 1.355 +Other Measurements\n\ 1.356 +\n\ 1.357 +250.00 MB ── heap-allocated\n\ 1.358 +\n\ 1.359 +End of Main Process\n\ 1.360 +"; 1.361 + 1.362 + let alCollapsedExpected = 1.363 +"\ 1.364 +Main Process\n\ 1.365 +Explicit Allocations\n\ 1.366 +\n\ 1.367 +250.00 MB (100.0%) -- explicit\n\ 1.368 +├──120.20 MB (48.08%) -- a\n\ 1.369 +│ ├───50.00 MB (20.00%) ── b\n\ 1.370 +│ ├───40.00 MB (16.00%) -- c\n\ 1.371 +│ │ ├──25.00 MB (10.00%) ── d\n\ 1.372 +│ │ └──15.00 MB (06.00%) ── e\n\ 1.373 +│ ├───30.00 MB (12.00%) ── f\n\ 1.374 +│ └────0.20 MB (00.08%) ++ l\n\ 1.375 +├──100.00 MB (40.00%) ── g\n\ 1.376 +├───19.00 MB (07.60%) -- j\n\ 1.377 +│ ├──10.00 MB (04.00%) ── k\n\ 1.378 +│ └───9.00 MB (03.60%) ── k2\n\ 1.379 +├───10.00 MB (04.00%) ── heap-unclassified\n\ 1.380 +└────0.80 MB (00.32%) ++ h\n\ 1.381 +\n\ 1.382 +Other Measurements\n\ 1.383 +\n\ 1.384 +250.00 MB ── heap-allocated\n\ 1.385 +\n\ 1.386 +End of Main Process\n\ 1.387 +"; 1.388 + 1.389 + // Test the following cases: 1.390 + // - explicit/a/c is significant, we collapse it, it's unchanged upon 1.391 + // update, we re-expand it 1.392 + // - explicit/a/l is insignificant, we expand it, it's unchanged upon 1.393 + // update, we re-collapse it 1.394 + // - explicit/a is significant, we collapse it (which hides its 1.395 + // sub-trees), it's unchanged upon update, we re-expand it 1.396 + // - explicit/h is significant, we collapse it, it becomes insignificant 1.397 + // upon update (and should remain collapsed) 1.398 + // - explicit/j is insignificant, we expand it, it becomes significant 1.399 + // upon update (and should remain expanded) 1.400 + // 1.401 + let idsToClick = [ 1.402 + { id: "measureButton", swap: 0, expected: startExpected }, 1.403 + { id: "Main Process:explicit/a/c", swap: 0, expected: acCollapsedExpected }, 1.404 + { id: "Main Process:explicit/a/l", swap: 0, expected: alExpandedExpected }, 1.405 + { id: "Main Process:explicit/a", swap: 0, expected: aCollapsedExpected }, 1.406 + { id: "Main Process:explicit/h", swap: 0, expected: hCollapsedExpected }, 1.407 + { id: "Main Process:explicit/j", swap: 0, expected: jExpandedExpected }, 1.408 + { id: "measureButton", swap: 1, expected: updatedExpected }, 1.409 + { id: "Main Process:explicit/a", swap: 0, expected: aExpandedExpected }, 1.410 + { id: "Main Process:explicit/a/c", swap: 0, expected: acExpandedExpected }, 1.411 + { id: "Main Process:explicit/a/l", swap: 0, expected: alCollapsedExpected } 1.412 + ]; 1.413 + 1.414 + SimpleTest.waitForFocus(chain(idsToClick)); 1.415 + 1.416 + SimpleTest.waitForExplicitFinish(); 1.417 + ]]> 1.418 + </script> 1.419 +</window>