summaryrefslogtreecommitdiffstats
path: root/dom/file/ipc/tests/test_ipcBlob_emptyMultiplex.html
blob: 04870694677e2f6c61946ff89215332a321826d0 (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
<!DOCTYPE HTML>
<html>
<head>
  <title>Test an empty IPCBlob together with other parts</title>
  <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<script type="text/javascript">

function checkContent(msg, content) {
  return new Promise(resolve => {
    let fr = new FileReader();
    fr.readAsText(new Blob(content));
    fr.onloadend = () => {
      is(fr.result, "Hello world!", "The content matches: " + msg);
      resolve();
    };
  });
}

SimpleTest.waitForExplicitFinish();

let url = SimpleTest.getTestFileURL("script_file.js");

let script = SpecialPowers.loadChromeScript(url);
script.addMessageListener("emptyfile.opened", message => {
  checkContent("middle", ["Hello ", message.file, "world!"]).
  then(() => checkContent("begin", [message.file, "Hello world!"])).
  then(() => checkContent("end", ["Hello world!", message.file])).
  then(() => checkContent("random", [message.file, message.file, "Hello world!", message.file])).
  then(() => checkContent("random 2", [message.file, message.file, "Hello ",
                                       message.file, "world", message.file,
                                       message.file, "!", message.file, "",
                                       message.file, message.file])).
  then(SimpleTest.finish);
});

script.sendAsyncMessage("emptyfile.open");

</script>
</pre>
</body>
</html>