4895132a99090e7070a980f6d5fb85305e921fb4
[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/common/UIString.js");
8 InspectorTest.importScript("../../../../../Source/devtools/front_end/common/utilities.js");
9 InspectorTest.importScript("../../../../../Source/devtools/front_end/profiler/HeapSnapshotCommon.js");
10 InspectorTest.importScript("../../../../../Source/devtools/front_end/profiler/heap_snapshot_worker/HeapSnapshot.js");
11 InspectorTest.importScript("../../../../../Source/devtools/front_end/profiler/heap_snapshot_worker/JSHeapSnapshot.js");
12
13 InspectorTest.fail = function(message)
14 {
15     InspectorTest.log("FAIL: " + message);
16     InspectorTest.completeTest();
17 }
18
19 InspectorTest.assert = function(result, message)
20 {
21     if (!result)
22         InspectorTest.fail(message);
23 }
24
25 InspectorTest.takeHeapSnapshot = function(callback)
26 {
27     var chunks = [];
28     InspectorTest.eventHandler["HeapProfiler.addHeapSnapshotChunk"] = function(messageObject)
29     {
30         chunks.push(messageObject["params"]["chunk"]);
31     }
32
33     function didTakeHeapSnapshot(messageObject)
34     {
35         var serializedSnapshot = chunks.join("");
36         var parsed = JSON.parse(serializedSnapshot);
37         parsed.nodes = new Uint32Array(parsed.nodes);
38         parsed.edges = new Uint32Array(parsed.edges);
39         var snapshot = new WebInspector.JSHeapSnapshot(parsed, new WebInspector.HeapSnapshotProgress());
40         callback(snapshot);
41         InspectorTest.log("SUCCESS: didGetHeapSnapshot");
42         InspectorTest.completeTest();
43     }
44     InspectorTest.sendCommand("HeapProfiler.takeHeapSnapshot", {}, didTakeHeapSnapshot);
45 }