Bug 1928092 - QM: Add a disabled test for a failure during temporary origin initialization; r=dom-storage-reviewers,asuth, a=dmeehan

Differential Revision: https://phabricator.services.mozilla.com/D227922
This commit is contained in:
Jan Varga 2024-11-10 11:17:22 +00:00
parent e5927b4e66
commit d1ed871969
2 changed files with 90 additions and 0 deletions

View File

@ -0,0 +1,87 @@
/**
* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
const { PrincipalUtils } = ChromeUtils.importESModule(
"resource://testing-common/dom/quota/test/modules/PrincipalUtils.sys.mjs"
);
const { QuotaUtils } = ChromeUtils.importESModule(
"resource://testing-common/dom/quota/test/modules/QuotaUtils.sys.mjs"
);
async function testSteps() {
const origin = "https://example.com";
const principal = PrincipalUtils.createPrincipal(origin);
info("Clearing");
{
const request = Services.qms.clear();
await QuotaUtils.requestFinished(request);
}
info("Initializing");
{
const request = Services.qms.init();
await QuotaUtils.requestFinished(request);
}
info("Initializing temporary storage");
{
const request = Services.qms.initTemporaryStorage();
await QuotaUtils.requestFinished(request);
}
info("Initializing origin");
const ex = await QuotaUtils.withArtificialFailures(
Ci.nsIQuotaArtificialFailure.CATEGORY_CREATE_DIRECTORY_METADATA2,
/* probability */ 100,
Cr.NS_ERROR_UNEXPECTED,
async function () {
const request = Services.qms.initializeTemporaryOrigin(
"default",
principal,
/* aCreateIfNonExistent */ true
);
try {
await QuotaUtils.requestFinished(request);
return null;
} catch (ex) {
return ex;
}
}
);
Assert.ok(ex, "Should have thrown");
Assert.strictEqual(
ex.resultCode,
NS_ERROR_UNEXPECTED,
"Threw right result code"
);
info("Listing origins");
const origins = await (async function () {
const request = Services.qms.listOrigins();
const result = await QuotaUtils.requestFinished(request);
return result;
})();
Assert.equal(origins.length, 1, "Returned one origin");
Assert.equal(origins[0], origin, "Returned correct origin");
info("Listing cached origins");
const cachedOrigins = await (async function () {
const request = Services.qms.listCachedOrigins();
const result = await QuotaUtils.requestFinished(request);
return result;
})();
Assert.equal(cachedOrigins.length, 1, "Returned one origin");
Assert.equal(cachedOrigins[0], origin, "Returned correct origin");
}

View File

@ -89,6 +89,9 @@ skip-if = ["condprof"] # frequent perma fail, then goes away.
["test_initializeTemporaryOrigin.js"]
["test_initializeTemporaryOrigin_failure.js"]
skip-if = ["true"]
["test_listCachedOrigins.js"]
["test_listOrigins.js"]