Backed out changeset e6afe93a2282 (bug 1305230)
authorSebastian Hengst <archaeopteryx@coole-files.de>
Fri, 13 Oct 2017 13:25:27 +0200
changeset 386139 def0af88e262abbcd845dbf1596345618ee7a77d
parent 386138 478cffed4b5f02992cc56ccd74e4ed7d3efe8466
child 386140 2f665a0a379f84020e34a982cca213b0b52c7894
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)
bugs1305230
milestone58.0a1
backs oute6afe93a22826c75f028ebe252cdc0907905fa5e
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 e6afe93a2282 (bug 1305230)
dom/file/tests/common_blob.js
dom/file/tests/fileutils.js
dom/file/tests/mochitest.ini
dom/file/tests/test_fileapi_slice.html
dom/file/tests/test_fileapi_slice_image.html
--- a/dom/file/tests/common_blob.js
+++ b/dom/file/tests/common_blob.js
@@ -78,108 +78,16 @@ function testBlob(file, contents, testNa
         XHRLoadHandler(event, resolve, contents, "XMLHttpRequest send of " + testName);
       });
       xhr.overrideMimeType('text/plain; charset=x-user-defined');
       xhr.send(file);
     });
   });
 }
 
-function testSlice(file, size, type, contents, fileType) {
-  is(file.type, type, fileType + " file is correct type");
-  is(file.size, size, fileType + " file is correct size");
-  ok(file instanceof File, fileType + " file is a File");
-  ok(file instanceof Blob, fileType + " file is also a Blob");
-
-  let slice = file.slice(0, size);
-  ok(slice instanceof Blob, fileType + " fullsize slice is a Blob");
-  ok(!(slice instanceof File), fileType + " fullsize slice is not a File");
-
-  slice = file.slice(0, 1234);
-  ok(slice instanceof Blob, fileType + " sized slice is a Blob");
-  ok(!(slice instanceof File), fileType + " sized slice is not a File");
-
-  slice = file.slice(0, size, "foo/bar");
-  is(slice.type, "foo/bar", fileType + " fullsize slice foo/bar type");
-
-  slice = file.slice(0, 5432, "foo/bar");
-  is(slice.type, "foo/bar", fileType + " sized slice foo/bar type");
-
-  is(slice.slice(0, 10).type, "", fileType + " slice-slice type");
-  is(slice.slice(0, 10).size, 10, fileType + " slice-slice size");
-  is(slice.slice(0, 10, "hello/world").type, "hello/world", fileType + " slice-slice hello/world type");
-  is(slice.slice(0, 10, "hello/world").size, 10, fileType + " slice-slice hello/world size");
-
-  // Start, end, expected size
-  var indexes = [[0, size, size],
-                 [0, 1234, 1234],
-                 [size-500, size, 500],
-                 [size-500, size+500, 500],
-                 [size+500, size+1500, 0],
-                 [0, 0, 0],
-                 [1000, 1000, 0],
-                 [size, size, 0],
-                 [undefined, undefined, size],
-                 [0, undefined, size],
-                 [100, undefined, size-100],
-                 [-100, undefined, 100],
-                 [100, -100, size-200],
-                 [-size-100, undefined, size],
-                 [-2*size-100, 500, 500],
-                 [0, -size-100, 0],
-                 [100, -size-100, 0],
-                 [50, -size+100, 50],
-                 [0, 33000, 33000],
-                 [1000, 34000, 33000],
-                ];
-
-  function runNextTest() {
-    if (indexes.length == 0) {
-      return Promise.resolve(true);
-    }
-
-    let index = indexes.shift();
-
-    let sliceContents;
-    let testName;
-    if (index[0] == undefined) {
-      slice = file.slice();
-      sliceContents = contents.slice();
-      testName = fileType + " slice()";
-    } else if (index[1] == undefined) {
-      slice = file.slice(index[0]);
-      sliceContents = contents.slice(index[0]);
-      testName = fileType + " slice(" + index[0] + ")";
-    } else {
-      slice = file.slice(index[0], index[1]);
-      sliceContents = contents.slice(index[0], index[1]);
-      testName = fileType + " slice(" + index[0] + ", " + index[1] + ")";
-    }
-
-    is(slice.type, "", testName + " type");
-    is(slice.size, index[2], testName + " size");
-    is(sliceContents.length, index[2], testName + " data size");
-
-    return testBlob(slice, sliceContents, testName).then(runNextTest);
-  }
-
-  return runNextTest()
-  .then(() => {
-    // Slice of slice
-    let slice = file.slice(0, 40000);
-    return testBlob(slice.slice(5000, 42000), contents.slice(5000, 40000), "file slice slice");
-  })
-  .then(() => {
-    // ...of slice of slice
-    let slice = file.slice(0, 40000).slice(5000, 42000).slice(400, 700);
-    SpecialPowers.gc();
-    return testBlob(slice, contents.slice(5400, 5700), "file slice slice slice");
-  });
-}
-
 function convertXHRBinary(s) {
   let res = "";
   for (let i = 0; i < s.length; ++i) {
     res += String.fromCharCode(s.charCodeAt(i) & 255);
   }
   return res;
 }
 
@@ -227,53 +135,8 @@ function checkMPSubmission(sub, expected
     }
     // Do not use |is(sub[i].body, expected[i].value, "...");| that may output raw binary data.
     is(sub[i].body.length, expected[i].value.length,
        "Length of correct value");
     ok(sub[i].body == expected[i].value,
        "Content of correct value");
   }
 }
-
-function createCanvasURL() {
-  return new Promise(resolve => {
-    // Create a decent-sized image
-    let cx = $("canvas").getContext('2d');
-    let s = cx.canvas.width;
-    let grad = cx.createLinearGradient(0, 0, s-1, s-1);
-    for (i = 0; i < 0.95; i += .1) {
-      grad.addColorStop(i, "white");
-      grad.addColorStop(i + .05, "black");
-    }
-    grad.addColorStop(1, "white");
-    cx.fillStyle = grad;
-    cx.fillRect(0, 0, s-1, s-1);
-    cx.fillStyle = "rgba(200, 0, 0, 0.9)";
-    cx.fillRect(.1 * s, .1 * s, .7 * s, .7 * s);
-    cx.strokeStyle = "rgba(0, 0, 130, 0.5)";
-    cx.lineWidth = .14 * s;
-    cx.beginPath();
-    cx.arc(.6 * s, .6 * s, .3 * s, 0, Math.PI*2, true);
-    cx.stroke();
-    cx.closePath();
-    cx.fillStyle = "rgb(0, 255, 0)";
-    cx.beginPath();
-    cx.arc(.1 * s, .8 * s, .1 * s, 0, Math.PI*2, true);
-    cx.fill();
-    cx.closePath();
-
-    let data = atob(cx.canvas.toDataURL("image/png").substring("data:text/png;base64,".length + 1));
-
-    // This might fail if we dramatically improve the png encoder. If that happens
-    // please increase the complexity or size of the image generated above to ensure
-    // that we're testing with files that are large enough.
-    ok(data.length > 65536, "test data sufficiently large");
-
-    resolve(data);
-  });
-}
-
-function createFile(data, name) {
-  return new Promise(resolve => {
-    SpecialPowers.createFiles([{name, data}],
-                              files => { resolve(files[0]); });
-  });
-}
new file mode 100644
--- /dev/null
+++ b/dom/file/tests/fileutils.js
@@ -0,0 +1,244 @@
+// Utility functions
+var testRanCounter = 0;
+var expectedTestCount = 0;
+
+function testHasRun() {
+ ++testRanCounter;
+ if (testRanCounter == expectedTestCount) {
+    SimpleTest.finish();
+  }
+}
+
+
+function testFile(file, contents, test) {
+  SimpleTest.requestLongerTimeout(2);
+
+  // Load file using FileReader
+  var r = new FileReader();
+  r.onload = getFileReaderLoadHandler(contents, contents.length, "FileReader.readAsBinaryString of " + test);
+  r.readAsBinaryString(file);
+  expectedTestCount++;
+
+  // Load file using URL.createObjectURL and XMLHttpRequest
+  var xhr = new XMLHttpRequest;
+  xhr.open("GET", URL.createObjectURL(file));
+  xhr.onload = getXHRLoadHandler(contents, contents.length,
+                                 "XMLHttpRequest load of " + test);
+  xhr.overrideMimeType('text/plain; charset=x-user-defined');
+  xhr.send();
+  expectedTestCount++;
+
+  // Send file to server using FormData and XMLHttpRequest
+  xhr = new XMLHttpRequest();
+  xhr.onload = function(event) {
+    checkMPSubmission(JSON.parse(event.target.responseText),
+                      [{ name: "hello", value: "world"},
+                       { name: "myfile",
+                         value: contents,
+                         fileName: file.name || "blob",
+                         contentType: file.type || "application/octet-stream" }]);
+    testHasRun();
+  }
+  xhr.open("POST", "../../../dom/html/test/form_submit_server.sjs");
+  var fd = new FormData;
+  fd.append("hello", "world");
+  fd.append("myfile", file);
+  xhr.send(fd);
+  expectedTestCount++;
+
+  // Send file to server using plain XMLHttpRequest
+  var xhr = new XMLHttpRequest;
+  xhr.open("POST", "../../../dom/xhr/tests/file_XHRSendData.sjs");
+  xhr.onload = function (event) {
+    is(event.target.getResponseHeader("Result-Content-Type"),
+       file.type ? file.type : null,
+       "request content-type in XMLHttpRequest send of " + test);
+    is(event.target.getResponseHeader("Result-Content-Length"),
+       String(file.size),
+       "request content-length in XMLHttpRequest send of " + test);
+  };
+  xhr.addEventListener("load",
+                       getXHRLoadHandler(contents, contents.length,
+                                         "XMLHttpRequest send of " + test));
+  xhr.overrideMimeType('text/plain; charset=x-user-defined');
+  xhr.send(file);
+  expectedTestCount++;
+}
+
+function getFileReaderLoadHandler(expectedResult, expectedLength, testName) {
+  return function (event) {
+    is(event.target.readyState, FileReader.DONE,
+       "[FileReader] readyState in test " + testName);
+    is(event.target.error, null,
+       "[FileReader] no error in test " + testName);
+    // Do not use |is(event.target.result, expectedResult, "...");| that may output raw binary data.
+    is(event.target.result.length, expectedResult.length,
+       "[FileReader] Length of result in test " + testName);
+    ok(event.target.result == expectedResult,
+       "[FileReader] Content of result in test " + testName);
+    is(event.lengthComputable, true,
+       "[FileReader] lengthComputable in test " + testName);
+    is(event.loaded, expectedLength,
+       "[FileReader] Loaded length in test " + testName);
+    is(event.total, expectedLength,
+       "[FileReader] Total length in test " + testName);
+    testHasRun();
+  }
+}
+
+function getXHRLoadHandler(expectedResult, expectedLength, testName) {
+  return function (event) {
+    is(event.target.readyState, 4,
+       "[XHR] readyState in test " + testName);
+    is(event.target.status, 200,
+       "[XHR] no error in test " + testName);
+    // Do not use |is(convertXHRBinary(event.target.responseText), expectedResult, "...");| that may output raw binary data.
+    var convertedData = convertXHRBinary(event.target.responseText);
+    is(convertedData.length, expectedResult.length,
+       "[XHR] Length of result in test " + testName);
+    ok(convertedData == expectedResult,
+       "[XHR] Content of result in test " + testName);
+    is(event.lengthComputable, event.total != 0,
+       "[XHR] lengthComputable in test " + testName);
+    is(event.loaded, expectedLength,
+       "[XHR] Loaded length in test " + testName);
+    is(event.total, expectedLength,
+       "[XHR] Total length in test " + testName);
+
+    testHasRun();
+  }
+}
+
+function convertXHRBinary(s) {
+  var res = "";
+  for (var i = 0; i < s.length; ++i) {
+    res += String.fromCharCode(s.charCodeAt(i) & 255);
+  }
+  return res;
+}
+
+function gc() {
+  window.QueryInterface(SpecialPowers.Ci.nsIInterfaceRequestor)
+        .getInterface(SpecialPowers.Ci.nsIDOMWindowUtils)
+        .garbageCollect();
+}
+
+function checkMPSubmission(sub, expected) {
+  function getPropCount(o) {
+    var x, l = 0;
+    for (x in o) ++l;
+    return l;
+  }
+
+  is(sub.length, expected.length,
+     "Correct number of items");
+  var i;
+  for (i = 0; i < expected.length; ++i) {
+    if (!("fileName" in expected[i])) {
+      is(sub[i].headers["Content-Disposition"],
+         "form-data; name=\"" + expected[i].name + "\"",
+         "Correct name (A)");
+      is (getPropCount(sub[i].headers), 1,
+          "Wrong number of headers (A)");
+    }
+    else {
+      is(sub[i].headers["Content-Disposition"],
+         "form-data; name=\"" + expected[i].name + "\"; filename=\"" +
+           expected[i].fileName + "\"",
+         "Correct name (B)");
+      is(sub[i].headers["Content-Type"],
+         expected[i].contentType,
+         "Correct content type (B)");
+      is (getPropCount(sub[i].headers), 2,
+          "Wrong number of headers (B)");
+    }
+    // Do not use |is(sub[i].body, expected[i].value, "...");| that may output raw binary data.
+    is(sub[i].body.length, expected[i].value.length,
+       "Length of correct value");
+    ok(sub[i].body == expected[i].value,
+       "Content of correct value");
+  }
+}
+
+function testSlice(file, size, type, contents, fileType) {
+  is(file.type, type, fileType + " file is correct type");
+  is(file.size, size, fileType + " file is correct size");
+  ok(file instanceof File, fileType + " file is a File");
+  ok(file instanceof Blob, fileType + " file is also a Blob");
+  
+  var slice = file.slice(0, size);
+  ok(slice instanceof Blob, fileType + " fullsize slice is a Blob");
+  ok(!(slice instanceof File), fileType + " fullsize slice is not a File");
+
+  slice = file.slice(0, 1234);
+  ok(slice instanceof Blob, fileType + " sized slice is a Blob");
+  ok(!(slice instanceof File), fileType + " sized slice is not a File");
+  
+  slice = file.slice(0, size, "foo/bar");
+  is(slice.type, "foo/bar", fileType + " fullsize slice foo/bar type");
+
+  slice = file.slice(0, 5432, "foo/bar");
+  is(slice.type, "foo/bar", fileType + " sized slice foo/bar type");
+  
+  is(slice.slice(0, 10).type, "", fileType + " slice-slice type");
+  is(slice.slice(0, 10).size, 10, fileType + " slice-slice size");
+  is(slice.slice(0, 10, "hello/world").type, "hello/world", fileType + " slice-slice hello/world type");
+  is(slice.slice(0, 10, "hello/world").size, 10, fileType + " slice-slice hello/world size");
+
+  // Start, end, expected size
+  var indexes = [[0, size, size],
+                 [0, 1234, 1234],
+                 [size-500, size, 500],
+                 [size-500, size+500, 500],
+                 [size+500, size+1500, 0],
+                 [0, 0, 0],
+                 [1000, 1000, 0],
+                 [size, size, 0],
+                 [undefined, undefined, size],
+                 [0, undefined, size],
+                 [100, undefined, size-100],
+                 [-100, undefined, 100],
+                 [100, -100, size-200],
+                 [-size-100, undefined, size],
+                 [-2*size-100, 500, 500],
+                 [0, -size-100, 0],
+                 [100, -size-100, 0],
+                 [50, -size+100, 50],
+                 [0, 33000, 33000],
+                 [1000, 34000, 33000],
+                ];
+  
+  for (var i = 0; i < indexes.length; ++i) {
+    var sliceContents;
+    var testName;
+    if (indexes[i][0] == undefined) {
+      slice = file.slice();
+      sliceContents = contents.slice();
+      testName = fileType + " slice()";
+    }
+    else if (indexes[i][1] == undefined) {
+      slice = file.slice(indexes[i][0]);
+      sliceContents = contents.slice(indexes[i][0]);
+      testName = fileType + " slice(" + indexes[i][0] + ")";
+    }
+    else {
+      slice = file.slice(indexes[i][0], indexes[i][1]);
+      sliceContents = contents.slice(indexes[i][0], indexes[i][1]);
+      testName = fileType + " slice(" + indexes[i][0] + ", " + indexes[i][1] + ")";
+    }
+    is(slice.type, "", testName + " type");
+    is(slice.size, indexes[i][2], testName + " size");
+    is(sliceContents.length, indexes[i][2], testName + " data size");
+    testFile(slice, sliceContents, testName);
+  }
+
+  // Slice of slice
+  var slice = file.slice(0, 40000);
+  testFile(slice.slice(5000, 42000), contents.slice(5000, 40000), "file slice slice");
+  
+  // ...of slice of slice
+  slice = slice.slice(5000, 42000).slice(400, 700);
+  SpecialPowers.gc();
+  testFile(slice, contents.slice(5400, 5700), "file slice slice slice");
+}
+
--- a/dom/file/tests/mochitest.ini
+++ b/dom/file/tests/mochitest.ini
@@ -5,16 +5,17 @@ support-files =
   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
   fileapi_chromeScript.js
   !/dom/html/test/form_submit_server.sjs
   !/dom/xhr/tests/file_XHRSendData.sjs
 
 [test_blob_fragment_and_query.html]
 [test_blobconstructor.html]
 [test_blobURL_expiring.html]
 [test_file_from_blob.html]
@@ -22,12 +23,10 @@ support-files =
 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
 [test_fileapi_slice.html]
 skip-if = (toolkit == 'android') # Android: Bug 775227
-[test_fileapi_slice_image.html]
-skip-if = (toolkit == 'android') # Android: Bug 775227
 [test_mozfiledataurl.html]
 skip-if = toolkit == 'android' #TIMED_OUT
--- a/dom/file/tests/test_fileapi_slice.html
+++ b/dom/file/tests/test_fileapi_slice.html
@@ -1,47 +1,163 @@
 <!DOCTYPE HTML>
 <html>
 <head>
-  <title>Test for File API + Slice</title>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=575946
+-->
+  <title>Test for Bug 575946</title>
   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
-  <script type="text/javascript" src="common_blob.js"></script>
+  <script type="text/javascript" src="fileutils.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
 </head>
 
 <body>
-
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=575946">Mozilla Bug 575946</a>
 <p id="display">
   <canvas id=canvas width=1100 height=1100 hidden moz-opaque></canvas>
+  <canvas id=testcanvas hidden moz-opaque></canvas>
+  <input id="fileList" type="file"></input>
 </p>
 
-<script type="text/javascript">
+<script class="testbody" type="text/javascript">
 
 SimpleTest.waitForExplicitFinish();
 
 // Create files containing data we'll test with. We'll want long
 // strings to ensure they span multiple buffers while loading
 
-let canvasData;
-let fileData;
+// Create a decent-sized image
+cx = $("canvas").getContext('2d');
+var s = cx.canvas.width;
+var grad = cx.createLinearGradient(0, 0, s-1, s-1);
+for (i = 0; i < 0.95; i += .1) {
+  grad.addColorStop(i, "white");
+  grad.addColorStop(i + .05, "black");
+}
+grad.addColorStop(1, "white");
+cx.fillStyle = grad;
+cx.fillRect(0, 0, s-1, s-1);
+cx.fillStyle = "rgba(200, 0, 0, 0.9)";
+cx.fillRect(.1 * s, .1 * s, .7 * s, .7 * s);
+cx.strokeStyle = "rgba(0, 0, 130, 0.5)";
+cx.lineWidth = .14 * s;
+cx.beginPath();
+cx.arc(.6 * s, .6 * s, .3 * s, 0, Math.PI*2, true);
+cx.stroke();
+cx.closePath();
+cx.fillStyle = "rgb(0, 255, 0)";
+cx.beginPath();
+cx.arc(.1 * s, .8 * s, .1 * s, 0, Math.PI*2, true);
+cx.fill();
+cx.closePath();
+
 
-createCanvasURL()
-.then(data => {
-  canvasData = data;
-  return createFile(data, "basicTestFile");
-})
+function imageLoadHandler(event) {
+  var origcanvas = $("canvas");
+  var testcanvas = $("testcanvas");
+  var image = event.target;
+  is(image.naturalWidth, origcanvas.width, "width correct");
+  is(image.naturalHeight, origcanvas.height, "height correct");
+
+  testcanvas.width = origcanvas.width;
+  testcanvas.height = origcanvas.height;
+  testcanvas.getContext("2d").drawImage(image, 0, 0);
+  // Do not use |is(testcanvas.toDataURL("image/png"), origcanvas.toDataURL("image/png"), "...");| that results in a _very_ long line.
+  var origDataURL = origcanvas.toDataURL("image/png");
+  var testDataURL = testcanvas.toDataURL("image/png");
+  is(testDataURL.length, origDataURL.length,
+     "Length of correct image data");
+  ok(testDataURL == origDataURL,
+     "Content of correct image data");
+
+  testHasRun();
+}
+
+var fileData =
+  atob(cx.canvas.toDataURL("image/png").substring("data:text/png;base64,".length + 1));
+var size = fileData.length;
+var testBinaryData = "";
+
+// This might fail if we dramatically improve the png encoder. If that happens
+// please increase the complexity or size of the image generated above to ensure
+// that we're testing with files that are large enough.
+ok(size > 65536, "test data sufficiently large");
+
+SpecialPowers.createFiles([{name: "basicTestFile", data: fileData}],
+                          basicTest);
+
+function basicTest(files) {
+  var fileFile = files[0];
 
-.then(file => {
-  fileData = file;
-  return testSlice(fileData, canvasData.length, "", canvasData, "fileFile");
-})
+  // Test that basic properties work
+  var memFile = cx.canvas.mozGetAsFile("image/png");
+  testSlice(memFile, size, "image/png", fileData, "memFile");
+  testSlice(fileFile, size, "", fileData, "fileFile");
+
+  // Try loading directly from slice into an image
+  for (var i = 0; i < 256; i++) {
+    testBinaryData += String.fromCharCode(i);
+  }
+  while (testBinaryData.length < 20000) {
+    testBinaryData += testBinaryData;
+  }
+
+  // image in the middle
+  SpecialPowers.createFiles([{name: "middleTestFile",
+                             data: testBinaryData + fileData + testBinaryData}],
+                            imageMiddleTest);
+}
+
+function imageMiddleTest(files) {
+  var imgfile = files[0];
+  is(imgfile.size, size + testBinaryData.length * 2, "correct file size (middle)");
+  var img = new Image;
+  img.src = URL.createObjectURL(imgfile.slice(testBinaryData.length, testBinaryData.length + size));
+  img.onload = imageLoadHandler;
+  expectedTestCount++;
+
+  // image at start
+  SpecialPowers.createFiles([{name: "startTestFile",
+                             data: fileData + testBinaryData}],
+                            imageStartTest);
+}
 
-.then(file => {
-  let cx = $("canvas").getContext('2d');
-  let memFile = cx.canvas.mozGetAsFile("image/png");
-  return testSlice(memFile, canvasData.length, "image/png", canvasData, "memFile");
-})
+function imageStartTest(files) {
+  var imgfile = files[0];
+  is(imgfile.size, size + testBinaryData.length, "correct file size (start)");
+  var img = new Image;
+  img.src = URL.createObjectURL(imgfile.slice(0, size));
+  img.onload = imageLoadHandler;
+  expectedTestCount++;
+
+  // image at end
+  SpecialPowers.createFiles([{name: "endTestFile",
+                             data: testBinaryData + fileData}],
+                            imageEndTest);
+}
 
-.then(SimpleTest.finish);
+function imageEndTest(files) {
+  var imgfile = files[0];
+  is(imgfile.size, size + testBinaryData.length, "correct file size (end)");
+  var img = new Image;
+  img.src = URL.createObjectURL(imgfile.slice(testBinaryData.length, testBinaryData.length + size));
+  img.onload = imageLoadHandler;
+  expectedTestCount++;
+
+  // image past end
+  SpecialPowers.createFiles([{name: "pastEndTestFile",
+                             data: testBinaryData + fileData}],
+                            imagePastEndTest);
+}
+
+function imagePastEndTest(files) {
+  var imgfile = files[0];
+  is(imgfile.size, size + testBinaryData.length, "correct file size (past end)");
+  var img = new Image;
+  img.src = URL.createObjectURL(imgfile.slice(testBinaryData.length, testBinaryData.length + size + 1000));
+  img.onload = imageLoadHandler;
+  expectedTestCount++;
+}
 
 </script>
 </body>
 </html>
deleted file mode 100644
--- a/dom/file/tests/test_fileapi_slice_image.html
+++ /dev/null
@@ -1,138 +0,0 @@
-<!DOCTYPE HTML>
-<html>
-<head>
-  <title>Test for File API + Slice</title>
-  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
-  <script type="text/javascript" src="common_blob.js"></script>
-  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
-</head>
-
-<body>
-
-<p id="display">
-  <canvas id=canvas width=1100 height=1100 hidden moz-opaque></canvas>
-  <canvas id=testcanvas hidden moz-opaque></canvas>
-</p>
-
-<script type="text/javascript">
-
-SimpleTest.waitForExplicitFinish();
-
-// Create files containing data we'll test with. We'll want long
-// strings to ensure they span multiple buffers while loading
-
-let canvasData;
-let testBinaryData;
-
-function imageLoadHandler(event, resolve) {
-  let origcanvas = $("canvas");
-  let testcanvas = $("testcanvas");
-  let image = event.target;
-  is(image.naturalWidth, origcanvas.width, "width correct");
-  is(image.naturalHeight, origcanvas.height, "height correct");
-
-  testcanvas.width = origcanvas.width;
-  testcanvas.height = origcanvas.height;
-  testcanvas.getContext("2d").drawImage(image, 0, 0);
-  // Do not use |is(testcanvas.toDataURL("image/png"), origcanvas.toDataURL("image/png"), "...");| that results in a _very_ long line.
-  let origDataURL = origcanvas.toDataURL("image/png");
-  let testDataURL = testcanvas.toDataURL("image/png");
-  is(testDataURL.length, origDataURL.length,
-     "Length of correct image data");
-  ok(testDataURL == origDataURL,
-     "Content of correct image data");
-  resolve();
-}
-
-createCanvasURL()
-.then(data => {
-  for (var i = 0; i < 256; i++) {
-    testBinaryData += String.fromCharCode(i);
-  }
-  while (testBinaryData.length < 20000) {
-    testBinaryData += testBinaryData;
-  }
-
-  canvasData = data;
-})
-
-// image in the middle
-.then(() => {
-  return createFile(testBinaryData + canvasData + testBinaryData, "middleTestFile");
-})
-
-// image in the middle - loader
-.then(file => {
-  return new Promise(resolve => {
-    is(file.size, canvasData.length + testBinaryData.length * 2, "correct file size (middle)");
-
-    var img = new Image();
-    img.src = URL.createObjectURL(file.slice(testBinaryData.length,
-                                             testBinaryData.length + canvasData.length));
-    img.onload = event => {
-      imageLoadHandler(event, resolve);
-    }
-  });
-})
-
-// image at start
-.then(() => {
-  return createFile(canvasData + testBinaryData, "startTestFile");
-})
-
-// image at start - loader
-.then(file => {
-  return new Promise(resolve => {
-    is(file.size, canvasData.length + testBinaryData.length, "correct file size (start)");
-
-    var img = new Image();
-    img.src = URL.createObjectURL(file.slice(0, canvasData.length));
-    img.onload = event => {
-      imageLoadHandler(event, resolve);
-    }
-  });
-})
-
-// image at end
-.then(() => {
-  return createFile(testBinaryData + canvasData, "endTestFile");
-})
-
-// image at end - loader
-.then(file => {
-  return new Promise(resolve => {
-    is(file.size, canvasData.length + testBinaryData.length, "correct file size (end)");
-
-    var img = new Image();
-    img.src = URL.createObjectURL(file.slice(testBinaryData.length,
-                                             testBinaryData.length + canvasData.length));
-    img.onload = event => {
-      imageLoadHandler(event, resolve);
-    }
-  });
-})
-
-// image past end
-.then(() => {
-  return createFile(testBinaryData + canvasData, "pastEndTestFile");
-})
-
-// image past end - loader
-.then(file => {
-  return new Promise(resolve => {
-    is(file.size, canvasData.length + testBinaryData.length, "correct file size (end)");
-
-    var img = new Image();
-    img.src = URL.createObjectURL(file.slice(testBinaryData.length,
-                                             testBinaryData.length + canvasData.length + 1000));
-    img.onload = event => {
-      imageLoadHandler(event, resolve);
-    }
-  });
-})
-
-.then(SimpleTest.finish);
-
-</script>
-</body>
-</html>