1 function initialize_LayerTreeTests()
4 InspectorTest.preloadPanel("layers");
6 InspectorTest.layerTreeModel = WebInspector.targetManager.mainTarget().layerTreeModel;
8 InspectorTest.labelForLayer = function(layer)
10 var node = layer.nodeForSelfOrAncestor();
11 var label = node ? WebInspector.DOMPresentationUtils.fullQualifiedSelector(node, false) : "<invalid node id>";
12 var height = layer.height();
13 var width = layer.width();
14 if (height <= 200 && width <= 200)
15 label += " " + height + "x" + width;
16 if (typeof layer.__extraData !== "undefined")
17 label += " (" + layer.__extraData + ")";
21 InspectorTest.dumpLayerTree = function(prefix, root)
26 root = InspectorTest.layerTreeModel.layerTree().contentRoot();
28 InspectorTest.addResult("No layer root, perhaps not in the composited mode! ");
29 InspectorTest.completeTest();
33 InspectorTest.addResult(prefix + InspectorTest.labelForLayer(root));
34 root.children().forEach(InspectorTest.dumpLayerTree.bind(InspectorTest, prefix + " "));
37 InspectorTest.dumpLayerTreeOutline = function(prefix, root)
42 root = WebInspector.panels.layers._layerTree._treeOutline;
43 if (root.representedObject)
44 InspectorTest.addResult(prefix + InspectorTest.labelForLayer(root.representedObject));
45 root.children.forEach(InspectorTest.dumpLayerTreeOutline.bind(InspectorTest, prefix + " "));
48 InspectorTest.dumpLayers3DView = function(prefix, root)
53 root = WebInspector.panels.layers._layers3DView._rotatingContainerElement;
55 InspectorTest.addResult(prefix + InspectorTest.labelForLayer(root.__layer));
56 for (var element = root.firstElementChild; element; element = element.nextSibling)
57 InspectorTest.dumpLayers3DView(prefix + " ", element);
60 InspectorTest.evaluateAndRunWhenTreeChanges = function(expression, callback)
62 function eventHandler()
64 InspectorTest.layerTreeModel.removeEventListener(WebInspector.LayerTreeModel.Events.LayerTreeChanged, eventHandler);
67 InspectorTest.evaluateInPage(expression, function() {
68 InspectorTest.layerTreeModel.addEventListener(WebInspector.LayerTreeModel.Events.LayerTreeChanged, eventHandler);
72 InspectorTest.findLayerByNodeIdAttribute = function(nodeIdAttribute)
75 function testLayer(layer)
77 var node = layer.node();
80 if (!node || node.getAttribute("id") !== nodeIdAttribute)
85 InspectorTest.layerTreeModel.layerTree().forEachLayer(testLayer);
87 InspectorTest.addResult("ERROR: No layer for " + nodeIdAttribute);
91 InspectorTest.requestLayers = function(callback)
93 InspectorTest.layerTreeModel.addEventListener(WebInspector.LayerTreeModel.Events.LayerTreeChanged, onLayerTreeChanged);
94 InspectorTest.layerTreeModel.enable();
95 function onLayerTreeChanged()
97 InspectorTest.layerTreeModel.removeEventListener(WebInspector.LayerTreeModel.Events.LayerTreeChanged, onLayerTreeChanged);
102 InspectorTest.dumpModelScrollRects = function()
104 function dumpScrollRectsForLayer(layer)
106 if (layer._scrollRects.length > 0)
107 InspectorTest.addObject(layer._scrollRects);
110 InspectorTest.addResult("Model elements dump");
111 InspectorTest.layerTreeModel.layerTree().forEachLayer(dumpScrollRectsForLayer.bind(this));
114 InspectorTest.dispatchMouseEvent = function(eventType, button, element, offsetX, offsetY)
116 var totalOffset = element.totalOffset();
117 var scrollOffset = element.scrollOffset();
118 var eventArguments = {
122 screenX: totalOffset.left - scrollOffset.left + offsetX,
123 screenY: totalOffset.top - scrollOffset.top + offsetY,
124 clientX: totalOffset.left + offsetX,
125 clientY: totalOffset.top + offsetY,
128 if (eventType === "mouseout") {
129 eventArguments.screenX = 0;
130 eventArguments.screenY = 0;
131 eventArguments.clientX = 0;
132 eventArguments.clientY = 0;
134 element.dispatchEvent(new MouseEvent(eventType, eventArguments));