Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / http / tests / inspector / layers-test.js
blob8f5c3fa71aa2fc3ff4fddcf00226c3c27801b3f6
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 + ")";
15 return label;
18 InspectorTest.dumpLayerTree = function(prefix, root)
20 if (!prefix)
21 prefix = "";
22 if (!root) {
23 root = InspectorTest.layerTreeModel.layerTree().contentRoot();
24 if (!root) {
25 InspectorTest.addResult("No layer root, perhaps not in the composited mode! ");
26 InspectorTest.completeTest();
27 return;
30 InspectorTest.addResult(prefix + InspectorTest.labelForLayer(root));
31 root.children().forEach(InspectorTest.dumpLayerTree.bind(InspectorTest, prefix + " "));
34 InspectorTest.dumpLayers3DView = function(prefix, root)
36 if (!prefix)
37 prefix = "";
38 if (!root)
39 root = WebInspector.panels.layers._layers3DView._rotatingContainerElement;
40 if (root.__layer)
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);
51 callback();
53 InspectorTest.evaluateInPage(expression, function() {
54 InspectorTest.layerTreeModel.addEventListener(WebInspector.LayerTreeModel.Events.LayerTreeChanged, eventHandler);
55 });
58 InspectorTest.findLayerByNodeIdAttribute = function(nodeIdAttribute)
60 var result;
61 function testLayer(layer)
63 var node = layer.node();
64 if (!node)
65 return false;
66 if (!node || node.getAttribute("id") !== nodeIdAttribute)
67 return false;
68 result = layer;
69 return true;
71 InspectorTest.layerTreeModel.layerTree().forEachLayer(testLayer);
72 if (!result)
73 InspectorTest.addResult("ERROR: No layer for " + nodeIdAttribute);
74 return result;
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);
84 callback();
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 = {
105 bubbles: true,
106 cancelable: true,
107 view: window,
108 screenX: totalOffset.left - scrollOffset.left + offsetX,
109 screenY: totalOffset.top - scrollOffset.top + offsetY,
110 clientX: totalOffset.left + offsetX,
111 clientY: totalOffset.top + offsetY,
112 button: button
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));