6e019d7e1d9a2884200045236e0632c85e40c475
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / http / tests / inspector / layers-test.js
1 function initialize_LayerTreeTests()
2 {
3     // FIXME: remove once out of experimental.
4     WebInspector.moduleManager.registerModule("layers");
5     var extensions = WebInspector.moduleManager.extensions(WebInspector.Panel).forEach(function(extension) {
6         if (extension.module().name() === "layers")
7             WebInspector.inspectorView.addPanel(new WebInspector.ModuleManagerExtensionPanelDescriptor(extension));
8     });
9     InspectorTest._layerTreeModel = WebInspector.panel("layers")._model;
10
11     InspectorTest.labelForLayer = function(layer)
12     {
13         var node = WebInspector.domAgent.nodeForId(layer.nodeIdForSelfOrAncestor());
14         var label = WebInspector.DOMPresentationUtils.fullQualifiedSelector(node, false);
15         var height = layer.height();
16         var width = layer.width();
17         if (height <= 200 && width <= 200)
18             label += " " + height + "x" + width;
19         if (typeof layer.__extraData !== "undefined")
20             label += " (" + layer.__extraData + ")";
21         return label;
22     }
23
24     InspectorTest.dumpLayerTree = function(prefix, root)
25     {
26         if (!prefix)
27             prefix = "";
28         if (!root) {
29             root = InspectorTest._layerTreeModel.contentRoot();
30             if (!root) {
31                 InspectorTest.addResult("No layer root, perhaps not in the composited mode! ");
32                 InspectorTest.completeTest();
33                 return;
34             }
35         }
36         InspectorTest.addResult(prefix + InspectorTest.labelForLayer(root));
37         root.children().forEach(InspectorTest.dumpLayerTree.bind(InspectorTest, prefix + "    "));
38     }
39
40     InspectorTest.dumpLayerTreeOutline = function(prefix, root)
41     {
42         if (!prefix)
43             prefix = "";
44         if (!root)
45             root = WebInspector.panel("layers")._layerTree._treeOutline;
46         if (root.representedObject)
47             InspectorTest.addResult(prefix + InspectorTest.labelForLayer(root.representedObject));
48         root.children.forEach(InspectorTest.dumpLayerTreeOutline.bind(InspectorTest, prefix + "    "));
49     }
50
51     InspectorTest.dumpLayers3DView = function(prefix, root)
52     {
53         if (!prefix)
54             prefix = "";
55         if (!root)
56             root = WebInspector.panel("layers")._layers3DView._rotatingContainerElement;
57         if (root.__layer)
58             InspectorTest.addResult(prefix + InspectorTest.labelForLayer(root.__layer));
59         for (var element = root.firstElementChild; element; element = element.nextSibling)
60             InspectorTest.dumpLayers3DView(prefix + "    ", element);
61     }
62
63     InspectorTest.evaluateAndRunWhenTreeChanges = function(expression, callback)
64     {
65         function eventHandler()
66         {
67             InspectorTest._layerTreeModel.removeEventListener(WebInspector.LayerTreeModel.Events.LayerTreeChanged, eventHandler);
68             callback();
69         }
70         InspectorTest.evaluateInPage(expression, function() {
71             InspectorTest._layerTreeModel.addEventListener(WebInspector.LayerTreeModel.Events.LayerTreeChanged, eventHandler);
72         });
73     }
74
75     InspectorTest.findLayerByNodeIdAttribute = function(nodeIdAttribute)
76     {
77         var result;
78         function testLayer(layer)
79         {
80             if (!layer.nodeId())
81                 return false;
82             var node = WebInspector.domAgent.nodeForId(layer.nodeId());
83             if (!node || node.getAttribute("id") !== nodeIdAttribute)
84                 return false;
85             result = layer;
86             return true;
87         }
88         InspectorTest._layerTreeModel.forEachLayer(testLayer);
89         if (!result)
90             InspectorTest.addResult("ERROR: No layer for " + nodeIdAttribute);
91         return result;
92     }
93
94     InspectorTest.requestLayers = function(callback)
95     {
96         InspectorTest._layerTreeModel.addEventListener(WebInspector.LayerTreeModel.Events.LayerTreeChanged, onLayerTreeChanged);
97         InspectorTest._layerTreeModel.enable();
98         function onLayerTreeChanged()
99         {
100             InspectorTest._layerTreeModel.removeEventListener(WebInspector.LayerTreeModel.Events.LayerTreeChanged, onLayerTreeChanged);
101             callback();
102         }
103     }
104 }