test_persistent_notification_restart.py (1705B)
1 # This Source Code Form is subject to the terms of the Mozilla Public 2 # License, v. 2.0. If a copy of the MPL was not distributed with this 3 # file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 5 # Test for bug 1881043: verify that persistent notifications are still 6 # persisted when restarting the browser. 7 8 from marionette_harness import MarionetteTestCase 9 10 11 class PersistentNotificationRestartTestCase(MarionetteTestCase): 12 def setUp(self): 13 super().setUp() 14 15 install_url = self.marionette.absolute_url( 16 "serviceworker/install_serviceworker.html" 17 ) 18 self.marionette.navigate(install_url) 19 20 self.marionette.set_permission({"name": "notifications"}, "granted") 21 self.marionette.execute_script( 22 """ 23 return (async () => { 24 const reg = await navigator.serviceWorker.ready; 25 const notifications = await reg.getNotifications(); 26 for (const n of notifications) { 27 n.close(); 28 } 29 await reg.showNotification("foo"); 30 })(); 31 """ 32 ) 33 34 def test_stored_notification_after_restart(self): 35 self.assertTrue(self.is_notification_stored()) 36 self.marionette.restart() 37 self.assertTrue(self.is_notification_stored()) 38 39 def is_notification_stored(self): 40 return self.marionette.execute_script( 41 """ 42 return (async () => { 43 const reg = await navigator.serviceWorker.getRegistration(); 44 const notifications = await reg.getNotifications(); 45 return notifications.length > 0; 46 })() 47 """ 48 )