Source code
Revision control
Copy as Markdown
Other Tools
Test Info:
- Manifest: dom/quota/test/xpcshell/xpcshell.toml
/**
* Any copyright is dedicated to the Public Domain.
*/
const { PrincipalUtils } = ChromeUtils.importESModule(
);
const { QuotaUtils } = ChromeUtils.importESModule(
);
const { SimpleDBUtils } = ChromeUtils.importESModule(
);
async function testSteps() {
const categories = [
Ci.nsIQuotaArtificialFailure.CATEGORY_NONE,
Ci.nsIQuotaArtificialFailure.CATEGORY_INITIALIZE_ORIGIN,
];
const name = "foo";
for (let category of categories) {
info("Creating database");
{
const connection = SimpleDBUtils.createConnection(principal);
const openRequest = connection.open(name);
await SimpleDBUtils.requestFinished(openRequest);
const closeRequest = connection.close();
await SimpleDBUtils.requestFinished(closeRequest);
}
info("Resetting storage");
{
const request = Services.qms.reset();
await QuotaUtils.requestFinished(request);
}
info("Opening database");
const ex = await QuotaUtils.withArtificialFailures(
category,
/* probability */ 100,
Cr.NS_ERROR_FILE_ACCESS_DENIED,
async function () {
const connection = SimpleDBUtils.createConnection(principal);
const request = connection.open(name);
try {
await SimpleDBUtils.requestFinished(request);
return null;
} catch (ex) {
return ex;
}
}
);
if (category == Ci.nsIQuotaArtificialFailure.CATEGORY_NONE) {
Assert.ok(!ex, "Should not have thrown");
} else {
Assert.ok(ex, "Should have thrown");
Assert.strictEqual(
ex.resultCode,
// NS_ERROR_FILE_ACCESS_DENIED is mapped to NS_ERROR_FAILURE during error
// propagation.
NS_ERROR_FAILURE,
"Threw right result code"
);
}
info("Clearing storage");
{
const request = Services.qms.clear();
await QuotaUtils.requestFinished(request);
}
}
}