toolkit/components/aboutmemory/tests/test_aboutmemory2.xul

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing code.

michael@0 1 <?xml version="1.0"?>
michael@0 2 <?xml-stylesheet type="text/css" href="chrome://global/skin"?>
michael@0 3 <?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
michael@0 4 <window title="about:memory"
michael@0 5 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
michael@0 6 <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
michael@0 7 <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
michael@0 8
michael@0 9 <!-- This file tests the collapsing and expanding of sub-trees in
michael@0 10 about:memory. -->
michael@0 11
michael@0 12 <!-- test results are displayed in the html:body -->
michael@0 13 <body xmlns="http://www.w3.org/1999/xhtml"></body>
michael@0 14
michael@0 15 <!-- test code goes here -->
michael@0 16 <script type="application/javascript">
michael@0 17 <![CDATA[
michael@0 18 "use strict";
michael@0 19
michael@0 20 const Cc = Components.classes;
michael@0 21 const Ci = Components.interfaces;
michael@0 22 let mgr = Cc["@mozilla.org/memory-reporter-manager;1"].
michael@0 23 getService(Ci.nsIMemoryReporterManager);
michael@0 24
michael@0 25 // Hide all the real reporters; we'll restore them at the end.
michael@0 26 mgr.blockRegistrationAndHideExistingReporters();
michael@0 27
michael@0 28 // Setup various fake-but-deterministic reporters.
michael@0 29 const KB = 1024;
michael@0 30 const MB = KB * KB;
michael@0 31 const HEAP = Ci.nsIMemoryReporter.KIND_HEAP;
michael@0 32 const OTHER = Ci.nsIMemoryReporter.KIND_OTHER;
michael@0 33 const BYTES = Ci.nsIMemoryReporter.UNITS_BYTES;
michael@0 34
michael@0 35 let hiPath = "explicit/h/i";
michael@0 36 let hi2Path = "explicit/h/i2";
michael@0 37 let jkPath = "explicit/j/k";
michael@0 38 let jk2Path = "explicit/j/k2";
michael@0 39
michael@0 40 let fakeReporters = [
michael@0 41 { collectReports: function(aCbObj, aClosure) {
michael@0 42 function f(aP, aK, aA) {
michael@0 43 aCbObj.callback("", aP, aK, BYTES, aA, "Desc.", aClosure);
michael@0 44 }
michael@0 45 f("heap-allocated", OTHER, 250 * MB);
michael@0 46 f("explicit/a/b", HEAP, 50 * MB);
michael@0 47 f("explicit/a/c/d", HEAP, 25 * MB);
michael@0 48 f("explicit/a/c/e", HEAP, 15 * MB);
michael@0 49 f("explicit/a/f", HEAP, 30 * MB);
michael@0 50 f("explicit/g", HEAP, 100 * MB);
michael@0 51 f(hiPath, HEAP, 10 * MB);
michael@0 52 f(hi2Path, HEAP, 9 * MB);
michael@0 53 f(jkPath, HEAP, 0.5 * MB);
michael@0 54 f(jk2Path, HEAP, 0.3 * MB);
michael@0 55 f("explicit/a/l/m", HEAP, 0.1 * MB);
michael@0 56 f("explicit/a/l/n", HEAP, 0.1 * MB);
michael@0 57 }
michael@0 58 }
michael@0 59 ];
michael@0 60
michael@0 61 for (let i = 0; i < fakeReporters.length; i++) {
michael@0 62 mgr.registerStrongReporterEvenIfBlocked(fakeReporters[i]);
michael@0 63 }
michael@0 64
michael@0 65 ]]>
michael@0 66 </script>
michael@0 67
michael@0 68 <iframe id="amFrame" height="500" src="about:memory"></iframe>
michael@0 69
michael@0 70 <script type="application/javascript">
michael@0 71 <![CDATA[
michael@0 72 function finish()
michael@0 73 {
michael@0 74 mgr.unblockRegistrationAndRestoreOriginalReporters();
michael@0 75 SimpleTest.finish();
michael@0 76 }
michael@0 77
michael@0 78 // Click on the identified element, then cut+paste the entire page and
michael@0 79 // check that the cut text matches what we expect.
michael@0 80 function test(aId, aSwap, aExpected, aNext) {
michael@0 81 let win = document.getElementById("amFrame").contentWindow;
michael@0 82 if (aId) {
michael@0 83 let node = win.document.getElementById(aId);
michael@0 84
michael@0 85 // Yuk: clicking a button is easy; but for tree entries we need to
michael@0 86 // click on a child of the span identified via |id|.
michael@0 87 if (node.nodeName === "button") {
michael@0 88 if (aSwap) {
michael@0 89 // We swap hipath/hi2Path and jkPath/jk2Path just before updating, to
michael@0 90 // test what happens when significant nodes become insignificant and
michael@0 91 // vice versa.
michael@0 92 hiPath = "explicit/j/k";
michael@0 93 hi2Path = "explicit/j/k2";
michael@0 94 jkPath = "explicit/h/i";
michael@0 95 jk2Path = "explicit/h/i2";
michael@0 96 }
michael@0 97 node.click();
michael@0 98 } else {
michael@0 99 node.childNodes[0].click();
michael@0 100 }
michael@0 101 }
michael@0 102
michael@0 103 SimpleTest.executeSoon(function() {
michael@0 104 let mostRecentActual;
michael@0 105 document.getElementById("amFrame").focus();
michael@0 106 SimpleTest.waitForClipboard(
michael@0 107 function(aActual) {
michael@0 108 mostRecentActual = aActual;
michael@0 109 return aActual === aExpected;
michael@0 110 },
michael@0 111 function() {
michael@0 112 synthesizeKey("A", {accelKey: true});
michael@0 113 synthesizeKey("C", {accelKey: true});
michael@0 114 },
michael@0 115 aNext,
michael@0 116 function() {
michael@0 117 ok(false, "pasted text doesn't match");
michael@0 118 dump("******EXPECTED******\n");
michael@0 119 dump(aExpected);
michael@0 120 dump("*******ACTUAL*******\n");
michael@0 121 dump(mostRecentActual);
michael@0 122 dump("********************\n");
michael@0 123 finish();
michael@0 124 }
michael@0 125 );
michael@0 126 });
michael@0 127 }
michael@0 128
michael@0 129 // Returns a function that chains together one test() call per id.
michael@0 130 function chain(aIds) {
michael@0 131 let x = aIds.shift();
michael@0 132 if (x) {
michael@0 133 return function() { test(x.id, x.swap, x.expected, chain(aIds)); }
michael@0 134 } else {
michael@0 135 return function() { finish(); };
michael@0 136 }
michael@0 137 }
michael@0 138
michael@0 139 let startExpected =
michael@0 140 "\
michael@0 141 Main Process\n\
michael@0 142 Explicit Allocations\n\
michael@0 143 \n\
michael@0 144 250.00 MB (100.0%) -- explicit\n\
michael@0 145 ├──120.20 MB (48.08%) -- a\n\
michael@0 146 │ ├───50.00 MB (20.00%) ── b\n\
michael@0 147 │ ├───40.00 MB (16.00%) -- c\n\
michael@0 148 │ │ ├──25.00 MB (10.00%) ── d\n\
michael@0 149 │ │ └──15.00 MB (06.00%) ── e\n\
michael@0 150 │ ├───30.00 MB (12.00%) ── f\n\
michael@0 151 │ └────0.20 MB (00.08%) ++ l\n\
michael@0 152 ├──100.00 MB (40.00%) ── g\n\
michael@0 153 ├───19.00 MB (07.60%) -- h\n\
michael@0 154 │ ├──10.00 MB (04.00%) ── i\n\
michael@0 155 │ └───9.00 MB (03.60%) ── i2\n\
michael@0 156 ├───10.00 MB (04.00%) ── heap-unclassified\n\
michael@0 157 └────0.80 MB (00.32%) ++ j\n\
michael@0 158 \n\
michael@0 159 Other Measurements\n\
michael@0 160 \n\
michael@0 161 250.00 MB ── heap-allocated\n\
michael@0 162 \n\
michael@0 163 End of Main Process\n\
michael@0 164 ";
michael@0 165
michael@0 166 let acCollapsedExpected =
michael@0 167 "\
michael@0 168 Main Process\n\
michael@0 169 Explicit Allocations\n\
michael@0 170 \n\
michael@0 171 250.00 MB (100.0%) -- explicit\n\
michael@0 172 ├──120.20 MB (48.08%) -- a\n\
michael@0 173 │ ├───50.00 MB (20.00%) ── b\n\
michael@0 174 │ ├───40.00 MB (16.00%) ++ c\n\
michael@0 175 │ ├───30.00 MB (12.00%) ── f\n\
michael@0 176 │ └────0.20 MB (00.08%) ++ l\n\
michael@0 177 ├──100.00 MB (40.00%) ── g\n\
michael@0 178 ├───19.00 MB (07.60%) -- h\n\
michael@0 179 │ ├──10.00 MB (04.00%) ── i\n\
michael@0 180 │ └───9.00 MB (03.60%) ── i2\n\
michael@0 181 ├───10.00 MB (04.00%) ── heap-unclassified\n\
michael@0 182 └────0.80 MB (00.32%) ++ j\n\
michael@0 183 \n\
michael@0 184 Other Measurements\n\
michael@0 185 \n\
michael@0 186 250.00 MB ── heap-allocated\n\
michael@0 187 \n\
michael@0 188 End of Main Process\n\
michael@0 189 ";
michael@0 190
michael@0 191 let alExpandedExpected =
michael@0 192 "\
michael@0 193 Main Process\n\
michael@0 194 Explicit Allocations\n\
michael@0 195 \n\
michael@0 196 250.00 MB (100.0%) -- explicit\n\
michael@0 197 ├──120.20 MB (48.08%) -- a\n\
michael@0 198 │ ├───50.00 MB (20.00%) ── b\n\
michael@0 199 │ ├───40.00 MB (16.00%) ++ c\n\
michael@0 200 │ ├───30.00 MB (12.00%) ── f\n\
michael@0 201 │ └────0.20 MB (00.08%) -- l\n\
michael@0 202 │ ├──0.10 MB (00.04%) ── m\n\
michael@0 203 │ └──0.10 MB (00.04%) ── n\n\
michael@0 204 ├──100.00 MB (40.00%) ── g\n\
michael@0 205 ├───19.00 MB (07.60%) -- h\n\
michael@0 206 │ ├──10.00 MB (04.00%) ── i\n\
michael@0 207 │ └───9.00 MB (03.60%) ── i2\n\
michael@0 208 ├───10.00 MB (04.00%) ── heap-unclassified\n\
michael@0 209 └────0.80 MB (00.32%) ++ j\n\
michael@0 210 \n\
michael@0 211 Other Measurements\n\
michael@0 212 \n\
michael@0 213 250.00 MB ── heap-allocated\n\
michael@0 214 \n\
michael@0 215 End of Main Process\n\
michael@0 216 ";
michael@0 217
michael@0 218 let aCollapsedExpected =
michael@0 219 "\
michael@0 220 Main Process\n\
michael@0 221 Explicit Allocations\n\
michael@0 222 \n\
michael@0 223 250.00 MB (100.0%) -- explicit\n\
michael@0 224 ├──120.20 MB (48.08%) ++ a\n\
michael@0 225 ├──100.00 MB (40.00%) ── g\n\
michael@0 226 ├───19.00 MB (07.60%) -- h\n\
michael@0 227 │ ├──10.00 MB (04.00%) ── i\n\
michael@0 228 │ └───9.00 MB (03.60%) ── i2\n\
michael@0 229 ├───10.00 MB (04.00%) ── heap-unclassified\n\
michael@0 230 └────0.80 MB (00.32%) ++ j\n\
michael@0 231 \n\
michael@0 232 Other Measurements\n\
michael@0 233 \n\
michael@0 234 250.00 MB ── heap-allocated\n\
michael@0 235 \n\
michael@0 236 End of Main Process\n\
michael@0 237 ";
michael@0 238
michael@0 239 let hCollapsedExpected =
michael@0 240 "\
michael@0 241 Main Process\n\
michael@0 242 Explicit Allocations\n\
michael@0 243 \n\
michael@0 244 250.00 MB (100.0%) -- explicit\n\
michael@0 245 ├──120.20 MB (48.08%) ++ a\n\
michael@0 246 ├──100.00 MB (40.00%) ── g\n\
michael@0 247 ├───19.00 MB (07.60%) ++ h\n\
michael@0 248 ├───10.00 MB (04.00%) ── heap-unclassified\n\
michael@0 249 └────0.80 MB (00.32%) ++ j\n\
michael@0 250 \n\
michael@0 251 Other Measurements\n\
michael@0 252 \n\
michael@0 253 250.00 MB ── heap-allocated\n\
michael@0 254 \n\
michael@0 255 End of Main Process\n\
michael@0 256 ";
michael@0 257
michael@0 258 let jExpandedExpected =
michael@0 259 "\
michael@0 260 Main Process\n\
michael@0 261 Explicit Allocations\n\
michael@0 262 \n\
michael@0 263 250.00 MB (100.0%) -- explicit\n\
michael@0 264 ├──120.20 MB (48.08%) ++ a\n\
michael@0 265 ├──100.00 MB (40.00%) ── g\n\
michael@0 266 ├───19.00 MB (07.60%) ++ h\n\
michael@0 267 ├───10.00 MB (04.00%) ── heap-unclassified\n\
michael@0 268 └────0.80 MB (00.32%) -- j\n\
michael@0 269 ├──0.50 MB (00.20%) ── k\n\
michael@0 270 └──0.30 MB (00.12%) ── k2\n\
michael@0 271 \n\
michael@0 272 Other Measurements\n\
michael@0 273 \n\
michael@0 274 250.00 MB ── heap-allocated\n\
michael@0 275 \n\
michael@0 276 End of Main Process\n\
michael@0 277 ";
michael@0 278
michael@0 279 // The important thing here is that two values have been swapped.
michael@0 280 // explicit/h/i should remain collapsed, and explicit/j/k should remain
michael@0 281 // expanded. See bug 724863.
michael@0 282 let updatedExpected =
michael@0 283 "\
michael@0 284 Main Process\n\
michael@0 285 Explicit Allocations\n\
michael@0 286 \n\
michael@0 287 250.00 MB (100.0%) -- explicit\n\
michael@0 288 ├──120.20 MB (48.08%) ++ a\n\
michael@0 289 ├──100.00 MB (40.00%) ── g\n\
michael@0 290 ├───19.00 MB (07.60%) -- j\n\
michael@0 291 │ ├──10.00 MB (04.00%) ── k\n\
michael@0 292 │ └───9.00 MB (03.60%) ── k2\n\
michael@0 293 ├───10.00 MB (04.00%) ── heap-unclassified\n\
michael@0 294 └────0.80 MB (00.32%) ++ h\n\
michael@0 295 \n\
michael@0 296 Other Measurements\n\
michael@0 297 \n\
michael@0 298 250.00 MB ── heap-allocated\n\
michael@0 299 \n\
michael@0 300 End of Main Process\n\
michael@0 301 ";
michael@0 302
michael@0 303 let aExpandedExpected =
michael@0 304 "\
michael@0 305 Main Process\n\
michael@0 306 Explicit Allocations\n\
michael@0 307 \n\
michael@0 308 250.00 MB (100.0%) -- explicit\n\
michael@0 309 ├──120.20 MB (48.08%) -- a\n\
michael@0 310 │ ├───50.00 MB (20.00%) ── b\n\
michael@0 311 │ ├───40.00 MB (16.00%) ++ c\n\
michael@0 312 │ ├───30.00 MB (12.00%) ── f\n\
michael@0 313 │ └────0.20 MB (00.08%) -- l\n\
michael@0 314 │ ├──0.10 MB (00.04%) ── m\n\
michael@0 315 │ └──0.10 MB (00.04%) ── n\n\
michael@0 316 ├──100.00 MB (40.00%) ── g\n\
michael@0 317 ├───19.00 MB (07.60%) -- j\n\
michael@0 318 │ ├──10.00 MB (04.00%) ── k\n\
michael@0 319 │ └───9.00 MB (03.60%) ── k2\n\
michael@0 320 ├───10.00 MB (04.00%) ── heap-unclassified\n\
michael@0 321 └────0.80 MB (00.32%) ++ h\n\
michael@0 322 \n\
michael@0 323 Other Measurements\n\
michael@0 324 \n\
michael@0 325 250.00 MB ── heap-allocated\n\
michael@0 326 \n\
michael@0 327 End of Main Process\n\
michael@0 328 ";
michael@0 329
michael@0 330 let acExpandedExpected =
michael@0 331 "\
michael@0 332 Main Process\n\
michael@0 333 Explicit Allocations\n\
michael@0 334 \n\
michael@0 335 250.00 MB (100.0%) -- explicit\n\
michael@0 336 ├──120.20 MB (48.08%) -- a\n\
michael@0 337 │ ├───50.00 MB (20.00%) ── b\n\
michael@0 338 │ ├───40.00 MB (16.00%) -- c\n\
michael@0 339 │ │ ├──25.00 MB (10.00%) ── d\n\
michael@0 340 │ │ └──15.00 MB (06.00%) ── e\n\
michael@0 341 │ ├───30.00 MB (12.00%) ── f\n\
michael@0 342 │ └────0.20 MB (00.08%) -- l\n\
michael@0 343 │ ├──0.10 MB (00.04%) ── m\n\
michael@0 344 │ └──0.10 MB (00.04%) ── n\n\
michael@0 345 ├──100.00 MB (40.00%) ── g\n\
michael@0 346 ├───19.00 MB (07.60%) -- j\n\
michael@0 347 │ ├──10.00 MB (04.00%) ── k\n\
michael@0 348 │ └───9.00 MB (03.60%) ── k2\n\
michael@0 349 ├───10.00 MB (04.00%) ── heap-unclassified\n\
michael@0 350 └────0.80 MB (00.32%) ++ h\n\
michael@0 351 \n\
michael@0 352 Other Measurements\n\
michael@0 353 \n\
michael@0 354 250.00 MB ── heap-allocated\n\
michael@0 355 \n\
michael@0 356 End of Main Process\n\
michael@0 357 ";
michael@0 358
michael@0 359 let alCollapsedExpected =
michael@0 360 "\
michael@0 361 Main Process\n\
michael@0 362 Explicit Allocations\n\
michael@0 363 \n\
michael@0 364 250.00 MB (100.0%) -- explicit\n\
michael@0 365 ├──120.20 MB (48.08%) -- a\n\
michael@0 366 │ ├───50.00 MB (20.00%) ── b\n\
michael@0 367 │ ├───40.00 MB (16.00%) -- c\n\
michael@0 368 │ │ ├──25.00 MB (10.00%) ── d\n\
michael@0 369 │ │ └──15.00 MB (06.00%) ── e\n\
michael@0 370 │ ├───30.00 MB (12.00%) ── f\n\
michael@0 371 │ └────0.20 MB (00.08%) ++ l\n\
michael@0 372 ├──100.00 MB (40.00%) ── g\n\
michael@0 373 ├───19.00 MB (07.60%) -- j\n\
michael@0 374 │ ├──10.00 MB (04.00%) ── k\n\
michael@0 375 │ └───9.00 MB (03.60%) ── k2\n\
michael@0 376 ├───10.00 MB (04.00%) ── heap-unclassified\n\
michael@0 377 └────0.80 MB (00.32%) ++ h\n\
michael@0 378 \n\
michael@0 379 Other Measurements\n\
michael@0 380 \n\
michael@0 381 250.00 MB ── heap-allocated\n\
michael@0 382 \n\
michael@0 383 End of Main Process\n\
michael@0 384 ";
michael@0 385
michael@0 386 // Test the following cases:
michael@0 387 // - explicit/a/c is significant, we collapse it, it's unchanged upon
michael@0 388 // update, we re-expand it
michael@0 389 // - explicit/a/l is insignificant, we expand it, it's unchanged upon
michael@0 390 // update, we re-collapse it
michael@0 391 // - explicit/a is significant, we collapse it (which hides its
michael@0 392 // sub-trees), it's unchanged upon update, we re-expand it
michael@0 393 // - explicit/h is significant, we collapse it, it becomes insignificant
michael@0 394 // upon update (and should remain collapsed)
michael@0 395 // - explicit/j is insignificant, we expand it, it becomes significant
michael@0 396 // upon update (and should remain expanded)
michael@0 397 //
michael@0 398 let idsToClick = [
michael@0 399 { id: "measureButton", swap: 0, expected: startExpected },
michael@0 400 { id: "Main Process:explicit/a/c", swap: 0, expected: acCollapsedExpected },
michael@0 401 { id: "Main Process:explicit/a/l", swap: 0, expected: alExpandedExpected },
michael@0 402 { id: "Main Process:explicit/a", swap: 0, expected: aCollapsedExpected },
michael@0 403 { id: "Main Process:explicit/h", swap: 0, expected: hCollapsedExpected },
michael@0 404 { id: "Main Process:explicit/j", swap: 0, expected: jExpandedExpected },
michael@0 405 { id: "measureButton", swap: 1, expected: updatedExpected },
michael@0 406 { id: "Main Process:explicit/a", swap: 0, expected: aExpandedExpected },
michael@0 407 { id: "Main Process:explicit/a/c", swap: 0, expected: acExpandedExpected },
michael@0 408 { id: "Main Process:explicit/a/l", swap: 0, expected: alCollapsedExpected }
michael@0 409 ];
michael@0 410
michael@0 411 SimpleTest.waitForFocus(chain(idsToClick));
michael@0 412
michael@0 413 SimpleTest.waitForExplicitFinish();
michael@0 414 ]]>
michael@0 415 </script>
michael@0 416 </window>

mercurial