Bug 1186932 - Implement support for form submission of a picked directory - part 3 - tests + fixes, r=smaug

This commit is contained in:
Andrea Marchesini
2016-07-14 09:02:30 +02:00
parent 875665eb2e
commit 78bb245a81
4 changed files with 292 additions and 56 deletions

View File

@@ -624,6 +624,10 @@ private:
};
// An helper class for the dispatching of the 'change' event.
// This class is used when the FilePicker finished its task (or when files and
// directories are set by some chrome/test only method).
// The task of this class is to postpone the dispatching of 'change' and 'input'
// events at the end of the exploration of the directories.
class DispatchChangeEventCallback final : public GetFilesCallback
{
public:
@@ -668,32 +672,6 @@ private:
RefPtr<HTMLInputElement> mInputElement;
};
// This callback is used for postponing the calling of SetFilesOrDirectories
// when the exploration of the directory is completed.
class AfterSetFilesOrDirectoriesCallback : public GetFilesCallback
{
public:
AfterSetFilesOrDirectoriesCallback(HTMLInputElement* aInputElement,
bool aSetValueChanged)
: mInputElement(aInputElement)
, mSetValueChanged(aSetValueChanged)
{
MOZ_ASSERT(aInputElement);
}
void
Callback(nsresult aStatus, const Sequence<RefPtr<File>>& aFiles) override
{
if (NS_SUCCEEDED(aStatus)) {
mInputElement->AfterSetFilesOrDirectoriesInternal(mSetValueChanged);
}
}
private:
RefPtr<HTMLInputElement> mInputElement;
bool mSetValueChanged;
};
class HTMLInputElementState final : public nsISupports
{
public:
@@ -3314,6 +3292,7 @@ HTMLInputElement::SetFiles(nsIDOMFileList* aFiles,
AfterSetFilesOrDirectories(aSetValueChanged);
}
// This method is used for testing only.
void
HTMLInputElement::MozSetDndFilesAndDirectories(const nsTArray<OwningFileOrDirectory>& aFilesOrDirectories)
{
@@ -3322,23 +3301,28 @@ HTMLInputElement::MozSetDndFilesAndDirectories(const nsTArray<OwningFileOrDirect
}
SetFilesOrDirectories(aFilesOrDirectories, true);
RefPtr<DispatchChangeEventCallback> dispatchChangeEventCallback =
new DispatchChangeEventCallback(this);
if (Preferences::GetBool("dom.webkitBlink.dirPicker.enabled", false) &&
HasAttr(kNameSpaceID_None, nsGkAtoms::webkitdirectory)) {
ErrorResult rv;
GetFilesHelper* helper = GetOrCreateGetFilesHelper(true /* recursionFlag */,
rv);
if (NS_WARN_IF(rv.Failed())) {
rv.SuppressException();
return;
}
helper->AddCallback(dispatchChangeEventCallback);
} else {
dispatchChangeEventCallback->DispatchEvents();
}
}
void
HTMLInputElement::AfterSetFilesOrDirectories(bool aSetValueChanged)
{
if (Preferences::GetBool("dom.webkitBlink.dirPicker.enabled", false) &&
HasAttr(kNameSpaceID_None, nsGkAtoms::webkitdirectory)) {
// This will call AfterSetFilesOrDirectoriesInternal eventually.
ExploreDirectoryRecursively(aSetValueChanged);
return;
}
AfterSetFilesOrDirectoriesInternal(aSetValueChanged);
}
void
HTMLInputElement::AfterSetFilesOrDirectoriesInternal(bool aSetValueChanged)
{
// No need to flush here, if there's no frame at this point we
// don't need to force creation of one just to tell it about this
@@ -8533,22 +8517,6 @@ HTMLInputElement::GetOrCreateGetFilesHelper(bool aRecursiveFlag,
return mGetFilesNonRecursiveHelper;
}
void
HTMLInputElement::ExploreDirectoryRecursively(bool aSetValueChanged)
{
ErrorResult rv;
GetFilesHelper* helper = GetOrCreateGetFilesHelper(true /* recursionFlag */,
rv);
if (NS_WARN_IF(rv.Failed())) {
AfterSetFilesOrDirectoriesInternal(aSetValueChanged);
return;
}
RefPtr<AfterSetFilesOrDirectoriesCallback> callback =
new AfterSetFilesOrDirectoriesCallback(this, aSetValueChanged);
helper->AddCallback(callback);
}
void
HTMLInputElement::UpdateEntries(const nsTArray<OwningFileOrDirectory>& aFilesOrDirectories)
{