| OLD | NEW |
| 1 <html> | 1 <html> |
| 2 <head> | 2 <head> |
| 3 <script src="../../http/tests/inspector/inspector-test.js"></script> | 3 <script src="../../http/tests/inspector/inspector-test.js"></script> |
| 4 <script src="heap-snapshot-test.js"></script> | 4 <script src="heap-snapshot-test.js"></script> |
| 5 <script> | 5 <script> |
| 6 | 6 |
| 7 function test() | 7 function test() |
| 8 { | 8 { |
| 9 var source = InspectorTest.createHeapSnapshotMockRaw(); | 9 var source = InspectorTest.createHeapSnapshotMockRaw(); |
| 10 var sourceStringified = JSON.stringify(source); | 10 var sourceStringified = JSON.stringify(source); |
| 11 var partSize = sourceStringified.length >> 3; | 11 var partSize = sourceStringified.length >> 3; |
| 12 | 12 |
| 13 function injectMockProfile(callback) { | 13 function injectMockProfile(callback) { |
| 14 var dispatcher = InspectorTest.mainTarget._dispatchers["HeapProfiler"]._
dispatcher; | 14 var dispatcher = InspectorTest.mainTarget._dispatchers["HeapProfiler"]._
dispatcher; |
| 15 var panel = WebInspector.panels.profiles; | 15 var panel = UI.panels.profiles; |
| 16 panel._reset(); | 16 panel._reset(); |
| 17 | 17 |
| 18 var profileType = WebInspector.ProfileTypeRegistry.instance.heapSnapsho
tProfileType; | 18 var profileType = Profiler.ProfileTypeRegistry.instance.heapSnapshotPro
fileType; |
| 19 | 19 |
| 20 InspectorTest.override(InspectorTest.HeapProfilerAgent, "takeHeapSnapsho
t", takeHeapSnapshotMock); | 20 InspectorTest.override(InspectorTest.HeapProfilerAgent, "takeHeapSnapsho
t", takeHeapSnapshotMock); |
| 21 function takeHeapSnapshotMock(reportProgress, callback) { | 21 function takeHeapSnapshotMock(reportProgress, callback) { |
| 22 if (reportProgress) { | 22 if (reportProgress) { |
| 23 profileType._reportHeapSnapshotProgress({data: {done: 50, total:
100, finished: false}}); | 23 profileType._reportHeapSnapshotProgress({data: {done: 50, total:
100, finished: false}}); |
| 24 profileType._reportHeapSnapshotProgress({data: {done: 100, total
: 100, finished: true}}); | 24 profileType._reportHeapSnapshotProgress({data: {done: 100, total
: 100, finished: true}}); |
| 25 } | 25 } |
| 26 for (var i = 0, l = sourceStringified.length; i < l; i += partSize) | 26 for (var i = 0, l = sourceStringified.length; i < l; i += partSize) |
| 27 dispatcher.addHeapSnapshotChunk(sourceStringified.slice(i, i + p
artSize)); | 27 dispatcher.addHeapSnapshotChunk(sourceStringified.slice(i, i + p
artSize)); |
| 28 setTimeout(callback, 0); | 28 setTimeout(callback, 0); |
| 29 } | 29 } |
| 30 | 30 |
| 31 function tempFileReady() | 31 function tempFileReady() |
| 32 { | 32 { |
| 33 callback(this); | 33 callback(this); |
| 34 } | 34 } |
| 35 InspectorTest.addSniffer(WebInspector.HeapProfileHeader.prototype, "_did
WriteToTempFile", tempFileReady); | 35 InspectorTest.addSniffer(Profiler.HeapProfileHeader.prototype, "_didWrit
eToTempFile", tempFileReady); |
| 36 profileType._takeHeapSnapshot(function() {}); | 36 profileType._takeHeapSnapshot(function() {}); |
| 37 } | 37 } |
| 38 | 38 |
| 39 WebInspector.console.log = function(message) { | 39 Common.console.log = function(message) { |
| 40 InspectorTest.addResult("InspectorTest.consoleModel.log: " + message); | 40 InspectorTest.addResult("InspectorTest.consoleModel.log: " + message); |
| 41 } | 41 } |
| 42 | 42 |
| 43 InspectorTest.runTestSuite([ | 43 InspectorTest.runTestSuite([ |
| 44 function heapSnapshotSaveToFileTest(next) | 44 function heapSnapshotSaveToFileTest(next) |
| 45 { | 45 { |
| 46 function snapshotLoaded(profileHeader) | 46 function snapshotLoaded(profileHeader) |
| 47 { | 47 { |
| 48 var savedSnapshotData; | 48 var savedSnapshotData; |
| 49 function saveMock(url, data) | 49 function saveMock(url, data) |
| 50 { | 50 { |
| 51 savedSnapshotData = data; | 51 savedSnapshotData = data; |
| 52 WebInspector.fileManager._savedURL({data: url}); | 52 Workspace.fileManager._savedURL({data: url}); |
| 53 } | 53 } |
| 54 InspectorTest.override(InspectorFrontendHost, "save", saveMock); | 54 InspectorTest.override(InspectorFrontendHost, "save", saveMock); |
| 55 | 55 |
| 56 var oldAppend = InspectorFrontendHost.append; | 56 var oldAppend = InspectorFrontendHost.append; |
| 57 InspectorFrontendHost.append = function appendMock(url, data) | 57 InspectorFrontendHost.append = function appendMock(url, data) |
| 58 { | 58 { |
| 59 savedSnapshotData += data; | 59 savedSnapshotData += data; |
| 60 WebInspector.fileManager._appendedToURL({data: url}); | 60 Workspace.fileManager._appendedToURL({data: url}); |
| 61 } | 61 } |
| 62 function closeMock(url) | 62 function closeMock(url) |
| 63 { | 63 { |
| 64 InspectorTest.assertEquals(sourceStringified, savedSnapshotD
ata, "Saved snapshot data"); | 64 InspectorTest.assertEquals(sourceStringified, savedSnapshotD
ata, "Saved snapshot data"); |
| 65 InspectorFrontendHost.append = oldAppend; | 65 InspectorFrontendHost.append = oldAppend; |
| 66 next(); | 66 next(); |
| 67 } | 67 } |
| 68 InspectorTest.override(WebInspector.FileManager.prototype, "clos
e", closeMock); | 68 InspectorTest.override(Workspace.FileManager.prototype, "close",
closeMock); |
| 69 profileHeader.saveToFile(); | 69 profileHeader.saveToFile(); |
| 70 } | 70 } |
| 71 | 71 |
| 72 injectMockProfile(snapshotLoaded); | 72 injectMockProfile(snapshotLoaded); |
| 73 }, | 73 }, |
| 74 | 74 |
| 75 function heapSnapshotLoadFromFileTest(next) | 75 function heapSnapshotLoadFromFileTest(next) |
| 76 { | 76 { |
| 77 var panel = WebInspector.panels.profiles; | 77 var panel = UI.panels.profiles; |
| 78 | 78 |
| 79 var fileMock = { | 79 var fileMock = { |
| 80 name: "mock.heapsnapshot", | 80 name: "mock.heapsnapshot", |
| 81 size: sourceStringified.length | 81 size: sourceStringified.length |
| 82 }; | 82 }; |
| 83 | 83 |
| 84 InspectorTest.override(WebInspector.HeapProfileHeader.prototype, '_c
reateFileReader', function(fileMock, delegate) { | 84 InspectorTest.override(Profiler.HeapProfileHeader.prototype, '_creat
eFileReader', function(fileMock, delegate) { |
| 85 return { | 85 return { |
| 86 start: function(receiver) { | 86 start: function(receiver) { |
| 87 delegate.onTransferStarted(this); | 87 delegate.onTransferStarted(this); |
| 88 receiver.write(sourceStringified); | 88 receiver.write(sourceStringified); |
| 89 delegate.onChunkTransferred(this); | 89 delegate.onChunkTransferred(this); |
| 90 receiver.close(); | 90 receiver.close(); |
| 91 delegate.onTransferFinished(this); | 91 delegate.onTransferFinished(this); |
| 92 }, | 92 }, |
| 93 | 93 |
| 94 loadedSize: function() | 94 loadedSize: function() |
| 95 { | 95 { |
| 96 return fileMock.size; | 96 return fileMock.size; |
| 97 }, | 97 }, |
| 98 | 98 |
| 99 fileSize: function() | 99 fileSize: function() |
| 100 { | 100 { |
| 101 return fileMock.size; | 101 return fileMock.size; |
| 102 }, | 102 }, |
| 103 | 103 |
| 104 fileName: function() | 104 fileName: function() |
| 105 { | 105 { |
| 106 return fileMock.name; | 106 return fileMock.name; |
| 107 } | 107 } |
| 108 }; | 108 }; |
| 109 }); | 109 }); |
| 110 InspectorTest.addSniffer(WebInspector.HeapProfileHeader.prototype, "
_snapshotReceived", function() { next(); }); | 110 InspectorTest.addSniffer(Profiler.HeapProfileHeader.prototype, "_sna
pshotReceived", function() { next(); }); |
| 111 panel._loadFromFile(fileMock); | 111 panel._loadFromFile(fileMock); |
| 112 }, | 112 }, |
| 113 | 113 |
| 114 function heapSnapshotRejectToSaveToFileTest(next) | 114 function heapSnapshotRejectToSaveToFileTest(next) |
| 115 { | 115 { |
| 116 function snapshotLoaded(profileHeader) | 116 function snapshotLoaded(profileHeader) |
| 117 { | 117 { |
| 118 if (profileHeader.canSaveToFile()) | 118 if (profileHeader.canSaveToFile()) |
| 119 next(); | 119 next(); |
| 120 else | 120 else |
| 121 profileHeader.addEventListener(WebInspector.ProfileHeader.Ev
ents.ProfileReceived, onCanSaveProfile, this); | 121 profileHeader.addEventListener(Profiler.ProfileHeader.Events
.ProfileReceived, onCanSaveProfile, this); |
| 122 function onCanSaveProfile() | 122 function onCanSaveProfile() |
| 123 { | 123 { |
| 124 InspectorTest.assertTrue(profileHeader.canSaveToFile()); | 124 InspectorTest.assertTrue(profileHeader.canSaveToFile()); |
| 125 next(); | 125 next(); |
| 126 } | 126 } |
| 127 } | 127 } |
| 128 | 128 |
| 129 injectMockProfile(snapshotLoaded); | 129 injectMockProfile(snapshotLoaded); |
| 130 } | 130 } |
| 131 ]); | 131 ]); |
| 132 } | 132 } |
| 133 | 133 |
| 134 </script> | 134 </script> |
| 135 </head> | 135 </head> |
| 136 | 136 |
| 137 <body onload="runTest()"> | 137 <body onload="runTest()"> |
| 138 <p> | 138 <p> |
| 139 This test checks HeapSnapshots loader. | 139 This test checks HeapSnapshots loader. |
| 140 </p> | 140 </p> |
| 141 | 141 |
| 142 </body> | 142 </body> |
| 143 </html> | 143 </html> |
| OLD | NEW |