Skip to content

Commit af481d1

Browse files
committed
fixup! lib,src: implement QuotaExceededError as DOMException-derived interface
1 parent 6ac0aa3 commit af481d1

File tree

1 file changed

+26
-27
lines changed

1 file changed

+26
-27
lines changed

test/parallel/test-webstorage.js

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -93,34 +93,33 @@ test('localStorage is persisted if it is used', async () => {
9393
describe('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, /filled/);
109-
assert.match(cp.stderr, /QuotaExceededError: Setting the value exceeded the quota/);
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, /filled/);
122-
assert.match(cp.stderr, /QuotaExceededError/);
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

126125
test('disabled with --no-webstorage', async () => {

0 commit comments

Comments
 (0)