tor-browser

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

back-forward-cache-open-transaction.window.js (1738B)


      1 // META: title=BFCache support test for page with open IndexedDB transaction
      2 // META: script=/common/dispatcher/dispatcher.js
      3 // META: script=/common/utils.js
      4 // META: script=/html/browsers/browsing-the-web/back-forward-cache/resources/rc-helper.js
      5 // META: script=/html/browsers/browsing-the-web/remote-context-helper/resources/remote-context-helper.js
      6 // META: timeout=long
      7 
      8 'use strict';
      9 
     10 promise_test(async t => {
     11  const rcHelper = new RemoteContextHelper();
     12 
     13  // Open a window with noopener so that BFCache will work.
     14  const rc1 = await rcHelper.addWindow(
     15      /*config=*/ null, /*options=*/ {features: 'noopener'});
     16 
     17  const dbname = t.name + Math.random();
     18  await rc1.executeScript((dbname) => {
     19    return new Promise(resolve => {
     20      // Create an IndexedDB database and the object store named `store` as the
     21      // test scope for the transaction later on.
     22      const db = indexedDB.open(/*name=*/ dbname, /*version=*/ 1);
     23      db.onupgradeneeded = () => {
     24        db.result.createObjectStore('store');
     25        addEventListener('pagehide', () => {
     26          let transaction = db.result.transaction(['store'], 'readwrite');
     27          let store = transaction.objectStore('store');
     28          store.put('key', 'value');
     29 
     30          // Queue a request to close the connection, while keeping the transaction
     31          // open, so that the BFCache eligibility will be determined solely by the
     32          // pending transaction.
     33          db.result.close();
     34        });
     35        // Only resolve the promise when the connection is established
     36        // and the `pagehide` event listener is added.
     37        resolve();
     38      };
     39    });
     40  }, [dbname]);
     41 
     42  await assertBFCacheEligibility(rc1, /*shouldRestoreFromBFCache=*/ true);
     43 });