Implement HTML5 multiple file upload
This commit is contained in:
parent
0efbbe0fbc
commit
ea2f785ba8
|
@ -33,7 +33,7 @@ module Capybara::Webkit
|
||||||
end
|
end
|
||||||
|
|
||||||
def set(value)
|
def set(value)
|
||||||
invoke "set", value
|
invoke "set", *[value].flatten
|
||||||
end
|
end
|
||||||
|
|
||||||
def select_option
|
def select_option
|
||||||
|
|
|
@ -221,13 +221,12 @@ QString WebPage::chooseFile(QWebFrame *parentFrame, const QString &suggestedFile
|
||||||
Q_UNUSED(parentFrame);
|
Q_UNUSED(parentFrame);
|
||||||
Q_UNUSED(suggestedFile);
|
Q_UNUSED(suggestedFile);
|
||||||
|
|
||||||
return getLastAttachedFileName();
|
return getAttachedFileNames().first();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WebPage::extension(Extension extension, const ExtensionOption *option, ExtensionReturn *output) {
|
bool WebPage::extension(Extension extension, const ExtensionOption *option, ExtensionReturn *output) {
|
||||||
if (extension == ChooseMultipleFilesExtension) {
|
if (extension == ChooseMultipleFilesExtension) {
|
||||||
QStringList names = QStringList() << getLastAttachedFileName();
|
static_cast<ChooseMultipleFilesExtensionReturn*>(output)->fileNames = getAttachedFileNames();
|
||||||
static_cast<ChooseMultipleFilesExtensionReturn*>(output)->fileNames = names;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if (extension == QWebPage::ErrorPageExtension) {
|
else if (extension == QWebPage::ErrorPageExtension) {
|
||||||
|
@ -239,8 +238,8 @@ bool WebPage::extension(Extension extension, const ExtensionOption *option, Exte
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString WebPage::getLastAttachedFileName() {
|
QStringList WebPage::getAttachedFileNames() {
|
||||||
return currentFrame()->evaluateJavaScript(QString("Capybara.lastAttachedFile")).toString();
|
return currentFrame()->evaluateJavaScript(QString("Capybara.attachedFiles")).toStringList();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebPage::handleSslErrorsForReply(QNetworkReply *reply, const QList<QSslError> &errors) {
|
void WebPage::handleSslErrorsForReply(QNetworkReply *reply, const QList<QSslError> &errors) {
|
||||||
|
|
|
@ -66,7 +66,7 @@ class WebPage : public QWebPage {
|
||||||
QString m_userAgent;
|
QString m_userAgent;
|
||||||
bool m_loading;
|
bool m_loading;
|
||||||
bool m_failed;
|
bool m_failed;
|
||||||
QString getLastAttachedFileName();
|
QStringList getAttachedFileNames();
|
||||||
void loadJavascript();
|
void loadJavascript();
|
||||||
void setUserStylesheet();
|
void setUserStylesheet();
|
||||||
bool m_confirm;
|
bool m_confirm;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
Capybara = {
|
Capybara = {
|
||||||
nextIndex: 0,
|
nextIndex: 0,
|
||||||
nodes: {},
|
nodes: {},
|
||||||
lastAttachedFile: "",
|
attachedFiles: [],
|
||||||
|
|
||||||
invoke: function () {
|
invoke: function () {
|
||||||
return this[CapybaraInvocation.functionName].apply(this, CapybaraInvocation.arguments);
|
return this[CapybaraInvocation.functionName].apply(this, CapybaraInvocation.arguments);
|
||||||
|
@ -260,7 +260,7 @@ Capybara = {
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (type === "file") {
|
} else if (type === "file") {
|
||||||
this.lastAttachedFile = value;
|
this.attachedFiles = Array.prototype.slice.call(arguments, 1);
|
||||||
this.click(index);
|
this.click(index);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue