Permalink
Browse files

Implement HTML5 multiple file upload

  • Loading branch information...
1 parent 0efbbe0 commit ea2f785ba868c5c4dc871e5aff6a4b222731b380 @mhoran mhoran committed Nov 18, 2012
Showing with 8 additions and 9 deletions.
  1. +1 −1 lib/capybara/webkit/node.rb
  2. +4 −5 src/WebPage.cpp
  3. +1 −1 src/WebPage.h
  4. +2 −2 src/capybara.js
View
2 lib/capybara/webkit/node.rb
@@ -33,7 +33,7 @@ def inner_html=(value)
end
def set(value)
- invoke "set", value
+ invoke "set", *[value].flatten
end
def select_option
View
9 src/WebPage.cpp
@@ -221,13 +221,12 @@ QString WebPage::chooseFile(QWebFrame *parentFrame, const QString &suggestedFile
Q_UNUSED(parentFrame);
Q_UNUSED(suggestedFile);
- return getLastAttachedFileName();
+ return getAttachedFileNames().first();
}
bool WebPage::extension(Extension extension, const ExtensionOption *option, ExtensionReturn *output) {
if (extension == ChooseMultipleFilesExtension) {
- QStringList names = QStringList() << getLastAttachedFileName();
- static_cast<ChooseMultipleFilesExtensionReturn*>(output)->fileNames = names;
+ static_cast<ChooseMultipleFilesExtensionReturn*>(output)->fileNames = getAttachedFileNames();
return true;
}
else if (extension == QWebPage::ErrorPageExtension) {
@@ -239,8 +238,8 @@ bool WebPage::extension(Extension extension, const ExtensionOption *option, Exte
return false;
}
-QString WebPage::getLastAttachedFileName() {
- return currentFrame()->evaluateJavaScript(QString("Capybara.lastAttachedFile")).toString();
+QStringList WebPage::getAttachedFileNames() {
+ return currentFrame()->evaluateJavaScript(QString("Capybara.attachedFiles")).toStringList();
}
void WebPage::handleSslErrorsForReply(QNetworkReply *reply, const QList<QSslError> &errors) {
View
2 src/WebPage.h
@@ -66,7 +66,7 @@ class WebPage : public QWebPage {
QString m_userAgent;
bool m_loading;
bool m_failed;
- QString getLastAttachedFileName();
+ QStringList getAttachedFileNames();
void loadJavascript();
void setUserStylesheet();
bool m_confirm;
View
4 src/capybara.js
@@ -1,7 +1,7 @@
Capybara = {
nextIndex: 0,
nodes: {},
- lastAttachedFile: "",
+ attachedFiles: [],
invoke: function () {
return this[CapybaraInvocation.functionName].apply(this, CapybaraInvocation.arguments);
@@ -260,7 +260,7 @@ Capybara = {
}
} else if (type === "file") {
- this.lastAttachedFile = value;
+ this.attachedFiles = Array.prototype.slice.call(arguments, 1);
this.click(index);
} else {

0 comments on commit ea2f785

Please sign in to comment.