summaryrefslogtreecommitdiffstats
path: root/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_debug_storage.js
blob: 56f1b0befb9a4353c84709d4542c501832cd682f (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
81
82
83
84
85
86
87
88
89
90
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";

/* import-globals-from helper-addons.js */
Services.scriptloader.loadSubScript(CHROME_URL_ROOT + "helper-addons.js", this);

add_task(async () => {
  const EXTENSION_NAME = "temporary-web-extension";
  const EXTENSION_ID = "test-devtools@mozilla.org";

  await enableExtensionDebugging();

  const { document, tab, window } = await openAboutDebugging();
  await selectThisFirefoxPage(document, window.AboutDebugging.store);

  const { extension } = await installTemporaryExtensionFromXPI(
    {
      background() {
        const open = indexedDB.open("TestDatabase", 1);

        open.onupgradeneeded = function () {
          const db = open.result;
          db.createObjectStore("TestStore", { keyPath: "id" });
        };

        open.onsuccess = function () {
          const db = open.result;
          const tx = db.transaction("TestStore", "readwrite");
          const store = tx.objectStore("TestStore");

          store.put({ id: 1, name: "John", age: 12 });
          store.put({ id: 2, name: "Bob", age: 24 });
          tx.oncomplete = () => db.close();
        };
      },
      id: EXTENSION_ID,
      name: EXTENSION_NAME,
    },
    document
  );

  const { devtoolsWindow } = await openAboutDevtoolsToolbox(
    document,
    tab,
    window,
    EXTENSION_NAME
  );

  info("Select the storage panel");
  const toolbox = getToolbox(devtoolsWindow);
  await toolbox.selectTool("storage");
  const storage = toolbox.getCurrentPanel();

  info("Check the content of the storage panel treeview");
  const ids = [
    "indexedDB",
    `moz-extension://${extension.uuid}`,
    "TestDatabase (default)",
    "TestStore",
  ];
  ok(
    !!storage.panelWindow.document.querySelector(
      `[data-id='${JSON.stringify(ids)}']`
    ),
    "The indexedDB database for the extension is visible"
  );

  info("Select the indexedDB database for the extension");
  const updated = storage.UI.once("store-objects-updated");
  storage.UI.tree.selectedItem = ids;
  await updated;

  info("Wait until table populated");
  await waitUntil(() => storage.UI.table.items.size === 2);
  const items = storage.UI.table.items;

  info("Check the content of the storage panel table");
  is(items.size, 2);
  const user1 = JSON.parse(items.get(1).value);
  const user2 = JSON.parse(items.get(2).value);
  is(user1.name, "John", "user 1 has the expected name");
  is(user1.age, 12, "user 1 has the expected age");
  is(user2.name, "Bob", "user 2 has the expected name");
  is(user2.age, 24, "user 2 has the expected age");

  await closeWebExtAboutDevtoolsToolbox(devtoolsWindow, window);
  await removeTemporaryExtension(EXTENSION_NAME, document);
  await removeTab(tab);
});