summaryrefslogtreecommitdiffstats
path: root/dom/localstorage/test/browser_private_ls.js
blob: d4708c8e23bac2f6cf9533c94a6e99db4a918b31 (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
/**
 * This test is mainly to verify that datastores are cleared when the last
 * private browsing context exited.
 */

async function lsCheckFunc() {
  let storage = content.localStorage;

  if (storage.length) {
    return false;
  }

  // Store non-ASCII value to verify bug 1552428.
  storage.setItem("foo", "úžasné");

  return true;
}

function checkTabWindowLS(tab) {
  return SpecialPowers.spawn(tab.linkedBrowser, [], lsCheckFunc);
}

add_task(async function() {
  const pageUrl =
    "http://example.com/browser/dom/localstorage/test/page_private_ls.html";

  for (let i = 0; i < 2; i++) {
    let privateWin = await BrowserTestUtils.openNewBrowserWindow({
      private: true,
    });

    let privateTab = await BrowserTestUtils.openNewForegroundTab(
      privateWin.gBrowser,
      pageUrl
    );

    ok(
      await checkTabWindowLS(privateTab),
      "LS works correctly in a private-browsing page."
    );

    await BrowserTestUtils.closeWindow(privateWin);
  }
});