summaryrefslogtreecommitdiffstats
path: root/dom/quota/test/xpcshell/test_basics.js
blob: efe5aa7926cc4e1f1ab3dbe2c395718a10da32da (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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/**
 * Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/
 */

function* testSteps() {
  const storageFile = "storage.sqlite";

  const metadataFiles = [
    {
      path: "storage/permanent/chrome/.metadata",
      shouldExistAfterInit: false,
    },

    {
      path: "storage/permanent/chrome/.metadata-tmp",
      shouldExistAfterInit: false,
    },

    {
      path: "storage/permanent/chrome/.metadata-v2",
      shouldExistAfterInit: true,
    },

    {
      path: "storage/permanent/chrome/.metadata-v2-tmp",
      shouldExistAfterInit: false,
    },
  ];

  info("Clearing");

  clear(continueToNextStepSync);
  yield undefined;

  info("Verifying initialization status");

  verifyInitializationStatus(false, false).then(continueToNextStepSync);
  yield undefined;

  info("Getting usage");

  getCurrentUsage(grabUsageAndContinueHandler);
  let usage = yield undefined;

  Assert.equal(usage, 0, "Usage is zero");

  info("Verifying initialization status");

  verifyInitializationStatus(true, false).then(continueToNextStepSync);
  yield undefined;

  info("Clearing");

  clear(continueToNextStepSync);
  yield undefined;

  info("Verifying initialization status");

  verifyInitializationStatus(false, false).then(continueToNextStepSync);
  yield undefined;

  info("Installing package");

  // The profile contains just one empty IndexedDB database. The file
  // create_db.js in the package was run locally, specifically it was
  // temporarily added to xpcshell.ini and then executed:
  // mach xpcshell-test --interactive dom/quota/test/xpcshell/create_db.js
  installPackage("basics_profile");

  info("Getting usage");

  getCurrentUsage(grabUsageAndContinueHandler);
  usage = yield undefined;

  Assert.greater(usage, 0, "Usage is not zero");

  info("Verifying initialization status");

  verifyInitializationStatus(true, false).then(continueToNextStepSync);
  yield undefined;

  info("Clearing");

  clear(continueToNextStepSync);
  yield undefined;

  info("Checking storage file");

  let file = getRelativeFile(storageFile);

  let exists = file.exists();
  ok(!exists, "Storage file doesn't exist");

  info("Verifying initialization status");

  verifyInitializationStatus(false, false).then(continueToNextStepSync);
  yield undefined;

  info("Initializing");

  request = init(continueToNextStepSync);
  yield undefined;

  Assert.equal(request.resultCode, NS_OK, "Initialization succeeded");

  exists = file.exists();
  ok(exists, "Storage file does exist");

  info("Verifying initialization status");

  verifyInitializationStatus(true, false).then(continueToNextStepSync);
  yield undefined;

  info("Initializing origin");

  request = initPersistentOrigin(getCurrentPrincipal(), continueToNextStepSync);
  yield undefined;

  Assert.equal(request.resultCode, NS_OK, "Initialization succeeded");

  ok(request.result, "Origin directory was created");

  for (let metadataFile of metadataFiles) {
    file = getRelativeFile(metadataFile.path);

    exists = file.exists();

    if (metadataFile.shouldExistAfterInit) {
      ok(exists, "Metadata file does exist");
    } else {
      ok(!exists, "Metadata file doesn't exist");
    }
  }

  info("Verifying initialization status");

  verifyInitializationStatus(true, false).then(continueToNextStepSync);

  yield undefined;

  finishTest();
}