Backed out changeset a7b1484b2367 (bug 1400098)
authorSebastian Hengst <archaeopteryx@coole-files.de>
Fri, 13 Oct 2017 13:25:44 +0200
changeset 386142 5a9bea5b8dd2f74954a38b5d90298f14f2167b51
parent 386141 9abaf5195566c45d9c9dafbcb7624a9c3a3b123b
child 386143 933be59f89bdd36a320527bc29b44566bae9ad3b
push id32676
push userarchaeopteryx@coole-files.de
push dateFri, 13 Oct 2017 21:38:18 +0000
treeherdermozilla-central@a31334a65a1c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1400098
milestone58.0a1
backs outa7b1484b2367547280e18559dc25205479d23a23
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Backed out changeset a7b1484b2367 (bug 1400098)
dom/file/tests/common_fileReader.js
dom/file/tests/mochitest.ini
dom/file/tests/test_fileapi.html
dom/file/tests/test_fileapi_worker.html
dom/file/tests/worker_fileReader.js
dom/workers/test/fileapi_chromeScript.js
dom/workers/test/mochitest.ini
dom/workers/test/test_fileReader.html
dom/workers/test/worker_fileReader.js
--- a/dom/file/tests/common_fileReader.js
+++ b/dom/file/tests/common_fileReader.js
@@ -1,178 +1,99 @@
-function test_setup() {
-  return new Promise(resolve => {
-    const minFileSize = 20000;
-
-    // Create strings containing data we'll test with. We'll want long
-    // strings to ensure they span multiple buffers while loading
-    let testTextData = "asd b\tlah\u1234w\u00a0r";
-    while (testTextData.length < minFileSize) {
-      testTextData = testTextData + testTextData;
-    }
-
-    let testASCIIData = "abcdef 123456\n";
-    while (testASCIIData.length < minFileSize) {
-      testASCIIData = testASCIIData + testASCIIData;
-    }
-
-    let testBinaryData = "";
-    for (let i = 0; i < 256; i++) {
-      testBinaryData += String.fromCharCode(i);
-    }
-    while (testBinaryData.length < minFileSize) {
-      testBinaryData = testBinaryData + testBinaryData;
-    }
-
-    let dataurldata0 = testBinaryData.substr(0, testBinaryData.length -
-                                             testBinaryData.length % 3);
-    let dataurldata1 = testBinaryData.substr(0, testBinaryData.length - 2 -
-                                             testBinaryData.length % 3);
-    let dataurldata2 = testBinaryData.substr(0, testBinaryData.length - 1 -
-                                             testBinaryData.length % 3);
-
-
-    //Set up files for testing
-    let openerURL = SimpleTest.getTestFileURL("fileapi_chromeScript.js");
-    let opener = SpecialPowers.loadChromeScript(openerURL);
-
-    opener.addMessageListener("files.opened", message => {
-      let [
-        asciiFile,
-        binaryFile,
-        nonExistingFile,
-        utf8TextFile,
-        utf16TextFile,
-        emptyFile,
-        dataUrlFile0,
-        dataUrlFile1,
-        dataUrlFile2,
-      ] = message;
-
-      resolve({ blobs:{ asciiFile, binaryFile, nonExistingFile, utf8TextFile,
-                        utf16TextFile, emptyFile, dataUrlFile0, dataUrlFile1,
-                        dataUrlFile2 },
-                data: { text: testTextData,
-                        ascii: testASCIIData,
-                        binary: testBinaryData,
-                        url0: dataurldata0,
-                        url1: dataurldata1,
-                        url2: dataurldata2, }});
-    });
-
-    opener.sendAsyncMessage("files.open", [
-      testASCIIData,
-      testBinaryData,
-      null,
-      convertToUTF8(testTextData),
-      convertToUTF16(testTextData),
-      "",
-      dataurldata0,
-      dataurldata1,
-      dataurldata2,
-    ]);
-  });
-}
-
-function runTests(data) {
+function runTests(asciiFile, binaryFile, nonExistingFile, utf8TextFile,
+                  utf16TextFile, emptyFile, dataUrlFile0, dataUrlFile1,
+                  dataUrlFile2, testTextData) {
   return test_basic()
     .then(() => {
-      return test_readAsText(data.blobs.asciiFile, data.data.ascii);
+      return test_readAsText(asciiFile, testASCIIData);
     })
     .then(() => {
-      return test_readAsTextWithEncoding(data.blobs.asciiFile, data.data.ascii,
-                                         data.data.ascii.length, "");
+      return test_readAsTextWithEncoding(asciiFile, testASCIIData,
+                                         testASCIIData.length, "");
     })
     .then(() => {
-      return test_readAsTextWithEncoding(data.blobs.asciiFile, data.data.ascii,
-                                         data.data.ascii.length, "iso8859-1");
+      return test_readAsTextWithEncoding(asciiFile, testASCIIData,
+                                         testASCIIData.length, "iso8859-1");
     })
     .then(() => {
-      return test_readAsTextWithEncoding(data.blobs.utf8TextFile, data.data.text,
-                                         convertToUTF8(data.data.text).length,
+      return test_readAsTextWithEncoding(utf8TextFile, testTextData,
+                                         convertToUTF8(testTextData).length,
                                          "utf8");
     })
     .then(() => {
-      return test_readAsTextWithEncoding(data.blobs.utf16TextFile, data.data.text,
-                                         convertToUTF16(data.data.text).length,
+      return test_readAsTextWithEncoding(utf16TextFile, testTextData,
+                                         convertToUTF16(testTextData).length,
                                          "utf-16");
     })
     .then(() => {
-      return test_readAsBinaryString(data.blobs.binaryFile, data.data.binary);
+      return test_readAsBinaryString(binaryFile, testBinaryData);
     })
     .then(() => {
-      return test_readAsArrayBuffer(data.blobs.binaryFile, data.data.binary);
+      return test_readAsArrayBuffer(binaryFile, testBinaryData);
     })
     .then(() => {
       return test_onlyResult()
     })
     .then(() => {
-      return test_readAsText(data.blobs.emptyFile, "");
+      return test_readAsText(emptyFile, "");
     })
     .then(() => {
-      return test_readAsTextWithEncoding(data.blobs.emptyFile, "", 0, "");
+      return test_readAsTextWithEncoding(emptyFile, "", 0, "");
     })
     .then(() => {
-      return test_readAsTextWithEncoding(data.blobs.emptyFile, "", 0, "utf8");
+      return test_readAsTextWithEncoding(emptyFile, "", 0, "utf8");
     })
     .then(() => {
-      return test_readAsTextWithEncoding(data.blobs.emptyFile, "", 0, "utf-16");
+      return test_readAsTextWithEncoding(emptyFile, "", 0, "utf-16");
     })
     .then(() => {
-      return test_readAsBinaryString(data.blobs.emptyFile, "");
+      return test_readAsBinaryString(emptyFile, "");
     })
     .then(() => {
-      return test_readAsArrayBuffer(data.blobs.emptyFile, "");
+      return test_readAsArrayBuffer(emptyFile, "");
     })
     .then(() => {
-      return test_readAsDataURL(data.blobs.emptyFile, convertToDataURL(""), 0);
+      return test_readAsDataURL(emptyFile, convertToDataURL(""), 0);
     })
     .then(() => {
-      return test_readAsTextTwice(data.blobs.asciiFile, data.data.ascii);
+      return test_readAsTextTwice(asciiFile, testASCIIData);
     })
     .then(() => {
-      return test_readAsBinaryStringTwice(data.blobs.binaryFile,
-                                          data.data.binary);
+      return test_readAsBinaryStringTwice(binaryFile, testBinaryData);
     })
     .then(() => {
-      return test_readAsDataURLTwice(data.blobs.binaryFile,
-                                     convertToDataURL(data.data.binary),
-                                     data.data.binary.length);
+      return test_readAsDataURLTwice(binaryFile, convertToDataURL(testBinaryData),
+                                     testBinaryData.length);
     })
     .then(() => {
-      return test_readAsArrayBufferTwice(data.blobs.binaryFile,
-                                         data.data.binary);
+      return test_readAsArrayBufferTwice(binaryFile, testBinaryData);
     })
     .then(() => {
-      return test_readAsArrayBufferTwice2(data.blobs.binaryFile,
-                                          data.data.binary);
+      return test_readAsArrayBufferTwice2(binaryFile, testBinaryData);
     })
     .then(() => {
-      return test_readAsDataURL_customLength(data.blobs.dataUrlFile0,
-                                             convertToDataURL(data.data.url0),
-                                             data.data.url0.length, 0);
+      return test_readAsDataURL_customLength(dataUrlFile0, convertToDataURL(dataurldata0),
+                                             dataurldata0.length, 0);
     })
     .then(() => {
-      return test_readAsDataURL_customLength(data.blobs.dataUrlFile1,
-                                             convertToDataURL(data.data.url1),
-                                             data.data.url1.length, 1);
+      return test_readAsDataURL_customLength(dataUrlFile1, convertToDataURL(dataurldata1),
+                                             dataurldata1.length, 1);
+    })
+    .then(() => {
+      return test_readAsDataURL_customLength(dataUrlFile2, convertToDataURL(dataurldata2),
+                                             dataurldata2.length, 2);
     })
     .then(() => {
-      return test_readAsDataURL_customLength(data.blobs.dataUrlFile2,
-                                             convertToDataURL(data.data.url2),
-                                             data.data.url2.length, 2);
+      return test_abort(asciiFile);
     })
     .then(() => {
-      return test_abort(data.blobs.asciiFile);
+      return test_abort_readAsX(asciiFile, testASCIIData);
     })
     .then(() => {
-      return test_abort_readAsX(data.blobs.asciiFile, data.data.ascii);
-    })
-    .then(() => {
-      return test_nonExisting(data.blobs.nonExistingFile);
+      return test_nonExisting(nonExistingFile);
     });
 }
 
 function convertToUTF16(s) {
   let res = "";
   for (let i = 0; i < s.length; ++i) {
     c = s.charCodeAt(i);
     res += String.fromCharCode(c & 255, c >>> 8);
@@ -207,25 +128,23 @@ function loadEventHandler_arrayBuffer(ev
   is(event.total, data.length, "total in test " + testName);
   is(event.target.result.byteLength, data.length, "array buffer size in test " + testName);
 
   let u8v = new Uint8Array(event.target.result);
   is(String.fromCharCode.apply(String, u8v), data,
      "array buffer contents in test " + testName);
   u8v = null;
 
-  if ("SpecialPowers" in self) {
-    SpecialPowers.gc();
+  SpecialPowers.gc();
 
-    is(event.target.result.byteLength, data.length,
-       "array buffer size after gc in test " + testName);
-    u8v = new Uint8Array(event.target.result);
-    is(String.fromCharCode.apply(String, u8v), data,
-       "array buffer contents after gc in test " + testName);
-  }
+  is(event.target.result.byteLength, data.length,
+     "array buffer size after gc in test " + testName);
+  u8v = new Uint8Array(event.target.result);
+  is(String.fromCharCode.apply(String, u8v), data,
+     "array buffer contents after gc in test " + testName);
 
   resolve();
 }
 
 function test_basic() {
   return new Promise(resolve => {
     is(FileReader.EMPTY, 0, "correct EMPTY value");
     is(FileReader.LOADING, 1, "correct LOADING value");
--- a/dom/file/tests/mochitest.ini
+++ b/dom/file/tests/mochitest.ini
@@ -1,12 +1,11 @@
 [DEFAULT]
 support-files =
   create_file_objects.js
-  common_fileReader.js
   file_blobURL_expiring.html
   file_mozfiledataurl_img.jpg
   file_mozfiledataurl_audio.ogg
   file_mozfiledataurl_doc.html
   file_mozfiledataurl_text.txt
   file_mozfiledataurl_inner.html
   file_nonascii_blob_url.html
   fileutils.js
@@ -18,14 +17,13 @@ support-files =
 [test_blobconstructor.html]
 [test_blobURL_expiring.html]
 [test_file_from_blob.html]
 [test_ipc_messagemanager_blob.html]
 support-files = file_ipc_messagemanager_blob.html
 [test_nonascii_blob_url.html]
 [test_file_negative_date.html]
 [test_fileapi.html]
-[test_fileapi_worker.html]
-support-files = worker_fileReader.js
+support-files = common_fileReader.js
 [test_fileapi_slice.html]
 skip-if = (toolkit == 'android') # Android: Bug 775227
 [test_mozfiledataurl.html]
 skip-if = toolkit == 'android' #TIMED_OUT
--- a/dom/file/tests/test_fileapi.html
+++ b/dom/file/tests/test_fileapi.html
@@ -5,19 +5,76 @@
   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
   <script type="text/javascript" src="common_fileReader.js"></script>
 </head>
 
 <body>
 <script class="testbody" type="text/javascript">
 
+const minFileSize = 20000;
 SimpleTest.waitForExplicitFinish();
 
-test_setup()
-.then(data => {
-  return runTests(data);
-})
-.then(SimpleTest.finish);
+// Create strings containing data we'll test with. We'll want long
+// strings to ensure they span multiple buffers while loading
+var testTextData = "asd b\tlah\u1234w\u00a0r";
+while (testTextData.length < minFileSize) {
+  testTextData = testTextData + testTextData;
+}
+
+var testASCIIData = "abcdef 123456\n";
+while (testASCIIData.length < minFileSize) {
+  testASCIIData = testASCIIData + testASCIIData;
+}
+
+var testBinaryData = "";
+for (var i = 0; i < 256; i++) {
+  testBinaryData += String.fromCharCode(i);
+}
+while (testBinaryData.length < minFileSize) {
+  testBinaryData = testBinaryData + testBinaryData;
+}
+
+var dataurldata0 = testBinaryData.substr(0, testBinaryData.length -
+					 testBinaryData.length % 3);
+var dataurldata1 = testBinaryData.substr(0, testBinaryData.length - 2 -
+					 testBinaryData.length % 3);
+var dataurldata2 = testBinaryData.substr(0, testBinaryData.length - 1 -
+					 testBinaryData.length % 3);
+
+
+//Set up files for testing
+var openerURL = SimpleTest.getTestFileURL("fileapi_chromeScript.js");
+var opener = SpecialPowers.loadChromeScript(openerURL);
+opener.addMessageListener("files.opened", onFilesOpened);
+opener.sendAsyncMessage("files.open", [
+  testASCIIData,
+  testBinaryData,
+  null,
+  convertToUTF8(testTextData),
+  convertToUTF16(testTextData),
+  "",
+  dataurldata0,
+  dataurldata1,
+  dataurldata2,
+]);
+
+function onFilesOpened(message) {
+  let [
+    asciiFile,
+    binaryFile,
+    nonExistingFile,
+    utf8TextFile,
+    utf16TextFile,
+    emptyFile,
+    dataUrlFile0,
+    dataUrlFile1,
+    dataUrlFile2,
+  ] = message;
+
+  runTests(asciiFile, binaryFile, nonExistingFile, utf8TextFile, utf16TextFile,
+           emptyFile, dataUrlFile0, dataUrlFile1, dataUrlFile2, testTextData)
+  .then(SimpleTest.finish);
+}
 
 </script>
 </body>
 </html>
deleted file mode 100644
--- a/dom/file/tests/test_fileapi_worker.html
+++ /dev/null
@@ -1,37 +0,0 @@
-<!DOCTYPE HTML>
-<html>
-<head>
-  <title>Test for FileReader API in workers</title>
-  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
-  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
-  <script type="text/javascript" src="common_fileReader.js"></script>
-</head>
-
-<body>
-<script class="testbody" type="text/javascript">
-
-SimpleTest.waitForExplicitFinish();
-
-test_setup()
-.then(data => {
-  let worker = new Worker('worker_fileReader.js');
-  worker.postMessage(data);
-
-  worker.onmessage = event => {
-    if (event.data.type == 'finish') {
-      SimpleTest.finish();
-      return;
-    }
-
-    if (event.data.type == 'check') {
-      ok(event.data.status, event.data.msg);
-      return;
-    }
-
-    ok(false, "Unknown message.");
-  }
-});
-
-</script>
-</body>
-</html>
deleted file mode 100644
--- a/dom/file/tests/worker_fileReader.js
+++ /dev/null
@@ -1,15 +0,0 @@
-importScripts('common_fileReader.js');
-
-function ok(a, msg) {
-  postMessage({type:'check', msg, status: !!a});
-}
-
-function is(a, b, msg) {
-  ok(a === b, msg);
-}
-
-onmessage = event => {
-  runTests(event.data).then(() => {
-    postMessage({ type: 'finish' });
-  });
-};
new file mode 100644
--- /dev/null
+++ b/dom/workers/test/fileapi_chromeScript.js
@@ -0,0 +1,42 @@
+var { classes: Cc, interfaces: Ci, utils: Cu } = Components;
+Cu.importGlobalProperties(["File"]);
+
+var fileNum = 1;
+
+function createFileWithData(fileData) {
+  var willDelete = fileData === null;
+  var dirSvc = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties);
+  var testFile = dirSvc.get("ProfD", Ci.nsIFile);
+  testFile.append("fileAPItestfile" + fileNum);
+  fileNum++;
+  var outStream = Cc["@mozilla.org/network/file-output-stream;1"].createInstance(Ci.nsIFileOutputStream);
+  outStream.init(testFile, 0x02 | 0x08 | 0x20, // write, create, truncate
+                 0o666, 0);
+  if (willDelete) {
+    fileData = "some irrelevant test data\n";
+  }
+  outStream.write(fileData, fileData.length);
+  outStream.close();
+
+  return File.createFromNsIFile(testFile).then(function(domFile) {
+    if (willDelete) {
+      testFile.remove(/* recursive: */ false);
+    }
+    return domFile;
+  });
+}
+
+addMessageListener("files.open", function (message) {
+  let promises = [];
+  let list = [];
+
+  for (let fileData of message) {
+    promises.push(createFileWithData(fileData).then(domFile => {
+      list.push(domFile);
+    }));
+  }
+
+  Promise.all(promises).then(() => {
+    sendAsyncMessage("files.opened", list);
+  });
+});
--- a/dom/workers/test/mochitest.ini
+++ b/dom/workers/test/mochitest.ini
@@ -93,16 +93,18 @@ support-files =
   empty.html
   referrer.sjs
   referrer_test_server.sjs
   sharedWorker_ports.js
   sharedWorker_lifetime.js
   worker_referrer.js
   websocket_https.html
   websocket_https_worker.js
+  worker_fileReader.js
+  fileapi_chromeScript.js
   importScripts_3rdParty_worker.js
   worker_bug1278777.js
   worker_setTimeoutWith0.js
   worker_bug1301094.js
   script_createFile.js
   worker_suspended.js
   window_suspended.html
   !/dom/base/test/file_bug945152.jar
@@ -222,15 +224,16 @@ skip-if = toolkit == 'android' #bug 9828
 [test_worker_interfaces_secureContext.html]
 scheme=https
 [test_workersDisabled.html]
 [test_referrer.html]
 [test_referrer_header_worker.html]
 [test_importScripts_3rdparty.html]
 [test_sharedWorker_ports.html]
 [test_sharedWorker_lifetime.html]
+[test_fileReader.html]
 [test_navigator_workers_hardwareConcurrency.html]
 [test_bug1278777.html]
 [test_setTimeoutWith0.html]
 [test_bug1301094.html]
 [test_subworkers_suspended.html]
 skip-if = toolkit == 'android' #bug 1366501
 [test_bug1317725.html]
new file mode 100644
--- /dev/null
+++ b/dom/workers/test/test_fileReader.html
@@ -0,0 +1,100 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>Test for FileReader in workers</title>
+  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+
+<body>
+<script type="text/javascript">
+
+const minFileSize = 20000;
+SimpleTest.waitForExplicitFinish();
+
+// Create strings containing data we'll test with. We'll want long
+// strings to ensure they span multiple buffers while loading
+var testTextData = "asd b\tlah\u1234w\u00a0r";
+while (testTextData.length < minFileSize) {
+  testTextData = testTextData + testTextData;
+}
+
+var testASCIIData = "abcdef 123456\n";
+while (testASCIIData.length < minFileSize) {
+  testASCIIData = testASCIIData + testASCIIData;
+}
+
+var testBinaryData = "";
+for (var i = 0; i < 256; i++) {
+  testBinaryData += String.fromCharCode(i);
+}
+while (testBinaryData.length < minFileSize) {
+  testBinaryData = testBinaryData + testBinaryData;
+}
+
+var dataurldata0 = testBinaryData.substr(0, testBinaryData.length -
+					 testBinaryData.length % 3);
+var dataurldata1 = testBinaryData.substr(0, testBinaryData.length - 2 -
+					 testBinaryData.length % 3);
+var dataurldata2 = testBinaryData.substr(0, testBinaryData.length - 1 -
+					 testBinaryData.length % 3);
+
+
+//Set up files for testing
+var openerURL = SimpleTest.getTestFileURL("fileapi_chromeScript.js");
+var opener = SpecialPowers.loadChromeScript(openerURL);
+opener.addMessageListener("files.opened", onFilesOpened);
+opener.sendAsyncMessage("files.open", [
+  testASCIIData,
+  testBinaryData,
+  null,
+  convertToUTF8(testTextData),
+  convertToUTF16(testTextData),
+  "",
+  dataurldata0,
+  dataurldata1,
+  dataurldata2,
+]);
+
+function onFilesOpened(message) {
+  var worker = new Worker('worker_fileReader.js');
+  worker.postMessage({ blobs: message,
+                       testTextData: testTextData,
+                       testASCIIData: testASCIIData,
+                       testBinaryData: testBinaryData,
+                       dataurldata0: dataurldata0,
+                       dataurldata1: dataurldata1,
+                       dataurldata2: dataurldata2 });
+
+  worker.onmessage = function(e) {
+    var msg = e.data;
+    if (msg.type == 'finish') {
+      SimpleTest.finish();
+      return;
+    }
+
+    if (msg.type == 'check') {
+      ok(msg.status, msg.msg);
+      return;
+    }
+
+    ok(false, "Unknown message.");
+  }
+}
+
+function convertToUTF16(s) {
+  res = "";
+  for (var i = 0; i < s.length; ++i) {
+    c = s.charCodeAt(i);
+    res += String.fromCharCode(c & 255, c >>> 8);
+  }
+  return res;
+}
+
+function convertToUTF8(s) {
+  return unescape(encodeURIComponent(s));
+}
+
+</script>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/dom/workers/test/worker_fileReader.js
@@ -0,0 +1,419 @@
+var testRanCounter = 0;
+var expectedTestCount = 0;
+var testSetupFinished = false;
+
+function ok(a, msg) {
+  postMessage({type: 'check', status: !!a, msg: msg });
+}
+
+function is(a, b, msg) {
+  ok(a === b, msg);
+}
+
+function finish() {
+  postMessage({type: 'finish'});
+}
+
+function convertToUTF16(s) {
+  res = "";
+  for (var i = 0; i < s.length; ++i) {
+    c = s.charCodeAt(i);
+    res += String.fromCharCode(c & 255, c >>> 8);
+  }
+  return res;
+}
+
+function convertToUTF8(s) {
+  return unescape(encodeURIComponent(s));
+}
+
+function convertToDataURL(s) {
+  return "data:application/octet-stream;base64," + btoa(s);
+}
+
+onmessage = function(message) {
+  is(FileReader.EMPTY, 0, "correct EMPTY value");
+  is(FileReader.LOADING, 1, "correct LOADING value");
+  is(FileReader.DONE, 2, "correct DONE value");
+
+  // List of blobs.
+  var asciiFile = message.data.blobs.shift();
+  var binaryFile = message.data.blobs.shift();
+  var nonExistingFile = message.data.blobs.shift();
+  var utf8TextFile = message.data.blobs.shift();
+  var utf16TextFile = message.data.blobs.shift();
+  var emptyFile = message.data.blobs.shift();
+  var dataUrlFile0 = message.data.blobs.shift();
+  var dataUrlFile1 = message.data.blobs.shift();
+  var dataUrlFile2 = message.data.blobs.shift();
+
+  // List of buffers for testing.
+  var testTextData = message.data.testTextData;
+  var testASCIIData = message.data.testASCIIData;
+  var testBinaryData = message.data.testBinaryData;
+  var dataurldata0 = message.data.dataurldata0;
+  var dataurldata1 = message.data.dataurldata1;
+  var dataurldata2 = message.data.dataurldata2;
+
+  // Test that plain reading works and fires events as expected, both
+  // for text and binary reading
+
+  var onloadHasRunText = false;
+  var onloadStartHasRunText = false;
+  r = new FileReader();
+  is(r.readyState, FileReader.EMPTY, "correct initial text readyState");
+  r.onload = getLoadHandler(testASCIIData, testASCIIData.length, "plain reading");
+  r.addEventListener("load", function() { onloadHasRunText = true });
+  r.addEventListener("loadstart", function() { onloadStartHasRunText = true });
+  r.readAsText(asciiFile);
+  is(r.readyState, FileReader.LOADING, "correct loading text readyState");
+  is(onloadHasRunText, false, "text loading must be async");
+  is(onloadStartHasRunText, true, "text loadstart should fire sync");
+  expectedTestCount++;
+
+  var onloadHasRunBinary = false;
+  var onloadStartHasRunBinary = false;
+  r = new FileReader();
+  is(r.readyState, FileReader.EMPTY, "correct initial binary readyState");
+  r.addEventListener("load", function() { onloadHasRunBinary = true });
+  r.addEventListener("loadstart", function() { onloadStartHasRunBinary = true });
+  r.readAsBinaryString(binaryFile);
+  r.onload = getLoadHandler(testBinaryData, testBinaryData.length, "binary reading");
+  is(r.readyState, FileReader.LOADING, "correct loading binary readyState");
+  is(onloadHasRunBinary, false, "binary loading must be async");
+  is(onloadStartHasRunBinary, true, "binary loadstart should fire sync");
+  expectedTestCount++;
+
+  var onloadHasRunArrayBuffer = false;
+  var onloadStartHasRunArrayBuffer = false;
+  r = new FileReader();
+  is(r.readyState, FileReader.EMPTY, "correct initial arrayBuffer readyState");
+  r.addEventListener("load", function() { onloadHasRunArrayBuffer = true });
+  r.addEventListener("loadstart", function() { onloadStartHasRunArrayBuffer = true });
+  r.readAsArrayBuffer(binaryFile);
+  r.onload = getLoadHandlerForArrayBuffer(testBinaryData, testBinaryData.length, "array buffer reading");
+  is(r.readyState, FileReader.LOADING, "correct loading arrayBuffer readyState");
+  is(onloadHasRunArrayBuffer, false, "arrayBuffer loading must be async");
+  is(onloadStartHasRunArrayBuffer, true, "arrayBuffer loadstart should fire sync");
+  expectedTestCount++;
+
+  // Test a variety of encodings, and make sure they work properly
+  r = new FileReader();
+  r.onload = getLoadHandler(testASCIIData, testASCIIData.length, "no encoding reading");
+  r.readAsText(asciiFile, "");
+  expectedTestCount++;
+
+  r = new FileReader();
+  r.onload = getLoadHandler(testASCIIData, testASCIIData.length, "iso8859 reading");
+  r.readAsText(asciiFile, "iso-8859-1");
+  expectedTestCount++;
+
+  r = new FileReader();
+  r.onload = getLoadHandler(testTextData,
+                            convertToUTF8(testTextData).length,
+                            "utf8 reading");
+  r.readAsText(utf8TextFile, "utf8");
+  expectedTestCount++;
+
+  r = new FileReader();
+  r.readAsText(utf16TextFile, "utf-16");
+  r.onload = getLoadHandler(testTextData,
+                            convertToUTF16(testTextData).length,
+                            "utf16 reading");
+  expectedTestCount++;
+
+  // Test get result without reading
+  r = new FileReader();
+  is(r.readyState, FileReader.EMPTY,
+     "readyState in test reader get result without reading");
+  is(r.error, null,
+     "no error in test reader get result without reading");
+  is(r.result, null,
+     "result in test reader get result without reading");
+
+  // Test loading an empty file works (and doesn't crash!)
+  r = new FileReader();
+  r.onload = getLoadHandler("", 0, "empty no encoding reading");
+  r.readAsText(emptyFile, "");
+  expectedTestCount++;
+
+  r = new FileReader();
+  r.onload = getLoadHandler("", 0, "empty utf8 reading");
+  r.readAsText(emptyFile, "utf8");
+  expectedTestCount++;
+
+  r = new FileReader();
+  r.onload = getLoadHandler("", 0, "empty utf16 reading");
+  r.readAsText(emptyFile, "utf-16");
+  expectedTestCount++;
+
+  r = new FileReader();
+  r.onload = getLoadHandler("", 0, "empty binary string reading");
+  r.readAsBinaryString(emptyFile);
+  expectedTestCount++;
+
+  r = new FileReader();
+  r.onload = getLoadHandlerForArrayBuffer("", 0, "empty array buffer reading");
+  r.readAsArrayBuffer(emptyFile);
+  expectedTestCount++;
+
+  r = new FileReader();
+  r.onload = getLoadHandler(convertToDataURL(""), 0, "empty binary string reading");
+  r.readAsDataURL(emptyFile);
+  expectedTestCount++;
+
+  // Test reusing a FileReader to read multiple times
+  r = new FileReader();
+  r.onload = getLoadHandler(testASCIIData,
+                            testASCIIData.length,
+                            "to-be-reused reading text")
+  var makeAnotherReadListener = function(event) {
+    r = event.target;
+    r.removeEventListener("load", makeAnotherReadListener);
+    r.onload = getLoadHandler(testASCIIData,
+                              testASCIIData.length,
+                              "reused reading text");
+    r.readAsText(asciiFile);
+  };
+  r.addEventListener("load", makeAnotherReadListener);
+  r.readAsText(asciiFile);
+  expectedTestCount += 2;
+
+  r = new FileReader();
+  r.onload = getLoadHandler(testBinaryData,
+                            testBinaryData.length,
+                            "to-be-reused reading binary")
+  var makeAnotherReadListener2 = function(event) {
+    r = event.target;
+    r.removeEventListener("load", makeAnotherReadListener2);
+    r.onload = getLoadHandler(testBinaryData,
+                              testBinaryData.length,
+                              "reused reading binary");
+    r.readAsBinaryString(binaryFile);
+  };
+  r.addEventListener("load", makeAnotherReadListener2);
+  r.readAsBinaryString(binaryFile);
+  expectedTestCount += 2;
+
+  r = new FileReader();
+  r.onload = getLoadHandler(convertToDataURL(testBinaryData),
+                            testBinaryData.length,
+                            "to-be-reused reading data url")
+  var makeAnotherReadListener3 = function(event) {
+    r = event.target;
+    r.removeEventListener("load", makeAnotherReadListener3);
+    r.onload = getLoadHandler(convertToDataURL(testBinaryData),
+                              testBinaryData.length,
+                              "reused reading data url");
+    r.readAsDataURL(binaryFile);
+  };
+  r.addEventListener("load", makeAnotherReadListener3);
+  r.readAsDataURL(binaryFile);
+  expectedTestCount += 2;
+
+  r = new FileReader();
+  r.onload = getLoadHandlerForArrayBuffer(testBinaryData,
+                                          testBinaryData.length,
+                                          "to-be-reused reading arrayBuffer")
+  var makeAnotherReadListener4 = function(event) {
+    r = event.target;
+    r.removeEventListener("load", makeAnotherReadListener4);
+    r.onload = getLoadHandlerForArrayBuffer(testBinaryData,
+                                            testBinaryData.length,
+                                            "reused reading arrayBuffer");
+    r.readAsArrayBuffer(binaryFile);
+  };
+  r.addEventListener("load", makeAnotherReadListener4);
+  r.readAsArrayBuffer(binaryFile);
+  expectedTestCount += 2;
+
+  // Test first reading as ArrayBuffer then read as something else
+  // (BinaryString) and doesn't crash
+  r = new FileReader();
+  r.onload = getLoadHandlerForArrayBuffer(testBinaryData,
+                                          testBinaryData.length,
+                                          "to-be-reused reading arrayBuffer")
+  var makeAnotherReadListener5 = function(event) {
+    r = event.target;
+    r.removeEventListener("load", makeAnotherReadListener5);
+    r.onload = getLoadHandler(testBinaryData,
+                              testBinaryData.length,
+                              "reused reading binary string");
+    r.readAsBinaryString(binaryFile);
+  };
+  r.addEventListener("load", makeAnotherReadListener5);
+  r.readAsArrayBuffer(binaryFile);
+  expectedTestCount += 2;
+
+  //Test data-URI encoding on differing file sizes
+  is(dataurldata0.length % 3, 0, "Want to test data with length % 3 == 0");
+  r = new FileReader();
+  r.onload = getLoadHandler(convertToDataURL(dataurldata0),
+                            dataurldata0.length,
+                            "dataurl reading, %3 = 0");
+  r.readAsDataURL(dataUrlFile0);
+  expectedTestCount++;
+
+  is(dataurldata1.length % 3, 1, "Want to test data with length % 3 == 1");
+  r = new FileReader();
+  r.onload = getLoadHandler(convertToDataURL(dataurldata1),
+                            dataurldata1.length,
+                            "dataurl reading, %3 = 1");
+  r.readAsDataURL(dataUrlFile1);
+  expectedTestCount++;
+
+  is(dataurldata2.length % 3, 2, "Want to test data with length % 3 == 2");
+  r = new FileReader();
+  r.onload = getLoadHandler(convertToDataURL(dataurldata2),
+                            dataurldata2.length,
+                            "dataurl reading, %3 = 2");
+  r.readAsDataURL(dataUrlFile2),
+  expectedTestCount++;
+
+
+  // Test abort()
+  var abortHasRun = false;
+  var loadEndHasRun = false;
+  r = new FileReader();
+  r.onabort = function (event) {
+    is(abortHasRun, false, "abort should only fire once");
+    is(loadEndHasRun, false, "loadend shouldn't have fired yet");
+    abortHasRun = true;
+    is(event.target.readyState, FileReader.DONE, "should be DONE while firing onabort");
+    is(event.target.error.name, "AbortError", "error set to AbortError for aborted reads");
+    is(event.target.result, null, "file data should be null on aborted reads");
+  }
+  r.onloadend = function (event) {
+    is(abortHasRun, true, "abort should fire before loadend");
+    is(loadEndHasRun, false, "loadend should only fire once");
+    loadEndHasRun = true;
+    is(event.target.readyState, FileReader.DONE, "should be DONE while firing onabort");
+    is(event.target.error.name, "AbortError", "error set to AbortError for aborted reads");
+    is(event.target.result, null, "file data should be null on aborted reads");
+  }
+  r.onload = function() { ok(false, "load should not fire for aborted reads") };
+  r.onerror = function() { ok(false, "error should not fire for aborted reads") };
+  r.onprogress = function() { ok(false, "progress should not fire for aborted reads") };
+  var abortThrew = false;
+  try {
+    r.abort();
+  } catch(e) {
+    abortThrew = true;
+  }
+  is(abortThrew, false, "abort() never throws");
+  is(abortHasRun, false, "abort() is a no-op unless loading");
+  r.readAsText(asciiFile);
+  r.abort();
+  is(abortHasRun, true, "1 abort should fire sync");
+  is(loadEndHasRun, true, "loadend should fire sync");
+
+  // Test calling readAsX to cause abort()
+  var reuseAbortHasRun = false;
+  r = new FileReader();
+  r.onabort = function (event) { reuseAbortHasRun = true; }
+  r.onload = function() { ok(true, "load should fire for aborted reads") };
+  var abortThrew = false;
+  try {
+    r.abort();
+  } catch(e) {
+    abortThrew = true;
+  }
+  is(abortThrew, false, "abort() never throws");
+  is(reuseAbortHasRun, false, "abort() is a no-op unless loading");
+  r.readAsText(asciiFile);
+
+  var readThrew = false;
+  try {
+  r.readAsText(asciiFile);
+  } catch(e) {
+    readThrew = true;
+  }
+
+  is(readThrew, true, "readAsText() must throw if loading");
+  is(reuseAbortHasRun, false, "2 abort should fire sync");
+  r.onload = getLoadHandler(testASCIIData, testASCIIData.length, "reuse-as-abort reading");
+  expectedTestCount++;
+
+
+  // Test reading from nonexistent files
+  r = new FileReader();
+  var didThrow = false;
+  r.onerror = function (event) {
+    is(event.target.readyState, FileReader.DONE, "should be DONE while firing onerror");
+    is(event.target.error.name, "NotFoundError", "error set to NotFoundError for nonexistent files");
+    is(event.target.result, null, "file data should be null on aborted reads");
+    testHasRun();
+  };
+  r.onload = function (event) {
+    is(false, "nonexistent file shouldn't load! (FIXME: bug 1122788)");
+    testHasRun();
+  };
+  try {
+    r.readAsDataURL(nonExistingFile);
+    expectedTestCount++;
+  } catch(ex) {
+    didThrow = true;
+  }
+  // Once this test passes, we should test that onerror gets called and
+  // that the FileReader object is in the right state during that call.
+  is(didThrow, false, "shouldn't throw when opening nonexistent file, should fire error instead");
+
+
+  function getLoadHandler(expectedResult, expectedLength, testName) {
+    return function (event) {
+      is(event.target.readyState, FileReader.DONE,
+         "readyState in test " + testName);
+      is(event.target.error, null,
+         "no error in test " + testName);
+      is(event.target.result, expectedResult,
+         "result in test " + testName);
+      is(event.lengthComputable, true,
+         "lengthComputable in test " + testName);
+      is(event.loaded, expectedLength,
+         "loaded in test " + testName);
+      is(event.total, expectedLength,
+         "total in test " + testName);
+      testHasRun();
+    }
+  }
+
+  function getLoadHandlerForArrayBuffer(expectedResult, expectedLength, testName) {
+    return function (event) {
+      is(event.target.readyState, FileReader.DONE,
+         "readyState in test " + testName);
+      is(event.target.error, null,
+         "no error in test " +  testName);
+      is(event.lengthComputable, true,
+         "lengthComputable in test " + testName);
+      is(event.loaded, expectedLength,
+         "loaded in test " + testName);
+      is(event.total, expectedLength,
+         "total in test " + testName);
+      is(event.target.result.byteLength, expectedLength,
+         "array buffer size in test " + testName);
+      var u8v = new Uint8Array(event.target.result);
+      is(String.fromCharCode.apply(String, u8v), expectedResult,
+         "array buffer contents in test " + testName);
+      u8v = null;
+      is(event.target.result.byteLength, expectedLength,
+         "array buffer size after gc in test " + testName);
+      u8v = new Uint8Array(event.target.result);
+      is(String.fromCharCode.apply(String, u8v), expectedResult,
+         "array buffer contents after gc in test " + testName);
+      testHasRun();
+    }
+  }
+
+  function testHasRun() {
+    //alert(testRanCounter);
+    ++testRanCounter;
+    if (testRanCounter == expectedTestCount) {
+      is(testSetupFinished, true, "test setup should have finished; check for exceptions");
+      is(onloadHasRunText, true, "onload text should have fired by now");
+      is(onloadHasRunBinary, true, "onload binary should have fired by now");
+      finish();
+    }
+  }
+
+  testSetupFinished = true;
+}