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 var heapProfileType = WebInspector.ProfileTypeRegistry.instance.heapSnapshotProfileType;
18 heapProfileType.addEventListener(WebInspector.HeapSnapshotProfileType.SnapshotReceived, finishHeapSnapshot);
19 InspectorTest.addSniffer(heapProfileType, "_snapshotReceived", snapshotReceived);
20 heapProfileType._takeHeapSnapshot(function() {});
22 function finishHeapSnapshot(uid)
24 InspectorTest.addResult("PASS: snapshot was taken");
25 var profiles = heapProfileType.getProfiles();
28 return clear("FAILED: no profiles found");
30 if (profiles.length > 1)
31 return clear("FAILED: wrong number of recorded profiles was found. profiles.length = " + profiles.length);
33 var profile = profiles[profiles.length - 1];
34 WebInspector.panels.profiles.showProfile(profile);
37 function snapshotReceived(profile)
39 InspectorTest.addResult("PASS: snapshot was received");
40 var snapshotProxy = profile._snapshotProxy;
41 snapshotProxy.callMethod(didGetBodyWrapperIds, "idsOfObjectsWithName", "HTMLBodyElement");
44 function didGetBodyWrapperIds(bodyWrapperIds)
46 if (bodyWrapperIds.length < 3)
47 return clear("FAILED: less than 3 HTMLBodyElement objects were detected");
49 InspectorTest.addResult("PASS: more than 2 HTMLBodyElements were found");
51 for (var i = 0; i < bodyWrapperIds.length; i++)
52 HeapProfilerAgent.getObjectByHeapObjectId("" + bodyWrapperIds[i], undefined, didGetObjectByHeapObjectId);
54 var resolvedObjectsCount = 0;
55 var remoteObjects = [];
56 function didGetObjectByHeapObjectId(error, object)
59 remoteObjects.push(WebInspector.RemoteObject.fromPayload(object));
61 if (++resolvedObjectsCount === bodyWrapperIds.length)
62 requestPropertiesOfResolvedObjects();
65 function requestPropertiesOfResolvedObjects()
67 if (!remoteObjects.length)
68 return clear("FAILED: no resolved objects were detected");
70 InspectorTest.addResult("PASS: got at least one HTMLBodyElement wrapper");
72 for (var i = 0; i < remoteObjects.length; i++)
73 remoteObjects[i].getOwnProperties(didGetOwnProperties);
76 var didGetOwnPropertiesCount = 0;
77 function didGetOwnProperties()
79 if (++didGetOwnPropertiesCount !== remoteObjects.length)
87 function clear(errorMessage)
90 InspectorTest.addResult(errorMessage);
92 WebInspector.panels.profiles._reset();
98 InspectorTest.addResult("PASS: profile was deleted");
99 InspectorTest.completeTest();
106 <body onload="handleLoad()">
108 Test that resolving heap snaphot object to a JS object will not crash on DOM wrapper boilerplate. Test passes if it doesn't crash.