summaryrefslogtreecommitdiffstats
path: root/devtools/client/storage/test/browser_storage_localstorage_navigation.js
blob: 92a8eab210881ca33d2e6ec7da844aa5cd423be6 (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
/* 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 URL1 = buildURLWithContent(
    "example.com",
    `<h1>example.com</h1>` +
      `<script>localStorage.setItem("lorem", "ipsum");</script>`
  );
  const URL2 = buildURLWithContent(
    "example.net",
    `<h1>example.net</h1>` +
      `<script>localStorage.setItem("foo", "bar");</script>`
  );

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

  // Check first domain
  // check that both host appear in the storage tree
  checkTree(doc, ["localStorage", "https://example.com"]);
  // check the table for values
  await selectTreeItem(["localStorage", "https://example.com"]);
  checkStorageData("lorem", "ipsum");

  // clear up local storage data before navigating
  info("Cleaning up localStorage…");
  await SpecialPowers.spawn(gBrowser.selectedBrowser, [], async function () {
    const win = content.wrappedJSObject;
    await win.localStorage.clear();
  });

  // Check second domain
  await navigateTo(URL2);
  // wait for storage tree refresh, and check host
  info("Waiting for storage tree to refresh and show correct host…");
  await waitUntil(() => isInTree(doc, ["localStorage", "https://example.net"]));
  ok(
    !isInTree(doc, ["localStorage", "https://example.com"]),
    "example.com item is not in the tree anymore"
  );

  // reload the current tab and check data
  await reloadBrowser();
  // wait for storage tree refresh, and check host
  info("Waiting for storage tree to refresh and show correct host…");
  await waitUntil(() => isInTree(doc, ["localStorage", "https://example.net"]));

  // check the table for values
  await selectTreeItem(["localStorage", "https://example.net"]);
  checkStorageData("foo", "bar");

  info("Check that the localStorage node still has the expected label");
  is(
    getTreeNodeLabel(doc, ["localStorage"]),
    "Local Storage",
    "localStorage item is properly displayed"
  );
});