summaryrefslogtreecommitdiffstats
path: root/dom/tests/mochitest/localstorage/test_localStorageSessionPrefOverride.html
blob: 9fe6a48ec65c3f879443ea06f95a9eb162dc25de (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
<html>
  <head>
    <title>Local Storage Session Pref Override</title>
    <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    <script type="text/javascript" src="/tests/SimpleTest/SpawnTask.js"></script>
    <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    <script>
      const ACCEPT_SESSION = 2;

      add_task(function*() {
        yield new Promise((resolve, reject) => {
          SpecialPowers.pushPrefEnv({"set": [["network.cookie.lifetimePolicy",
                                              ACCEPT_SESSION]]},
                                    resolve);
        });

        // Before setting permission
        yield new Promise((resolve) => {
          var frame = document.createElement('iframe');
          frame.src = "frameLocalStorageSessionOnly.html";

          var listener = (e) => {
            is(e.data, true, "Before adding permission should be session only");
            window.removeEventListener('message', listener);
            resolve();
          };
          window.addEventListener('message', listener);
          document.body.appendChild(frame);
        });

        // After setting permission
        yield new Promise((resolve) => {
          SpecialPowers.pushPermissions([{"type": "cookie", "allow": 1, "context": document}],
                                        resolve);
        });

        yield new Promise((resolve) => {
          var frame = document.createElement('iframe');
          frame.src = "frameLocalStorageSessionOnly.html";

          var listener = (e) => {
            is(e.data, false, "After adding permission should not be session only");
            window.removeEventListener('message', listener);
            resolve();
          };
          window.addEventListener('message', listener);
          document.body.appendChild(frame);
        });
      });
    </script>
  </head>
  <body>
  </body>
</html>