Backed out changeset 856c3889f319 (bug 1305230)
authorSebastian Hengst <archaeopteryx@coole-files.de>
Fri, 13 Oct 2017 13:25:38 +0200
changeset 386141 9abaf5195566c45d9c9dafbcb7624a9c3a3b123b
parent 386140 2f665a0a379f84020e34a982cca213b0b52c7894
child 386142 5a9bea5b8dd2f74954a38b5d90298f14f2167b51
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 out856c3889f319b81a38da582967e4a561376f1821
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 856c3889f319 (bug 1305230)
dom/file/tests/common_blob.js
dom/file/tests/mochitest.ini
dom/file/tests/test_blobconstructor.html
deleted file mode 100644
--- a/dom/file/tests/common_blob.js
+++ /dev/null
@@ -1,142 +0,0 @@
-function testBlob(file, contents, testName) {
-  // Load file using FileReader
-  return new Promise(resolve => {
-    let r = new FileReader();
-    r.onload = event => {
-      is(event.target.readyState, FileReader.DONE,
-         "[FileReader] readyState in test FileReader.readAsBinaryString of " + testName);
-      is(event.target.error, null,
-         "[FileReader] no error in test FileReader.readAsBinaryString of " + testName);
-      // Do not use |is(event.target.result, contents, "...");| that may output raw binary data.
-      is(event.target.result.length, contents.length,
-         "[FileReader] Length of result in test FileReader.readAsBinaryString of " + testName);
-      ok(event.target.result == contents,
-         "[FileReader] Content of result in test FileReader.readAsBinaryString of " + testName);
-      is(event.lengthComputable, true,
-         "[FileReader] lengthComputable in test FileReader.readAsBinaryString of " + testName);
-      is(event.loaded, contents.length,
-         "[FileReader] Loaded length in test FileReader.readAsBinaryString of " + testName);
-      is(event.total, contents.length,
-         "[FileReader] Total length in test FileReader.readAsBinaryString of " + testName);
-      resolve();
-    }
-    r.readAsBinaryString(file);
-  })
-
-  // Load file using URL.createObjectURL and XMLHttpRequest
-  .then(() => {
-    return new Promise(resolve => {
-      let xhr = new XMLHttpRequest();
-      xhr.open("GET", URL.createObjectURL(file));
-      xhr.onload = event => {
-        XHRLoadHandler(event, resolve, contents, "XMLHttpRequest load of " + testName);
-      };
-      xhr.overrideMimeType('text/plain; charset=x-user-defined');
-      xhr.send();
-    });
-  })
-
-  // Send file to server using FormData and XMLHttpRequest
-  .then(() => {
-    return new Promise(resolve => {
-      let 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" }]);
-        resolve();
-      }
-      xhr.open("POST", "../../../dom/html/test/form_submit_server.sjs");
-
-      let fd = new FormData;
-      fd.append("hello", "world");
-      fd.append("myfile", file);
-
-      xhr.send(fd);
-    });
-  })
-
-  // Send file to server using plain XMLHttpRequest
-  .then(() => {
-    return new Promise(resolve => {
-      let 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 " + testName);
-        is(event.target.getResponseHeader("Result-Content-Length"),
-           String(file.size),
-           "request content-length in XMLHttpRequest send of " + testName);
-      };
-
-      xhr.addEventListener("load", event => {
-        XHRLoadHandler(event, resolve, contents, "XMLHttpRequest send of " + testName);
-      });
-      xhr.overrideMimeType('text/plain; charset=x-user-defined');
-      xhr.send(file);
-    });
-  });
-}
-
-function convertXHRBinary(s) {
-  let res = "";
-  for (let i = 0; i < s.length; ++i) {
-    res += String.fromCharCode(s.charCodeAt(i) & 255);
-  }
-  return res;
-}
-
-function XHRLoadHandler(event, resolve, contents, testName) {
-  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), contents, "...");| that may output raw binary data.
-  let convertedData = convertXHRBinary(event.target.responseText);
-  is(convertedData.length, contents.length, "[XHR] Length of result in test " + testName);
-  ok(convertedData == contents, "[XHR] Content of result in test " + testName);
-  is(event.lengthComputable, event.total != 0, "[XHR] lengthComputable in test " + testName);
-  is(event.loaded, contents.length, "[XHR] Loaded length in test " + testName);
-  is(event.total, contents.length, "[XHR] Total length in test " + testName);
-  resolve();
-}
-
-function checkMPSubmission(sub, expected) {
-  function getPropCount(o) {
-    let x, l = 0;
-    for (x in o) ++l;
-    return l;
-  }
-
-  is(sub.length, expected.length,
-     "Correct number of items");
-  let 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");
-  }
-}
--- a/dom/file/tests/mochitest.ini
+++ b/dom/file/tests/mochitest.ini
@@ -1,11 +1,10 @@
 [DEFAULT]
 support-files =
-  common_blob.js
   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
--- a/dom/file/tests/test_blobconstructor.html
+++ b/dom/file/tests/test_blobconstructor.html
@@ -2,17 +2,17 @@
 <html>
 <!--
 https://bugzilla.mozilla.org/show_bug.cgi?id=721569
 -->
 <head>
   <title>Test for Blob constructor (Bug 721569)</title>
   <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
   <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=721569">Mozilla Bug 721569</a>
 <p id="display"></p>
 <div id="content" style="display: none">
   
 </div>
@@ -191,56 +191,56 @@ let testData =
     // Test type coercion of a number
     [[3, int8View, "foo"], {},
                             [{start: 0, length: 8, contents:  "3ABCDEFG"},
                              {start: 8, length:10, contents:  "HIJKLMNOPf"},
                              {start: 17, length: 4, contents: "foo"},
                              {start: 4, length: 8, contents:  "DEFGHIJK"}]]
  ];
 
-let currentTest = null;
 let testCounter = 0;
 
-function runTests() {
-  if (!currentTest || currentTest[2].length == 0) {
-    if (testData.length == 0) {
-      SimpleTest.finish();
-      return;
-    }
+function doTest(data) {
+  testCounter++;
+
+  var [blobs, options, tests] = data;
+
+  function runTest(test) {
 
-    currentTest = testData.shift();
-    ++testCounter;
-  }
+    let blob;
+    if (options !== undefined) {
+      blob = new Blob(blobs, options);
+    } else {
+      blob = new Blob(blobs);
+    }
+    ok(blob, "Test " + testCounter + " got blob");
+    ok(blob instanceof Blob, "Test " + testCounter + " blob is a Blob");
+    ok(!(blob instanceof File), "Test " + testCounter + " blob is not a File");
 
-  let [blobs, options] = currentTest;
-  let test = currentTest[2].shift();
+    let slice = blob.slice(test.start, test.start + test.length);
+    ok(slice, "Test " + testCounter + " got slice");
+    ok(slice instanceof Blob, "Test " + testCounter + " slice is a Blob");
+    ok(!(slice instanceof File), "Test " + testCounter + " slice is not a File");
+    is(slice.size, test.contents.length,
+       "Test " + testCounter + " slice is correct size");
 
-  let blob;
-  if (options !== undefined) {
-    blob = new Blob(blobs, options);
+    testFile(slice, test.contents, "Test " + testCounter);
+  }
+  if (Array.isArray(tests)) {
+    tests.forEach(runTest);
   } else {
-    blob = new Blob(blobs);
+    try {
+      let blob = new Blob(blobs, options);
+      ok(false, "NOT REACHED");
+    } catch (e) {
+      is(e.name, tests, "Blob constructor should throw " + tests);
+    }
   }
-
-  ok(blob, "Test " + testCounter + " got blob");
-  ok(blob instanceof Blob, "Test " + testCounter + " blob is a Blob");
-  ok(!(blob instanceof File), "Test " + testCounter + " blob is not a File");
-
-  let slice = blob.slice(test.start, test.start + test.length);
-  ok(slice, "Test " + testCounter + " got slice");
-  ok(slice instanceof Blob, "Test " + testCounter + " slice is a Blob");
-  ok(!(slice instanceof File), "Test " + testCounter + " slice is not a File");
-  is(slice.size, test.contents.length, "Test " + testCounter + " slice is correct size");
-
-  testBlob(slice, test.contents, "Test " + testCounter).then(() => {
-    SpecialPowers.gc();
-    runTests();
-  });
+  SpecialPowers.gc();
 }
 
-SimpleTest.requestLongerTimeout(2);
 SimpleTest.waitForExplicitFinish();
-runTests();
+testData.forEach(doTest);
 
 </script>
 </pre>
 </body>
 </html>