Upstream version 7.36.149.0
[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.inspectorView.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() {});
21
22     function finishHeapSnapshot(uid)
23     {
24         InspectorTest.addResult("PASS: snapshot was taken");
25         var profiles = heapProfileType.getProfiles();
26
27         if (!profiles.length)
28             return clear("FAILED: no profiles found");
29
30         if (profiles.length > 1)
31             return clear("FAILED: wrong number of recorded profiles was found. profiles.length = " + profiles.length);
32
33         var profile = profiles[profiles.length - 1];
34         WebInspector.panels.profiles.showProfile(profile);
35     }
36
37     function snapshotReceived(profile)
38     {
39         InspectorTest.addResult("PASS: snapshot was received");
40         var snapshotProxy = profile._snapshotProxy;
41         snapshotProxy.callMethod(didGetBodyWrapperIds, "idsOfObjectsWithName", "HTMLBodyElement");
42     }
43
44     function didGetBodyWrapperIds(bodyWrapperIds)
45     {
46         if (bodyWrapperIds.length < 3)
47             return clear("FAILED: less than 3 HTMLBodyElement objects were detected");
48
49         InspectorTest.addResult("PASS: more than 2 HTMLBodyElements were found");
50
51         for (var i = 0; i < bodyWrapperIds.length; i++)
52             HeapProfilerAgent.getObjectByHeapObjectId("" + bodyWrapperIds[i], undefined, didGetObjectByHeapObjectId);
53
54         var resolvedObjectsCount = 0;
55         var remoteObjects = [];
56         function didGetObjectByHeapObjectId(error, object)
57         {
58             if (!error)
59                 remoteObjects.push(WebInspector.runtimeModel.createRemoteObject(object));
60
61             if (++resolvedObjectsCount  === bodyWrapperIds.length)
62                 requestPropertiesOfResolvedObjects();
63         }
64
65         function requestPropertiesOfResolvedObjects()
66         {
67             if (!remoteObjects.length)
68                 return clear("FAILED: no resolved objects were detected");
69
70             InspectorTest.addResult("PASS: got at least one HTMLBodyElement wrapper");
71
72             for (var i = 0; i < remoteObjects.length; i++)
73                 remoteObjects[i].getOwnProperties(didGetOwnProperties);
74         }
75
76         var didGetOwnPropertiesCount = 0;
77         function didGetOwnProperties()
78         {
79             if (++didGetOwnPropertiesCount !== remoteObjects.length)
80                 return;
81
82             clear();
83         }
84
85     }
86
87     function clear(errorMessage)
88     {
89         if (errorMessage)
90             InspectorTest.addResult(errorMessage);
91         setTimeout(done, 0);
92         WebInspector.panels.profiles._reset();
93         return !errorMessage;
94     }
95
96     function done()
97     {
98         InspectorTest.addResult("PASS: profile was deleted");
99         InspectorTest.completeTest();
100     }
101 }
102
103 </script>
104 </head>
105
106 <body onload="handleLoad()">
107 <p>
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.
109 </p>
110
111 </body>
112 </html>