pagehide-event-handler-microtasks.window.js (1192B)
1 // META: title=Assure microtasks posted by pagehide event handler are dispatched as page is BFCached 2 // META: script=/common/dispatcher/dispatcher.js 3 // META: script=/common/utils.js 4 // META: script=./resources/test-helper.js 5 6 'use strict'; 7 8 promise_test(async t => { 9 const uuid = token(); 10 const url = remoteExecutorUrl(uuid, {protocol: 'http:'}); 11 const win = window.open(url, '_blank', 'noopener'); 12 const context = new RemoteContext(uuid); 13 14 // Navigate within the same eval, as (1) we can't navigate externally 15 // because of potential race against the eval, and (2) we can't navigate 16 // as a separate eval step as it would block on this one returning, 17 // which would only happen upon `pagehide`. 18 const {persisted} = await context.execute_script( 19 () => new Promise(resolve => { 20 window.addEventListener('pagehide', async (event) => { 21 await Promise.resolve(); // ... so the rest will run as a microtask. 22 resolve({persisted: event.persisted}); 23 }, false); 24 location.href += '&navigated'; 25 })); 26 27 assert_true(persisted); // Validate we're BFCached. 28 }, 'Assure microtasks posted by pagehide event handler are dispatched');