diff options
-rw-r--r-- | chrome/test/webdriver/commands/webelement_commands.cc | 54 | ||||
-rw-r--r-- | chrome/test/webdriver/test/chromedriver_tests.py | 11 |
2 files changed, 33 insertions, 32 deletions
diff --git a/chrome/test/webdriver/commands/webelement_commands.cc b/chrome/test/webdriver/commands/webelement_commands.cc index 267595d..98936a6 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); + + // 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); } diff --git a/chrome/test/webdriver/test/chromedriver_tests.py b/chrome/test/webdriver/test/chromedriver_tests.py index 6a5468a..7f36cf7 100644 --- a/chrome/test/webdriver/test/chromedriver_tests.py +++ b/chrome/test/webdriver/test/chromedriver_tests.py @@ -676,8 +676,7 @@ class FileUploadControlTest(ChromeDriverTest): super(FileUploadControlTest, self).setUp() self._driver = self.GetNewDriver() - # See crbug.com/93909. - def DISABLED_testSetFilePathToFileUploadControl(self): + def testSetFilePathToFileUploadControl(self): """Verify a file path is set to the file upload control.""" self._driver.get(GetTestDataUrl() + '/upload.html') @@ -709,10 +708,9 @@ class FileUploadControlTest(ChromeDriverTest): multiple = fileupload_single.get_attribute('multiple') self.assertEqual('false', multiple) self.assertRaises(WebDriverException, fileupload_single.send_keys, - filepaths[0], filepaths[1], filepaths[2], filepaths[3]) + '\n'.join(filepaths)) - # See crbug.com/93909. - def DISABLED_testSetMultipleFilePathsToFileUploadControl(self): + def testSetMultipleFilePathsToFileUploadControl(self): """Verify multiple file paths are set to the file upload control.""" self._driver.get(GetTestDataUrl() + '/upload.html') @@ -729,8 +727,7 @@ class FileUploadControlTest(ChromeDriverTest): fileupload_multi = self._driver.find_element_by_name('fileupload_multi') multiple = fileupload_multi.get_attribute('multiple') self.assertEqual('true', multiple) - fileupload_multi.send_keys(filepaths[0], filepaths[1], filepaths[2], - filepaths[3]) + fileupload_multi.send_keys('\n'.join(filepaths)) files_on_element = self._driver.execute_script( 'return document.getElementById("fileupload_multi").files;') |