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

/**
 * This test is mainly to verify that init, initTemporaryStorage,
 * getUsageForPrincipal and clearStoragesForPrincipal are able to ignore
 * unknown files and directories in the storage/default directory and its
 * subdirectories.
 */
async function testSteps() {
  const principal = getPrincipal("http://example.com");

  async function testFunctionality(testFunction) {
    const modes = [
      {
        initializedStorage: false,
        initializedTemporaryStorage: false,
      },
      {
        initializedStorage: true,
        initializedTemporaryStorage: false,
      },
      {
        initializedStorage: true,
        initializedTemporaryStorage: true,
      },
    ];

    for (const mode of modes) {
      info("Clearing");

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

      info("Installing package");

      // The profile contains unknown files and unknown directories placed
      // across the repositories, origin directories and client directories.
      // The file make_unknownFiles.js was run locally, specifically it was
      // temporarily enabled in xpcshell.ini and then executed:
      // mach test --interactive dom/quota/test/xpcshell/make_unknownFiles.js
      installPackage("unknownFiles_profile");

      if (mode.initializedStorage) {
        info("Initializing storage");

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

      if (mode.initializedTemporaryStorage) {
        info("Initializing temporary storage");

        request = initTemporaryStorage();
        await requestFinished(request);
      }

      info("Verifying initialization status");

      await verifyInitializationStatus(
        mode.initializedStorage,
        mode.initializedTemporaryStorage
      );

      await testFunction(
        mode.initializedStorage,
        mode.initializedTemporaryStorage
      );

      info("Clearing");

      request = clear();
      await requestFinished(request);
    }
  }

  // init and initTemporaryStorage functionality is tested in the
  // testFunctionality function as part of the multi mode testing

  info("Testing getUsageForPrincipal functionality");

  await testFunctionality(async function() {
    info("Getting origin usage");

    request = getOriginUsage(principal);
    await requestFinished(request);

    ok(
      request.result instanceof Ci.nsIQuotaOriginUsageResult,
      "The result is nsIQuotaOriginUsageResult instance"
    );
    is(request.result.usage, 115025, "Correct total usage");
    is(request.result.fileUsage, 200, "Correct file usage");
  });

  info("Testing clearStoragesForPrincipal functionality");

  await testFunctionality(async function() {
    info("Clearing origin");

    request = clearOrigin(principal, "default");
    await requestFinished(request);
  });
}