summaryrefslogtreecommitdiffstats
path: root/devtools/client/storage/test/browser_storage_indexeddb_navigation.js
blob: 3235f101211c72807dfa598d2a1a57a970929253 (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
/* 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";

requestLongerTimeout(3);

add_task(async function () {
  const URL1 = URL_ROOT_COM_SSL + "storage-indexeddb-simple.html";
  const URL2 = URL_ROOT_NET_SSL + "storage-indexeddb-simple-alt.html";

  // open tab
  await openTabAndSetupStorage(URL1);
  const doc = gPanelWindow.document;

  // Check first domain
  // check that host appears in the storage tree
  checkTree(doc, ["indexedDB", "https://example.com"]);
  // check the table for values
  await selectTreeItem([
    "indexedDB",
    "https://example.com",
    "db (default)",
    "store",
  ]);
  checkStorageData("lorem", JSON.stringify({ key: "lorem", value: "ipsum" }));

  // clear db before navigating to a new domain
  info("Removing database…");
  await clearStorage();

  // Check second domain
  await navigateTo(URL2);
  info("Creating database in the second domain…");
  await SpecialPowers.spawn(gBrowser.selectedBrowser, [], async function () {
    const win = content.wrappedJSObject;
    await win.setup();
  });
  // wait for storage tree refresh, and check host
  info("Checking storage tree…");
  await waitUntil(() => isInTree(doc, ["indexedDB", "https://example.net"]));

  ok(
    !isInTree(doc, ["indexedDB", "https://example.com"]),
    "example.com item is not in the tree anymore"
  );

  // TODO: select tree and check on storage data.
  // We cannot do it yet since we do not detect newly created indexed db's when
  // navigating. See Bug 1273802

  // reload the current tab, and check again
  await reloadBrowser();
  // wait for storage tree refresh, and check host
  info("Checking storage tree…");
  await waitUntil(() => isInTree(doc, ["indexedDB", "https://example.net"]));

  info("Check that the indexedDB node still has the expected label");
  is(
    getTreeNodeLabel(doc, ["indexedDB"]),
    "Indexed DB",
    "indexedDB item is properly displayed"
  );
});

async function clearStorage() {
  await SpecialPowers.spawn(gBrowser.selectedBrowser, [], async function () {
    const win = content.wrappedJSObject;
    await win.clear();
  });
}