toolkit/components/aboutmemory/tests/test_aboutmemory2.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.

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

mercurial