- add third_party src.
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / inspector-protocol / heap-profiler / resources / heap-snapshot-common.js
1 // This script is supposed to be evaluated in dummy inspector front-end which is loaded from
2 // ../../../http/tests/inspector-protocol/resources/protocol-test.html and the relative paths
3 // below are relative to that location.
4
5 if (!window.WebInspector)
6     window.WebInspector = {};
7 InspectorTest.importScript("../../../../../Source/devtools/front_end/HeapSnapshot.js");
8 InspectorTest.importScript("../../../../../Source/devtools/front_end/JSHeapSnapshot.js");
9 InspectorTest.importScript("../../../../../Source/devtools/front_end/UIString.js");
10 InspectorTest.importScript("../../../../../Source/devtools/front_end/utilities.js");
11
12 InspectorTest.fail = function(message)
13 {
14     InspectorTest.log("FAIL: " + message);
15     InspectorTest.completeTest();
16 }
17
18 InspectorTest.assert = function(result, message)
19 {
20     if (!result)
21         InspectorTest.fail(message);
22 }
23
24 InspectorTest.takeHeapSnapshot = function(callback)
25 {
26     InspectorTest.eventHandler["HeapProfiler.addProfileHeader"] = function(messageObject)
27     {
28         var profileId = messageObject["params"]["header"]["uid"];
29         InspectorTest.sendCommand("HeapProfiler.getHeapSnapshot", { "uid": profileId }, didGetHeapSnapshot);
30
31         var chunks = [];
32         InspectorTest.eventHandler["HeapProfiler.addHeapSnapshotChunk"] = function(messageObject)
33         {
34             chunks.push(messageObject["params"]["chunk"]);
35         }
36
37         function didGetHeapSnapshot(messageObject)
38         {
39             var serializedSnapshot = chunks.join("");
40             var parsed = JSON.parse(serializedSnapshot);
41             var snapshot = new WebInspector.JSHeapSnapshot(parsed, new WebInspector.HeapSnapshotProgress());
42             callback(snapshot);
43             InspectorTest.log("SUCCESS: didGetHeapSnapshot");
44             InspectorTest.sendCommand("HeapProfiler.removeProfile", { "uid": profileId }, didRemoveSnapshot);
45         }
46
47         function didRemoveSnapshot(messageObject)
48         {
49             InspectorTest.completeTest();
50         }
51     }
52
53     InspectorTest.sendCommand("HeapProfiler.takeHeapSnapshot", {});
54 }