3 <script src="../../http/tests/inspector/inspector-test.js"></script>
4 <script src="heap-snapshot-test.js"></script>
9 // Make sure there is a body wrapper.
10 document.body.fieldOnDomWrapper = 2012;
16 WebInspector.showPanel("profiles");
17 WebInspector.panels.profiles._createTemporaryProfile("HEAP");
18 var heapProfileType = WebInspector.panels.profiles.getProfileType("HEAP");
19 heapProfileType.addEventListener(WebInspector.HeapSnapshotProfileType.SnapshotReceived, finishHeapSnapshot);
20 InspectorTest.addSniffer(heapProfileType, "_snapshotReceived", snapshotReceived);
21 heapProfileType._takeHeapSnapshot(function() {});
23 function finishHeapSnapshot(uid)
25 InspectorTest.addResult("PASS: snapshot was taken");
26 var profiles = heapProfileType.getProfiles();
29 return clear("FAILED: no profiles found");
31 if (profiles.length > 1)
32 return clear("FAILED: wrong number of recorded profiles was found. profiles.length = " + profiles.length);
34 var profile = profiles[profiles.length - 1];
35 WebInspector.panels.profiles._showProfile(profile);
38 function snapshotReceived(profile)
40 InspectorTest.addResult("PASS: snapshot was received");
41 var snapshotProxy = profile._snapshotProxy;
42 var snapshot = snapshotProxy._worker._worker._dispatcher._objects[snapshotProxy._objectId];
44 var bodyWrapperIds = [];
45 for (var it = snapshot._allNodes(); it.hasNext(); it.next()) {
46 if (it.item().name() === "HTMLBodyElement")
47 bodyWrapperIds.push(it.item().id());
50 if (bodyWrapperIds.length < 3)
51 return clear("FAILED: less than 3 HTMLBodyElement objects were detected");
53 InspectorTest.addResult("PASS: more than 2 HTMLBodyElements were found");
55 for (var i = 0; i < bodyWrapperIds.length; i++)
56 HeapProfilerAgent.getObjectByHeapObjectId("" + bodyWrapperIds[i], undefined, didGetObjectByHeapObjectId);
58 var resolvedObjectsCount = 0;
59 var remoteObjects = [];
60 function didGetObjectByHeapObjectId(error, object)
63 remoteObjects.push(WebInspector.RemoteObject.fromPayload(object));
65 if (++resolvedObjectsCount === bodyWrapperIds.length)
66 requestPropertiesOfResolvedObjects();
69 function requestPropertiesOfResolvedObjects()
71 if (!remoteObjects.length)
72 return clear("FAILED: no resolved objects were detected");
74 InspectorTest.addResult("PASS: got at least one HTMLBodyElement wrapper");
76 for (var i = 0; i < remoteObjects.length; i++)
77 remoteObjects[i].getOwnProperties(didGetOwnProperties);
80 var didGetOwnPropertiesCount = 0;
81 function didGetOwnProperties()
83 if (++didGetOwnPropertiesCount !== remoteObjects.length)
91 function clear(errorMessage)
94 InspectorTest.addResult(errorMessage);
95 HeapProfilerAgent.clearProfiles(done);
96 WebInspector.panels.profiles._reset();
102 InspectorTest.addResult("PASS: profile was deleted");
103 InspectorTest.completeTest();
110 <body onload="handleLoad()">
112 Test that resolving heap snaphot object to a JS object will not crash on DOM wrapper boilerplate. Test passes if it doesn't crash.