| 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 | 9 |
| 10 function createTestEnvironmentInWorker() | 10 function createTestEnvironmentInWorker() |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 var nodeE = snapshot.createNode(15); | 54 var nodeE = snapshot.createNode(15); |
| 55 InspectorTest.assertEquals("E", nodeE.name(), "E name"); | 55 InspectorTest.assertEquals("E", nodeE.name(), "E name"); |
| 56 InspectorTest.assertEquals("object", nodeE.type(), "E type"); | 56 InspectorTest.assertEquals("object", nodeE.type(), "E type"); |
| 57 InspectorTest.assertEquals(0, nodeE.edgesCount(), "E edges"); | 57 InspectorTest.assertEquals(0, nodeE.edgesCount(), "E edges"); |
| 58 }, | 58 }, |
| 59 | 59 |
| 60 function heapSnapshotNodeIteratorTest() | 60 function heapSnapshotNodeIteratorTest() |
| 61 { | 61 { |
| 62 var snapshot = InspectorTest.createJSHeapSnapshotMockObject(); | 62 var snapshot = InspectorTest.createJSHeapSnapshotMockObject(); |
| 63 var nodeRoot = snapshot.createNode(snapshot._rootNodeIndex); | 63 var nodeRoot = snapshot.createNode(snapshot._rootNodeIndex); |
| 64 var iterator = new WebInspector.HeapSnapshotNodeIterator(nodeRoo
t); | 64 var iterator = new HeapSnapshotWorker.HeapSnapshotNodeIterator(n
odeRoot); |
| 65 var names = []; | 65 var names = []; |
| 66 for (; iterator.hasNext(); iterator.next()) | 66 for (; iterator.hasNext(); iterator.next()) |
| 67 names.push(iterator.item().name()); | 67 names.push(iterator.item().name()); |
| 68 InspectorTest.assertEquals(",A,B,C,D,E", names.join(","), "node
iterator"); | 68 InspectorTest.assertEquals(",A,B,C,D,E", names.join(","), "node
iterator"); |
| 69 }, | 69 }, |
| 70 | 70 |
| 71 function heapSnapshotEdgeSimpleTest() | 71 function heapSnapshotEdgeSimpleTest() |
| 72 { | 72 { |
| 73 var snapshot = InspectorTest.createJSHeapSnapshotMockObject(); | 73 var snapshot = InspectorTest.createJSHeapSnapshotMockObject(); |
| 74 var nodeRoot = snapshot.createNode(snapshot._rootNodeIndex); | 74 var nodeRoot = snapshot.createNode(snapshot._rootNodeIndex); |
| 75 var edgeIterator = new WebInspector.HeapSnapshotEdgeIterator(nod
eRoot); | 75 var edgeIterator = new HeapSnapshotWorker.HeapSnapshotEdgeIterat
or(nodeRoot); |
| 76 InspectorTest.assertEquals(true, edgeIterator.hasNext(), "has ed
ges"); | 76 InspectorTest.assertEquals(true, edgeIterator.hasNext(), "has ed
ges"); |
| 77 var edge = edgeIterator.item(); | 77 var edge = edgeIterator.item(); |
| 78 InspectorTest.assertEquals("shortcut", edge.type(), "edge type")
; | 78 InspectorTest.assertEquals("shortcut", edge.type(), "edge type")
; |
| 79 InspectorTest.assertEquals("a", edge.name(), "edge name"); | 79 InspectorTest.assertEquals("a", edge.name(), "edge name"); |
| 80 InspectorTest.assertEquals("A", edge.node().name(), "edge node n
ame"); | 80 InspectorTest.assertEquals("A", edge.node().name(), "edge node n
ame"); |
| 81 | 81 |
| 82 var edgesCount = 0; | 82 var edgesCount = 0; |
| 83 for (; edgeIterator.hasNext(); edgeIterator.next()) | 83 for (; edgeIterator.hasNext(); edgeIterator.next()) |
| 84 ++edgesCount; | 84 ++edgesCount; |
| 85 InspectorTest.assertEquals(nodeRoot.edgesCount(), edgesCount, "e
dges count"); | 85 InspectorTest.assertEquals(nodeRoot.edgesCount(), edgesCount, "e
dges count"); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 111 depthFirstTraversal(edges.item().node()); | 111 depthFirstTraversal(edges.item().node()); |
| 112 } | 112 } |
| 113 } | 113 } |
| 114 | 114 |
| 115 depthFirstTraversal(nodeRoot); | 115 depthFirstTraversal(nodeRoot); |
| 116 var reference = ",a,A,1,B,bc,C,ce,E,bd,D,ac,C,ce,E,b,B,bc,C,ce,E
,bd,D"; | 116 var reference = ",a,A,1,B,bc,C,ce,E,bd,D,ac,C,ce,E,b,B,bc,C,ce,E
,bd,D"; |
| 117 InspectorTest.assertEquals(reference, names.join(","), "mock tra
versal"); | 117 InspectorTest.assertEquals(reference, names.join(","), "mock tra
versal"); |
| 118 | 118 |
| 119 // Now check against a real HeapSnapshot instance. | 119 // Now check against a real HeapSnapshot instance. |
| 120 names = []; | 120 names = []; |
| 121 var snapshot = new WebInspector.JSHeapSnapshot(InspectorTest.cre
ateHeapSnapshotMock(), new WebInspector.HeapSnapshotProgress()); | 121 var snapshot = new HeapSnapshotWorker.JSHeapSnapshot(InspectorTe
st.createHeapSnapshotMock(), new HeapSnapshotWorker.HeapSnapshotProgress()); |
| 122 depthFirstTraversal(snapshot.rootNode()); | 122 depthFirstTraversal(snapshot.rootNode()); |
| 123 InspectorTest.assertEquals(reference, names.join(","), "snapshot
traversal"); | 123 InspectorTest.assertEquals(reference, names.join(","), "snapshot
traversal"); |
| 124 }, | 124 }, |
| 125 | 125 |
| 126 function heapSnapshotSimpleTest() | 126 function heapSnapshotSimpleTest() |
| 127 { | 127 { |
| 128 var snapshot = new WebInspector.JSHeapSnapshot(InspectorTest.cre
ateHeapSnapshotMock(), new WebInspector.HeapSnapshotProgress()); | 128 var snapshot = new HeapSnapshotWorker.JSHeapSnapshot(InspectorTe
st.createHeapSnapshotMock(), new HeapSnapshotWorker.HeapSnapshotProgress()); |
| 129 InspectorTest.assertEquals(6, snapshot.nodeCount, "node count"); | 129 InspectorTest.assertEquals(6, snapshot.nodeCount, "node count"); |
| 130 InspectorTest.assertEquals(20, snapshot.totalSize, "total size")
; | 130 InspectorTest.assertEquals(20, snapshot.totalSize, "total size")
; |
| 131 }, | 131 }, |
| 132 | 132 |
| 133 function heapSnapshotContainmentEdgeIndexesTest() | 133 function heapSnapshotContainmentEdgeIndexesTest() |
| 134 { | 134 { |
| 135 var snapshot = new WebInspector.JSHeapSnapshot(InspectorTest.cre
ateHeapSnapshotMock(), new WebInspector.HeapSnapshotProgress()); | 135 var snapshot = new HeapSnapshotWorker.JSHeapSnapshot(InspectorTe
st.createHeapSnapshotMock(), new HeapSnapshotWorker.HeapSnapshotProgress()); |
| 136 var actual = snapshot._firstEdgeIndexes; | 136 var actual = snapshot._firstEdgeIndexes; |
| 137 var expected = [0, 6, 12, 18, 21, 21, 21]; | 137 var expected = [0, 6, 12, 18, 21, 21, 21]; |
| 138 InspectorTest.assertEquals(expected.length, actual.length, "Edge
indexes size"); | 138 InspectorTest.assertEquals(expected.length, actual.length, "Edge
indexes size"); |
| 139 for (var i = 0; i < expected.length; ++i) | 139 for (var i = 0; i < expected.length; ++i) |
| 140 InspectorTest.assertEquals(expected[i], actual[i], "Edge ind
exes"); | 140 InspectorTest.assertEquals(expected[i], actual[i], "Edge ind
exes"); |
| 141 }, | 141 }, |
| 142 | 142 |
| 143 function heapSnapshotPostOrderIndexTest() | 143 function heapSnapshotPostOrderIndexTest() |
| 144 { | 144 { |
| 145 var snapshot = new WebInspector.JSHeapSnapshot(InspectorTest.cre
ateHeapSnapshotMock(), new WebInspector.HeapSnapshotProgress()); | 145 var snapshot = new HeapSnapshotWorker.JSHeapSnapshot(InspectorTe
st.createHeapSnapshotMock(), new HeapSnapshotWorker.HeapSnapshotProgress()); |
| 146 var postOrderIndex2NodeOrdinal = snapshot._buildPostOrderIndex()
.postOrderIndex2NodeOrdinal; | 146 var postOrderIndex2NodeOrdinal = snapshot._buildPostOrderIndex()
.postOrderIndex2NodeOrdinal; |
| 147 var expected = [5,3,4,2,1,0]; | 147 var expected = [5,3,4,2,1,0]; |
| 148 for (var i = 0; i < expected.length; ++i) | 148 for (var i = 0; i < expected.length; ++i) |
| 149 InspectorTest.assertEquals(expected[i], postOrderIndex2NodeO
rdinal[i], "Post ordered indexes"); | 149 InspectorTest.assertEquals(expected[i], postOrderIndex2NodeO
rdinal[i], "Post ordered indexes"); |
| 150 }, | 150 }, |
| 151 | 151 |
| 152 function heapSnapshotDominatorsTreeTest() | 152 function heapSnapshotDominatorsTreeTest() |
| 153 { | 153 { |
| 154 var snapshot = new WebInspector.JSHeapSnapshot(InspectorTest.cre
ateHeapSnapshotMock(), new WebInspector.HeapSnapshotProgress()); | 154 var snapshot = new HeapSnapshotWorker.JSHeapSnapshot(InspectorTe
st.createHeapSnapshotMock(), new HeapSnapshotWorker.HeapSnapshotProgress()); |
| 155 var result = snapshot._buildPostOrderIndex(); | 155 var result = snapshot._buildPostOrderIndex(); |
| 156 var dominatorsTree = snapshot._buildDominatorTree(result.postOrd
erIndex2NodeOrdinal, result.nodeOrdinal2PostOrderIndex); | 156 var dominatorsTree = snapshot._buildDominatorTree(result.postOrd
erIndex2NodeOrdinal, result.nodeOrdinal2PostOrderIndex); |
| 157 var expected = [0, 0, 0, 0, 2, 3]; | 157 var expected = [0, 0, 0, 0, 2, 3]; |
| 158 for (var i = 0; i < expected.length; ++i) | 158 for (var i = 0; i < expected.length; ++i) |
| 159 InspectorTest.assertEquals(expected[i], dominatorsTree[i], "
Dominators Tree"); | 159 InspectorTest.assertEquals(expected[i], dominatorsTree[i], "
Dominators Tree"); |
| 160 }, | 160 }, |
| 161 | 161 |
| 162 function heapSnapshotRetainedSizeTest() | 162 function heapSnapshotRetainedSizeTest() |
| 163 { | 163 { |
| 164 var snapshot = new WebInspector.JSHeapSnapshot(InspectorTest.cre
ateHeapSnapshotMock(), new WebInspector.HeapSnapshotProgress()); | 164 var snapshot = new HeapSnapshotWorker.JSHeapSnapshot(InspectorTe
st.createHeapSnapshotMock(), new HeapSnapshotWorker.HeapSnapshotProgress()); |
| 165 var actualRetainedSizes = new Array(snapshot.nodeCount); | 165 var actualRetainedSizes = new Array(snapshot.nodeCount); |
| 166 for (var nodeOrdinal = 0; nodeOrdinal < snapshot.nodeCount; ++no
deOrdinal) | 166 for (var nodeOrdinal = 0; nodeOrdinal < snapshot.nodeCount; ++no
deOrdinal) |
| 167 actualRetainedSizes[nodeOrdinal] = snapshot._retainedSizes[n
odeOrdinal]; | 167 actualRetainedSizes[nodeOrdinal] = snapshot._retainedSizes[n
odeOrdinal]; |
| 168 var expectedRetainedSizes = [20, 2, 8, 10, 5, 6]; | 168 var expectedRetainedSizes = [20, 2, 8, 10, 5, 6]; |
| 169 InspectorTest.assertEquals(JSON.stringify(expectedRetainedSizes)
, JSON.stringify(actualRetainedSizes), "Retained sizes"); | 169 InspectorTest.assertEquals(JSON.stringify(expectedRetainedSizes)
, JSON.stringify(actualRetainedSizes), "Retained sizes"); |
| 170 }, | 170 }, |
| 171 | 171 |
| 172 function heapSnapshotLargeRetainedSize(next) | 172 function heapSnapshotLargeRetainedSize(next) |
| 173 { | 173 { |
| 174 var builder = new InspectorTest.HeapSnapshotBuilder(); | 174 var builder = new InspectorTest.HeapSnapshotBuilder(); |
| 175 var node = builder.rootNode; | 175 var node = builder.rootNode; |
| 176 | 176 |
| 177 var iterations = 6; | 177 var iterations = 6; |
| 178 var nodeSize = 1000 * 1000 * 1000; | 178 var nodeSize = 1000 * 1000 * 1000; |
| 179 for (var i = 0; i < 6; i++) { | 179 for (var i = 0; i < 6; i++) { |
| 180 var newNode = new InspectorTest.HeapNode("Node" + i, nodeSiz
e); | 180 var newNode = new InspectorTest.HeapNode("Node" + i, nodeSiz
e); |
| 181 node.linkNode(newNode, InspectorTest.HeapEdge.Type.element); | 181 node.linkNode(newNode, InspectorTest.HeapEdge.Type.element); |
| 182 node = newNode; | 182 node = newNode; |
| 183 } | 183 } |
| 184 | 184 |
| 185 var snapshot = builder.createJSHeapSnapshot(); | 185 var snapshot = builder.createJSHeapSnapshot(); |
| 186 InspectorTest.assertEquals( | 186 InspectorTest.assertEquals( |
| 187 iterations * nodeSize, snapshot.rootNode().retainedSize(), | 187 iterations * nodeSize, snapshot.rootNode().retainedSize(), |
| 188 "Ensure that root node retained size supports values exceedi
ng 2^32 bytes."); | 188 "Ensure that root node retained size supports values exceedi
ng 2^32 bytes."); |
| 189 }, | 189 }, |
| 190 | 190 |
| 191 function heapSnapshotDominatedNodesTest() | 191 function heapSnapshotDominatedNodesTest() |
| 192 { | 192 { |
| 193 var snapshot = new WebInspector.JSHeapSnapshot(InspectorTest.cre
ateHeapSnapshotMock(), new WebInspector.HeapSnapshotProgress()); | 193 var snapshot = new HeapSnapshotWorker.JSHeapSnapshot(InspectorTe
st.createHeapSnapshotMock(), new HeapSnapshotWorker.HeapSnapshotProgress()); |
| 194 | 194 |
| 195 var expectedDominatedNodes = [21, 14, 7, 28, 35]; | 195 var expectedDominatedNodes = [21, 14, 7, 28, 35]; |
| 196 var actualDominatedNodes = snapshot._dominatedNodes; | 196 var actualDominatedNodes = snapshot._dominatedNodes; |
| 197 InspectorTest.assertEquals(expectedDominatedNodes.length, actual
DominatedNodes.length, "Dominated Nodes length"); | 197 InspectorTest.assertEquals(expectedDominatedNodes.length, actual
DominatedNodes.length, "Dominated Nodes length"); |
| 198 for (var i = 0; i < expectedDominatedNodes.length; ++i) | 198 for (var i = 0; i < expectedDominatedNodes.length; ++i) |
| 199 InspectorTest.assertEquals(expectedDominatedNodes[i], actual
DominatedNodes[i], "Dominated Nodes"); | 199 InspectorTest.assertEquals(expectedDominatedNodes[i], actual
DominatedNodes[i], "Dominated Nodes"); |
| 200 | 200 |
| 201 var expectedDominatedNodeIndex = [0, 3, 3, 4, 5, 5, 5]; | 201 var expectedDominatedNodeIndex = [0, 3, 3, 4, 5, 5, 5]; |
| 202 var actualDominatedNodeIndex = snapshot._firstDominatedNodeIndex
; | 202 var actualDominatedNodeIndex = snapshot._firstDominatedNodeIndex
; |
| 203 InspectorTest.assertEquals(expectedDominatedNodeIndex.length, ac
tualDominatedNodeIndex.length, "Dominated Nodes Index length"); | 203 InspectorTest.assertEquals(expectedDominatedNodeIndex.length, ac
tualDominatedNodeIndex.length, "Dominated Nodes Index length"); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 231 | 231 |
| 232 var expectedFlags = [0, 0, 4, 4, 0]; | 232 var expectedFlags = [0, 0, 4, 4, 0]; |
| 233 InspectorTest.assertEquals( | 233 InspectorTest.assertEquals( |
| 234 JSON.stringify(expectedFlags), | 234 JSON.stringify(expectedFlags), |
| 235 JSON.stringify(snapshot._flags), | 235 JSON.stringify(snapshot._flags), |
| 236 "We are expecting that only window(third element) and PageOw
nedNode(forth element) have flag === 4."); | 236 "We are expecting that only window(third element) and PageOw
nedNode(forth element) have flag === 4."); |
| 237 }, | 237 }, |
| 238 | 238 |
| 239 function heapSnapshotRetainersTest() | 239 function heapSnapshotRetainersTest() |
| 240 { | 240 { |
| 241 var snapshot = new WebInspector.JSHeapSnapshot(InspectorTest.cre
ateHeapSnapshotMock(), new WebInspector.HeapSnapshotProgress()); | 241 var snapshot = new HeapSnapshotWorker.JSHeapSnapshot(InspectorTe
st.createHeapSnapshotMock(), new HeapSnapshotWorker.HeapSnapshotProgress()); |
| 242 var expectedRetainers = { | 242 var expectedRetainers = { |
| 243 "": [], | 243 "": [], |
| 244 "A": [""], | 244 "A": [""], |
| 245 "B": ["", "A"], | 245 "B": ["", "A"], |
| 246 "C": ["A", "B"], | 246 "C": ["A", "B"], |
| 247 "D": ["B"], | 247 "D": ["B"], |
| 248 "E": ["C"]}; | 248 "E": ["C"]}; |
| 249 for (var nodes = snapshot._allNodes(); nodes.hasNext(); nodes.ne
xt()) { | 249 for (var nodes = snapshot._allNodes(); nodes.hasNext(); nodes.ne
xt()) { |
| 250 var names = []; | 250 var names = []; |
| 251 for (var retainers = nodes.item().retainers(); retainers.has
Next(); retainers.next()) | 251 for (var retainers = nodes.item().retainers(); retainers.has
Next(); retainers.next()) |
| 252 names.push(retainers.item().node().name()); | 252 names.push(retainers.item().node().name()); |
| 253 names.sort(); | 253 names.sort(); |
| 254 InspectorTest.assertEquals(expectedRetainers[nodes.item().na
me()].join(","), names.join(","), "retainers of \"" + nodes.item().name() + "\""
); | 254 InspectorTest.assertEquals(expectedRetainers[nodes.item().na
me()].join(","), names.join(","), "retainers of \"" + nodes.item().name() + "\""
); |
| 255 } | 255 } |
| 256 }, | 256 }, |
| 257 | 257 |
| 258 function heapSnapshotAggregatesTest() | 258 function heapSnapshotAggregatesTest() |
| 259 { | 259 { |
| 260 var snapshot = new WebInspector.JSHeapSnapshot(InspectorTest.cre
ateHeapSnapshotMock(), new WebInspector.HeapSnapshotProgress()); | 260 var snapshot = new HeapSnapshotWorker.JSHeapSnapshot(InspectorTe
st.createHeapSnapshotMock(), new HeapSnapshotWorker.HeapSnapshotProgress()); |
| 261 var expectedAggregates = { | 261 var expectedAggregates = { |
| 262 "A": { count: 1, self: 2, maxRet: 2, type: "object", name: "
A" }, | 262 "A": { count: 1, self: 2, maxRet: 2, type: "object", name: "
A" }, |
| 263 "B": { count: 1, self: 3, maxRet: 8, type: "object", name: "
B" }, | 263 "B": { count: 1, self: 3, maxRet: 8, type: "object", name: "
B" }, |
| 264 "C": { count: 1, self: 4, maxRet: 10, type: "object", name:
"C" }, | 264 "C": { count: 1, self: 4, maxRet: 10, type: "object", name:
"C" }, |
| 265 "D": { count: 1, self: 5, maxRet: 5, type: "object", name: "
D" }, | 265 "D": { count: 1, self: 5, maxRet: 5, type: "object", name: "
D" }, |
| 266 "E": { count: 1, self: 6, maxRet: 6, type: "object", name: "
E" } | 266 "E": { count: 1, self: 6, maxRet: 6, type: "object", name: "
E" } |
| 267 }; | 267 }; |
| 268 var aggregates = snapshot.aggregates(false); | 268 var aggregates = snapshot.aggregates(false); |
| 269 for (var name in aggregates) { | 269 for (var name in aggregates) { |
| 270 var aggregate = aggregates[name]; | 270 var aggregate = aggregates[name]; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 283 var indexes = snapshot.aggregates(true); | 283 var indexes = snapshot.aggregates(true); |
| 284 for (var name in aggregates) { | 284 for (var name in aggregates) { |
| 285 var aggregate = aggregates[name]; | 285 var aggregate = aggregates[name]; |
| 286 var expectedIndex = expectedIndexes[name]; | 286 var expectedIndex = expectedIndexes[name]; |
| 287 InspectorTest.assertEquals(expectedIndex.join(","), aggregat
e.idxs.join(","), "indexes of \"" + name + "\""); | 287 InspectorTest.assertEquals(expectedIndex.join(","), aggregat
e.idxs.join(","), "indexes of \"" + name + "\""); |
| 288 } | 288 } |
| 289 }, | 289 }, |
| 290 | 290 |
| 291 function heapSnapshotFlagsTest() | 291 function heapSnapshotFlagsTest() |
| 292 { | 292 { |
| 293 var snapshot = new WebInspector.JSHeapSnapshot(InspectorTest.cre
ateHeapSnapshotMockWithDOM(), new WebInspector.HeapSnapshotProgress()); | 293 var snapshot = new HeapSnapshotWorker.JSHeapSnapshot(InspectorTe
st.createHeapSnapshotMockWithDOM(), new HeapSnapshotWorker.HeapSnapshotProgress(
)); |
| 294 var expectedCanBeQueried = { | 294 var expectedCanBeQueried = { |
| 295 "": false, | 295 "": false, |
| 296 "A": true, | 296 "A": true, |
| 297 "B": true, | 297 "B": true, |
| 298 "C": true, | 298 "C": true, |
| 299 "D": true, | 299 "D": true, |
| 300 "E": false, | 300 "E": false, |
| 301 "F": false, | 301 "F": false, |
| 302 "G": false, | 302 "G": false, |
| 303 "H": false, | 303 "H": false, |
| 304 "M": false, | 304 "M": false, |
| 305 "N": false, | 305 "N": false, |
| 306 "Window": true | 306 "Window": true |
| 307 }; | 307 }; |
| 308 for (var nodes = snapshot._allNodes(); nodes.hasNext(); nodes.ne
xt()) { | 308 for (var nodes = snapshot._allNodes(); nodes.hasNext(); nodes.ne
xt()) { |
| 309 var node = nodes.item(); | 309 var node = nodes.item(); |
| 310 InspectorTest.assertEquals(expectedCanBeQueried[node.name()]
, node.canBeQueried(), "canBeQueried of \"" + node.name() + "\""); | 310 InspectorTest.assertEquals(expectedCanBeQueried[node.name()]
, node.canBeQueried(), "canBeQueried of \"" + node.name() + "\""); |
| 311 } | 311 } |
| 312 }, | 312 }, |
| 313 | 313 |
| 314 function heapSnapshotNodesProviderTest() | 314 function heapSnapshotNodesProviderTest() |
| 315 { | 315 { |
| 316 var snapshot = new WebInspector.JSHeapSnapshot(InspectorTest.cre
ateHeapSnapshotMock(), new WebInspector.HeapSnapshotProgress()); | 316 var snapshot = new HeapSnapshotWorker.JSHeapSnapshot(InspectorTe
st.createHeapSnapshotMock(), new HeapSnapshotWorker.HeapSnapshotProgress()); |
| 317 | 317 |
| 318 function nodeFilter(node) | 318 function nodeFilter(node) |
| 319 { | 319 { |
| 320 return node.type() === "object" && node.name() !== "B" && no
de.name() !== "D"; | 320 return node.type() === "object" && node.name() !== "B" && no
de.name() !== "D"; |
| 321 } | 321 } |
| 322 | 322 |
| 323 var allNodeIndexes = []; | 323 var allNodeIndexes = []; |
| 324 for (var i = 0; i < snapshot.nodes.length; i += snapshot._nodeFi
eldCount) | 324 for (var i = 0; i < snapshot.nodes.length; i += snapshot._nodeFi
eldCount) |
| 325 allNodeIndexes.push(i); | 325 allNodeIndexes.push(i); |
| 326 var provider = new WebInspector.HeapSnapshotNodesProvider(snapsh
ot, nodeFilter, allNodeIndexes); | 326 var provider = new HeapSnapshotWorker.HeapSnapshotNodesProvider(
snapshot, nodeFilter, allNodeIndexes); |
| 327 // Sort by names in reverse order. | 327 // Sort by names in reverse order. |
| 328 provider.sortAndRewind({fieldName1: "name", ascending1: false, f
ieldName2: "id", ascending2: false}); | 328 provider.sortAndRewind({fieldName1: "name", ascending1: false, f
ieldName2: "id", ascending2: false}); |
| 329 var range = provider.serializeItemsRange(0, 3); | 329 var range = provider.serializeItemsRange(0, 3); |
| 330 InspectorTest.assertEquals(3, range.totalLength, "Node range tot
al length"); | 330 InspectorTest.assertEquals(3, range.totalLength, "Node range tot
al length"); |
| 331 InspectorTest.assertEquals(0, range.startPosition, "Node range s
tart position"); | 331 InspectorTest.assertEquals(0, range.startPosition, "Node range s
tart position"); |
| 332 InspectorTest.assertEquals(3, range.endPosition, "Node range end
position"); | 332 InspectorTest.assertEquals(3, range.endPosition, "Node range end
position"); |
| 333 var names = range.items.map(function(item) | 333 var names = range.items.map(function(item) |
| 334 { | 334 { |
| 335 return item.name; | 335 return item.name; |
| 336 }); | 336 }); |
| 337 InspectorTest.assertEquals("E,C,A", names.join(","), "nodes prov
ider names"); | 337 InspectorTest.assertEquals("E,C,A", names.join(","), "nodes prov
ider names"); |
| 338 }, | 338 }, |
| 339 | 339 |
| 340 function heapSnapshotEdgesProviderTest() | 340 function heapSnapshotEdgesProviderTest() |
| 341 { | 341 { |
| 342 var snapshot = new WebInspector.JSHeapSnapshot(InspectorTest.cre
ateHeapSnapshotMock(), new WebInspector.HeapSnapshotProgress()); | 342 var snapshot = new HeapSnapshotWorker.JSHeapSnapshot(InspectorTe
st.createHeapSnapshotMock(), new HeapSnapshotWorker.HeapSnapshotProgress()); |
| 343 | 343 |
| 344 function edgeFilter(edge) | 344 function edgeFilter(edge) |
| 345 { | 345 { |
| 346 return edge.name() === "b"; | 346 return edge.name() === "b"; |
| 347 } | 347 } |
| 348 | 348 |
| 349 var provider = snapshot.createEdgesProviderForTest(snapshot.root
NodeIndex, edgeFilter); | 349 var provider = snapshot.createEdgesProviderForTest(snapshot.root
NodeIndex, edgeFilter); |
| 350 provider.sortAndRewind({fieldName1: "!edgeName", ascending1: fal
se, fieldName2: "id", ascending2: false}); | 350 provider.sortAndRewind({fieldName1: "!edgeName", ascending1: fal
se, fieldName2: "id", ascending2: false}); |
| 351 var range = provider.serializeItemsRange(0, 10); | 351 var range = provider.serializeItemsRange(0, 10); |
| 352 InspectorTest.assertEquals(1, range.totalLength, "Edge range tot
al length"); | 352 InspectorTest.assertEquals(1, range.totalLength, "Edge range tot
al length"); |
| 353 InspectorTest.assertEquals(0, range.startPosition, "Edge range s
tart position"); | 353 InspectorTest.assertEquals(0, range.startPosition, "Edge range s
tart position"); |
| 354 InspectorTest.assertEquals(1, range.endPosition, "Edge range end
position"); | 354 InspectorTest.assertEquals(1, range.endPosition, "Edge range end
position"); |
| 355 var names = range.items.map(function(item) | 355 var names = range.items.map(function(item) |
| 356 { | 356 { |
| 357 return item.name; | 357 return item.name; |
| 358 }); | 358 }); |
| 359 InspectorTest.assertEquals("b", names.join(","), "edges provider
names"); | 359 InspectorTest.assertEquals("b", names.join(","), "edges provider
names"); |
| 360 }, | 360 }, |
| 361 | 361 |
| 362 function heapSnapshotLoaderTest() | 362 function heapSnapshotLoaderTest() |
| 363 { | 363 { |
| 364 var source = InspectorTest.createHeapSnapshotMockRaw(); | 364 var source = InspectorTest.createHeapSnapshotMockRaw(); |
| 365 var sourceStringified = JSON.stringify(source); | 365 var sourceStringified = JSON.stringify(source); |
| 366 var partSize = sourceStringified.length >> 3; | 366 var partSize = sourceStringified.length >> 3; |
| 367 | 367 |
| 368 var loader = new WebInspector.HeapSnapshotLoader(); | 368 var loader = new HeapSnapshotWorker.HeapSnapshotLoader(); |
| 369 for (var i = 0, l = sourceStringified.length; i < l; i += partSi
ze) | 369 for (var i = 0, l = sourceStringified.length; i < l; i += partSi
ze) |
| 370 loader.write(sourceStringified.slice(i, i + partSize)); | 370 loader.write(sourceStringified.slice(i, i + partSize)); |
| 371 loader.close(); | 371 loader.close(); |
| 372 var result = loader.buildSnapshot(false); | 372 var result = loader.buildSnapshot(false); |
| 373 result.nodes = new Uint32Array(result.nodes); | 373 result.nodes = new Uint32Array(result.nodes); |
| 374 result.containmentEdges = new Uint32Array(result.containmentEdge
s); | 374 result.containmentEdges = new Uint32Array(result.containmentEdge
s); |
| 375 function assertSnapshotEquals(reference, actual) | 375 function assertSnapshotEquals(reference, actual) |
| 376 { | 376 { |
| 377 InspectorTest.assertEquals(JSON.stringify(reference), JSON.s
tringify(actual)); | 377 InspectorTest.assertEquals(JSON.stringify(reference), JSON.s
tringify(actual)); |
| 378 } | 378 } |
| 379 assertSnapshotEquals(new WebInspector.JSHeapSnapshot(InspectorTe
st.createHeapSnapshotMock(), new WebInspector.HeapSnapshotProgress(), false), re
sult); | 379 assertSnapshotEquals(new HeapSnapshotWorker.JSHeapSnapshot(Inspe
ctorTest.createHeapSnapshotMock(), new HeapSnapshotWorker.HeapSnapshotProgress()
, false), result); |
| 380 }, | 380 }, |
| 381 ]; | 381 ]; |
| 382 | 382 |
| 383 var result = []; | 383 var result = []; |
| 384 for (var i = 0; i < testSuite.length; i++) { | 384 for (var i = 0; i < testSuite.length; i++) { |
| 385 var test = testSuite[i]; | 385 var test = testSuite[i]; |
| 386 result.push(""); | 386 result.push(""); |
| 387 result.push("Running: " + test.name); | 387 result.push("Running: " + test.name); |
| 388 try { | 388 try { |
| 389 test(); | 389 test(); |
| 390 } catch (e) { | 390 } catch (e) { |
| 391 result.push("FAIL: " + e); | 391 result.push("FAIL: " + e); |
| 392 } | 392 } |
| 393 } | 393 } |
| 394 return result.join("\n"); | 394 return result.join("\n"); |
| 395 } | 395 } |
| 396 | 396 |
| 397 var proxy = new WebInspector.HeapSnapshotWorkerProxy(function(eventName, arg
) | 397 var proxy = new Profiler.HeapSnapshotWorkerProxy(function(eventName, arg) |
| 398 { | 398 { |
| 399 InspectorTest.addResult("Unexpected event from worker: " + eventName); | 399 InspectorTest.addResult("Unexpected event from worker: " + eventName); |
| 400 }); | 400 }); |
| 401 var source = "(" + createTestEnvironmentInWorker + ")();" + | 401 var source = "(" + createTestEnvironmentInWorker + ")();" + |
| 402 "(" + InspectorTest.createHeapSnapshotMockFactories + ")();" + | 402 "(" + InspectorTest.createHeapSnapshotMockFactories + ")();" + |
| 403 "(" + runTestSuiteInWorker + ")();"; | 403 "(" + runTestSuiteInWorker + ")();"; |
| 404 proxy.evaluateForTest(source, function(result) | 404 proxy.evaluateForTest(source, function(result) |
| 405 { | 405 { |
| 406 InspectorTest.addResult(result); | 406 InspectorTest.addResult(result); |
| 407 InspectorTest.completeTest(); | 407 InspectorTest.completeTest(); |
| 408 }); | 408 }); |
| 409 } | 409 } |
| 410 | 410 |
| 411 </script> | 411 </script> |
| 412 </head> | 412 </head> |
| 413 | 413 |
| 414 <body onload="runTest()"> | 414 <body onload="runTest()"> |
| 415 <p> | 415 <p> |
| 416 This test checks HeapSnapshots module. | 416 This test checks HeapSnapshots module. |
| 417 </p> | 417 </p> |
| 418 | 418 |
| 419 </body> | 419 </body> |
| 420 </html> | 420 </html> |
| OLD | NEW |