Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / inspector / profiler / heap-snapshot-test.js
index 791ccf0..d2b8a2b 100644 (file)
@@ -1,5 +1,7 @@
 var initialize_HeapSnapshotTest = function() {
 
+InspectorTest.preloadPanel("profiles");
+
 InspectorTest.createHeapSnapshotMockFactories = function() {
 
 InspectorTest.createJSHeapSnapshotMockObject = function()
@@ -29,23 +31,23 @@ InspectorTest.createJSHeapSnapshotMockObject = function()
         //       b\   v   /
         //         -> B (6) -bd- D (12)
         //
-        _nodes: [
+        nodes: new Uint32Array([
             0, 0, 2,    //  0: root
             1, 1, 2,    //  3: A
             1, 2, 2,    //  6: B
             1, 3, 1,    //  9: C
             1, 4, 0,    // 12: D
-            1, 5, 0]  // 15: E
-        _containmentEdges: [
+            1, 5, 0]),  // 15: E
+        containmentEdges: new Uint32Array([
             2,  6, 3,   //  0: shortcut 'a' to node 'A'
             1,  7, 6,   //  3: property 'b' to node 'B'
             0,  1, 6,   //  6: element '1' to node 'B'
             1,  8, 9,   //  9: property 'ac' to node 'C'
             1,  9, 9,   // 12: property 'bc' to node 'C'
             1, 10, 12,  // 15: property 'bd' to node 'D'
-            1, 11, 15]// 18: property 'ce' to node 'E'
-        _strings: ["", "A", "B", "C", "D", "E", "a", "b", "ac", "bc", "bd", "ce"],
-        _firstEdgeIndexes: [0, 6, 12, 18, 21, 21, 21],
+            1, 11, 15]),// 18: property 'ce' to node 'E'
+        strings: ["", "A", "B", "C", "D", "E", "a", "b", "ac", "bc", "bd", "ce"],
+        _firstEdgeIndexes: new Uint32Array([0, 6, 12, 18, 21, 21, 21]),
         createNode: WebInspector.JSHeapSnapshot.prototype.createNode,
         createEdge: WebInspector.JSHeapSnapshot.prototype.createEdge,
         createRetainingEdge: WebInspector.JSHeapSnapshot.prototype.createRetainingEdge
@@ -60,11 +62,11 @@ InspectorTest.createHeapSnapshotMockRaw = function()
     // A triple in parentheses indicates node index, self size and
     // retained size.
     //
-    //          --- A (14,2,2) --ac- C (40,4,10) -ce- E(57,6,6)
+    //          --- A (7,2,2) --ac- C (21,4,10) -ce- E(35,6,6)
     //         /    |                /
-    //  "" (1,0,20) 1       --bc-----
+    //  "" (0,0,20) 1       --bc-----
     //         \    v      /
-    //          --- B (27,3,8) --bd- D (50,5,5)
+    //          --- B (14,3,8) --bd- D (28,5,5)
     //
     return {
         snapshot: {
@@ -85,7 +87,7 @@ InspectorTest.createHeapSnapshotMockRaw = function()
             1, 5, 6, 6,  6, 21, 0], // E (35)
         edges: [
             // root node edges
-            2,  6,  7, // shortcut 'a' to node 'A'
+            1,  6,  7, // property 'a' to node 'A'
             1,  7, 14, // property 'b' to node 'B'
 
             // A node edges
@@ -186,7 +188,8 @@ InspectorTest.HeapNode.Type = {
     "closure": "closure",
     "regexp": "regexp",
     "number": "number",
-    "native": "native"
+    "native": "native",
+    "synthetic": "synthetic"
 };
 
 InspectorTest.HeapNode.prototype = {
@@ -258,7 +261,8 @@ InspectorTest.HeapEdge.Type = {
     "property": "property",
     "internal": "internal",
     "hidden": "hidden",
-    "shortcut": "shortcut"
+    "shortcut": "shortcut",
+    "weak": "weak"
 };
 
 InspectorTest.HeapSnapshotBuilder = function()
@@ -327,6 +331,12 @@ InspectorTest.HeapSnapshotBuilder.prototype = {
         return rawSnapshot;
     },
 
+    createJSHeapSnapshot: function()
+    {
+        var parsedSnapshot = InspectorTest._postprocessHeapSnapshotMock(this.generateSnapshot());
+        return new WebInspector.JSHeapSnapshot(parsedSnapshot, new WebInspector.HeapSnapshotProgress());
+    },
+
     _registerNode: function(node)
     {
         this._nodes.push(node);
@@ -378,7 +388,7 @@ InspectorTest.createHeapSnapshot = function(instanceCount, firstId)
     var builder = new InspectorTest.HeapSnapshotBuilder();
     var rootNode = builder.rootNode;
 
-    var gcRootsNode = new InspectorTest.HeapNode("(GC roots)");
+    var gcRootsNode = new InspectorTest.HeapNode("(GC roots)", 0, InspectorTest.HeapNode.Type.synthetic);
     rootNode.linkNode(gcRootsNode, InspectorTest.HeapEdge.Type.element);
 
     var windowNode = new InspectorTest.HeapNode("Window", 20);
@@ -404,7 +414,6 @@ InspectorTest.createHeapSnapshotMockFactories();
 
 InspectorTest.startProfilerTest = function(callback)
 {
-    WebInspector.showPanel("profiles");
     WebInspector.settings.showAdvancedHeapSnapshotProperties.set(true);
 
     InspectorTest.addResult("Profiler was enabled.");
@@ -418,7 +427,6 @@ InspectorTest.startProfilerTest = function(callback)
     WebInspector.HeapSnapshotContainmentDataGrid.prototype.defaultPopulateCount = function() { return 10; };
     WebInspector.HeapSnapshotConstructorsDataGrid.prototype.defaultPopulateCount = function() { return 10; };
     WebInspector.HeapSnapshotDiffDataGrid.prototype.defaultPopulateCount = function() { return 5; };
-    WebInspector.HeapSnapshotDominatorsDataGrid.prototype.defaultPopulateCount = function() { return 3; }
     InspectorTest.addResult("Detailed heap profiles were enabled.");
     InspectorTest.safeWrap(callback)();
 };
@@ -475,39 +483,28 @@ InspectorTest.checkArrayIsSorted = function(contents, sortType, sortOrder)
     }
     function parseSize(size)
     {
-        if (size.substr(0, 1) === '"') size = JSON.parse(size);
         // Remove thousands separator.
-        return parseInt(size.replace(/[\u2009,]/g, ""));
-    }
-    function extractField(data, field)
-    {
-        if (data.substr(0, 1) !== "{") return data;
-        data = JSON.parse(data);
-        if (!data[field])
-            InspectorTest.addResult("No " + field + " field in " + JSON.stringify(data));
-        return data[field];
-    }
-    function extractId(data)
-    {
-        return parseInt(extractField(data, "nodeId"));
+        return parseInt(size.replace(/[\u2009,]/g, ""), 10);
     }
     var extractor = {
-        text: function (data) { return extractField(data, "value"); },
+        text: function (data) { data; },
         number: function (data) { return parseInt(data, 10); },
-        size: function (data) { return parseSize(data); },
-        name: function (data) { return extractField(data, "name"); },
-        id: function (data) { return extractId(data); }
+        size: parseSize,
+        name: function (data) { return data; },
+        id: function (data) { return parseInt(data, 10); }
     }[sortType];
-    var acceptableComparisonResult = {
-        ascending: -1,
-        descending: 1
-    }[sortOrder];
 
     if (!extractor) {
         InspectorTest.addResult("Invalid sort type: " + sortType);
         return;
     }
-    if (!acceptableComparisonResult) {
+
+    var acceptableComparisonResult;
+    if (sortOrder === WebInspector.DataGrid.Order.Ascending) {
+        acceptableComparisonResult = -1;
+    } else if (sortOrder === WebInspector.DataGrid.Order.Descending) {
+        acceptableComparisonResult = 1;
+    } else {
         InspectorTest.addResult("Invalid sort order: " + sortOrder);
         return;
     }
@@ -516,8 +513,9 @@ InspectorTest.checkArrayIsSorted = function(contents, sortType, sortOrder)
         var a = extractor(contents[i]);
         var b = extractor(contents[i + 1]);
         var result = simpleComparator(a, b);
-        if (result !== 0 && result !== acceptableComparisonResult)
+        if (result !== 0 && result !== acceptableComparisonResult) {
             InspectorTest.addResult("Elements " + i + " and " + (i + 1) + " are out of order: " + a + " " + b + " (" + sortOrder + ")");
+        }
     }
 };
 
@@ -529,7 +527,7 @@ InspectorTest.clickColumn = function(column, callback)
 
     function sortingComplete()
     {
-        InspectorTest._currentGrid().removeEventListener("sorting complete", sortingComplete, this);
+        InspectorTest._currentGrid().removeEventListener(WebInspector.HeapSnapshotSortableDataGrid.Events.SortingComplete, sortingComplete, this);
         InspectorTest.assertEquals(column.identifier, this._currentGrid().sortColumnIdentifier(), "unexpected sorting");
         column.sort = this._currentGrid().sortOrder();
         function callCallback()
@@ -538,7 +536,7 @@ InspectorTest.clickColumn = function(column, callback)
         }
         setTimeout(callCallback, 0);
     }
-    InspectorTest._currentGrid().addEventListener("sorting complete", sortingComplete, this);
+    InspectorTest._currentGrid().addEventListener(WebInspector.HeapSnapshotSortableDataGrid.Events.SortingComplete, sortingComplete, this);
     this._currentGrid()._clickInHeaderCell(event);
 };
 
@@ -552,7 +550,7 @@ InspectorTest.clickRowAndGetRetainers = function(row, callback)
         }
     };
     this._currentGrid()._mouseDownInDataTable(event);
-    var rootNode = InspectorTest.currentProfileView().retainmentDataGrid.rootNode();
+    var rootNode = InspectorTest.currentProfileView()._retainmentDataGrid.rootNode();
     function populateComplete()
     {
         rootNode.removeEventListener(WebInspector.HeapSnapshotGridNode.Events.PopulateComplete, populateComplete, this);
@@ -582,15 +580,17 @@ InspectorTest.columnContents = function(column, row)
 {
     // Make sure invisible nodes are removed from the view port.
     this._currentGrid().updateVisibleNodes();
+    var columnOrdinal = InspectorTest.viewColumns().indexOf(column);
     var result = [];
     var parent = row || this._currentGrid().rootNode();
     for (var node = parent.children[0]; node; node = node.traverseNextNode(true, parent, true)) {
         if (!node.selectable)
             continue;
-        var data = node.data[column.identifier];
-        if (typeof data === "object")
-            data = JSON.stringify(data);
-        result.push(data);
+        var content = node.element().children[columnOrdinal];
+        // Do not inlcude percents
+        if (content.firstElementChild)
+            content = content.firstElementChild;
+        result.push(content.textContent);
     }
     return result;
 };
@@ -641,11 +641,7 @@ InspectorTest.findAndExpandWindow = function(callback)
 InspectorTest.findAndExpandRow = function(name, callback)
 {
     callback = InspectorTest.safeWrap(callback);
-    function propertyMatcher(data)
-    {
-        return data.value === name;
-    }
-    var row = InspectorTest.findRow("object", propertyMatcher);
+    var row = InspectorTest.findRow(name);
     InspectorTest.assertEquals(true, !!row, '"' + name + '" row');
     InspectorTest.expandRow(row, callback);
 };
@@ -660,25 +656,20 @@ InspectorTest.findButtonsNode = function(row, startNode)
     return null;
 };
 
-InspectorTest.findRow = function(columnIdentifier, matcher, parent)
+InspectorTest.findRow = function(name, parent)
 {
-    parent = parent || this._currentGrid().rootNode();
-    if (typeof matcher !== "function") {
-        var value = matcher;
-        matcher = function(x) { return x === value; };
-    }
-    for (var node = parent.children[0]; node; node = node.traverseNextNode(true, parent, true)) {
-        if (matcher(node.data[columnIdentifier]))
-            return node;
-    }
-    return null;
+    function matcher(x)
+    {
+        return x._name === name;
+    };
+    return InspectorTest.findMatchingRow(matcher, parent);
 };
 
-InspectorTest.findRow2 = function(matcher, parent)
+InspectorTest.findMatchingRow = function(matcher, parent)
 {
     parent = parent || this._currentGrid().rootNode();
     for (var node = parent.children[0]; node; node = node.traverseNextNode(true, parent, true)) {
-        if (matcher(node.data))
+        if (matcher(node))
             return node;
     }
     return null;
@@ -688,7 +679,9 @@ InspectorTest.switchToView = function(title, callback)
 {
     callback = InspectorTest.safeWrap(callback);
     var view = WebInspector.panels.profiles.visibleView;
-    view.changeView(title, callback);
+    view._changePerspectiveAndWait(title, callback);
+    // Increase the grid container height so the viewport don't limit the number of nodes.
+    InspectorTest._currentGrid().scrollContainer.style.height = "10000px";
 };
 
 InspectorTest.takeAndOpenSnapshot = function(generator, callback)
@@ -696,16 +689,16 @@ InspectorTest.takeAndOpenSnapshot = function(generator, callback)
     callback = InspectorTest.safeWrap(callback);
     var snapshot = generator();
     var profileType =  WebInspector.ProfileTypeRegistry.instance.heapSnapshotProfileType;
-    function pushGeneratedSnapshot(reportProgress, callback)
+    function pushGeneratedSnapshot(reportProgress, callback2)
     {
         var profile = profileType.profileBeingRecorded();
         if (reportProgress) {
-            profileType.reportHeapSnapshotProgress(50, 100, false);
-            profileType.reportHeapSnapshotProgress(100, 100, true);
+            profileType._reportHeapSnapshotProgress({data: {done: 50, total: 100, finished: false}});
+            profileType._reportHeapSnapshotProgress({data: {done: 100, total: 100, finished: true}});
         }
         snapshot.snapshot.typeId = "HEAP";
-        profileType.addHeapSnapshotChunk(JSON.stringify(snapshot));
-        setTimeout(callback, 0);
+        profileType._addHeapSnapshotChunk({data: JSON.stringify(snapshot)});
+        setTimeout(callback2, 0);
     }
     InspectorTest.override(HeapProfilerAgent, "takeHeapSnapshot", pushGeneratedSnapshot);
     InspectorTest._takeAndOpenSnapshotCallback = callback;
@@ -724,7 +717,7 @@ InspectorTest.currentProfileView = function()
 
 InspectorTest._currentGrid = function()
 {
-    return this.currentProfileView().dataGrid;
+    return this.currentProfileView()._dataGrid;
 };
 
 InspectorTest._snapshotViewShown = function()
@@ -732,13 +725,13 @@ InspectorTest._snapshotViewShown = function()
     if (InspectorTest._takeAndOpenSnapshotCallback) {
         var callback = InspectorTest._takeAndOpenSnapshotCallback;
         InspectorTest._takeAndOpenSnapshotCallback = null;
-        var dataGrid = this.dataGrid;
+        var dataGrid = this._dataGrid;
         function sortingComplete()
         {
-            dataGrid.removeEventListener("sorting complete", sortingComplete, null);
+            dataGrid.removeEventListener(WebInspector.HeapSnapshotSortableDataGrid.Events.SortingComplete, sortingComplete, null);
             callback();
         }
-        dataGrid.addEventListener("sorting complete", sortingComplete, null);
+        dataGrid.addEventListener(WebInspector.HeapSnapshotSortableDataGrid.Events.SortingComplete, sortingComplete, null);
     }
 };