feat: promisify webContents.hasServiceWorker() (#16535)
* feat: promisify contents.hasServiceWorker() * spec: add initial test for hasServiceWorker()
This commit is contained in:
parent
5a35c3a279
commit
d105dcc0d3
8 changed files with 60 additions and 23 deletions
|
@ -228,6 +228,23 @@ describe('webContents module', () => {
|
|||
})
|
||||
})
|
||||
|
||||
describe('ServiceWorker APIs', () => {
|
||||
it('can successfully register a ServiceWorker', async () => {
|
||||
await w.loadFile(path.join(fixtures, 'api', 'service-worker', 'service-worker.html'))
|
||||
const hasSW = await w.webContents.hasServiceWorker()
|
||||
expect(hasSW).to.be.true()
|
||||
})
|
||||
|
||||
it('can successfully register a ServiceWorker (callback)', (done) => {
|
||||
w.loadFile(path.join(fixtures, 'api', 'service-worker', 'service-worker.html')).then(() => {
|
||||
w.webContents.hasServiceWorker(hasSW => {
|
||||
expect(hasSW).to.be.true()
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('isCurrentlyAudible() API', () => {
|
||||
it('returns whether audio is playing', async () => {
|
||||
const webContents = remote.getCurrentWebContents()
|
||||
|
|
12
spec/fixtures/api/service-worker/service-worker.html
vendored
Normal file
12
spec/fixtures/api/service-worker/service-worker.html
vendored
Normal file
|
@ -0,0 +1,12 @@
|
|||
<html>
|
||||
<body>
|
||||
<script>
|
||||
window.onerror = (err) => console.log(error)
|
||||
|
||||
navigator.serviceWorker.register('service-worker.js', {
|
||||
scope: './'
|
||||
}).then(sw => {
|
||||
console.log("registered")
|
||||
}).catch(err => console.log(error))
|
||||
</script>
|
||||
</body>
|
5
spec/fixtures/api/service-worker/service-worker.js
vendored
Normal file
5
spec/fixtures/api/service-worker/service-worker.js
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
console.log('Service worker startups.')
|
||||
|
||||
self.addEventListener('install', (event) => {
|
||||
console.log('Service worker installed.')
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue