5 <title>Test for FileReaderSync when the worker is closing
</title>
6 <script src=
"/tests/SimpleTest/SimpleTest.js"></script>
7 <link rel=
"stylesheet" type=
"text/css" href=
"/tests/SimpleTest/test.css"/>
10 <script type=
"application/javascript">
12 // In order to exercise FileReaderSync::SyncRead's syncLoop-using AsyncWait()
13 // path, we need to provide a stream that will both
1) not have all the data
14 // immediately available (eliminating memory-backed Blobs) and
2) return
15 // NS_BASE_STREAM_WOULD_BLOCK. Under e10s, any Blob/File sourced from the
16 // parent process (as loadChromeScript performs) will be backed by an
17 // RemoteLazyInputStream and will behave this way on first use (when it is in
18 // the eInit state). For ease of testing, we reuse script_createFile.js which
19 // involves a file on disk, but a memory-backed Blob from the parent process
20 // would be equally fine. Under non-e10s, this File will not do the right
21 // thing because a synchronous nsFileInputStream will be made directly
22 // available and the AsyncWait path won't be taken, but the test will still
25 var url = SimpleTest.getTestFileURL(
"script_createFile.js");
26 var script = SpecialPowers.loadChromeScript(url);
28 function onOpened(message) {
29 function workerCode() {
30 onmessage = function(e) {
32 var fr = new FileReaderSync();
33 self.postMessage(fr.readAsText(e.data));
37 var b = new Blob([workerCode+'workerCode();']);
38 var w = new Worker(URL.createObjectURL(b));
39 w.onmessage = function(e) {
40 is(e.data,
"Hello world!",
"The blob content is OK!");
44 w.postMessage(message.data);
47 script.addMessageListener(
"nonEmptyFile.opened", onOpened);
48 script.sendAsyncMessage(
"nonEmptyFile.open");
50 SimpleTest.waitForExplicitFinish();