node/test/fixtures/wpt/webstorage/eventTestHarness.js
cjihrig 3d09e579d3 deps,lib,src: add experimental web storage
This commit introduces an experimental implementation of the Web
Storage API using SQLite as the backing data store.

PR-URL: https://github.com/nodejs/node/pull/52435
Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
2024-06-14 18:40:04 +00:00

54 lines
1.5 KiB
JavaScript

storageEventList = [];
iframe = document.createElement("IFRAME");
document.body.appendChild(iframe);
function runAfterNStorageEvents(callback, expectedNumEvents)
{
countStorageEvents(callback, expectedNumEvents, 0)
}
function countStorageEvents(callback, expectedNumEvents, times)
{
function onTimeout()
{
var currentCount = storageEventList.length;
if (currentCount == expectedNumEvents) {
callback();
} else if (currentCount > expectedNumEvents) {
msg = "got at least " + currentCount + ", expected only " + expectedNumEvents + " events";
callback(msg);
} else if (times > 50) {
msg = "Timeout: only got " + currentCount + ", expected " + expectedNumEvents + " events";
callback(msg);
} else {
countStorageEvents(callback, expectedNumEvents, times+1);
}
}
setTimeout(onTimeout, 20);
}
function clearStorage(storageName, callback)
{
if (window[storageName].length === 0) {
storageEventList = [];
setTimeout(callback, 0);
} else {
window[storageName].clear();
runAfterNStorageEvents(function() {
storageEventList = [];
callback();
}, 1);
}
}
function testStorages(testCallback)
{
testCallback("sessionStorage");
var hit = false;
add_result_callback(function() {
if (!hit) {
hit = true;
testCallback("localStorage");
}
});
}