This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| it('should register install, activate and fetch event listeners', function() { | |
| const eventsListenedTo = []; | |
| global.self = { | |
| // Mock methods here | |
| addEventListener: (eventName, cb) => { | |
| eventsListenedTo.push(eventName); | |
| }, | |
| }; | |
| const myServiceWorkerLib = new Lib(); | |
| myServiceWorkerLib.setUpEventListeners(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| self.addEventListener('push', function(event) { | |
| let pushData = null; | |
| if (event.data) { | |
| pushData = event.data.text(); | |
| } | |
| // Send message to page | |
| const promiseChain = self.clients.matchAll({ | |
| includeUncontrolled: true | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| navigator.serviceWorker.addEventListener('message', function(event) { | |
| // Service worker received a push message | |
| // TODO: Perform assertions / check test passed. | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const webdriverChrome = require('selenium-webdriver/chrome'); | |
| const notificationPermission = {}; | |
| notificationPermission[testServerAddress + ',*'] = { | |
| setting: 1, | |
| }; | |
| const chromePreferences = { | |
| profile: { | |
| content_settings: { | |
| exceptions: { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const webdriverFirefox = require(‘selenium-webdriver/firefox’); | |
| const ffProfile = new webdriverFirefox.Profile(); | |
| ffProfile.setPreference('dom.push.testing.ignorePermission', true); | |
| ffProfile.setPreference('notification.prompt.testing', true); | |
| ffProfile.setPreference('notification.prompt.testing.allow', true); | |
| Const options = new webdriverFirefox.Options(); | |
| options.setProfile(ffProfile); | |
| const builder = new webdriver | |
| .Builder() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| app.use('/', express.static(rootDirectory, { | |
| setHeaders: (res) => { | |
| res.setHeader('Service-Worker-Allowed', '/'); | |
| }, | |
| })); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| app.get('/test/iframe/:random', function(req, res) { | |
| res.sendFile(path.join(__dirname, 'test-iframe.html')); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // OK when ‘Service-Worker-Allowed’ header is set to ‘/’ | |
| navigator.serviceWorker.register(‘/blog/sw.js’, {scope: ‘/’}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // OK | |
| navigator.serviceWorker.register(‘/blog/sw.js’, {scope: ‘/blog/article/’}); | |
| // Not OK | |
| navigator.serviceWorker.register(‘/blog/sw.js’, {scope: ‘/’}); | |
| // Not OK | |
| navigator.serviceWorker.register(‘/blog/sw.js’, {scope: ‘/about/’}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| navigator.serviceWorker.register('/sw.js', {scope: '/blog/'}); |