Skip to content

Commit

Permalink
[WPT] Add WPT for BFCache eviction after version change event (web-pl…
Browse files Browse the repository at this point in the history
…atform-tests#37186)

In the WPT added from https://crrev.com/c/3985294, add another section
that triggers versionchange event sent from the second document, which should
evict the BFCache page with open IndexedDB connection.

Bug: 1331187
Change-Id: Ife5aa8b73c7ecfef6a0cbd443378867d95f96655
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4060130
Reviewed-by: Fergal Daly <[email protected]>
Reviewed-by: Rakina Zata Amni <[email protected]>
Commit-Queue: Mingyu Lei <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1084281}

Co-authored-by: Mingyu Lei <[email protected]>
  • Loading branch information
chromium-wpt-export-bot and lozy219 authored Dec 20, 2022
1 parent 6649a76 commit 07e9b12
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
24 changes: 15 additions & 9 deletions IndexedDB/back-forward-cache-open-connection.window.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// META: title=BFCache support test for page with open IndexedDB connection
// META: title=Testing BFCache support for page with open IndexedDB connection, and eviction behavior when receiving versionchange event.
// META: script=/common/dispatcher/dispatcher.js
// META: script=/common/utils.js
// META: script=resources/support.js
// META: script=/html/browsers/browsing-the-web/back-forward-cache/resources/rc-helper.js
// META: script=/html/browsers/browsing-the-web/remote-context-helper/resources/remote-context-helper.js

Expand All @@ -13,13 +14,18 @@ promise_test(async t => {
const rc1 = await rcHelper.addWindow(
/*config=*/ null, /*options=*/ {features: 'noopener'});

await rc1.executeScript(() => {
// Create an IndexedDB database.
const db = indexedDB.open(/*name=*/ 'test_idb', /*version=*/ 1);
db.onupgradeneeded = () => {
db.result.createObjectStore('store');
};
});

await createIndexedDBForTesting(rc1, 'test_idb', 1);
await assertBFCache(rc1, /*shouldRestoreFromBFCache=*/ true);

// The page is ensured to be eligible for BFCache even with open connection,
// otherwise the previous assertion will fail with PRECONDITION_FAILED.
// Now we can test if the versionchange event will evict the BFCache.
await createIndexedDBForTesting(rc1, 'test_idb_2', 1);

const rc2 = await rc1.navigateToNew();
// Create an IndexedDB database with higher version.
await createIndexedDBForTesting(rc2, 'test_idb_2', 2);
await rc2.historyBack();
// The previous page receiving versionchange event should be evicted.
await assert_not_bfcached(rc1);
});
14 changes: 14 additions & 0 deletions IndexedDB/resources/support.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,17 @@ function barrier_func(count, func) {
func();
};
}

// Create an IndexedDB by executing script on the given remote context
// with |dbName| and |version|.
async function createIndexedDBForTesting(rc, dbName, version) {
await rc.executeScript((dbName, version) => {
let request = indexedDB.open(dbName, version);
request.onupgradeneeded = () => {
request.result.createObjectStore('store');
}
request.onversionchange = () => {
fail(t, 'unexpectedly received versionchange event.');
}
}, [dbName, version]);
}

0 comments on commit 07e9b12

Please sign in to comment.