summaryrefslogtreecommitdiffstats
path: root/dom/indexedDB/test/unit/test_open_and_databases.js
blob: b13cba067a2767182c16bebde618402a808486b3 (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
/**
 * Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/
 */

/* exported testSteps */
async function testSteps() {
  const openInfos = [
    { name: "foo-a", version: 1 },
    { name: "foo-b", version: 1 },
  ];

  info("Creating databases");

  for (let index = 0; index < openInfos.length; index++) {
    const openInfo = openInfos[index];

    const request = indexedDB.open(openInfo.name, openInfo.version);

    await expectingUpgrade(request);

    const event = await expectingSuccess(request);

    const database = event.target.result;

    database.close();
  }

  info("Getting databases");

  const databasesPromise = indexedDB.databases();

  info("Opening databases");

  const openPromises = [];

  for (let index = 0; index < openInfos.length; index++) {
    const openInfo = openInfos[index];

    const request = indexedDB.open(openInfo.name, openInfo.version);

    const promise = expectingSuccess(request);

    openPromises.push(promise);
  }

  info("Waiting for databases operation to complete");

  const databaseInfos = await databasesPromise;

  info("Verifying databases");

  is(
    databaseInfos.length,
    openInfos.length,
    "The result of databases() should contain one result per database"
  );

  for (let index = 0; index < openInfos.length; index++) {
    const openInfo = openInfos[index];

    ok(
      databaseInfos.some(function (element) {
        return (
          element.name === openInfo.name && element.version === openInfo.version
        );
      }),
      "The result of databases() should be a sequence of the correct names " +
        "and versions of all databases for the origin"
    );
  }

  info("Waiting for open operations to complete");

  await Promise.all(openPromises);
}