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