- add third_party src.
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / inspector / profiler / heap-snapshot-inspect-dom-wrapper.html
1 <html>
2 <head>
3 <script src="../../http/tests/inspector/inspector-test.js"></script>
4 <script src="heap-snapshot-test.js"></script>
5 <script>
6
7 function handleLoad()
8 {
9     // Make sure there is a body wrapper.
10     document.body.fieldOnDomWrapper = 2012;
11     runTest();
12 }
13
14 function test()
15 {
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() {});
22
23     function finishHeapSnapshot(uid)
24     {
25         InspectorTest.addResult("PASS: snapshot was taken");
26         var profiles = heapProfileType.getProfiles();
27
28         if (!profiles.length)
29             return clear("FAILED: no profiles found");
30
31         if (profiles.length > 1)
32             return clear("FAILED: wrong number of recorded profiles was found. profiles.length = " + profiles.length);
33
34         var profile = profiles[profiles.length - 1];
35         WebInspector.panels.profiles._showProfile(profile);
36     }
37
38     function snapshotReceived(profile)
39     {
40         InspectorTest.addResult("PASS: snapshot was received");
41         var snapshotProxy = profile._snapshotProxy;
42         var snapshot = snapshotProxy._worker._worker._dispatcher._objects[snapshotProxy._objectId];
43
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());
48         }
49
50         if (bodyWrapperIds.length < 3)
51             return clear("FAILED: less than 3 HTMLBodyElement objects were detected");
52
53         InspectorTest.addResult("PASS: more than 2 HTMLBodyElements were found");
54
55         for (var i = 0; i < bodyWrapperIds.length; i++)
56             HeapProfilerAgent.getObjectByHeapObjectId("" + bodyWrapperIds[i], undefined, didGetObjectByHeapObjectId);
57
58         var resolvedObjectsCount = 0;
59         var remoteObjects = [];
60         function didGetObjectByHeapObjectId(error, object)
61         {
62             if (!error)
63                 remoteObjects.push(WebInspector.RemoteObject.fromPayload(object));
64
65             if (++resolvedObjectsCount  === bodyWrapperIds.length)
66                 requestPropertiesOfResolvedObjects();
67         }
68
69         function requestPropertiesOfResolvedObjects()
70         {
71             if (!remoteObjects.length)
72                 return clear("FAILED: no resolved objects were detected");
73
74             InspectorTest.addResult("PASS: got at least one HTMLBodyElement wrapper");
75
76             for (var i = 0; i < remoteObjects.length; i++)
77                 remoteObjects[i].getOwnProperties(didGetOwnProperties);
78         }
79
80         var didGetOwnPropertiesCount = 0;
81         function didGetOwnProperties()
82         {
83             if (++didGetOwnPropertiesCount !== remoteObjects.length)
84                 return;
85
86             clear();
87         }
88
89     }
90
91     function clear(errorMessage)
92     {
93         if (errorMessage)
94             InspectorTest.addResult(errorMessage);
95         HeapProfilerAgent.clearProfiles(done);
96         WebInspector.panels.profiles._reset();
97         return !errorMessage;
98     }
99
100     function done()
101     {
102         InspectorTest.addResult("PASS: profile was deleted");
103         InspectorTest.completeTest();
104     }
105 }
106
107 </script>
108 </head>
109
110 <body onload="handleLoad()">
111 <p>
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.
113 </p>
114
115 </body>
116 </html>