import*as Platform from"../platform/platform.js";import*as TestRunner from"./TestRunner.js";export{TestRunner};function _setupTestHelpers(e){self.TestRunner.BrowserAgent=e.browserAgent(),self.TestRunner.CSSAgent=e.cssAgent(),self.TestRunner.DeviceOrientationAgent=e.deviceOrientationAgent(),self.TestRunner.DOMAgent=e.domAgent(),self.TestRunner.DOMDebuggerAgent=e.domdebuggerAgent(),self.TestRunner.DebuggerAgent=e.debuggerAgent(),self.TestRunner.EmulationAgent=e.emulationAgent(),self.TestRunner.HeapProfilerAgent=e.heapProfilerAgent(),self.TestRunner.InputAgent=e.inputAgent(),self.TestRunner.InspectorAgent=e.inspectorAgent(),self.TestRunner.NetworkAgent=e.networkAgent(),self.TestRunner.OverlayAgent=e.overlayAgent(),self.TestRunner.PageAgent=e.pageAgent(),self.TestRunner.ProfilerAgent=e.profilerAgent(),self.TestRunner.RuntimeAgent=e.runtimeAgent(),self.TestRunner.TargetAgent=e.targetAgent(),self.TestRunner.networkManager=e.model(SDK.NetworkManager),self.TestRunner.securityOriginManager=e.model(SDK.SecurityOriginManager),self.TestRunner.resourceTreeModel=e.model(SDK.ResourceTreeModel),self.TestRunner.debuggerModel=e.model(SDK.DebuggerModel),self.TestRunner.runtimeModel=e.model(SDK.RuntimeModel),self.TestRunner.domModel=e.model(SDK.DOMModel),self.TestRunner.domDebuggerModel=e.model(SDK.DOMDebuggerModel),self.TestRunner.cssModel=e.model(SDK.CSSModel),self.TestRunner.cpuProfilerModel=e.model(SDK.CPUProfilerModel),self.TestRunner.overlayModel=e.model(SDK.OverlayModel),self.TestRunner.serviceWorkerManager=e.model(SDK.ServiceWorkerManager),self.TestRunner.tracingManager=e.model(SDK.TracingManager),self.TestRunner.mainTarget=e}self.Platform=self.Platform||{},self.Platform.StringUtilities=Platform.StringUtilities;export async function _executeTestScript(){const testScriptURL=Root.Runtime.queryParam("test");if(TestRunner.isDebugTest())return TestRunner.setInnerResult(console.log),TestRunner.setInnerCompleteTest((()=>console.log("Test completed"))),void(self.test=async function(){await eval(`import("${testScriptURL}")`)});try{await eval(`import("${testScriptURL}")`)}catch(err){TestRunner.addResult("TEST ENDED EARLY DUE TO UNCAUGHT ERROR:"),TestRunner.addResult(err&&err.stack||err),TestRunner.addResult("=== DO NOT COMMIT THIS INTO -expected.txt ==="),TestRunner.completeTest()}}let _startedTest=!1;export class _TestObserver{targetAdded(e){"main"===e.id()&&_setupTestHelpers(e),_startedTest||(_startedTest=!0,TestRunner.loadHTML(`\n      <head>\n        <base href="${TestRunner.url()}">\n      </head>\n      <body>\n      </body>\n    `).then((()=>_executeTestScript())))}targetRemoved(e){}}SDK.targetManager.observeTargets(new _TestObserver);