restriction-notification.https.html (3036B)
1 <!DOCTYPE html> 2 <!-- 3 https://wicg.github.io/nav-speculation/prerendering.html#patch-notifications 4 TODO(https://crbug.com/1198110): Add the following tests: 5 * Test the constructor returns synchronously while the creation of the 6 notification is deferred until activation. 7 --> 8 <title>Access to the Notification API before and after prerender activation</title> 9 <meta name="timeout" content="long"> 10 <script src="/resources/testharness.js"></script> 11 <script src="/resources/testharnessreport.js"></script> 12 <script src="/resources/testdriver.js"></script> 13 <script src="/resources/testdriver-vendor.js"></script> 14 <script src="/common/utils.js"></script> 15 <script src="../resources/utils.js"></script> 16 <script src="resources/utils.js"></script> 17 18 <body> 19 <script> 20 setup(() => assertSpeculationRulesIsSupported()); 21 22 promise_test(async t => { 23 const uid = token(); 24 const bc = new PrerenderChannel('test-channel', uid); 25 t.add_cleanup(_ => bc.close()); 26 27 await test_driver.set_permission({ 28 name: 'notifications' 29 }, 'granted'); 30 const gotMessage = new Promise(resolve => { 31 bc.addEventListener('message', e => { 32 resolve(e.data); 33 }, { 34 once: true 35 }); 36 }); 37 const url = `resources/notification-on-activation.html?uid=${uid}`; 38 window.open(url, '_blank', 'noopener'); 39 40 const result = await gotMessage; 41 assert_equals(result, 'notification showed'); 42 }, `it is allowed to access the notification API in the prerenderingchange 43 event`); 44 45 promise_test(async t => { 46 const uid = token(); 47 const bc = new PrerenderChannel('test-channel', uid); 48 t.add_cleanup(_ => bc.close()); 49 50 await test_driver.set_permission({ 51 name: 'notifications' 52 }, 'granted'); 53 const gotMessage = new Promise(resolve => { 54 bc.addEventListener('message', e => { 55 resolve(e.data); 56 }, { 57 once: true 58 }); 59 }); 60 const url = `resources/notification-before-activation.html?uid=${uid}`; 61 window.open(url, '_blank', 'noopener'); 62 63 const result = await gotMessage; 64 65 const expected = [{ 66 event: 'Notification permission is default', 67 prerendering: true 68 }, 69 { 70 event: 'started waiting notification', 71 prerendering: true 72 }, 73 { 74 event: 'prerendering change', 75 prerendering: false 76 }, 77 { 78 event: 'permission was granted', 79 prerendering: false 80 }, 81 { 82 event: 'notification displayed', 83 prerendering: false 84 }, 85 { 86 event: 'finished waiting notification', 87 prerendering: false 88 }, 89 ]; 90 91 length = Math.min(result.length, expected.length); 92 let i = 0; 93 for (i = 0; i < length; i++) { 94 assert_equals(result[i].event, expected[i].event, `event[${i}]`); 95 assert_equals(result[i].prerendering, expected[i].prerendering, 96 `prerendering[${i}]`); 97 } 98 assert_equals(i, expected.length); 99 100 // Send a close signal to PrerenderEventCollector on the prerendered page. 101 new PrerenderChannel('close', uid).postMessage(''); 102 }, 103 `Displaying Notification should be deferred until the prerendered page is 104 activated`); 105 </script>