Skip to content

Commit cfb1499

Browse files
janvargaservo-wpt-sync
authored andcommitted
wpt: Add tests for independent localStorage/sessionStorage quotas
The new tests verify that exhausting the quota of one Web Storage area does not significantly reduce the capacity available to the other one. Each test first measures the baseline capacity of one storage type by filling it until QuotaExceededError is thrown, then clears it, exhausts the other storage type, and measures the capacity again. Independence is verified by requiring that the second measurement remains broadly comparable to the baseline rather than collapsing to near-zero capacity, which would indicate a shared quota. Two directional tests are added: - sessionStorage retains comparable quota after localStorage exhaustion - localStorage retains comparable quota after sessionStorage exhaustion Gecko currently fails these new tests. This is consistent with the fact that the existing quota exhaustion tests also currently fail in Gecko. Signed-off-by: Jan Varga <[email protected]>
1 parent c66446b commit cfb1499

File tree

2 files changed

+86
-0
lines changed

2 files changed

+86
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
test(t => {
2+
localStorage.clear();
3+
sessionStorage.clear();
4+
5+
var key = "name";
6+
var val = "x".repeat(4 * 1024);
7+
8+
t.add_cleanup(() => {
9+
localStorage.clear();
10+
sessionStorage.clear();
11+
});
12+
13+
let indexBefore = 0;
14+
assert_throws_quotaexceedederror(() => {
15+
while (true) {
16+
localStorage.setItem("" + key + indexBefore, "" + val + indexBefore);
17+
indexBefore++;
18+
}
19+
}, null, null);
20+
21+
localStorage.clear();
22+
23+
let indexLocal = 0;
24+
assert_throws_quotaexceedederror(() => {
25+
while (true) {
26+
sessionStorage.setItem("" + key + indexLocal, "" + val + indexLocal);
27+
indexLocal++;
28+
}
29+
}, null, null);
30+
31+
let indexAfter = 0;
32+
assert_throws_quotaexceedederror(() => {
33+
while (true) {
34+
localStorage.setItem("" + key + indexAfter, "" + val + indexAfter);
35+
indexAfter++;
36+
}
37+
}, null, null);
38+
39+
assert_greater_than_equal(
40+
indexAfter,
41+
Math.floor(indexBefore / 2)
42+
);
43+
}, "localStorage retains comparable quota after sessionStorage exhaustion");
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
test(t => {
2+
sessionStorage.clear();
3+
localStorage.clear();
4+
5+
var key = "name";
6+
var val = "x".repeat(4 * 1024);
7+
8+
t.add_cleanup(() => {
9+
sessionStorage.clear();
10+
localStorage.clear();
11+
});
12+
13+
let indexBefore = 0;
14+
assert_throws_quotaexceedederror(() => {
15+
while (true) {
16+
sessionStorage.setItem("" + key + indexBefore, "" + val + indexBefore);
17+
indexBefore++;
18+
}
19+
}, null, null);
20+
21+
sessionStorage.clear();
22+
23+
let indexLocal = 0;
24+
assert_throws_quotaexceedederror(() => {
25+
while (true) {
26+
localStorage.setItem("" + key + indexLocal, "" + val + indexLocal);
27+
indexLocal++;
28+
}
29+
}, null, null);
30+
31+
let indexAfter = 0;
32+
assert_throws_quotaexceedederror(() => {
33+
while (true) {
34+
sessionStorage.setItem("" + key + indexAfter, "" + val + indexAfter);
35+
indexAfter++;
36+
}
37+
}, null, null);
38+
39+
assert_greater_than_equal(
40+
indexAfter,
41+
Math.floor(indexBefore / 2)
42+
);
43+
}, "sessionStorage retains comparable quota after localStorage exhaustion");

0 commit comments

Comments
 (0)