Bug 1360807 - FileReaderSync must work with sync inputStream - part 2 - tests, r=smaug
☠☠ backed out by 797a743271c6 ☠ ☠
authorAndrea Marchesini <amarchesini@mozilla.com>
Thu, 04 May 2017 14:50:46 +0200
changeset 572819 e59616a3997a930cedecf4dd520fe8a595dba493
parent 572818 c800cb830b36bd401b22724587b2a810a3234562
child 572820 41e9af8078dd30bb0dd8de901c9ad1869a6b677c
push id57195
push userbmo:rbarker@mozilla.com
push dateThu, 04 May 2017 20:08:56 +0000
reviewerssmaug
bugs1360807
milestone55.0a1
Bug 1360807 - FileReaderSync must work with sync inputStream - part 2 - tests, r=smaug
dom/file/ipc/tests/test_ipcBlob_fileReaderSync.html
--- a/dom/file/ipc/tests/test_ipcBlob_fileReaderSync.html
+++ b/dom/file/ipc/tests/test_ipcBlob_fileReaderSync.html
@@ -8,31 +8,84 @@
 </head>
 <body>
 <script type="text/javascript">
 
 function workerScript() {
   onmessage = function(event) {
     let readerMemoryBlob = new FileReaderSync();
     let status = readerMemoryBlob.readAsText(new Blob(['hello world'])) == 'hello world';
+    postMessage({ status, message: "FileReaderSync with memory blob still works" });
 
-    let readerIPCBlob = new FileReaderSync();
-    postMessage({ blob: event.data, data: readerIPCBlob.readAsText(event.data), status });
+    let readerIPCBlob1 = new FileReaderSync();
+    postMessage({ blob: event.data, method: 'readAsText',
+                  data: readerIPCBlob1.readAsText(event.data)});
+
+    let readerIPCBlob2 = new FileReaderSync();
+    postMessage({ blob: event.data, method: 'readAsArrayBuffer',
+                  data: readerIPCBlob2.readAsArrayBuffer(event.data)});
+
+    let readerIPCBlob3 = new FileReaderSync();
+    postMessage({ blob: event.data, method: 'readAsDataURL',
+                  data: readerIPCBlob3.readAsDataURL(event.data)});
+
+    let multipartBlob = new Blob(['wow', event.data]);
+
+    let readerIPCBlobMultipart1 = new FileReaderSync();
+    postMessage({ blob: multipartBlob, method: 'readAsText',
+                  data: readerIPCBlobMultipart1.readAsText(multipartBlob)});
+
+    let readerIPCBlobMultipart2 = new FileReaderSync();
+    postMessage({ blob: multipartBlob, method: 'readAsArrayBuffer',
+                  data: readerIPCBlobMultipart2.readAsArrayBuffer(multipartBlob)});
+
+    let readerIPCBlobMultipart3 = new FileReaderSync();
+    postMessage({ blob: multipartBlob, method: 'readAsDataURL',
+                  data: readerIPCBlobMultipart3.readAsDataURL(multipartBlob)});
+
+    postMessage({ finish: true });
+  }
+}
+
+let completed = false;
+let pendingTasks = 0;
+function maybeFinish() {
+  if (completed && !pendingTasks) {
+    SimpleTest.finish();
   }
 }
 
 let workerUrl = URL.createObjectURL(new Blob(["(", workerScript.toSource(), ")()"]));
 let worker = new Worker(workerUrl);
 worker.onmessage = event => {
-  let fr = new FileReader();
-  fr.readAsText(event.data.blob);
-  fr.onload = () => {
-    is(event.data.data, fr.result, "The file has been read");
-    ok(event.data.status, "FileReaderSync with memory blob still works");
-    SimpleTest.finish();
+  if ("status" in event.data) {
+    ok(event.data.status, event.data.message);
+    return;
+  }
+
+  if ("blob" in event.data) {
+    let fr = new FileReader();
+    fr[event.data.method](event.data.blob);
+    ++pendingTasks;
+    fr.onload = () => {
+      if (event.data.method != 'readAsArrayBuffer') {
+        is(event.data.data, fr.result, "The file has been read");
+      } else {
+        is(event.data.data.byteLength, fr.result.byteLength, "The file has been read");
+      }
+      --pendingTasks;
+      maybeFinish();
+    }
+
+    return;
+  }
+
+  if ("finish" in event.data) {
+    completed = true;
+    maybeFinish();
   }
 };
 
 let url = SimpleTest.getTestFileURL("script_file.js");
 let script = SpecialPowers.loadChromeScript(url);
 script.addMessageListener("file.opened", message => {
   worker.postMessage(message.file);
 });