Bug 1493908 - Part 2: Add a test to verify that persisted origins are not constrained by the group limit; r=asuth

This commit is contained in:
Jan Varga 2018-09-27 23:25:43 +02:00
Родитель 8fd43abb04
Коммит c30332cd26
3 изменённых файлов: 122 добавлений и 0 удалений

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

@ -7,6 +7,7 @@ const NS_OK = Cr.NS_OK;
const NS_ERROR_FAILURE = Cr.NS_ERROR_FAILURE;
const NS_ERROR_UNEXPECTED = Cr.NS_ERROR_UNEXPECTED;
const NS_ERROR_STORAGE_BUSY = Cr.NS_ERROR_STORAGE_BUSY;
const NS_ERROR_FILE_NO_DEVICE_SPACE = Cr.NS_ERROR_FILE_NO_DEVICE_SPACE;
function is(a, b, msg)
{
@ -96,6 +97,17 @@ function resetTesting()
SpecialPowers.clearUserPref("dom.simpleDB.enabled");
}
function setGlobalLimit(globalLimit)
{
SpecialPowers.setIntPref("dom.quotaManager.temporaryStorage.fixedLimit",
globalLimit);
}
function resetGlobalLimit()
{
SpecialPowers.clearUserPref("dom.quotaManager.temporaryStorage.fixedLimit");
}
function init(callback)
{
let request = SpecialPowers._getQuotaManager().init();
@ -335,6 +347,10 @@ var SpecialPowers = {
this._getPrefs().setBoolPref(prefName, value);
},
setIntPref: function(prefName, value) {
this._getPrefs().setIntPref(prefName, value);
},
clearUserPref: function(prefName) {
this._getPrefs().clearUserPref(prefName);
},

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

@ -0,0 +1,105 @@
/**
* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
/**
* This test is mainly to verify that persisted origins are not constrained by
* the group limit. It consits of these steps:
* - Set the limits as small as our limits allow. This does result in needing
* to perform 10 megs of writes which is a lot for a test but not horrible.
* - Create databases for 2 origins under the same group.
* - Have the foo2 origin use up the shared group quota.
* - Verify neither origin can write additional data (via a single byte write).
* - Do navigator.storage.persist() for that foo2 origin.
* - Verify that both origins can now write an additional byte. This
* demonstrates that:
* - foo2 no longer counts against the group limit at all since foo1 can
* write a byte.
* - foo2 is no longer constrained by the group limit itself.
*/
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;
const urls = [
"http://foo1.example.com",
"http://foo2.example.com",
];
const foo2Index = 1;
let index;
info("Setting limits");
setGlobalLimit(globalLimitKB);
let request = clear();
await requestFinished(request);
info("Opening databases");
let databases = [];
for (index = 0; index < urls.length; index++) {
let database = getSimpleDatabase(getPrincipal(urls[index]));
request = database.open("data");
await requestFinished(request);
databases.push(database);
}
info("Filling up the whole group");
try {
request = databases[foo2Index].write(new ArrayBuffer(groupLimitKB * 1024));
await requestFinished(request);
ok(true, "Should not have thrown");
} catch(ex) {
ok(false, "Should not have thrown");
}
info("Verifying no more data can be written");
for (index = 0; index < urls.length; index++) {
try {
request = databases[index].write(new ArrayBuffer(1));
await requestFinished(request);
ok(false, "Should have thrown");
} catch(ex) {
ok(true, "Should have thrown");
ok(ex == NS_ERROR_FILE_NO_DEVICE_SPACE, "Threw right code");
}
}
info("Persisting origin");
request = persist(getPrincipal(urls[foo2Index]));
await requestFinished(request);
info("Verifying more data data can be written");
for (index = 0; index < urls.length; index++) {
try {
request = databases[index].write(new ArrayBuffer(1));
await requestFinished(request);
ok(true, "Should not have thrown");
} catch(ex) {
ok(false, "Should not have thrown");
}
}
info("Closing databases");
for (index = 0; index < urls.length; index++) {
request = databases[index].close();
await requestFinished(request);
}
finishTest();
}

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

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