tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

evict-on-message.tentative.window.js (1714B)


      1 // META: title=BroadcastChannel message while in bfcache should evict the entry.
      2 // META: script=/common/dispatcher/dispatcher.js
      3 // META: script=/common/get-host-info.sub.js
      4 // META: script=/common/utils.js
      5 // META: script=/html/browsers/browsing-the-web/back-forward-cache/resources/rc-helper.js
      6 // META: script=/html/browsers/browsing-the-web/remote-context-helper/resources/remote-context-helper.js
      7 // META: script=/html/browsers/browsing-the-web/remote-context-helper-tests/resources/test-helper.js
      8 
      9 'use strict';
     10 
     11 promise_test(async t => {
     12  const rcHelper = new RemoteContextHelper();
     13  // Open a window with noopener so that BFCache will work.
     14  const rc1 = await rcHelper.addWindow(
     15      /*extraConfig=*/ {}, /*options=*/ {features: 'noopener'});
     16  await rc1.executeScript(() => {
     17    const channel = new BroadcastChannel('foo');
     18    channel.addEventListener('message', event => {
     19      channel.postMessage('Message received: ' + event.data);
     20    });
     21  });
     22  await prepareForBFCache(rc1);
     23  const newRemoteContextHelper = await rc1.navigateToNew();
     24  await assertSimplestScriptRuns(newRemoteContextHelper);
     25 
     26  // Post a message to a channel in bfcache. This should trigger eviction.
     27  const channel = new BroadcastChannel('foo');  // Access shared channel
     28  channel.postMessage('Sending a message should evict a bfcache entry.');
     29 
     30  await newRemoteContextHelper.historyBack();
     31 
     32  // It's possible that the pages with open broadcastchannel are not allowed
     33  // into bfcache. Set preconditionFailReasons to catch that case. Otherwise
     34  // expect the eviction reason.
     35  await assertNotRestoredFromBFCache(
     36      rc1, ['broadcastchannel-message'],
     37      /*preconditonFailReasons=*/['broadcastchannel']);
     38 });