self.ApplicationTestRunner=self.ApplicationTestRunner||{},ApplicationTestRunner.registerServiceWorker=function(e,r){return TestRunner.callFunctionInPageAsync("registerServiceWorker",[e,r])},ApplicationTestRunner.waitForActivated=function(e){return TestRunner.callFunctionInPageAsync("waitForActivated",[e])},ApplicationTestRunner.unregisterServiceWorker=function(e){return TestRunner.callFunctionInPageAsync("unregisterServiceWorker",[e])},ApplicationTestRunner.postToServiceWorker=function(e,r){return TestRunner.evaluateInPageAnonymously('postToServiceWorker("'+e+'","'+r+'")')},ApplicationTestRunner.waitForServiceWorker=function(e){self.SDK.targetManager.observeTargets({targetAdded:function(r){r.type()===SDK.Target.Type.ServiceWorker&&e&&(setTimeout(e.bind(null,r),0),e=null)},targetRemoved:function(e){}})},ApplicationTestRunner.dumpServiceWorkersView=function(){return UI.panels.resources.visibleView._currentWorkersView._sectionList.childTextNodes().map((function(e){return e.textContent==="Received "+new Date(0).toLocaleString()?"Invalid scriptResponseTime (unix epoch)":e.textContent.replace(/Received.*/,"Received").replace(/#\d+/,"#N").replace(/Start time.*/,"Start time").replace(/End time.*/,"End time")})).join("\n")},ApplicationTestRunner.deleteServiceWorkerRegistration=function(e){for(const r of TestRunner.serviceWorkerManager.registrations().values())r.scopeURL===e&&TestRunner.serviceWorkerManager.deleteRegistration(r.id)},ApplicationTestRunner.makeFetchInServiceWorker=function(e,r,n,t){TestRunner.callFunctionInPageAsync("makeFetchInServiceWorker",[e,r,n]).then(t)},TestRunner.deprecatedInitAsync("\n  let registrations = {};\n\n  function registerServiceWorker(script, scope) {\n    return navigator.serviceWorker.register(script, {\n      scope: scope\n    })\n    .then(reg => registrations[scope] = reg)\n    .catch(err => {\n      return Promise.reject(new Error('Service Worker registration error: ' +\n                                      err.toString()));\n    });\n  }\n\n  function waitForActivated(scope) {\n    let reg = registrations[scope];\n    if (!reg)\n      return Promise.reject(new Error('The registration'));\n    let worker = reg.installing || reg.waiting || reg.active;\n    if (worker.state === 'activated')\n      return Promise.resolve();\n    if (worker.state === 'redundant')\n      return Promise.reject(new Error('The worker is redundant'));\n    return new Promise(resolve => {\n        worker.addEventListener('statechange', () => {\n            if (worker.state === 'activated')\n              resolve();\n          });\n      });\n  }\n\n  function postToServiceWorker(scope, message) {\n    registrations[scope].active.postMessage(message);\n  }\n\n  function unregisterServiceWorker(scope) {\n    let registration = registrations[scope];\n\n    if (!registration)\n      return Promise.reject('ServiceWorker for ' + scope + ' is not registered');\n\n    return registration.unregister().then(() => delete registrations[scope]);\n  }\n\n  function makeFetchInServiceWorker(scope, url, requestInitializer) {\n    let script = 'resources/network-fetch-worker.js';\n\n    return navigator.serviceWorker.register(script, {\n      scope: scope\n    }).then(registration => {\n      let worker = registration.installing;\n\n      return new Promise(resolve => {\n        navigator.serviceWorker.onmessage = e => {\n          resolve(e.data);\n        };\n\n        worker.postMessage({\n          url: url,\n          init: requestInitializer\n        });\n      });\n    });\n  }\n");