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

add_task(async function () {
  const URL = URL_ROOT_COM_SSL + "storage-indexeddb-iframe.html";

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

  // 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("foo", JSON.stringify({ key: "foo", value: "bar" }));

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

  info("Add new data to the iframe DB");
  await SpecialPowers.spawn(gBrowser.selectedBrowser, [], async function () {
    const iframe = content.document.querySelector("iframe");
    return SpecialPowers.spawn(iframe, [], async function () {
      return new Promise(resolve => {
        const request = content.window.indexedDB.open("db", 1);
        request.onsuccess = event => {
          const db = event.target.result;
          const transaction = db.transaction(["store"], "readwrite");
          const addRequest = transaction
            .objectStore("store")
            .add({ key: "hello", value: "world" });
          addRequest.onsuccess = () => resolve();
        };
      });
    });
  });

  info("Refreshing table");
  doc.querySelector("#refresh-button").click();

  info("Check that table has new row");
  await waitUntil(() =>
    hasStorageData("hello", JSON.stringify({ key: "hello", value: "world" }))
  );
  ok(true, "Table has the new data");
});