3 <script src=
"../../http/tests/inspector/inspector-test.js"></script>
4 <script src=
"heap-snapshot-test.js"></script>
9 var source
= InspectorTest
.createHeapSnapshotMockRaw();
10 var sourceStringified
= JSON
.stringify(source
);
11 var partSize
= sourceStringified
.length
>> 3;
13 function injectMockProfile(callback
) {
14 var dispatcher
= InspectorBackend
._connection
._dispatchers
["HeapProfiler"]._dispatcher
;
15 var panel
= WebInspector
.panels
.profiles
;
18 var profileType
= WebInspector
.ProfileTypeRegistry
.instance
.heapSnapshotProfileType
;
20 InspectorTest
.override(InspectorTest
.HeapProfilerAgent
, "takeHeapSnapshot", takeHeapSnapshotMock
);
21 function takeHeapSnapshotMock(reportProgress
, callback
) {
23 profileType
._reportHeapSnapshotProgress({data
: {done
: 50, total
: 100, finished
: false}});
24 profileType
._reportHeapSnapshotProgress({data
: {done
: 100, total
: 100, finished
: true}});
26 for (var i
= 0, l
= sourceStringified
.length
; i
< l
; i
+= partSize
)
27 dispatcher
.addHeapSnapshotChunk(sourceStringified
.slice(i
, i
+ partSize
));
28 setTimeout(callback
, 0);
31 function tempFileReady()
35 InspectorTest
.addSniffer(WebInspector
.HeapProfileHeader
.prototype, "_didWriteToTempFile", tempFileReady
);
36 profileType
._takeHeapSnapshot(function() {});
39 WebInspector
.console
.log = function(message
) {
40 InspectorTest
.addResult("InspectorTest.consoleModel.log: " + message
);
43 InspectorTest
.runTestSuite([
44 function heapSnapshotSaveToFileTest(next
)
46 function snapshotLoaded(profileHeader
)
48 var savedSnapshotData
;
49 function saveMock(url
, data
)
51 savedSnapshotData
= data
;
52 WebInspector
.fileManager
._savedURL({data
: url
});
54 InspectorTest
.override(InspectorFrontendHost
, "save", saveMock
);
56 var oldAppend
= InspectorFrontendHost
.append
;
57 InspectorFrontendHost
.append
= function appendMock(url
, data
)
59 savedSnapshotData
+= data
;
60 WebInspector
.fileManager
._appendedToURL({data
: url
});
62 function closeMock(url
)
64 InspectorTest
.assertEquals(sourceStringified
, savedSnapshotData
, "Saved snapshot data");
65 InspectorFrontendHost
.append
= oldAppend
;
68 InspectorTest
.override(WebInspector
.FileManager
.prototype, "close", closeMock
);
69 profileHeader
.saveToFile();
72 injectMockProfile(snapshotLoaded
);
75 function heapSnapshotLoadFromFileTest(next
)
77 var panel
= WebInspector
.panels
.profiles
;
80 name
: "mock.heapsnapshot",
81 size
: sourceStringified
.length
84 InspectorTest
.override(WebInspector
.HeapProfileHeader
.prototype, '_createFileReader', function(fileMock
, delegate
) {
86 start: function(receiver
) {
87 delegate
.onTransferStarted(this);
88 receiver
.write(sourceStringified
);
89 delegate
.onChunkTransferred(this);
91 delegate
.onTransferFinished(this);
94 loadedSize: function()
101 return fileMock
.size
;
106 return fileMock
.name
;
110 InspectorTest
.addSniffer(WebInspector
.HeapProfileHeader
.prototype, "_snapshotReceived", function() { next(); });
111 panel
._loadFromFile(fileMock
);
114 function heapSnapshotRejectToSaveToFileTest(next
)
116 function snapshotLoaded(profileHeader
)
118 if (profileHeader
.canSaveToFile())
121 profileHeader
.addEventListener(WebInspector
.ProfileHeader
.Events
.ProfileReceived
, onCanSaveProfile
, this);
122 function onCanSaveProfile()
124 InspectorTest
.assertTrue(profileHeader
.canSaveToFile());
129 injectMockProfile(snapshotLoaded
);
137 <body onload=
"runTest()">
139 This test checks HeapSnapshots loader.