summaryrefslogtreecommitdiffstats
path: root/storage/test/unit/test_storage_service_special.js
blob: 50cde042afb4b13d8150a7e2c6188a776401b478 (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
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

// This file tests the openSpecialDatabase function of mozIStorageService.

add_task(async function test_invalid_storage_key() {
  try {
    Services.storage.openSpecialDatabase("abcd");
    do_throw("We should not get here!");
  } catch (e) {
    print(e);
    print("e.result is " + e.result);
    Assert.equal(Cr.NS_ERROR_INVALID_ARG, e.result);
  }
});

add_task(async function test_memdb_close_clone_fails() {
  for (const name of [null, "foo"]) {
    const db = Services.storage.openSpecialDatabase("memory", name);
    db.close();
    expectError(Cr.NS_ERROR_NOT_INITIALIZED, () => db.clone());
  }
});

add_task(async function test_memdb_no_file_on_disk() {
  for (const name of [null, "foo"]) {
    const db = Services.storage.openSpecialDatabase("memory", name);
    db.close();
    for (const dirKey of ["CurWorkD", "ProfD"]) {
      const dir = Services.dirsvc.get(dirKey, Ci.nsIFile);
      const file = dir.clone();
      file.append(!name ? ":memory:" : "file:foo?mode=memory&cache=shared");
      Assert.ok(!file.exists());
    }
  }
});

add_task(async function test_memdb_sharing() {
  for (const name of [null, "foo"]) {
    const db = Services.storage.openSpecialDatabase("memory", name);
    db.executeSimpleSQL("CREATE TABLE test(name TEXT)");
    const db2 = Services.storage.openSpecialDatabase("memory", name);
    Assert.ok(!!name == db2.tableExists("test"));
    db.close();
    db2.close();
  }
});