tor-browser

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

test_memory_allocations_03.html (2272B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 Bug 1067491 - Test that frames keep the same index while we are recording.
      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    await memory.startRecordingAllocations();
     26 
     27    // Allocate twice with the exact same stack (hence setTimeout rather than
     28    // allocating directly in the generator), but with getAllocations() calls in
     29    // between.
     30 
     31    const allocs = [];
     32    function allocator() {
     33      allocs.push({});
     34    }
     35 
     36    setTimeout(allocator, 1);
     37    await waitForTime(2);
     38    const first = await memory.getAllocations();
     39 
     40    setTimeout(allocator, 1);
     41    await waitForTime(2);
     42    const second = await memory.getAllocations();
     43 
     44    await memory.stopRecordingAllocations();
     45 
     46    // Assert that each frame in the first response has the same index in the
     47    // second response. This isn't commutative, so we don't check that all
     48    // of the second response's frames are the same in the first response,
     49    // because there might be new allocations that happen after the first query
     50    // but before the second.
     51 
     52    function assertSameFrame(a, b) {
     53      info("  First frame = " + JSON.stringify(a, null, 4));
     54      info("  Second frame = " + JSON.stringify(b, null, 4));
     55 
     56      is(!!a, !!b);
     57      if (!a || !b) {
     58        return;
     59      }
     60 
     61      is(a.source, b.source);
     62      is(a.line, b.line);
     63      is(a.column, b.column);
     64      is(a.functionDisplayName, b.functionDisplayName);
     65      is(a.parent, b.parent);
     66    }
     67 
     68    for (let i = 0; i < first.frames.length; i++) {
     69      info("Checking frames at index " + i + ":");
     70      assertSameFrame(first.frames[i], second.frames[i]);
     71    }
     72 
     73    await memory.detach();
     74    destroyServerAndFinish(target);
     75  })();
     76 };
     77 </script>
     78 </pre>
     79 </body>
     80 </html>