summaryrefslogtreecommitdiffstats
path: root/dom/quota/test/xpcshell/test_clearStoragesForOriginAttributesPattern.js
blob: 096cf2be7050c43f86a439fc1e64de04b02597b0 (plain)
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
/**
 * Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/
 */

async function testSteps() {
  const baseRelativePath = "storage/default";
  const userContextForRemoval = 2;

  const origins = [
    {
      userContextId: 1,
      baseDirName: "https+++example.com",
    },

    {
      userContextId: userContextForRemoval,
      baseDirName: "https+++example.com",
    },

    // TODO: Uncomment this once bug 1638831 is fixed.
    /*
    {
      userContextId: userContextForRemoval,
      baseDirName: "https+++example.org",
    },
    */
  ];

  function getOriginDirectory(origin) {
    return getRelativeFile(
      `${baseRelativePath}/${origin.baseDirName}^userContextId=` +
        `${origin.userContextId}`
    );
  }

  let request = init();
  await requestFinished(request);

  for (const origin of origins) {
    const directory = getOriginDirectory(origin);
    directory.create(Ci.nsIFile.DIRECTORY_TYPE, parseInt("0755", 8));
  }

  request = Services.qms.clearStoragesForOriginAttributesPattern(
    `{ "userContextId": ${userContextForRemoval} }`
  );
  await requestFinished(request);

  for (const origin of origins) {
    const directory = getOriginDirectory(origin);
    if (origin.userContextId === userContextForRemoval) {
      ok(!directory.exists(), "Origin directory should have been removed");
    } else {
      ok(directory.exists(), "Origin directory shouldn't have been removed");
    }
  }
}