@@ -93,34 +93,33 @@ test('localStorage is persisted if it is used', async () => {
9393describe ( 'webstorage quota for localStorage and sessionStorage' , ( ) => {
9494 const MAX_STORAGE_SIZE = 10 * 1024 * 1024 ;
9595
96- test ( 'localStorage can store and retrieve a max of 10 MB quota' , async ( ) => {
97- const localStorageFile = nextLocalStorage ( ) ;
98- const cp = await spawnPromisified ( process . execPath , [
99- '--localstorage-file' , localStorageFile ,
96+ for ( const storage of [ 'localStorage' , 'sessionStorage' ] ) {
97+ test ( `${ storage } can store a max of 10 MB quota` , async ( ) => {
98+ const args = [ ] ;
99+ if ( storage === 'localStorage' ) {
100+ args . push ( '--localstorage-file' , nextLocalStorage ( ) ) ;
101+ }
100102 // Each character is 2 bytes
101- '-pe' , `
102- localStorage['a'.repeat(${ MAX_STORAGE_SIZE } / 2)] = '';
103- console.error('filled');
104- localStorage.anything = 'should fail';
105- ` ,
106- ] ) ;
107-
108- assert . match ( cp . stderr , / f i l l e d / ) ;
109- 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 / ) ;
110- } ) ;
111-
112- test ( 'sessionStorage can store a max of 10 MB quota' , async ( ) => {
113- const cp = await spawnPromisified ( process . execPath , [
114- // Each character is 2 bytes
115- '-pe' , `sessionStorage['a'.repeat(${ MAX_STORAGE_SIZE } / 2)] = '';
116- console.error('filled');
117- sessionStorage.anything = 'should fail';
118- ` ,
119- ] ) ;
120-
121- assert . match ( cp . stderr , / f i l l e d / ) ;
122- assert . match ( cp . stderr , / Q u o t a E x c e e d e d E r r o r / ) ;
123- } ) ;
103+ args . push ( '-e' , `
104+ const assert = require('assert');
105+ ${ storage } ['a'.repeat(${ MAX_STORAGE_SIZE } / 2)] = '';
106+ assert.throws(
107+ () => { ${ storage } .anything = 'should fail'; },
108+ (err) => {
109+ assert.strictEqual(err.name, 'QuotaExceededError');
110+ assert.strictEqual(err.code, 22);
111+ assert(err instanceof DOMException);
112+ assert(err instanceof QuotaExceededError);
113+ assert.strictEqual(err.quota, null);
114+ assert.strictEqual(err.requested, null);
115+ return true;
116+ },
117+ );
118+ ` ) ;
119+ const cp = await spawnPromisified ( process . execPath , args ) ;
120+ assert . strictEqual ( cp . code , 0 ) ;
121+ } ) ;
122+ }
124123} ) ;
125124
126125test ( 'disabled with --no-webstorage' , async ( ) => {
0 commit comments