summaryrefslogtreecommitdiffstats
path: root/dom/ipc/tests/test_cpow_cookies.html
blob: d8f87cceddf4b68fc5a7ec01107a8cd45bc12ba3 (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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<!DOCTYPE HTML>
<html>
<head>
  <title>Test for recursive CPOW-getting-cookie bug</title>
  <script type="application/javascript"
          src="/tests/SimpleTest/SimpleTest.js">
  </script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>

  <script type="application/javascript;version=1.8">
    "use strict";

    SimpleTest.waitForExplicitFinish();

    const childFrameURL =
      "data:text/html,<!DOCTYPE HTML><html><body></body></html>";

    function childFrameScript() {
      "use strict";

      const Ci = Components.interfaces;

      function test1(message) {
        // NB: This is a no-op because we're a data: document with a null
        // principal.
        content.document.cookie = "a=b";
        message.target.sendAsyncMessage("testCPOWCookies:test1Finished", { pass: true });
      }

      addMessageListener("testCPOWCookies:test1", function(message) {
        test1(message);
      });
    }

    let test;
    function* testStructure(mm) {
      let lastResult;

      function testDone(msg) {
        test.next(msg.data);
      }

      mm.addMessageListener("testCPOWCookies:test1Finished", testDone);

      mm.sendAsyncMessage("testCPOWCookies:test1", {});
      lastResult = yield;
      ok(lastResult.pass, "got the right answer and didn't crash");

      SimpleTest.finish();
    }

    function runTests() {
      info("Browser prefs set.");

      let iframe = document.createElement("iframe");
      SpecialPowers.wrap(iframe).mozbrowser = true;
      iframe.id = "iframe";
      iframe.src = childFrameURL;

      iframe.addEventListener("mozbrowserloadend", function() {
        info("Got iframe load event.");
        let mm = SpecialPowers.getBrowserFrameMessageManager(iframe);
        mm.loadFrameScript("data:,(" + encodeURI(childFrameScript.toString()) + ")();",
                           false);

        test = testStructure(mm);
        test.next();
      });

      document.body.appendChild(iframe);
    }

    addEventListener("load", function() {
      info("Got load event.");

      SpecialPowers.addPermission("browser", true, document);
      SpecialPowers.pushPrefEnv({
        "set": [
          ["dom.ipc.browser_frames.oop_by_default", true],
          ["dom.mozBrowserFramesEnabled", true],
          ["network.disable.ipc.security", true],
          ["browser.pagethumbnails.capturing_disabled", true],
          ["security.data_uri.block_toplevel_data_uri_navigations", false],
        ]
      }, runTests);
    });
  </script>
</body>
</html>