|
| 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 | + |
| 7 | +'use strict'; |
| 8 | + |
| 9 | +promise_test(async t => { |
| 10 | + const rcHelper = new RemoteContextHelper(); |
| 11 | + |
| 12 | + // Open a window with noopener so that BFCache will work. |
| 13 | + const rc1 = await rcHelper.addWindow( |
| 14 | + /*config=*/ null, /*options=*/ {features: 'noopener'}); |
| 15 | + |
| 16 | + await rc1.executeScript(() => { |
| 17 | + // Create an IndexedDB database and the object store named `store` as the |
| 18 | + // test scope for the transaction later on. |
| 19 | + const db = indexedDB.open(/*name=*/ 'test_idb', /*version=*/ 1); |
| 20 | + db.onupgradeneeded = () => { |
| 21 | + db.result.createObjectStore('store'); |
| 22 | + }; |
| 23 | + addEventListener('pagehide', () => { |
| 24 | + let transaction = db.result.transaction(['store'], 'readwrite'); |
| 25 | + let store = transaction.objectStore('store'); |
| 26 | + store.put("key", "value"); |
| 27 | + |
| 28 | + // Queue a request to close the connection, while keeping the transaction |
| 29 | + // open, so that the BFCache eligibility will be determined solely by the |
| 30 | + // pending transaction. |
| 31 | + db.result.close(); |
| 32 | + }); |
| 33 | + }); |
| 34 | + |
| 35 | + await assertBFCache(rc1, /*shouldRestoreFromBFCache=*/ true); |
| 36 | +}); |
0 commit comments