Commit a0f76291 authored by kkania@chromium.org's avatar kkania@chromium.org

Fix file uploads in chromedriver. It should not be assumed that multiple file

names are separate elements in the input array.
BUG=92911,93909
TEST=none


Review URL: http://codereview.chromium.org/7701010

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@98796 0039d316-1c4b-4281-b951-d872f2087c98
parent 64df4f15
...@@ -7,14 +7,17 @@ ...@@ -7,14 +7,17 @@
#include "base/file_util.h" #include "base/file_util.h"
#include "base/format_macros.h" #include "base/format_macros.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/string_split.h"
#include "base/string_util.h" #include "base/string_util.h"
#include "base/stringprintf.h" #include "base/stringprintf.h"
#include "base/third_party/icu/icu_utf.h" #include "base/third_party/icu/icu_utf.h"
#include "base/utf_string_conversions.h"
#include "base/values.h" #include "base/values.h"
#include "chrome/test/webdriver/commands/response.h" #include "chrome/test/webdriver/commands/response.h"
#include "chrome/test/webdriver/webdriver_basic_types.h" #include "chrome/test/webdriver/webdriver_basic_types.h"
#include "chrome/test/webdriver/webdriver_error.h" #include "chrome/test/webdriver/webdriver_error.h"
#include "chrome/test/webdriver/webdriver_session.h" #include "chrome/test/webdriver/webdriver_session.h"
#include "chrome/test/webdriver/webdriver_util.h"
#include "third_party/webdriver/atoms.h" #include "third_party/webdriver/atoms.h"
namespace webdriver { namespace webdriver {
...@@ -529,48 +532,49 @@ Error* ElementValueCommand::HasAttributeWithLowerCaseValueASCII( ...@@ -529,48 +532,49 @@ Error* ElementValueCommand::HasAttributeWithLowerCaseValueASCII(
} }
Error* ElementValueCommand::DragAndDropFilePaths() const { Error* ElementValueCommand::DragAndDropFilePaths() const {
bool multiple = false;
Error* error = HasAttributeWithLowerCaseValueASCII("multiple", "true",
&multiple);
if (error) {
return error;
}
ListValue* path_list; ListValue* path_list;
if (!GetListParameter("value", &path_list)) { if (!GetListParameter("value", &path_list))
return new Error(kBadRequest, "Missing or invalid 'value' parameter"); return new Error(kBadRequest, "Missing or invalid 'value' parameter");
}
if (!multiple && path_list->GetSize() > 1) { // Compress array into single string.
return new Error(kBadRequest, "The element can not hold multiple files"); FilePath::StringType paths_string;
}
std::vector<FilePath::StringType> paths;
for (size_t i = 0; i < path_list->GetSize(); ++i) { for (size_t i = 0; i < path_list->GetSize(); ++i) {
FilePath::StringType path; FilePath::StringType path_part;
if (!path_list->GetString(i, &path)) { if (!path_list->GetString(i, &path_part)) {
return new Error( return new Error(
kBadRequest, kBadRequest,
base::StringPrintf("'value' list item #%" PRIuS " is not a string", "'value' is invalid: " + JsonStringify(path_list));
i + 1));
} }
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);
// 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( return new Error(
kBadRequest, kBadRequest,
base::StringPrintf("'%s' does not exist on the file system", 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; Point location;
error = session_->GetClickableLocation(element, &location); error = session_->GetClickableLocation(element, &location);
if (error) { if (error)
return error; return error;
}
return session_->DragAndDropFilePaths(location, paths); return session_->DragAndDropFilePaths(location, paths);
} }
......
...@@ -676,8 +676,7 @@ class FileUploadControlTest(ChromeDriverTest): ...@@ -676,8 +676,7 @@ class FileUploadControlTest(ChromeDriverTest):
super(FileUploadControlTest, self).setUp() super(FileUploadControlTest, self).setUp()
self._driver = self.GetNewDriver() self._driver = self.GetNewDriver()
# See crbug.com/93909. def testSetFilePathToFileUploadControl(self):
def DISABLED_testSetFilePathToFileUploadControl(self):
"""Verify a file path is set to the file upload control.""" """Verify a file path is set to the file upload control."""
self._driver.get(GetTestDataUrl() + '/upload.html') self._driver.get(GetTestDataUrl() + '/upload.html')
...@@ -709,10 +708,9 @@ class FileUploadControlTest(ChromeDriverTest): ...@@ -709,10 +708,9 @@ class FileUploadControlTest(ChromeDriverTest):
multiple = fileupload_single.get_attribute('multiple') multiple = fileupload_single.get_attribute('multiple')
self.assertEqual('false', multiple) self.assertEqual('false', multiple)
self.assertRaises(WebDriverException, fileupload_single.send_keys, self.assertRaises(WebDriverException, fileupload_single.send_keys,
filepaths[0], filepaths[1], filepaths[2], filepaths[3]) '\n'.join(filepaths))
# See crbug.com/93909. def testSetMultipleFilePathsToFileUploadControl(self):
def DISABLED_testSetMultipleFilePathsToFileUploadControl(self):
"""Verify multiple file paths are set to the file upload control.""" """Verify multiple file paths are set to the file upload control."""
self._driver.get(GetTestDataUrl() + '/upload.html') self._driver.get(GetTestDataUrl() + '/upload.html')
...@@ -729,8 +727,7 @@ class FileUploadControlTest(ChromeDriverTest): ...@@ -729,8 +727,7 @@ class FileUploadControlTest(ChromeDriverTest):
fileupload_multi = self._driver.find_element_by_name('fileupload_multi') fileupload_multi = self._driver.find_element_by_name('fileupload_multi')
multiple = fileupload_multi.get_attribute('multiple') multiple = fileupload_multi.get_attribute('multiple')
self.assertEqual('true', multiple) self.assertEqual('true', multiple)
fileupload_multi.send_keys(filepaths[0], filepaths[1], filepaths[2], fileupload_multi.send_keys('\n'.join(filepaths))
filepaths[3])
files_on_element = self._driver.execute_script( files_on_element = self._driver.execute_script(
'return document.getElementById("fileupload_multi").files;') 'return document.getElementById("fileupload_multi").files;')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment