Skip to content

Commit 5dbff81

Browse files
jakecastellitargos
authored andcommitted
test: add coverage for webstorage quota
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>
1 parent 1cafefd commit 5dbff81

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

test/parallel/test-webstorage.js

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const tmpdir = require('../common/tmpdir');
44
const assert = require('node:assert');
55
const { join } = require('node:path');
66
const { readdir } = require('node:fs/promises');
7-
const { test } = require('node:test');
7+
const { test, describe } = require('node:test');
88
const { spawnPromisified } = common;
99
let cnt = 0;
1010

@@ -109,3 +109,39 @@ test('localStorage is persisted if it is used', async () => {
109109
assert.strictEqual(cp.code, 0);
110110
assert.match(cp.stdout, /barbaz/);
111111
});
112+
113+
114+
describe('webstorage quota for localStorage and sessionStorage', () => {
115+
const MAX_STORAGE_SIZE = 10 * 1024 * 1024;
116+
117+
test('localStorage can store and retrieve a max of 10 MB quota', async () => {
118+
const localStorageFile = nextLocalStorage();
119+
const cp = await spawnPromisified(process.execPath, [
120+
'--experimental-webstorage',
121+
'--localstorage-file', localStorageFile,
122+
// Each character is 2 bytes
123+
'-pe', `
124+
localStorage['a'.repeat(${MAX_STORAGE_SIZE} / 2)] = '';
125+
console.error('filled');
126+
localStorage.anything = 'should fail';
127+
`,
128+
]);
129+
130+
assert.match(cp.stderr, /filled/);
131+
assert.match(cp.stderr, /QuotaExceededError: Setting the value exceeded the quota/);
132+
});
133+
134+
test('sessionStorage can store a max of 10 MB quota', async () => {
135+
const cp = await spawnPromisified(process.execPath, [
136+
'--experimental-webstorage',
137+
// Each character is 2 bytes
138+
'-pe', `sessionStorage['a'.repeat(${MAX_STORAGE_SIZE} / 2)] = '';
139+
console.error('filled');
140+
sessionStorage.anything = 'should fail';
141+
`,
142+
]);
143+
144+
assert.match(cp.stderr, /filled/);
145+
assert.match(cp.stderr, /QuotaExceededError/);
146+
});
147+
});

0 commit comments

Comments
 (0)