Backed out changeset 57563a99fe53 (bug 1459859) for failures on test_ext_webrequest_upload.html. CLOSED TREE

This commit is contained in:
Csoregi Natalia 2021-03-24 14:08:13 +02:00
Родитель ac48dedf2a
Коммит 2ca60f01bc
8 изменённых файлов: 110 добавлений и 115 удалений

Просмотреть файл

@ -120,7 +120,7 @@ void FormData::Append(const nsAString& aName, Blob& aBlob,
return;
}
AddNameBlobPair(aName, file);
AddNameBlobOrNullPair(aName, file);
}
void FormData::Append(const nsAString& aName, Directory* aDirectory) {
@ -165,10 +165,15 @@ bool FormData::Has(const nsAString& aName) {
return false;
}
nsresult FormData::AddNameBlobPair(const nsAString& aName, Blob* aBlob) {
MOZ_ASSERT(aBlob);
nsresult FormData::AddNameBlobOrNullPair(const nsAString& aName, Blob* aBlob) {
RefPtr<File> file;
if (!aBlob) {
FormDataTuple* data = mFormData.AppendElement();
SetNameValuePair(data, aName, u""_ns, true /* aWasNullBlob */);
return NS_OK;
}
ErrorResult rv;
file = GetOrCreateFileCalledBlob(*aBlob, rv);
if (NS_WARN_IF(rv.Failed())) {
@ -249,9 +254,10 @@ const OwningBlobOrDirectoryOrUSVString& FormData::GetValueAtIndex(
}
void FormData::SetNameValuePair(FormDataTuple* aData, const nsAString& aName,
const nsAString& aValue) {
const nsAString& aValue, bool aWasNullBlob) {
MOZ_ASSERT(aData);
aData->name = aName;
aData->wasNullBlob = aWasNullBlob;
aData->value.SetAsUSVString() = aValue;
}
@ -261,6 +267,7 @@ void FormData::SetNameFilePair(FormDataTuple* aData, const nsAString& aName,
MOZ_ASSERT(aFile);
aData->name = aName;
aData->wasNullBlob = false;
aData->value.SetAsBlob() = aFile;
}
@ -271,6 +278,7 @@ void FormData::SetNameDirectoryPair(FormDataTuple* aData,
MOZ_ASSERT(aDirectory);
aData->name = aName;
aData->wasNullBlob = false;
aData->value.SetAsDirectory() = aDirectory;
}
@ -326,12 +334,15 @@ nsresult FormData::CopySubmissionDataTo(
HTMLFormSubmission* aFormSubmission) const {
MOZ_ASSERT(aFormSubmission, "Must have FormSubmission!");
for (size_t i = 0; i < mFormData.Length(); ++i) {
if (mFormData[i].value.IsUSVString()) {
if (mFormData[i].wasNullBlob) {
MOZ_ASSERT(mFormData[i].value.IsUSVString());
aFormSubmission->AddNameBlobOrNullPair(mFormData[i].name, nullptr);
} else if (mFormData[i].value.IsUSVString()) {
aFormSubmission->AddNameValuePair(mFormData[i].name,
mFormData[i].value.GetAsUSVString());
} else if (mFormData[i].value.IsBlob()) {
aFormSubmission->AddNameBlobPair(mFormData[i].name,
mFormData[i].value.GetAsBlob());
aFormSubmission->AddNameBlobOrNullPair(mFormData[i].name,
mFormData[i].value.GetAsBlob());
} else {
MOZ_ASSERT(mFormData[i].value.IsDirectory());
aFormSubmission->AddNameDirectoryPair(

Просмотреть файл

@ -32,6 +32,7 @@ class FormData final : public nsISupports,
struct FormDataTuple {
nsString name;
bool wasNullBlob;
OwningBlobOrDirectoryOrUSVString value;
};
@ -41,7 +42,7 @@ class FormData final : public nsISupports,
const nsAString& aName);
void SetNameValuePair(FormDataTuple* aData, const nsAString& aName,
const nsAString& aValue);
const nsAString& aValue, bool aWasNullBlob = false);
void SetNameFilePair(FormDataTuple* aData, const nsAString& aName,
File* aFile);
@ -112,8 +113,8 @@ class FormData final : public nsISupports,
return NS_OK;
}
virtual nsresult AddNameBlobPair(const nsAString& aName,
Blob* aBlob) override;
virtual nsresult AddNameBlobOrNullPair(const nsAString& aName,
Blob* aBlob) override;
virtual nsresult AddNameDirectoryPair(const nsAString& aName,
Directory* aDirectory) override;

Просмотреть файл

@ -1,28 +1,21 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1187157
https://bugzilla.mozilla.org/show_bug.cgi?id=789315
-->
<head>
<meta charset="utf-8">
<title>Test for Bug 1187157</title>
<title>Test for Bug 789315</title>
<script src="/tests/SimpleTest/SimpleTest.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=1187157">Mozilla Bug 1187157</a>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=789315">Mozilla Bug 789315</a>
<form id="a"><input name="b" type="file"/></form>
<script type="text/javascript">
var obj = new FormData(document.getElementById('a')).get('b');
ok(obj instanceof File, "This should return a File");
is(obj.size, 0, "Size should be 0");
is(obj.name, "", "Name should be the empty string.");
is(
obj.type,
"application/octet-stream",
"Type should be application/octet-stream"
);
is(obj, "", "We want an empty string.");
</script>

Просмотреть файл

@ -17,24 +17,12 @@ SimpleTest.waitForExplicitFinish();
var f = document.getElementById('form');
var fd = new FormData(f);
var get = fd.get("test");
ok(get instanceof File, "We want a File object.");
is(get.name, "", "We want a File with an empty name.");
is(
get.type,
"application/octet-stream",
"We want a File with type application/octet-stream."
);
is(get.size, 0, "We want a File with an empty body.");
is(fd.get("test"), "", "We want an empty string.");
var getAll = fd.getAll("test");
ok(Array.isArray(getAll), "We want an array with 1 empty File.");
is(getAll.length, 1, "We want an array with 1 empty File.");
is(
getAll[0],
get,
"We want the File returned from getAll to be that returned from get."
);
ok(Array.isArray(getAll), "We want an array with 1 empty string.");
is(getAll.length, 1, "We want an array with 1 empty string.");
is(getAll[0], "", "We want an array with 1 empty string.");
var xhr = new XMLHttpRequest();
xhr.open("POST", "file_bug1250148.sjs", true);

Просмотреть файл

@ -90,8 +90,8 @@ class FSURLEncoded : public EncodingFormSubmission {
virtual nsresult AddNameValuePair(const nsAString& aName,
const nsAString& aValue) override;
virtual nsresult AddNameBlobPair(const nsAString& aName,
Blob* aBlob) override;
virtual nsresult AddNameBlobOrNullPair(const nsAString& aName,
Blob* aBlob) override;
virtual nsresult AddNameDirectoryPair(const nsAString& aName,
Directory* aDirectory) override;
@ -150,7 +150,8 @@ nsresult FSURLEncoded::AddNameValuePair(const nsAString& aName,
return NS_OK;
}
nsresult FSURLEncoded::AddNameBlobPair(const nsAString& aName, Blob* aBlob) {
nsresult FSURLEncoded::AddNameBlobOrNullPair(const nsAString& aName,
Blob* aBlob) {
if (!mWarnedFileControl) {
SendJSWarning(mDocument, "ForgotFileEnctypeWarning", nsTArray<nsString>());
mWarnedFileControl = true;
@ -411,10 +412,8 @@ nsresult FSMultipartFormData::AddNameValuePair(const nsAString& aName,
return NS_OK;
}
nsresult FSMultipartFormData::AddNameBlobPair(const nsAString& aName,
Blob* aBlob) {
MOZ_ASSERT(aBlob);
nsresult FSMultipartFormData::AddNameBlobOrNullPair(const nsAString& aName,
Blob* aBlob) {
// Encode the control name
nsAutoCString nameStr;
nsresult rv = EncodeVal(aName, nameStr, true);
@ -426,61 +425,66 @@ nsresult FSMultipartFormData::AddNameBlobPair(const nsAString& aName,
nsAutoCString filename;
nsAutoCString contentType;
nsCOMPtr<nsIInputStream> fileStream;
nsAutoString filename16;
RefPtr<File> file = aBlob->ToFile();
if (file) {
nsAutoString relativePath;
file->GetRelativePath(relativePath);
if (StaticPrefs::dom_webkitBlink_dirPicker_enabled() &&
!relativePath.IsEmpty()) {
filename16 = relativePath;
if (aBlob) {
nsAutoString filename16;
RefPtr<File> file = aBlob->ToFile();
if (file) {
nsAutoString relativePath;
file->GetRelativePath(relativePath);
if (StaticPrefs::dom_webkitBlink_dirPicker_enabled() &&
!relativePath.IsEmpty()) {
filename16 = relativePath;
}
if (filename16.IsEmpty()) {
RetrieveFileName(aBlob, filename16);
}
}
if (filename16.IsEmpty()) {
RetrieveFileName(aBlob, filename16);
}
}
rv = EncodeVal(filename16, filename, true);
NS_ENSURE_SUCCESS(rv, rv);
// Get content type
nsAutoString contentType16;
aBlob->GetType(contentType16);
if (contentType16.IsEmpty()) {
contentType16.AssignLiteral("application/octet-stream");
}
NS_ConvertUTF16toUTF8 contentType8(contentType16);
int32_t convertedBufLength = 0;
char* convertedBuf = nsLinebreakConverter::ConvertLineBreaks(
contentType8.get(), nsLinebreakConverter::eLinebreakAny,
nsLinebreakConverter::eLinebreakSpace, contentType8.Length(),
&convertedBufLength);
contentType.Adopt(convertedBuf, convertedBufLength);
// Get input stream
aBlob->CreateInputStream(getter_AddRefs(fileStream), error);
if (NS_WARN_IF(error.Failed())) {
return error.StealNSResult();
}
// Get size
size = aBlob->GetSize(error);
if (error.Failed()) {
error.SuppressException();
fileStream = nullptr;
}
if (fileStream) {
// Create buffered stream (for efficiency)
nsCOMPtr<nsIInputStream> bufferedStream;
rv = NS_NewBufferedInputStream(getter_AddRefs(bufferedStream),
fileStream.forget(), 8192);
rv = EncodeVal(filename16, filename, true);
NS_ENSURE_SUCCESS(rv, rv);
fileStream = bufferedStream;
// Get content type
nsAutoString contentType16;
aBlob->GetType(contentType16);
if (contentType16.IsEmpty()) {
contentType16.AssignLiteral("application/octet-stream");
}
NS_ConvertUTF16toUTF8 contentType8(contentType16);
int32_t convertedBufLength = 0;
char* convertedBuf = nsLinebreakConverter::ConvertLineBreaks(
contentType8.get(), nsLinebreakConverter::eLinebreakAny,
nsLinebreakConverter::eLinebreakSpace, contentType8.Length(),
&convertedBufLength);
contentType.Adopt(convertedBuf, convertedBufLength);
// Get input stream
aBlob->CreateInputStream(getter_AddRefs(fileStream), error);
if (NS_WARN_IF(error.Failed())) {
return error.StealNSResult();
}
// Get size
size = aBlob->GetSize(error);
if (error.Failed()) {
error.SuppressException();
fileStream = nullptr;
}
if (fileStream) {
// Create buffered stream (for efficiency)
nsCOMPtr<nsIInputStream> bufferedStream;
rv = NS_NewBufferedInputStream(getter_AddRefs(bufferedStream),
fileStream.forget(), 8192);
NS_ENSURE_SUCCESS(rv, rv);
fileStream = bufferedStream;
}
} else {
contentType.AssignLiteral("application/octet-stream");
}
AddDataChunk(nameStr, filename, contentType, fileStream, size);
@ -606,8 +610,8 @@ class FSTextPlain : public EncodingFormSubmission {
virtual nsresult AddNameValuePair(const nsAString& aName,
const nsAString& aValue) override;
virtual nsresult AddNameBlobPair(const nsAString& aName,
Blob* aBlob) override;
virtual nsresult AddNameBlobOrNullPair(const nsAString& aName,
Blob* aBlob) override;
virtual nsresult AddNameDirectoryPair(const nsAString& aName,
Directory* aDirectory) override;
@ -630,7 +634,8 @@ nsresult FSTextPlain::AddNameValuePair(const nsAString& aName,
return NS_OK;
}
nsresult FSTextPlain::AddNameBlobPair(const nsAString& aName, Blob* aBlob) {
nsresult FSTextPlain::AddNameBlobOrNullPair(const nsAString& aName,
Blob* aBlob) {
nsAutoString filename;
RetrieveFileName(aBlob, filename);
AddNameValuePair(aName, filename);

Просмотреть файл

@ -62,10 +62,11 @@ class HTMLFormSubmission {
*
* @param aName the name of the parameter
* @param aBlob the blob to submit. The file's name will be used if the Blob
* is actually a File, otherwise 'blob' string is used instead. Must not be
* null.
* is actually a File, otherwise 'blob' string is used instead if the aBlob is
* not null.
*/
virtual nsresult AddNameBlobPair(const nsAString& aName, Blob* aBlob) = 0;
virtual nsresult AddNameBlobOrNullPair(const nsAString& aName,
Blob* aBlob) = 0;
/**
* Submit a name/directory pair
@ -175,7 +176,7 @@ class DialogFormSubmission final : public HTMLFormSubmission {
return NS_OK;
}
nsresult AddNameBlobPair(const nsAString& aName, Blob* aBlob) override {
nsresult AddNameBlobOrNullPair(const nsAString& aName, Blob* aBlob) override {
MOZ_CRASH("This method should not be called");
return NS_OK;
}
@ -220,8 +221,8 @@ class FSMultipartFormData : public EncodingFormSubmission {
virtual nsresult AddNameValuePair(const nsAString& aName,
const nsAString& aValue) override;
virtual nsresult AddNameBlobPair(const nsAString& aName,
Blob* aBlob) override;
virtual nsresult AddNameBlobOrNullPair(const nsAString& aName,
Blob* aBlob) override;
virtual nsresult AddNameDirectoryPair(const nsAString& aName,
Directory* aDirectory) override;

Просмотреть файл

@ -5668,21 +5668,13 @@ HTMLInputElement::SubmitNamesValues(HTMLFormSubmission* aFormSubmission) {
GetFilesOrDirectoriesInternal();
if (files.IsEmpty()) {
ErrorResult rv;
RefPtr<Blob> blob = Blob::CreateStringBlob(
GetOwnerGlobal(), ""_ns, u"application/octet-stream"_ns);
RefPtr<File> file = blob->ToFile(u""_ns, rv);
if (!rv.Failed()) {
aFormSubmission->AddNameBlobPair(name, file);
}
return rv.StealNSResult();
aFormSubmission->AddNameBlobOrNullPair(name, nullptr);
return NS_OK;
}
for (uint32_t i = 0; i < files.Length(); ++i) {
if (files[i].IsFile()) {
aFormSubmission->AddNameBlobPair(name, files[i].GetAsFile());
aFormSubmission->AddNameBlobOrNullPair(name, files[i].GetAsFile());
} else {
MOZ_ASSERT(files[i].IsDirectory());
aFormSubmission->AddNameDirectoryPair(name, files[i].GetAsDirectory());

Просмотреть файл

@ -0,0 +1,4 @@
[form-data-set-empty-file.window.html]
[Empty <input type=file> is still added to the form's entry list]
expected: FAIL