Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / inspector / profiler / heap-snapshot-test.js
1 var initialize_HeapSnapshotTest = function() {
2
3 InspectorTest.createHeapSnapshotMockFactories = function() {
4
5 InspectorTest.createJSHeapSnapshotMockObject = function()
6 {
7     return {
8         _rootNodeIndex: 0,
9         _nodeTypeOffset: 0,
10         _nodeNameOffset: 1,
11         _nodeEdgeCountOffset: 2,
12         _nodeFieldCount: 3,
13         _edgeFieldsCount: 3,
14         _edgeTypeOffset: 0,
15         _edgeNameOffset: 1,
16         _edgeToNodeOffset: 2,
17         _nodeTypes: ["hidden", "object"],
18         _edgeTypes: ["element", "property", "shortcut"],
19         _edgeShortcutType: -1,
20         _edgeHiddenType: -1,
21         _edgeElementType: 0,
22         _realNodesLength: 18,
23         // Represents the following graph:
24         //   (numbers in parentheses indicate node offset)
25         //
26         //         -> A (3) --ac- C (9) -ce- E(15)
27         //       a/   |          /
28         //  "" (0)    1    - bc -
29         //       b\   v   /
30         //         -> B (6) -bd- D (12)
31         //
32         _nodes: [
33             0, 0, 2,    //  0: root
34             1, 1, 2,    //  3: A
35             1, 2, 2,    //  6: B
36             1, 3, 1,    //  9: C
37             1, 4, 0,    // 12: D
38             1, 5, 0],   // 15: E
39         _containmentEdges: [
40             2,  6, 3,   //  0: shortcut 'a' to node 'A'
41             1,  7, 6,   //  3: property 'b' to node 'B'
42             0,  1, 6,   //  6: element '1' to node 'B'
43             1,  8, 9,   //  9: property 'ac' to node 'C'
44             1,  9, 9,   // 12: property 'bc' to node 'C'
45             1, 10, 12,  // 15: property 'bd' to node 'D'
46             1, 11, 15], // 18: property 'ce' to node 'E'
47         _strings: ["", "A", "B", "C", "D", "E", "a", "b", "ac", "bc", "bd", "ce"],
48         _firstEdgeIndexes: [0, 6, 12, 18, 21, 21, 21],
49         createNode: WebInspector.JSHeapSnapshot.prototype.createNode,
50         createEdge: WebInspector.JSHeapSnapshot.prototype.createEdge,
51         createRetainingEdge: WebInspector.JSHeapSnapshot.prototype.createRetainingEdge
52     };
53 };
54
55 InspectorTest.createHeapSnapshotMockRaw = function()
56 {
57     // Effectively the same graph as in createJSHeapSnapshotMockObject,
58     // but having full set of fields.
59     //
60     // A triple in parentheses indicates node index, self size and
61     // retained size.
62     //
63     //          --- A (14,2,2) --ac- C (40,4,10) -ce- E(57,6,6)
64     //         /    |                /
65     //  "" (1,0,20) 1       --bc-----
66     //         \    v      /
67     //          --- B (27,3,8) --bd- D (50,5,5)
68     //
69     return {
70         snapshot: {
71             meta: {
72                 node_fields: ["type", "name", "id", "self_size", "retained_size", "dominator", "edge_count"],
73                 node_types: [["hidden", "object"], "", "", "", "", "", ""],
74                 edge_fields: ["type", "name_or_index", "to_node"],
75                 edge_types: [["element", "property", "shortcut"], "", ""]
76             },
77             node_count: 6,
78             edge_count: 7},
79         nodes: [
80             0, 0, 1, 0, 20,  0, 2,  // root (0)
81             1, 1, 2, 2,  2,  0, 2,  // A (7)
82             1, 2, 3, 3,  8,  0, 2,  // B (14)
83             1, 3, 4, 4, 10,  0, 1,  // C (21)
84             1, 4, 5, 5,  5, 14, 0,  // D (28)
85             1, 5, 6, 6,  6, 21, 0], // E (35)
86         edges: [
87             // root node edges
88             2,  6,  7, // shortcut 'a' to node 'A'
89             1,  7, 14, // property 'b' to node 'B'
90
91             // A node edges
92             0,  1, 14, // element 1 to node 'B'
93             1,  8, 21, // property 'ac' to node 'C'
94
95             // B node edges
96             1,  9, 21, // property 'bc' to node 'C'
97             1, 10, 28, // property 'bd' to node 'D'
98
99             // C node edges
100             1, 11, 35], // property 'ce' to node 'E'
101         strings: ["", "A", "B", "C", "D", "E", "a", "b", "ac", "bc", "bd", "ce"]
102     };
103 };
104
105 InspectorTest._postprocessHeapSnapshotMock = function(mock)
106 {
107     mock.nodes = new Uint32Array(mock.nodes);
108     mock.edges = new Uint32Array(mock.edges);
109     return mock;
110 };
111
112 InspectorTest.createHeapSnapshotMock = function()
113 {
114     return InspectorTest._postprocessHeapSnapshotMock(InspectorTest.createHeapSnapshotMockRaw());
115 };
116
117 InspectorTest.createHeapSnapshotMockWithDOM = function()
118 {
119     return InspectorTest._postprocessHeapSnapshotMock({
120         snapshot: {
121             meta: {
122                 node_fields: ["type", "name", "id", "edge_count"],
123                 node_types: [["hidden", "object", "synthetic"], "", "", ""],
124                 edge_fields: ["type", "name_or_index", "to_node"],
125                 edge_types: [["element", "hidden", "internal"], "", ""]
126             },
127             node_count: 13,
128             edge_count: 13
129         },
130         nodes: [
131             // A tree with Window objects.
132             //
133             //    |----->Window--->A
134             //    |             \
135             //    |----->Window--->B--->C
136             //    |        |     \
137             //  (root)   hidden   --->D--internal / "native"-->N
138             //    |          \        |
139             //    |----->E    H    internal
140             //    |                   v
141             //    |----->F--->G       M
142             //
143             /* (root) */    2,  0,  1, 4,
144             /* Window */    1, 11,  2, 2,
145             /* Window */    1, 11,  3, 3,
146             /* E */         2,  5,  4, 0,
147             /* F */         2,  6,  5, 1,
148             /* A */         1,  1,  6, 0,
149             /* B */         1,  2,  7, 1,
150             /* D */         1,  4,  8, 2,
151             /* H */         1,  8,  9, 0,
152             /* G */         1,  7, 10, 0,
153             /* C */         1,  3, 11, 0,
154             /* N */         1, 10, 12, 0,
155             /* M */         1,  9, 13, 0
156             ],
157         edges: [
158             /* from (root) */  0,  1,  4, 0, 2,  8, 0, 3, 12, 0, 4, 16,
159             /* from Window */  0,  1, 20, 0, 2, 24,
160             /* from Window */  0,  1, 24, 0, 2, 28, 1, 3, 32,
161             /* from F */       0,  1, 36,
162             /* from B */       0,  1, 40,
163             /* from D */       2, 12, 44, 2, 1, 48
164             ],
165         strings: ["", "A", "B", "C", "D", "E", "F", "G", "H", "M", "N", "Window", "native"]
166     });
167 };
168
169 InspectorTest.HeapNode = function(name, selfSize, type, id)
170 {
171     this._type = type || InspectorTest.HeapNode.Type.object;
172     this._name = name;
173     this._selfSize = selfSize || 0;
174     this._builder = null;
175     this._edges = {};
176     this._edgesCount = 0;
177     this._id = id;
178 }
179
180 InspectorTest.HeapNode.Type = {
181     "hidden": "hidden",
182     "array": "array",
183     "string": "string",
184     "object": "object",
185     "code": "code",
186     "closure": "closure",
187     "regexp": "regexp",
188     "number": "number",
189     "native": "native"
190 };
191
192 InspectorTest.HeapNode.prototype = {
193     linkNode: function(node, type, nameOrIndex)
194     {
195         if (!this._builder)
196             throw new Error("parent node is not connected to a snapshot");
197
198         if (!node._builder)
199             node._setBuilder(this._builder);
200
201         if (nameOrIndex === undefined)
202             nameOrIndex = this._edgesCount;
203         ++this._edgesCount;
204
205         if (nameOrIndex in this._edges)
206             throw new Error("Can't add edge with the same nameOrIndex. nameOrIndex: " + nameOrIndex + " oldNodeName: " + this._edges[nameOrIndex]._name + " newNodeName: " + node._name);
207         this._edges[nameOrIndex] = new InspectorTest.HeapEdge(node, type, nameOrIndex);
208     },
209
210     _setBuilder: function(builder)
211     {
212         if (this._builder)
213             throw new Error("node reusing is prohibited");
214
215         this._builder = builder;
216         this._ordinal = this._builder._registerNode(this);
217     },
218
219     _serialize: function(rawSnapshot)
220     {
221         rawSnapshot.nodes.push(this._builder.lookupNodeType(this._type));
222         rawSnapshot.nodes.push(this._builder.lookupOrAddString(this._name));
223         // JS engine snapshot impementation generates monotonicaly increasing odd id for JS objects,
224         // and even ids based on a hash for native DOMObject groups.
225         rawSnapshot.nodes.push(this._id || this._ordinal * 2 + 1);
226         rawSnapshot.nodes.push(this._selfSize);
227         rawSnapshot.nodes.push(0);                               // retained_size
228         rawSnapshot.nodes.push(0);                               // dominator
229         rawSnapshot.nodes.push(Object.keys(this._edges).length); // edge_count
230
231         for (var i in this._edges)
232             this._edges[i]._serialize(rawSnapshot);
233     }
234 }
235
236 InspectorTest.HeapEdge = function(targetNode, type, nameOrIndex)
237 {
238     this._targetNode = targetNode;
239     this._type = type;
240     this._nameOrIndex = nameOrIndex;
241 }
242
243 InspectorTest.HeapEdge.prototype = {
244     _serialize: function(rawSnapshot)
245     {
246         if (!this._targetNode._builder)
247             throw new Error("Inconsistent state of node: " + this._name + " no builder assigned");
248         var builder = this._targetNode._builder;
249         rawSnapshot.edges.push(builder.lookupEdgeType(this._type));
250         rawSnapshot.edges.push(typeof this._nameOrIndex === "string" ? builder.lookupOrAddString(this._nameOrIndex) : this._nameOrIndex);
251         rawSnapshot.edges.push(this._targetNode._ordinal * builder.nodeFieldsCount); // index
252     }
253 }
254
255 InspectorTest.HeapEdge.Type = {
256     "context": "context",
257     "element": "element",
258     "property": "property",
259     "internal": "internal",
260     "hidden": "hidden",
261     "shortcut": "shortcut"
262 };
263
264 InspectorTest.HeapSnapshotBuilder = function()
265 {
266     this._nodes = [];
267     this._string2id = {};
268     this._strings = [];
269     this.nodeFieldsCount = 7;
270
271     this._nodeTypesMap = {};
272     this._nodeTypesArray = [];
273     for (var nodeType in InspectorTest.HeapNode.Type) {
274         this._nodeTypesMap[nodeType] = this._nodeTypesArray.length
275         this._nodeTypesArray.push(nodeType);
276     }
277
278     this._edgeTypesMap = {};
279     this._edgeTypesArray = [];
280     for (var edgeType in InspectorTest.HeapEdge.Type) {
281         this._edgeTypesMap[edgeType] = this._edgeTypesArray.length
282         this._edgeTypesArray.push(edgeType);
283     }
284
285     this.rootNode = new InspectorTest.HeapNode("root", 0, "object");
286     this.rootNode._setBuilder(this);
287 }
288
289 InspectorTest.HeapSnapshotBuilder.prototype = {
290     generateSnapshot: function()
291     {
292         var rawSnapshot = {
293             "snapshot": {
294                 "meta": {
295                     "node_fields": ["type","name","id","self_size","retained_size","dominator","edge_count"],
296                     "node_types": [
297                         this._nodeTypesArray,
298                         "string",
299                         "number",
300                         "number",
301                         "number",
302                         "number",
303                         "number"
304                     ],
305                     "edge_fields": ["type","name_or_index","to_node"],
306                     "edge_types": [
307                         this._edgeTypesArray,
308                         "string_or_number",
309                         "node"
310                     ]
311                 }
312             },
313             "nodes": [],
314             "edges":[],
315             "strings": []
316         };
317
318         for (var i = 0; i < this._nodes.length; ++i)
319             this._nodes[i]._serialize(rawSnapshot);
320
321         rawSnapshot.strings = this._strings.slice();
322
323         var meta = rawSnapshot.snapshot.meta;
324         rawSnapshot.snapshot.edge_count = rawSnapshot.edges.length / meta.edge_fields.length;
325         rawSnapshot.snapshot.node_count = rawSnapshot.nodes.length / meta.node_fields.length;
326
327         return rawSnapshot;
328     },
329
330     _registerNode: function(node)
331     {
332         this._nodes.push(node);
333         return this._nodes.length - 1;
334     },
335
336     lookupNodeType: function(typeName)
337     {
338         if (typeName === undefined)
339             throw new Error("wrong node type: " + typeName);
340         if (!typeName in this._nodeTypesMap)
341             throw new Error("wrong node type name: " + typeName);
342         return this._nodeTypesMap[typeName];
343     },
344
345     lookupEdgeType: function(typeName)
346     {
347         if (!typeName in this._edgeTypesMap)
348             throw new Error("wrong edge type name: " + typeName);
349         return this._edgeTypesMap[typeName];
350     },
351
352     lookupOrAddString: function(string)
353     {
354         if (string in this._string2id)
355             return this._string2id[string];
356         this._string2id[string] = this._strings.length;
357         this._strings.push(string);
358         return this._strings.length - 1;
359     }
360 }
361
362 InspectorTest.createHeapSnapshot = function(instanceCount, firstId)
363 {
364     // Mocking results of running the following code:
365     //
366     // function A() { this.a = this; }
367     // function B() { this.a = new A(); }
368     // for (var i = 0; i < instanceCount; ++i) window[i] = new B();
369     //
370     // Set A and B object sizes to pseudo random numbers. It is used in sorting tests.
371
372     var seed = 881669;
373     function pseudoRandom(limit) {
374         seed = ((seed * 355109 + 153763) >> 2) & 0xffff;
375         return seed % limit;
376     }
377
378     var builder = new InspectorTest.HeapSnapshotBuilder();
379     var rootNode = builder.rootNode;
380
381     var gcRootsNode = new InspectorTest.HeapNode("(GC roots)");
382     rootNode.linkNode(gcRootsNode, InspectorTest.HeapEdge.Type.element);
383
384     var windowNode = new InspectorTest.HeapNode("Window", 20);
385     rootNode.linkNode(windowNode, InspectorTest.HeapEdge.Type.shortcut);
386     gcRootsNode.linkNode(windowNode, InspectorTest.HeapEdge.Type.element);
387
388     for (var i = 0; i < instanceCount; ++i) {
389         var sizeOfB = pseudoRandom(20) + 1;
390         var nodeB = new InspectorTest.HeapNode("B", sizeOfB, undefined, firstId++);
391         windowNode.linkNode(nodeB, InspectorTest.HeapEdge.Type.element);
392         var sizeOfA = pseudoRandom(50) + 1;
393         var nodeA = new InspectorTest.HeapNode("A", sizeOfA, undefined, firstId++);
394         nodeB.linkNode(nodeA, InspectorTest.HeapEdge.Type.property, "a");
395         nodeA.linkNode(nodeA, InspectorTest.HeapEdge.Type.property, "a");
396     }
397     return builder.generateSnapshot();
398 }
399
400 }
401
402 InspectorTest.createHeapSnapshotMockFactories();
403
404
405 InspectorTest.startProfilerTest = function(callback)
406 {
407     WebInspector.showPanel("profiles");
408     WebInspector.settings.showAdvancedHeapSnapshotProperties.set(true);
409
410     InspectorTest.addResult("Profiler was enabled.");
411     // We mock out HeapProfilerAgent -- as DRT runs in single-process mode, Inspector
412     // and test share the same heap. Taking a snapshot takes too long for a test,
413     // so we provide synthetic snapshots.
414     InspectorTest._panelReset = InspectorTest.override(WebInspector.panels.profiles, "_reset", function(){}, true);
415     InspectorTest.addSniffer(WebInspector.HeapSnapshotView.prototype, "show", InspectorTest._snapshotViewShown, true);
416
417     // Reduce the number of populated nodes to speed up testing.
418     WebInspector.HeapSnapshotContainmentDataGrid.prototype.defaultPopulateCount = function() { return 10; };
419     WebInspector.HeapSnapshotConstructorsDataGrid.prototype.defaultPopulateCount = function() { return 10; };
420     WebInspector.HeapSnapshotDiffDataGrid.prototype.defaultPopulateCount = function() { return 5; };
421     WebInspector.HeapSnapshotDominatorsDataGrid.prototype.defaultPopulateCount = function() { return 3; }
422     InspectorTest.addResult("Detailed heap profiles were enabled.");
423     InspectorTest.safeWrap(callback)();
424 };
425
426 InspectorTest.completeProfilerTest = function()
427 {
428     // There is no way to disable detailed heap profiles.
429     InspectorTest.addResult("");
430     InspectorTest.addResult("Profiler was disabled.");
431     InspectorTest.completeTest();
432 };
433
434 InspectorTest.runHeapSnapshotTestSuite = function(testSuite)
435 {
436     var testSuiteTests = testSuite.slice();
437     var completeTestStack;
438
439     function runner()
440     {
441         if (!testSuiteTests.length) {
442             if (completeTestStack)
443                 InspectorTest.addResult("FAIL: test already completed at " + completeTestStack);
444             InspectorTest.completeProfilerTest();
445             completeTestStack = new Error().stack;
446             return;
447         }
448
449         var nextTest = testSuiteTests.shift();
450         InspectorTest.addResult("");
451         InspectorTest.addResult("Running: " + /function\s([^(]*)/.exec(nextTest)[1]);
452         InspectorTest._panelReset.call(WebInspector.panels.profiles);
453         InspectorTest.safeWrap(nextTest)(runner, runner);
454     }
455
456     InspectorTest.startProfilerTest(runner);
457 };
458
459 InspectorTest.assertColumnContentsEqual = function(reference, actual)
460 {
461     var length = Math.min(reference.length, actual.length);
462     for (var i = 0; i < length; ++i)
463         InspectorTest.assertEquals(reference[i], actual[i], "row " + i);
464     if (reference.length > length)
465         InspectorTest.addResult("extra rows in reference array:\n" + reference.slice(length).join("\n"));
466     else if (actual.length > length)
467         InspectorTest.addResult("extra rows in actual array:\n" + actual.slice(length).join("\n"));
468 };
469
470 InspectorTest.checkArrayIsSorted = function(contents, sortType, sortOrder)
471 {
472     function simpleComparator(a, b)
473     {
474         return a < b ? -1 : (a > b ? 1 : 0);
475     }
476     function parseSize(size)
477     {
478         if (size.substr(0, 1) === '"') size = JSON.parse(size);
479         // Remove thousands separator.
480         return parseInt(size.replace(/[\u2009,]/g, ""));
481     }
482     function extractField(data, field)
483     {
484         if (data.substr(0, 1) !== "{") return data;
485         data = JSON.parse(data);
486         if (!data[field])
487             InspectorTest.addResult("No " + field + " field in " + JSON.stringify(data));
488         return data[field];
489     }
490     function extractId(data)
491     {
492         return parseInt(extractField(data, "nodeId"));
493     }
494     var extractor = {
495         text: function (data) { return extractField(data, "value"); },
496         number: function (data) { return parseInt(data, 10); },
497         size: function (data) { return parseSize(data); },
498         name: function (data) { return extractField(data, "name"); },
499         id: function (data) { return extractId(data); }
500     }[sortType];
501     var acceptableComparisonResult = {
502         ascending: -1,
503         descending: 1
504     }[sortOrder];
505
506     if (!extractor) {
507         InspectorTest.addResult("Invalid sort type: " + sortType);
508         return;
509     }
510     if (!acceptableComparisonResult) {
511         InspectorTest.addResult("Invalid sort order: " + sortOrder);
512         return;
513     }
514
515     for (var i = 0; i < contents.length - 1; ++i) {
516         var a = extractor(contents[i]);
517         var b = extractor(contents[i + 1]);
518         var result = simpleComparator(a, b);
519         if (result !== 0 && result !== acceptableComparisonResult)
520             InspectorTest.addResult("Elements " + i + " and " + (i + 1) + " are out of order: " + a + " " + b + " (" + sortOrder + ")");
521     }
522 };
523
524 InspectorTest.clickColumn = function(column, callback)
525 {
526     callback = InspectorTest.safeWrap(callback);
527     var cell = this._currentGrid()._headerTableHeaders[column.identifier];
528     var event = { target: { enclosingNodeOrSelfWithNodeName: function() { return cell; } } };
529
530     function sortingComplete()
531     {
532         InspectorTest._currentGrid().removeEventListener("sorting complete", sortingComplete, this);
533         InspectorTest.assertEquals(column.identifier, this._currentGrid().sortColumnIdentifier(), "unexpected sorting");
534         column.sort = this._currentGrid().sortOrder();
535         function callCallback()
536         {
537             callback(column);
538         }
539         setTimeout(callCallback, 0);
540     }
541     InspectorTest._currentGrid().addEventListener("sorting complete", sortingComplete, this);
542     this._currentGrid()._clickInHeaderCell(event);
543 };
544
545 InspectorTest.clickRowAndGetRetainers = function(row, callback)
546 {
547     callback = InspectorTest.safeWrap(callback);
548     var event = {
549         target: {
550             enclosingNodeOrSelfWithNodeName: function() { return row._element; },
551             selectedNode: row
552         }
553     };
554     this._currentGrid()._mouseDownInDataTable(event);
555     var rootNode = InspectorTest.currentProfileView().retainmentDataGrid.rootNode();
556     function populateComplete()
557     {
558         rootNode.removeEventListener(WebInspector.HeapSnapshotGridNode.Events.PopulateComplete, populateComplete, this);
559         callback(rootNode);
560     }
561     rootNode.addEventListener(WebInspector.HeapSnapshotGridNode.Events.PopulateComplete, populateComplete, this);
562 };
563
564 InspectorTest.clickShowMoreButton = function(buttonName, row, callback)
565 {
566     callback = InspectorTest.safeWrap(callback);
567     var parent = row.parent;
568     function populateComplete()
569     {
570         parent.removeEventListener(WebInspector.HeapSnapshotGridNode.Events.PopulateComplete, populateComplete, this);
571         function callCallback()
572         {
573             callback(parent);
574         }
575         setTimeout(callCallback, 0);
576     }
577     parent.addEventListener(WebInspector.HeapSnapshotGridNode.Events.PopulateComplete, populateComplete, this);
578     row[buttonName].click();
579 };
580
581 InspectorTest.columnContents = function(column, row)
582 {
583     // Make sure invisible nodes are removed from the view port.
584     this._currentGrid().updateVisibleNodes();
585     var result = [];
586     var parent = row || this._currentGrid().rootNode();
587     for (var node = parent.children[0]; node; node = node.traverseNextNode(true, parent, true)) {
588         if (!node.selectable)
589             continue;
590         var data = node.data[column.identifier];
591         if (typeof data === "object")
592             data = JSON.stringify(data);
593         result.push(data);
594     }
595     return result;
596 };
597
598 InspectorTest.countDataRows = function(row, filter)
599 {
600     var result = 0;
601     filter = filter || function(node) { return node.selectable; };
602     for (var node = row.children[0]; node; node = node.traverseNextNode(true, row, true)) {
603         if (filter(node))
604             ++result;
605     }
606     return result;
607 };
608
609 InspectorTest.expandRow = function(row, callback)
610 {
611     callback = InspectorTest.safeWrap(callback);
612     function populateComplete()
613     {
614         row.removeEventListener(WebInspector.HeapSnapshotGridNode.Events.PopulateComplete, populateComplete, this);
615         function callCallback()
616         {
617             callback(row);
618         }
619         setTimeout(callCallback, 0);
620     }
621     row.addEventListener(WebInspector.HeapSnapshotGridNode.Events.PopulateComplete, populateComplete, this);
622     (function expand()
623     {
624         if (row.hasChildren)
625             row.expand();
626         else
627             setTimeout(expand, 0);
628     })();
629 };
630
631 InspectorTest.findAndExpandGCRoots = function(callback)
632 {
633     InspectorTest.findAndExpandRow("(GC roots)", callback);
634 };
635
636 InspectorTest.findAndExpandWindow = function(callback)
637 {
638     InspectorTest.findAndExpandRow("Window", callback);
639 };
640
641 InspectorTest.findAndExpandRow = function(name, callback)
642 {
643     callback = InspectorTest.safeWrap(callback);
644     function propertyMatcher(data)
645     {
646         return data.value === name;
647     }
648     var row = InspectorTest.findRow("object", propertyMatcher);
649     InspectorTest.assertEquals(true, !!row, '"' + name + '" row');
650     InspectorTest.expandRow(row, callback);
651 };
652
653 InspectorTest.findButtonsNode = function(row, startNode)
654 {
655     var result = 0;
656     for (var node = startNode || row.children[0]; node; node = node.traverseNextNode(true, row, true)) {
657         if (!node.selectable && node.showNext)
658             return node;
659     }
660     return null;
661 };
662
663 InspectorTest.findRow = function(columnIdentifier, matcher, parent)
664 {
665     parent = parent || this._currentGrid().rootNode();
666     if (typeof matcher !== "function") {
667         var value = matcher;
668         matcher = function(x) { return x === value; };
669     }
670     for (var node = parent.children[0]; node; node = node.traverseNextNode(true, parent, true)) {
671         if (matcher(node.data[columnIdentifier]))
672             return node;
673     }
674     return null;
675 };
676
677 InspectorTest.findRow2 = function(matcher, parent)
678 {
679     parent = parent || this._currentGrid().rootNode();
680     for (var node = parent.children[0]; node; node = node.traverseNextNode(true, parent, true)) {
681         if (matcher(node.data))
682             return node;
683     }
684     return null;
685 };
686
687 InspectorTest.switchToView = function(title, callback)
688 {
689     callback = InspectorTest.safeWrap(callback);
690     var view = WebInspector.panels.profiles.visibleView;
691     view.changeView(title, callback);
692 };
693
694 InspectorTest.takeAndOpenSnapshot = function(generator, callback)
695 {
696     callback = InspectorTest.safeWrap(callback);
697     var snapshot = generator();
698     var profileType =  WebInspector.ProfileTypeRegistry.instance.heapSnapshotProfileType;
699     function pushGeneratedSnapshot(reportProgress, callback)
700     {
701         var profile = profileType.profileBeingRecorded();
702         if (reportProgress) {
703             profileType.reportHeapSnapshotProgress(50, 100, false);
704             profileType.reportHeapSnapshotProgress(100, 100, true);
705         }
706         snapshot.snapshot.typeId = "HEAP";
707         profileType.addHeapSnapshotChunk(JSON.stringify(snapshot));
708         setTimeout(callback, 0);
709     }
710     InspectorTest.override(HeapProfilerAgent, "takeHeapSnapshot", pushGeneratedSnapshot);
711     InspectorTest._takeAndOpenSnapshotCallback = callback;
712     profileType._takeHeapSnapshot(function() { });
713 };
714
715 InspectorTest.viewColumns = function()
716 {
717     return InspectorTest._currentGrid()._columnsArray;
718 };
719
720 InspectorTest.currentProfileView = function()
721 {
722     return WebInspector.panels.profiles.visibleView;
723 };
724
725 InspectorTest._currentGrid = function()
726 {
727     return this.currentProfileView().dataGrid;
728 };
729
730 InspectorTest._snapshotViewShown = function()
731 {
732     if (InspectorTest._takeAndOpenSnapshotCallback) {
733         var callback = InspectorTest._takeAndOpenSnapshotCallback;
734         InspectorTest._takeAndOpenSnapshotCallback = null;
735         var dataGrid = this.dataGrid;
736         function sortingComplete()
737         {
738             dataGrid.removeEventListener("sorting complete", sortingComplete, null);
739             callback();
740         }
741         dataGrid.addEventListener("sorting complete", sortingComplete, null);
742     }
743 };
744
745 };