4 Bug 1067491 - Test that frames keep the same index while we are recording.
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">
14 <script src=
"memory-helpers.js" type=
"application/javascript"></script>
18 window
.onload = function() {
19 SimpleTest
.waitForExplicitFinish();
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
32 function allocator() {
36 setTimeout(allocator
, 1);
38 const first
= await memory
.getAllocations();
40 setTimeout(allocator
, 1);
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));
61 is(a
.source
, b
.source
);
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
);