Bug 1943761 - Add class alignment to the mozsearch analysis file. r=asuth
[gecko.git] / dom / quota / test / xpcshell / test_artificialFailure.js
blobc09598115be29b00b806d55fa407ea58c38539dd
1 /**
2 * Any copyright is dedicated to the Public Domain.
3 * http://creativecommons.org/publicdomain/zero/1.0/
4 */
6 const { PrincipalUtils } = ChromeUtils.importESModule(
7 "resource://testing-common/dom/quota/test/modules/PrincipalUtils.sys.mjs"
8 );
9 const { QuotaUtils } = ChromeUtils.importESModule(
10 "resource://testing-common/dom/quota/test/modules/QuotaUtils.sys.mjs"
12 const { SimpleDBUtils } = ChromeUtils.importESModule(
13 "resource://testing-common/dom/simpledb/test/modules/SimpleDBUtils.sys.mjs"
16 async function testSteps() {
17 const categories = [
18 Ci.nsIQuotaArtificialFailure.CATEGORY_NONE,
19 Ci.nsIQuotaArtificialFailure.CATEGORY_INITIALIZE_ORIGIN,
21 const principal = PrincipalUtils.createPrincipal("https://example.com");
22 const name = "foo";
24 for (let category of categories) {
25 info("Creating database");
28 const connection = SimpleDBUtils.createConnection(principal);
30 const openRequest = connection.open(name);
31 await SimpleDBUtils.requestFinished(openRequest);
33 const closeRequest = connection.close();
34 await SimpleDBUtils.requestFinished(closeRequest);
37 info("Resetting storage");
40 const request = Services.qms.reset();
41 await QuotaUtils.requestFinished(request);
44 info("Opening database");
46 const ex = await QuotaUtils.withArtificialFailures(
47 category,
48 /* probability */ 100,
49 Cr.NS_ERROR_FILE_ACCESS_DENIED,
50 async function () {
51 const connection = SimpleDBUtils.createConnection(principal);
52 const request = connection.open(name);
53 try {
54 await SimpleDBUtils.requestFinished(request);
55 return null;
56 } catch (ex) {
57 return ex;
62 if (category == Ci.nsIQuotaArtificialFailure.CATEGORY_NONE) {
63 Assert.ok(!ex, "Should not have thrown");
64 } else {
65 Assert.ok(ex, "Should have thrown");
66 Assert.strictEqual(
67 ex.resultCode,
68 // NS_ERROR_FILE_ACCESS_DENIED is mapped to NS_ERROR_FAILURE during error
69 // propagation.
70 NS_ERROR_FAILURE,
71 "Threw right result code"
75 info("Clearing storage");
78 const request = Services.qms.clear();
79 await QuotaUtils.requestFinished(request);