Skip to content

Commit

Permalink
test: add coverage for webstorage quota
Browse files Browse the repository at this point in the history
PR-URL: #53964
Refs: #53871
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
  • Loading branch information
jakecastelli authored and targos committed Aug 14, 2024
1 parent 1cafefd commit 5dbff81
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion test/parallel/test-webstorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const tmpdir = require('../common/tmpdir');
const assert = require('node:assert');
const { join } = require('node:path');
const { readdir } = require('node:fs/promises');
const { test } = require('node:test');
const { test, describe } = require('node:test');
const { spawnPromisified } = common;
let cnt = 0;

Expand Down Expand Up @@ -109,3 +109,39 @@ test('localStorage is persisted if it is used', async () => {
assert.strictEqual(cp.code, 0);
assert.match(cp.stdout, /barbaz/);
});


describe('webstorage quota for localStorage and sessionStorage', () => {
const MAX_STORAGE_SIZE = 10 * 1024 * 1024;

test('localStorage can store and retrieve a max of 10 MB quota', async () => {
const localStorageFile = nextLocalStorage();
const cp = await spawnPromisified(process.execPath, [
'--experimental-webstorage',
'--localstorage-file', localStorageFile,
// Each character is 2 bytes
'-pe', `
localStorage['a'.repeat(${MAX_STORAGE_SIZE} / 2)] = '';
console.error('filled');
localStorage.anything = 'should fail';
`,
]);

assert.match(cp.stderr, /filled/);
assert.match(cp.stderr, /QuotaExceededError: Setting the value exceeded the quota/);
});

test('sessionStorage can store a max of 10 MB quota', async () => {
const cp = await spawnPromisified(process.execPath, [
'--experimental-webstorage',
// Each character is 2 bytes
'-pe', `sessionStorage['a'.repeat(${MAX_STORAGE_SIZE} / 2)] = '';
console.error('filled');
sessionStorage.anything = 'should fail';
`,
]);

assert.match(cp.stderr, /filled/);
assert.match(cp.stderr, /QuotaExceededError/);
});
});

0 comments on commit 5dbff81

Please sign in to comment.