summaryrefslogtreecommitdiffstats
path: root/dom/ipc/tests/test_bug1086684.html
blob: 962826ec6bcaf1cc77a468867532de240d7fe2c0 (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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<!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 =
      "http://mochi.test:8888/tests/dom/ipc/tests/file_bug1086684.html";

    function childFrameScript() {
      "use strict";

      let { MockFilePicker } =
        Components.utils.import("chrome://specialpowers/content/MockFilePicker.jsm", {});

      function parentReady(message) {
        MockFilePicker.init(content);
        MockFilePicker.returnFiles = [message.data.file];
        MockFilePicker.returnValue = MockFilePicker.returnOK;

        let input = content.document.getElementById("f");
        input.addEventListener("change", () => {
          MockFilePicker.cleanup();
          let value = input.value;
          message.target.sendAsyncMessage("testBug1086684:childDone", { value });
        });

        input.focus();
        input.click();
      }

      addMessageListener("testBug1086684:parentReady", function(message) {
        parentReady(message);
      });
    }

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

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

      mm.addMessageListener("testBug1086684:childDone", testDone);

      let blob = new Blob([]);
      let file = new File([blob], "helloworld.txt", { type: "text/plain" });

      mm.sendAsyncMessage("testBug1086684:parentReady", { file });
      value = yield;

      // Note that the "helloworld.txt" passed in above doesn't affect the
      // 'value' getter. Because we're mocking a file using a blob, we ask the
      // blob for its path, which is the empty string.
      is(value, "", "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]
        ]
      }, runTests);
    });
  </script>
</body>
</html>