| <html> |
| <head> |
| <script src="../../http/tests/inspector/inspector-test.js"></script> |
| <script src="heap-snapshot-test.js"></script> |
| <script> |
| |
| function test() |
| { |
| InspectorTest.assertSnapshotEquals = function(reference, actual) |
| { |
| InspectorTest.assertEquals(JSON.stringify(reference), JSON.stringify(actual)); |
| } |
| |
| WebInspector.showPanel("profiles"); |
| var source = InspectorTest.createHeapSnapshotMockRaw(); |
| var sourceStringified = JSON.stringify(source); |
| var partSize = sourceStringified.length >> 3; |
| |
| InspectorTest.runTestSuite([ |
| function heapSnapshotLoaderTest(next) |
| { |
| var loader = new WebInspector.HeapSnapshotLoader(); |
| for (var i = 0, l = sourceStringified.length; i < l; i += partSize) |
| loader.write(sourceStringified.slice(i, i + partSize)); |
| loader.close(); |
| var result = loader.buildSnapshot(); |
| result._nodes = new Uint32Array(result._nodes); |
| result._containmentEdges = new Uint32Array(result._containmentEdges); |
| InspectorTest.assertSnapshotEquals(new WebInspector.HeapSnapshot(InspectorTest.createHeapSnapshotMock()), result); |
| next(); |
| }, |
| |
| function heapSnapshotSaveToFileTest(next) |
| { |
| var profileUID = 42; |
| |
| var dispatcher = InspectorBackend._domainDispatchers["Profiler"]; |
| var panel = WebInspector.panels.profiles; |
| panel._reset(); |
| |
| dispatcher.addProfileHeader({ |
| typeId: WebInspector.HeapSnapshotProfileType.TypeId, |
| title: "heapSnapshotSaveToFileTest", |
| uid: profileUID, |
| maxJSObjectId: 6 |
| }); |
| |
| var profileHeader = panel._profiles[0]; |
| |
| var oldGetProfile = ProfilerAgent.getProfile; |
| ProfilerAgent.getProfile = function getProfileMock(profileTypeName, uid) { |
| for (var i = 0, l = sourceStringified.length; i < l; i += partSize) |
| dispatcher.addHeapSnapshotChunk(uid, sourceStringified.slice(i, i + partSize)); |
| dispatcher.finishHeapSnapshot(uid); |
| }; |
| |
| var savedSnapshotData; |
| var oldSave = InspectorFrontendHost.save; |
| InspectorFrontendHost.save = function saveMock(url, data) |
| { |
| savedSnapshotData = data; |
| WebInspector.fileManager.savedURL(url); |
| } |
| |
| var oldAppend = InspectorFrontendHost.append; |
| InspectorFrontendHost.append = function appendMock(url, data) |
| { |
| savedSnapshotData += data; |
| WebInspector.fileManager.appendedToURL(url); |
| } |
| |
| function parsed() |
| { |
| profileHeader.saveToFile(); |
| InspectorTest.assertEquals(sourceStringified, savedSnapshotData, "Saved snapshot data"); |
| |
| InspectorFrontendHost.save = oldSave; |
| InspectorFrontendHost.append = oldAppend; |
| ProfilerAgent.getProfile = oldGetProfile; |
| next(); |
| } |
| InspectorTest.addSniffer(profileHeader, "_snapshotReceived", parsed); |
| |
| panel.showProfile(profileHeader); |
| }, |
| |
| function heapSnapshotLoadFromFileTest(next) |
| { |
| var panel = WebInspector.panels.profiles; |
| |
| var fileMock = { |
| name: "mock.heapsnapshot", |
| size: sourceStringified.length |
| }; |
| |
| InspectorTest.override(WebInspector.HeapProfileHeader.prototype, '_createFileReader', function(fileMock, delegate) { |
| return { |
| start: function(receiver) { |
| delegate.onTransferStarted(this); |
| receiver.write(sourceStringified); |
| delegate.onChunkTransferred(this); |
| receiver.close(); |
| delegate.onTransferFinished(this); |
| }, |
| |
| loadedSize: function() |
| { |
| return fileMock.size; |
| }, |
| |
| fileSize: function() |
| { |
| return fileMock.size; |
| }, |
| |
| fileName: function() |
| { |
| return fileMock.name; |
| } |
| }; |
| }); |
| InspectorTest.addSniffer(WebInspector.HeapProfileHeader.prototype, "_snapshotReceived", function() { next(); }); |
| panel._loadFromFile(fileMock); |
| } |
| ]); |
| } |
| |
| </script> |
| </head> |
| |
| <body onload="runTest()"> |
| <p> |
| This test checks HeapSnapshots loader. |
| </p> |
| |
| </body> |
| </html> |