1 function initialize_LayerTreeTests()
3 InspectorTest
.layerTreeModel
= WebInspector
.targetManager
.mainTarget().layerTreeModel
;
5 InspectorTest
.labelForLayer = function(layer
)
7 var node
= layer
.nodeForSelfOrAncestor();
8 var label
= node
? WebInspector
.DOMPresentationUtils
.fullQualifiedSelector(node
, false) : "<invalid node id>";
9 var height
= layer
.height();
10 var width
= layer
.width();
11 if (height
<= 200 && width
<= 200)
12 label
+= " " + height
+ "x" + width
;
13 if (typeof layer
.__extraData
!== "undefined")
14 label
+= " (" + layer
.__extraData
+ ")";
18 InspectorTest
.dumpLayerTree = function(prefix
, root
)
23 root
= InspectorTest
.layerTreeModel
.layerTree().contentRoot();
25 InspectorTest
.addResult("No layer root, perhaps not in the composited mode! ");
26 InspectorTest
.completeTest();
30 InspectorTest
.addResult(prefix
+ InspectorTest
.labelForLayer(root
));
31 root
.children().forEach(InspectorTest
.dumpLayerTree
.bind(InspectorTest
, prefix
+ " "));
34 InspectorTest
.dumpLayers3DView = function(prefix
, root
)
39 root
= WebInspector
.panels
.layers
._layers3DView
._rotatingContainerElement
;
41 InspectorTest
.addResult(prefix
+ InspectorTest
.labelForLayer(root
.__layer
));
42 for (var element
= root
.firstElementChild
; element
; element
= element
.nextSibling
)
43 InspectorTest
.dumpLayers3DView(prefix
+ " ", element
);
46 InspectorTest
.evaluateAndRunWhenTreeChanges = function(expression
, callback
)
48 function eventHandler()
50 InspectorTest
.layerTreeModel
.removeEventListener(WebInspector
.LayerTreeModel
.Events
.LayerTreeChanged
, eventHandler
);
53 InspectorTest
.evaluateInPage(expression
, function() {
54 InspectorTest
.layerTreeModel
.addEventListener(WebInspector
.LayerTreeModel
.Events
.LayerTreeChanged
, eventHandler
);
58 InspectorTest
.findLayerByNodeIdAttribute = function(nodeIdAttribute
)
61 function testLayer(layer
)
63 var node
= layer
.node();
66 if (!node
|| node
.getAttribute("id") !== nodeIdAttribute
)
71 InspectorTest
.layerTreeModel
.layerTree().forEachLayer(testLayer
);
73 InspectorTest
.addResult("ERROR: No layer for " + nodeIdAttribute
);
77 InspectorTest
.requestLayers = function(callback
)
79 InspectorTest
.layerTreeModel
.addEventListener(WebInspector
.LayerTreeModel
.Events
.LayerTreeChanged
, onLayerTreeChanged
);
80 InspectorTest
.layerTreeModel
.enable();
81 function onLayerTreeChanged()
83 InspectorTest
.layerTreeModel
.removeEventListener(WebInspector
.LayerTreeModel
.Events
.LayerTreeChanged
, onLayerTreeChanged
);
88 InspectorTest
.dumpModelScrollRects = function()
90 function dumpScrollRectsForLayer(layer
)
92 if (layer
._scrollRects
.length
> 0)
93 InspectorTest
.addObject(layer
._scrollRects
);
96 InspectorTest
.addResult("Model elements dump");
97 InspectorTest
.layerTreeModel
.layerTree().forEachLayer(dumpScrollRectsForLayer
.bind(this));
100 InspectorTest
.dispatchMouseEvent = function(eventType
, button
, element
, offsetX
, offsetY
)
102 var totalOffset
= element
.totalOffset();
103 var scrollOffset
= element
.scrollOffset();
104 var eventArguments
= {
108 screenX
: totalOffset
.left
- scrollOffset
.left
+ offsetX
,
109 screenY
: totalOffset
.top
- scrollOffset
.top
+ offsetY
,
110 clientX
: totalOffset
.left
+ offsetX
,
111 clientY
: totalOffset
.top
+ offsetY
,
114 if (eventType
=== "mouseout") {
115 eventArguments
.screenX
= 0;
116 eventArguments
.screenY
= 0;
117 eventArguments
.clientX
= 0;
118 eventArguments
.clientY
= 0;
120 element
.dispatchEvent(new MouseEvent(eventType
, eventArguments
));