@@ -4,7 +4,7 @@ const tmpdir = require('../common/tmpdir');
4
4
const assert = require ( 'node:assert' ) ;
5
5
const { join } = require ( 'node:path' ) ;
6
6
const { readdir } = require ( 'node:fs/promises' ) ;
7
- const { test } = require ( 'node:test' ) ;
7
+ const { test, describe } = require ( 'node:test' ) ;
8
8
const { spawnPromisified } = common ;
9
9
let cnt = 0 ;
10
10
@@ -109,3 +109,39 @@ test('localStorage is persisted if it is used', async () => {
109
109
assert . strictEqual ( cp . code , 0 ) ;
110
110
assert . match ( cp . stdout , / b a r b a z / ) ;
111
111
} ) ;
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 , / f i l l e d / ) ;
131
+ assert . match ( cp . stderr , / Q u o t a E x c e e d e d E r r o r : S e t t i n g t h e v a l u e e x c e e d e d t h e q u o t a / ) ;
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 , / f i l l e d / ) ;
145
+ assert . match ( cp . stderr , / Q u o t a E x c e e d e d E r r o r / ) ;
146
+ } ) ;
147
+ } ) ;
0 commit comments