Bug 1389390 - Add a test to verify a persisted origin won't be evicted; r=janv

Bug 1298392 introduced persist() to QuotaManager. This patch intends to verify
that normally the oldest origin will be evicted if the global limit is reached,
but if the oldest origin is persisted, then it won't be evicted.

--HG--
extra : rebase_source : 72fc4cda25545df28cb15bffd9255ba51fe628ab
This commit is contained in:
Tom Tung 2018-09-25 17:14:53 +02:00
Родитель 3f076abbbe
Коммит f84d16cecf
3 изменённых файлов: 83 добавлений и 0 удалений

Просмотреть файл

@ -10,6 +10,9 @@ function getBuffer(size)
return buffer;
}
// May be called for any size, but you should call getBuffer() if you know
// that size is big and that randomness is not necessary because it is
// noticeably faster.
function getRandomBuffer(size)
{
let buffer = getBuffer(size);

Просмотреть файл

@ -0,0 +1,79 @@
/**
* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
async function fillOrigin(principal, size) {
let database = getSimpleDatabase(principal);
let request = database.open("data");
await requestFinished(request);
try {
request = database.write(getBuffer(size));
await requestFinished(request);
ok(true, "Should not have thrown");
} catch (ex) {
ok(false, "Should not have thrown");
}
request = database.close();
await requestFinished(request);
}
/**
* This test is mainly to verify that normally the oldest origin will be
* evicted if the global limit is reached, but if the oldest origin is
* persisted, then it won't be evicted.
*/
async function testSteps()
{
// The group limit is calculated as 20% of the global limit and the minimum
// value of the group limit is 10 MB.
const groupLimitKB = 10 * 1024;
const globalLimitKB = groupLimitKB * 5;
setGlobalLimit(globalLimitKB);
let request = clear();
await requestFinished(request);
for (let persistOldestOrigin of [false, true]) {
info("Testing " + (persistOldestOrigin ? "with" : "without") +
" persisting the oldest origin");
info("Step 1: Filling six separate origins to reach the global limit " +
"and trigger eviction");
for (let index = 1; index <= 6; index++) {
let spec = "http://example" + index + ".com";
if (index == 1 && persistOldestOrigin) {
request = persist(getPrincipal(spec));
await requestFinished(request);
}
await fillOrigin(getPrincipal(spec), groupLimitKB * 1024);
}
info("Step 2: Verifying origin directories");
for (let index = 1; index <= 6; index++) {
let path = "storage/default/http+++example" + index + ".com";
let file = getRelativeFile(path);
if (index == (persistOldestOrigin ? 2 : 1)) {
ok(!file.exists(), "The origin directory " + path + " doesn't exist");
} else {
ok(file.exists(), "The origin directory " + path + " does exist");
}
}
request = clear();
await requestFinished(request);
}
resetGlobalLimit();
request = reset();
await requestFinished(request);
}

Просмотреть файл

@ -29,6 +29,7 @@ support-files =
[test_obsoleteOriginAttributesUpgrade.js]
[test_originAttributesUpgrade.js]
[test_persist.js]
[test_persist_eviction.js]
[test_persist_groupLimit.js]
[test_removeAppsUpgrade.js]
[test_removeLocalStorage.js]