activate-after.https.window.js (2083B)
1 // META: script=/common/dispatcher/dispatcher.js 2 // META: script=/common/get-host-info.sub.js 3 // META: script=/common/utils.js 4 // META: script=/html/browsers/browsing-the-web/remote-context-helper/resources/remote-context-helper.js 5 // META: script=/html/browsers/browsing-the-web/back-forward-cache/resources/rc-helper.js 6 // META: script=/fetch/fetch-later/resources/fetch-later-helper.js 7 8 'use strict'; 9 10 parallelPromiseTest(async t => { 11 const uuid = token(); 12 const url = generateSetBeaconURL(uuid); 13 14 // Loads an iframe that creates a fetchLater request w/ short timeout. 15 const iframe = await loadScriptAsIframe(` 16 fetchLater("${url}", {activateAfter: 1000}); // 1s 17 `); 18 // Deletes the iframe to trigger deferred request sending. 19 document.body.removeChild(iframe); 20 21 // The iframe should have sent all requests. 22 await expectBeacon(uuid, {count: 1}); 23 }, 'fetchLater() sends out based on activateAfter.'); 24 25 parallelPromiseTest(async t => { 26 const uuid = token(); 27 const url = generateSetBeaconURL(uuid); 28 // Sets no option to test the default behavior when a document enters BFCache. 29 const helper = new RemoteContextHelper(); 30 // Opens a window with noopener so that BFCache will work. 31 const rc1 = await helper.addWindow( 32 /*config=*/ null, /*options=*/ {features: 'noopener'}); 33 34 // Creates a fetchLater request with short timeout. It should be sent out 35 // even if the document is then put into BFCache. 36 await rc1.executeScript(url => { 37 fetchLater(url, {activateAfter: 1000}); // 1s. 38 // Add a pageshow listener to stash the BFCache event. 39 window.addEventListener('pageshow', e => { 40 window.pageshowEvent = e; 41 }); 42 }, [url]); 43 // Navigates away to let page enter BFCache. 44 const rc2 = await rc1.navigateToNew(); 45 // Navigate back. 46 await rc2.historyBack(); 47 // Verify that the page was BFCached. 48 assert_true(await rc1.executeScript(() => { 49 return window.pageshowEvent.persisted; 50 })); 51 52 await expectBeacon(uuid, {count: 1}); 53 }, 'fetchLater() sends out based on activateAfter, even if document is in BFCache.');