1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 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 (e) {
ok(true, "Should have thrown");
Assert.equal(
e.resultCode,
NS_ERROR_FILE_NO_DEVICE_SPACE,
"Threw right result 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();
}
|