summaryrefslogtreecommitdiffstats
path: root/devtools/client/storage/test/browser_storage_indexeddb_delete_blocked.js
blob: 5b2781642602d9dc1feb9fe904c1cd15afd94721 (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
/* 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/. */

"use strict";

// Test what happens when deleting indexedDB database is blocked

add_task(async function () {
  await openTabAndSetupStorage(
    MAIN_DOMAIN_SECURED + "storage-idb-delete-blocked.html"
  );

  info("test state before delete");
  await checkState([
    [["indexedDB", "https://test1.example.org"], ["idb (default)"]],
  ]);

  info("do the delete");
  await selectTreeItem(["indexedDB", "https://test1.example.org"]);
  const front = gUI.getCurrentFront();
  let result = await front.removeDatabase(
    "https://test1.example.org",
    "idb (default)"
  );

  ok(result.blocked, "removeDatabase attempt is blocked");

  info("test state after blocked delete");
  await checkState([
    [["indexedDB", "https://test1.example.org"], ["idb (default)"]],
  ]);

  const eventWait = gUI.once("store-objects-edit");

  info("telling content to close the db");
  await SpecialPowers.spawn(gBrowser.selectedBrowser, [], async function () {
    const win = content.wrappedJSObject;
    await win.closeDb();
  });

  info("waiting for store edit events");
  await eventWait;

  info("test state after real delete");
  await checkState([[["indexedDB", "https://test1.example.org"], []]]);

  info("try to delete database from nonexistent host");
  let errorThrown = false;
  try {
    result = await front.removeDatabase(
      "https://test2.example.org",
      "idb (default)"
    );
  } catch (ex) {
    errorThrown = true;
  }

  ok(errorThrown, "error was reported when trying to delete");
});