Backed out changeset b71c8c052463 (bug 1943846) for causing mass failures. CLOSED...
[gecko.git] / devtools / server / tests / chrome / test_memory_allocations_03.html
blobca6a1ec1b496301ff4ac18ab9f152505decff0b7
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";
18 window.onload = function() {
19 SimpleTest.waitForExplicitFinish();
21 (async function() {
22 const { memory, target } = await startServerAndGetSelectedTabMemory();
23 await memory.attach();
25 await memory.startRecordingAllocations();
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.
31 const allocs = [];
32 function allocator() {
33 allocs.push({});
36 setTimeout(allocator, 1);
37 await waitForTime(2);
38 const first = await memory.getAllocations();
40 setTimeout(allocator, 1);
41 await waitForTime(2);
42 const second = await memory.getAllocations();
44 await memory.stopRecordingAllocations();
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.
52 function assertSameFrame(a, b) {
53 info(" First frame = " + JSON.stringify(a, null, 4));
54 info(" Second frame = " + JSON.stringify(b, null, 4));
56 is(!!a, !!b);
57 if (!a || !b) {
58 return;
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);
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]);
73 await memory.detach();
74 destroyServerAndFinish(target);
75 })();
77 </script>
78 </pre>
79 </body>
80 </html>