3 <script src="../../http/tests/inspector/inspector-test.js"></script>
4 <script src="../../http/tests/inspector/layers-test.js"></script>
10 var rootOffsetXInPixels, rootOffsetYInPixels, rootHeightInPixels, rootWidthInPixels;
12 const ButtonByEventType = { mousemove: -1, mousedown: 0, mouseup: 0 };
16 layerA = InspectorTest.findLayerByNodeIdAttribute("a");
17 layerB = InspectorTest.findLayerByNodeIdAttribute("b");
18 contentRoot = InspectorTest.layerTreeModel.layerTree().contentRoot();
19 layers = [{layer: layerA, name: "layer a"}, {layer: layerB, name: "layer b"}, {layer: contentRoot, name: "content root"}];
24 canvas = WebInspector.panels.layers._layers3DView._canvasElement;
25 var canvasWidth = canvas.offsetWidth;
26 var canvasHeight = canvas.offsetHeight;
27 var rootWidth = contentRoot.width();
28 var rootHeight = contentRoot.height();
29 var paddingX = canvasWidth * 0.1;
30 var paddingY = canvasHeight * 0.1;
31 var scaleX = rootWidth / (canvasWidth - paddingX);
32 var scaleY = rootHeight / (canvasHeight - paddingY);
33 var resultScale = Math.max(scaleX, scaleY);
34 var width = canvasWidth * resultScale;
35 var height = canvasHeight * resultScale;
36 var rootOffsetX = (width - rootWidth) / 2;
37 var rootOffsetY = (height - rootHeight) / 2;
38 rootOffsetXInPixels = rootOffsetX / width * canvasWidth;
39 rootOffsetYInPixels = rootOffsetY / height * canvasHeight;
40 rootHeightInPixels = rootHeight / height * canvasHeight;
41 rootWidthInPixels = rootHeight / width * canvasWidth;
44 function dispatchMouseEventOnCanvas(eventType, x, y)
46 InspectorTest.dispatchMouseEvent(eventType, ButtonByEventType[eventType], canvas, rootOffsetXInPixels + rootWidthInPixels * x, rootOffsetYInPixels + rootHeightInPixels * y);
49 function dumpStateForOutlineType(type)
51 var outlined = "none";
53 function checkLayer(layerInfo)
55 var l3dview = WebInspector.panels.layers._layers3DView;
56 if (l3dview._lastActiveObject[type] && layerInfo.layer.id() === l3dview._lastActiveObject[type].layer.id())
57 outlined = layerInfo.name;
60 layers.forEach(checkLayer);
61 InspectorTest.addResult(type + " layer: " + outlined);
64 function dumpOutlinedStateForLayers()
66 InspectorTest.addResult("State of layers:");
67 dumpStateForOutlineType(WebInspector.Layers3DView.OutlineType.Hovered);
68 dumpStateForOutlineType(WebInspector.Layers3DView.OutlineType.Selected);
71 function onGotLayers()
76 InspectorTest.addResult("Initial state");
77 dumpOutlinedStateForLayers();
79 InspectorTest.addResult("\nHovering content root");
80 dispatchMouseEventOnCanvas("mousemove", 0.1237135833164431, 0.11536508236291274);
81 dumpOutlinedStateForLayers();
83 InspectorTest.addResult("\nSelecting layer b");
84 dispatchMouseEventOnCanvas("mousedown", 0.5, 0.5);
85 dispatchMouseEventOnCanvas("mouseup", 0.5, 0.5);
86 dumpOutlinedStateForLayers();
88 InspectorTest.addResult("\nHovering layer a");
89 dispatchMouseEventOnCanvas("mousemove", 0.4, 0.2);
90 dumpOutlinedStateForLayers();
92 InspectorTest.addResult("\nSelecting content root");
93 dispatchMouseEventOnCanvas("mousedown", 0.5, 0.001);
94 dispatchMouseEventOnCanvas("mouseup", 0.5, 0.001);
95 dumpOutlinedStateForLayers();
97 InspectorTest.completeTest();
100 InspectorTest.requestLayers(onGotLayers);
104 <body onload="runTest()" style="height:500px;width:500px;">
105 <div id="a" style="transform:translateZ(0px) translateY(60px) rotateZ(45deg);width:300px;height:300px;margin-left:100px;">
106 <div id="b" style="transform:translateX(0px) translateY(0px) translateZ(0px) rotateX(45deg) rotateY(45deg);width:300px;height:300px;"></div>