summaryrefslogtreecommitdiffstats
path: root/devtools/client/storage/test/browser_storage_sessionstorage_navigation.js
blob: 22d6d5661fc3d3fde5e6e523cc132d21362582f0 (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";

add_task(async function () {
  const URL1 = buildURLWithContent(
    "example.com",
    `<h1>example.com</h1>` +
      `<script>sessionStorage.setItem("lorem", "ipsum");</script>`
  );
  const URL2 = buildURLWithContent(
    "example.net",
    `<h1>example.net</h1>` +
      `<script>sessionStorage.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, ["sessionStorage", "https://example.com"]);
  // check the table for values
  await selectTreeItem(["sessionStorage", "https://example.com"]);
  checkStorageData("lorem", "ipsum");

  // clear up session storage data before navigating
  info("Cleaning up sessionStorage…");
  await SpecialPowers.spawn(gBrowser.selectedBrowser, [], async function () {
    const win = content.wrappedJSObject;
    await win.sessionStorage.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, ["sessionStorage", "https://example.net"])
  );

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

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

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