import"../test_runner/test_runner.js";import"../layers/layers-legacy.js";import"../elements/elements-legacy.js";import"../components/components-legacy.js";self.LayersTestRunner=self.LayersTestRunner||{},LayersTestRunner.layerTreeModel=function(){return LayersTestRunner._layerTreeModel||(LayersTestRunner._layerTreeModel=TestRunner.mainTarget.model(Layers.LayerTreeModel)),LayersTestRunner._layerTreeModel},LayersTestRunner.labelForLayer=function(e){const n=e.nodeForSelfOrAncestor();let r=n?Elements.DOMPath.fullQualifiedSelector(n,!1):"<invalid node id>";const t=e.height(),s=e.width();return t<=200&&s<=200&&(r+=" "+t+"x"+s),"undefined"!==typeof e.__extraData&&(r+=" ("+e.__extraData+")"),r},LayersTestRunner.dumpLayerTree=function(e,n){if(e||(e=""),!n&&!(n=LayersTestRunner.layerTreeModel().layerTree().contentRoot()))return TestRunner.addResult("No layer root, perhaps not in the composited mode! "),void TestRunner.completeTest();TestRunner.addResult(e+LayersTestRunner.labelForLayer(n)),n.children().forEach(LayersTestRunner.dumpLayerTree.bind(LayersTestRunner,e+"    "))},LayersTestRunner.dumpLayers3DView=function(e,n){e||(e=""),n||(n=UI.panels.layers._layers3DView._rotatingContainerElement),n.__layer&&TestRunner.addResult(e+LayersTestRunner.labelForLayer(n.__layer));for(let r=n.firstElementChild;r;r=r.nextSibling)LayersTestRunner.dumpLayers3DView(e+"    ",r)},LayersTestRunner.evaluateAndWaitForTreeChange=async function(e){return await TestRunner.evaluateInPageAnonymously(e),LayersTestRunner.layerTreeModel().once(Layers.LayerTreeModel.Events.LayerTreeChanged)},LayersTestRunner.findLayerByNodeIdAttribute=function(e){let n;return LayersTestRunner.layerTreeModel().layerTree().forEachLayer((function(r){const t=r.node();return!!t&&(!(!t||t.getAttribute("id")!==e)&&(n=r,!0))})),n||TestRunner.addResult("ERROR: No layer for "+e),n},LayersTestRunner.requestLayers=function(){return LayersTestRunner.layerTreeModel().enable(),LayersTestRunner.layerTreeModel().once(Layers.LayerTreeModel.Events.LayerTreeChanged)},LayersTestRunner.dispatchMouseEvent=function(e,n,r,t,s){const a=r.totalOffset(),l={bubbles:!0,cancelable:!0,view:window,screenX:a.left-r.scrollLeft+t,screenY:a.top-r.scrollTop+s,clientX:a.left+t,clientY:a.top+s,button:n,composed:!0};"mouseout"===e&&(l.screenX=0,l.screenY=0,l.clientX=0,l.clientY=0),r.dispatchEvent(new MouseEvent(e,l))},LayersTestRunner.findLayerTreeElement=function(e){const n=LayerViewer.LayerTreeElement.layerToTreeElement.get(e);return n.reveal(),n.listItemElement},LayersTestRunner.dispatchMouseEventToLayerTree=function(e,n,r){const t=LayersTestRunner.findLayerTreeElement(r);TestRunner.assertTrue(Boolean(t)),LayersTestRunner.dispatchMouseEvent(e,n,t,t.clientWidth>>1,t.clientHeight>>1)},LayersTestRunner.dumpSelectedStyles=function(e,n){const r=[];n.classList.contains("selected")&&r.push("selected"),n.classList.contains("hovered")&&r.push("hovered"),TestRunner.addResult(e+": "+r.join(", "))};