tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_memory_allocations_07.html (1528B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 Bug 1192335 - Test getting the byte sizes for allocations.
      5 -->
      6 <head>
      7  <meta charset="utf-8">
      8  <title>Memory monitoring actor test</title>
      9  <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
     10  <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
     11 </head>
     12 <body>
     13 <pre id="test">
     14 <script src="memory-helpers.js" type="application/javascript"></script>
     15 <script>
     16 "use strict";
     17 
     18 window.onload = function() {
     19  SimpleTest.waitForExplicitFinish();
     20 
     21  (async function() {
     22    const { memory, target } = await startServerAndGetSelectedTabMemory();
     23    await memory.attach();
     24 
     25    const allocs = [];
     26    function allocator() {
     27      allocs.push({});
     28    }
     29 
     30    await memory.startRecordingAllocations();
     31 
     32    allocator();
     33    allocator();
     34    allocator();
     35 
     36    const response = await memory.getAllocations();
     37    await memory.stopRecordingAllocations();
     38 
     39    ok(response.allocationSizes, "The response should have bytesizes.");
     40    is(response.allocationSizes.length, response.allocations.length,
     41       "There should be a bytesize for every allocation.");
     42    ok(response.allocationSizes.length >= 3,
     43       "There are atleast 3 allocations.");
     44    ok(response.allocationSizes.every(isPositiveNumber),
     45       "every bytesize is a positive number");
     46 
     47    await memory.detach();
     48    destroyServerAndFinish(target);
     49  })();
     50 };
     51 
     52 function isPositiveNumber(n) {
     53  return typeof n === "number" && n > 0;
     54 }
     55 </script>
     56 </pre>
     57 </body>
     58 </html>