From 5d8cb5c3674fba185ac5ef4faea0cf6454f59e8d Mon Sep 17 00:00:00 2001 From: Sebastian Hengst Date: Tue, 26 Jan 2016 13:44:51 +0100 Subject: [PATCH] Backed out changeset 3a4b31e5c049 (bug 1241171) for W(5) orange on Linux x64 debug. r=bustage --- dom/base/FormData.cpp | 15 ++++++++++++++- dom/base/test/fileutils.js | 2 +- dom/html/test/formData_test.js | 3 ++- dom/html/test/test_formSubmission.html | 12 ++++++------ .../mochitest/fetch/test_fetch_basic_http.js | 2 +- dom/tests/mochitest/fetch/test_request.js | 4 ++-- .../resources/fetch-request-xhr-iframe.https.html | 2 +- 7 files changed, 27 insertions(+), 13 deletions(-) diff --git a/dom/base/FormData.cpp b/dom/base/FormData.cpp index 46cdfa87702..d1a53d35e50 100644 --- a/dom/base/FormData.cpp +++ b/dom/base/FormData.cpp @@ -343,7 +343,20 @@ FormData::GetSendInfo(nsIInputStream** aBody, uint64_t* aContentLength, for (uint32_t i = 0; i < mFormData.Length(); ++i) { if (mFormData[i].value.IsBlob()) { - fs.AddNameBlobPair(mFormData[i].name, mFormData[i].value.GetAsBlob()); + RefPtr file = mFormData[i].value.GetAsBlob()->ToFile(); + if (file) { + fs.AddNameBlobPair(mFormData[i].name, file); + continue; + } + + ErrorResult rv; + file = + mFormData[i].value.GetAsBlob()->ToFile(NS_LITERAL_STRING("blob"), rv); + if (NS_WARN_IF(rv.Failed())) { + return rv.StealNSResult(); + } + + fs.AddNameBlobPair(mFormData[i].name, file); } else if (mFormData[i].value.IsUSVString()) { fs.AddNameValuePair(mFormData[i].name, mFormData[i].value.GetAsUSVString()); diff --git a/dom/base/test/fileutils.js b/dom/base/test/fileutils.js index 3fe2312208e..25f6118b268 100644 --- a/dom/base/test/fileutils.js +++ b/dom/base/test/fileutils.js @@ -36,7 +36,7 @@ function testFile(file, contents, test) { [{ name: "hello", value: "world"}, { name: "myfile", value: contents, - fileName: file.name || "", + fileName: file.name || "blob", contentType: file.type || "application/octet-stream" }]); testHasRun(); } diff --git a/dom/html/test/formData_test.js b/dom/html/test/formData_test.js index ca5be7184b2..89fccda801a 100644 --- a/dom/html/test/formData_test.js +++ b/dom/html/test/formData_test.js @@ -79,6 +79,7 @@ function testSet() { function testFilename() { var f = new FormData(); + // Spec says if a Blob (which is not a File) is added, the name parameter is set to "blob". f.append("blob", new Blob(["hi"])); ok(f.get("blob") instanceof Blob, "We should have a blob back."); @@ -162,7 +163,7 @@ function testSend(doneCb) { } is(response[0].headers['Content-Disposition'], - 'form-data; name="empty"; filename=""'); + 'form-data; name="empty"; filename="blob"'); is(response[1].headers['Content-Disposition'], 'form-data; name="explicit"; filename="explicit-file-name"'); diff --git a/dom/html/test/test_formSubmission.html b/dom/html/test/test_formSubmission.html index 0edfeaeb854..52900d3a191 100644 --- a/dom/html/test/test_formSubmission.html +++ b/dom/html/test/test_formSubmission.html @@ -590,7 +590,7 @@ var expectedAugment = [ //{ name: "aNameUndef", value: "undefined" }, ]; -function checkMPSubmission(sub, expected, test) { +function checkMPSubmission(sub, expected, test, isFormData = false) { function getPropCount(o) { var x, l = 0; for (x in o) ++l; @@ -625,7 +625,7 @@ function checkMPSubmission(sub, expected, test) { else { is(sub[i].headers["Content-Disposition"], "form-data; name=\"" + mpquote(expected[i].name) + "\"; filename=\"" + - mpquote(expected[i].fileName) + "\"", + mpquote(expected[i].fileName != "" || !isFormData ? expected[i].fileName : "blob") + "\"", "Correct name in " + test); is(sub[i].headers["Content-Type"], expected[i].contentType, @@ -782,14 +782,14 @@ function runTest() { xhr.open("POST", "form_submit_server.sjs"); xhr.send(new FormData(form)); yield undefined; // Wait for XHR load - checkMPSubmission(JSON.parse(xhr.responseText), expectedSub, "send form using XHR and FormData"); + checkMPSubmission(JSON.parse(xhr.responseText), expectedSub, "send form using XHR and FormData", true); // Send disabled form using XHR and FormData setDisabled(document.querySelectorAll("input, select, textarea"), true); xhr.open("POST", "form_submit_server.sjs"); xhr.send(new FormData(form)); yield undefined; - checkMPSubmission(JSON.parse(xhr.responseText), [], "send disabled form using XHR and FormData"); + checkMPSubmission(JSON.parse(xhr.responseText), [], "send disabled form using XHR and FormData", true); setDisabled(document.querySelectorAll("input, select, textarea"), false); // Send FormData @@ -804,7 +804,7 @@ function runTest() { xhr.open("POST", "form_submit_server.sjs"); xhr.send(fd); yield undefined; - checkMPSubmission(JSON.parse(xhr.responseText), expectedAugment, "send FormData"); + checkMPSubmission(JSON.parse(xhr.responseText), expectedAugment, "send FormData", true); // Augment
using FormData fd = new FormData(form); @@ -813,7 +813,7 @@ function runTest() { xhr.send(fd); yield undefined; checkMPSubmission(JSON.parse(xhr.responseText), - expectedSub.concat(expectedAugment), "send augmented FormData"); + expectedSub.concat(expectedAugment), "send augmented FormData", true); SimpleTest.finish(); yield undefined; diff --git a/dom/tests/mochitest/fetch/test_fetch_basic_http.js b/dom/tests/mochitest/fetch/test_fetch_basic_http.js index a766cfc7830..b84445c69a7 100644 --- a/dom/tests/mochitest/fetch/test_fetch_basic_http.js +++ b/dom/tests/mochitest/fetch/test_fetch_basic_http.js @@ -169,7 +169,7 @@ function testFormDataSend() { } is(response[1].headers['Content-Disposition'], - 'form-data; name="empty"; filename=""'); + 'form-data; name="empty"; filename="blob"'); is(response[2].headers['Content-Disposition'], 'form-data; name="explicit"; filename="explicit-file-name"'); diff --git a/dom/tests/mochitest/fetch/test_request.js b/dom/tests/mochitest/fetch/test_request.js index f27374be830..33c56e1a1e6 100644 --- a/dom/tests/mochitest/fetch/test_request.js +++ b/dom/tests/mochitest/fetch/test_request.js @@ -417,7 +417,7 @@ function testFormDataBodyExtraction() { ok(fd.has("blob"), "Has entry 'blob'."); var entries = fd.getAll("blob"); is(entries.length, 1, "getAll returns all items."); - ok(entries[0] instanceof Blob, "getAll returns blobs."); + is(entries[0].name, "blob", "Filename should be blob."); }); var ws = "\r\n\r\n\r\n\r\n"; @@ -428,7 +428,7 @@ function testFormDataBodyExtraction() { ok(fd.has("blob"), "Has entry 'blob'."); var entries = fd.getAll("blob"); is(entries.length, 1, "getAll returns all items."); - ok(entries[0] instanceof Blob, "getAll returns blobs."); + is(entries[0].name, "blob", "Filename should be blob."); ok(fd.has("key"), "Has entry 'key'."); var f = fd.get("key"); diff --git a/testing/web-platform/mozilla/tests/service-workers/service-worker/resources/fetch-request-xhr-iframe.https.html b/testing/web-platform/mozilla/tests/service-workers/service-worker/resources/fetch-request-xhr-iframe.https.html index d11d2be734a..dc3b3458cea 100644 --- a/testing/web-platform/mozilla/tests/service-workers/service-worker/resources/fetch-request-xhr-iframe.https.html +++ b/testing/web-platform/mozilla/tests/service-workers/service-worker/resources/fetch-request-xhr-iframe.https.html @@ -108,7 +108,7 @@ function form_data_test() { '1234567890\r\n' + '--' + boundary + '\r\n' + 'Content-Disposition: form-data; name="sample blob"; ' + - 'filename=""\r\n' + + 'filename="blob"\r\n' + 'Content-Type: application/octet-stream\r\n' + '\r\n' + 'blob content\r\n' +