Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(589)

Unified Diff: chrome/test/webdriver/commands/webelement_commands.cc

Issue 7701010: Fix file uploads in chromedriver. It should not be assumed that multiple file (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ... Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/test/webdriver/test/chromedriver_tests.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/webdriver/commands/webelement_commands.cc
diff --git a/chrome/test/webdriver/commands/webelement_commands.cc b/chrome/test/webdriver/commands/webelement_commands.cc
index 267595db519cc5683fc4f03762863150b22d2166..98936a63b5f1f8433c0e938ed166ba5b7e09e12f 100644
--- a/chrome/test/webdriver/commands/webelement_commands.cc
+++ b/chrome/test/webdriver/commands/webelement_commands.cc
@@ -7,14 +7,17 @@
#include "base/file_util.h"
#include "base/format_macros.h"
#include "base/memory/scoped_ptr.h"
+#include "base/string_split.h"
#include "base/string_util.h"
#include "base/stringprintf.h"
#include "base/third_party/icu/icu_utf.h"
+#include "base/utf_string_conversions.h"
#include "base/values.h"
#include "chrome/test/webdriver/commands/response.h"
#include "chrome/test/webdriver/webdriver_basic_types.h"
#include "chrome/test/webdriver/webdriver_error.h"
#include "chrome/test/webdriver/webdriver_session.h"
+#include "chrome/test/webdriver/webdriver_util.h"
#include "third_party/webdriver/atoms.h"
namespace webdriver {
@@ -529,48 +532,49 @@ Error* ElementValueCommand::HasAttributeWithLowerCaseValueASCII(
}
Error* ElementValueCommand::DragAndDropFilePaths() const {
- bool multiple = false;
- Error* error = HasAttributeWithLowerCaseValueASCII("multiple", "true",
- &multiple);
-
- if (error) {
- return error;
- }
-
ListValue* path_list;
- if (!GetListParameter("value", &path_list)) {
+ if (!GetListParameter("value", &path_list))
return new Error(kBadRequest, "Missing or invalid 'value' parameter");
- }
- if (!multiple && path_list->GetSize() > 1) {
- return new Error(kBadRequest, "The element can not hold multiple files");
- }
-
- std::vector<FilePath::StringType> paths;
+ // Compress array into single string.
+ FilePath::StringType paths_string;
for (size_t i = 0; i < path_list->GetSize(); ++i) {
- FilePath::StringType path;
- if (!path_list->GetString(i, &path)) {
+ FilePath::StringType path_part;
+ if (!path_list->GetString(i, &path_part)) {
return new Error(
kBadRequest,
- base::StringPrintf("'value' list item #%" PRIuS " is not a string",
- i + 1));
+ "'value' is invalid: " + JsonStringify(path_list));
}
+ paths_string.append(path_part);
+ }
- if (!file_util::PathExists(FilePath(path))) {
+ // Separate the string into separate paths, delimited by \n.
+ std::vector<FilePath::StringType> paths;
+ base::SplitString(paths_string, '\n', &paths);
Huyen 2011/08/23 22:10:44 why not just directly go from array to vector of s
kkania 2011/08/25 20:16:58 not sure what you mean: The input is an array of
+
+ // Return an error if trying to drop multiple paths on a single file input.
+ bool multiple = false;
+ Error* error = HasAttributeWithLowerCaseValueASCII("multiple", "true",
+ &multiple);
+ if (error)
+ return error;
+ if (!multiple && paths.size() > 1)
+ return new Error(kBadRequest, "The element can not hold multiple files");
+
+ // Check the files exist.
+ for (size_t i = 0; i < paths.size(); ++i) {
+ if (!file_util::PathExists(FilePath(paths[i]))) {
return new Error(
kBadRequest,
base::StringPrintf("'%s' does not exist on the file system",
- path.c_str()));
+ UTF16ToUTF8(FilePath(paths[i]).LossyDisplayName()).c_str()));
}
-
- paths.push_back(path);
}
Point location;
error = session_->GetClickableLocation(element, &location);
- if (error) {
+ if (error)
return error;
- }
return session_->DragAndDropFilePaths(location, paths);
}
« no previous file with comments | « no previous file | chrome/test/webdriver/test/chromedriver_tests.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698