let timeOverrides,originalRequestMetadata;self.BindingsTestRunner=self.BindingsTestRunner||{},BindingsTestRunner.addFiles=function(e,t){for(const i in t){const n=t[i];e.addFile(i,n.content,n.time?n.time.getTime():0)}},BindingsTestRunner.overrideNetworkModificationTime=function(e){timeOverrides||(timeOverrides=new Map,originalRequestMetadata=TestRunner.override(Bindings.ContentProviderBasedProject.prototype,"requestMetadata",(function(e){if(!timeOverrides.has(e.url()))return originalRequestMetadata.call(this,e);const i=timeOverrides.get(e.url());return originalRequestMetadata.call(this,e).then(t.bind(null,i))}),!0));for(const i in e)timeOverrides.set(i,e[i]);function t(e,t){return e||t?new Workspace.UISourceCodeMetadata(e,t?t.contentSize:null):null}},BindingsTestRunner.AutomappingTest=function(e){this._workspace=e,this._networkProject=new Bindings.ContentProviderBasedProject(this._workspace,"AUTOMAPPING",Workspace.projectTypes.Network,"simple website"),e!==self.Workspace.workspace&&new Persistence.FileSystemWorkspaceBinding(self.Persistence.isolatedFileSystemManager,this._workspace),this._failedBindingsCount=0,this._automapping=new Persistence.Automapping(this._workspace,this._onStatusAdded.bind(this),this._onStatusRemoved.bind(this)),TestRunner.addSniffer(this._automapping,"_onBindingFailedForTest",this._onBindingFailed.bind(this),!0),TestRunner.addSniffer(this._automapping,"_onSweepHappenedForTest",this._onSweepHappened.bind(this),!0)},BindingsTestRunner.AutomappingTest.prototype={removeResources:function(e){for(const t of e)this._networkProject.removeFile(t)},addNetworkResources:function(e){for(const t in e){const i=e[t],n=i.contentType||Common.resourceTypes.Script,s=TextUtils.StaticContentProvider.fromString(t,n,i.content),o="string"===typeof i.content||i.time?new Workspace.UISourceCodeMetadata(i.time,i.content.length):null,r=this._networkProject.createUISourceCode(t,n);this._networkProject.addUISourceCodeWithProvider(r,s,o)}},waitUntilMappingIsStabilized:function(){const e=new Promise((e=>{this._stabilizedCallback=e}));return this._checkStabilized(),e},_onSweepHappened:function(){this._failedBindingsCount=0,this._checkStabilized()},_onStatusRemoved:function(e){TestRunner.addResult("Binding removed: "+e),this._checkStabilized()},_onStatusAdded:function(e){TestRunner.addResult("Binding created: "+e),this._checkStabilized()},_onBindingFailed:function(){++this._failedBindingsCount,this._checkStabilized()},_checkStabilized:function(){if(!this._stabilizedCallback||this._automapping._sweepThrottler._process)return;const e=this._workspace.uiSourceCodesForProjectType(Workspace.projectTypes.Network);if(this._failedBindingsCount+this._automapping._statuses.size===e.length){TestRunner.addResult("Mapping has stabilized.");const e=this._stabilizedCallback;delete this._stabilizedCallback,e.call(null)}}};