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

async function testSteps() {
  const origins = [
    "https://example.com",
    "https://localhost",
    "https://www.mozilla.org",
  ];

  function verifyResult(result, expectedOrigins) {
    ok(result instanceof Array, "Got an array object");
    ok(result.length == expectedOrigins.length, "Correct number of elements");

    info("Sorting elements");

    result.sort(function (a, b) {
      if (a < b) {
        return -1;
      }
      if (a > b) {
        return 1;
      }
      return 0;
    });

    info("Verifying elements");

    for (let i = 0; i < result.length; i++) {
      ok(result[i] == expectedOrigins[i], "Result matches expected origin");
    }
  }

  info("Clearing");

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

  info("Listing origins");

  request = listOrigins();
  await requestFinished(request);

  info("Verifying result");

  verifyResult(request.result, []);

  info("Clearing");

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

  info("Initializing");

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

  info("Initializing temporary storage");

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

  info("Initializing origins");

  for (const origin of origins) {
    request = initTemporaryOrigin("default", getPrincipal(origin));
    await requestFinished(request);
  }

  info("Listing origins");

  request = listOrigins();
  await requestFinished(request);

  info("Verifying result");

  verifyResult(request.result, origins);
}