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 dae3e4eba697cf4ea7397069c73313c502834cbb..3eb44883d0c91daf395ec923c75c411a73eb8c01 100644 |
--- a/chrome/test/webdriver/commands/webelement_commands.cc |
+++ b/chrome/test/webdriver/commands/webelement_commands.cc |
@@ -4,7 +4,9 @@ |
#include "chrome/test/webdriver/commands/webelement_commands.h" |
+#include "base/file_util.h" |
#include "base/memory/scoped_ptr.h" |
+#include "base/string_util.h" |
#include "base/stringprintf.h" |
#include "base/third_party/icu/icu_utf.h" |
#include "base/values.h" |
@@ -65,20 +67,15 @@ void ElementAttributeCommand::ExecuteGet(Response* const response) { |
return; |
} |
- std::string script = base::StringPrintf( |
- "return (%s).apply(null, arguments);", atoms::GET_ATTRIBUTE); |
- |
- ListValue args; |
- args.Append(element.ToValue()); |
- args.Append(Value::CreateStringValue(path_segments_.at(6))); |
- |
- Value* result = NULL; |
- Error* error = session_->ExecuteScript(script, &args, &result); |
+ const std::string key = path_segments_.at(6); |
+ Value* value; |
+ Error* error = session_->GetAttribute(element, key, &value); |
if (error) { |
response->SetError(error); |
return; |
} |
- response->SetValue(result); |
+ |
+ response->SetValue(value); |
} |
///////////////////// ElementClearCommand //////////////////// |
@@ -498,12 +495,96 @@ void ElementValueCommand::ExecuteGet(Response* const response) { |
} |
void ElementValueCommand::ExecutePost(Response* const response) { |
+ bool is_input = false; |
+ Error* error = HasAttributeWithLowerCaseValueASCII("tagName", "input", |
+ &is_input); |
+ if (error) { |
+ response->SetError(error); |
+ return; |
+ } |
+ |
+ bool is_file = false; |
+ error = HasAttributeWithLowerCaseValueASCII("type", "file", &is_file); |
+ if (error) { |
+ response->SetError(error); |
+ return; |
+ } |
+ |
+ // If the element is a file upload control, set the file paths to the element. |
+ // Otherwise send the value to the element as key input. |
+ if (is_input && is_file) { |
+ error = DragAndDropFilePaths(); |
+ } else { |
+ error = SendKeys(); |
+ } |
+ |
+ if (error) { |
+ response->SetError(error); |
+ return; |
+ } |
+} |
+ |
+Error* ElementValueCommand::HasAttributeWithLowerCaseValueASCII( |
+ const std::string& key, const std::string& value, bool* result) const { |
+ Value* unscoped_value = NULL; |
+ Error* error = session_->GetAttribute(element, key, &unscoped_value); |
+ scoped_ptr<Value> scoped_value(unscoped_value); |
+ unscoped_value = NULL; |
+ |
+ if (error) { |
+ return error; |
+ } |
+ |
+ std::string actual_value; |
+ if (!scoped_value->GetAsString(&actual_value)) { |
+ return new Error(kUnknownError, |
+ StringPrintf("Attribute '%s' did not have a string value", |
kkania
2011/06/07 15:12:04
base::StringPrintf is preferred
nodchip
2011/06/08 02:37:19
Done.
|
+ key.c_str())); |
+ } |
+ |
+ *result = LowerCaseEqualsASCII(actual_value, value.c_str()); |
+ return NULL; |
+} |
+ |
+Error* ElementValueCommand::DragAndDropFilePaths() const { |
+ ListValue* path_list; |
+ if (!GetListParameter("value", &path_list)) { |
+ return new Error(kBadRequest, "Missing or invalid 'value' parameter"); |
+ } |
+ |
+ std::vector<std::string> paths; |
+ for (size_t i = 0; i < path_list->GetSize(); ++i) { |
+ FilePath::StringType path; |
+ if (!path_list->GetString(i, &path)) { |
+ return new Error(kBadRequest, |
+ StringPrintf("%zd-th element in 'value' is not string", |
kkania
2011/06/07 15:12:04
The style guide says use %"PRIuS" for size_t (http
nodchip
2011/06/08 02:37:19
Done.
|
+ i)); |
+ } |
+ |
+ if (!file_util::PathExists(FilePath(path))) { |
kkania
2011/06/07 15:12:04
Does the spec actually disallow non-existent file
nodchip
2011/06/08 02:37:19
There are no spec about file uploading in the offi
|
+ return new Error(kBadRequest, |
+ StringPrintf("'%s' does not exist on the file system", |
kkania
2011/06/07 15:12:04
base::
nodchip
2011/06/08 02:37:19
Done.
|
+ path.c_str())); |
+ } |
+ |
+ paths.push_back(path); |
+ } |
+ |
+ gfx::Point location; |
+ Error* error = session_->GetClickableLocation(element, &location); |
+ if (error) { |
+ return error; |
+ } |
+ |
+ return session_->DragAndDropFilePaths(location, paths); |
+} |
+ |
+Error* ElementValueCommand::SendKeys() const { |
ListValue* key_list; |
if (!GetListParameter("value", &key_list)) { |
- response->SetError(new Error( |
- kBadRequest, "Missing or invalid 'value' parameter")); |
- return; |
+ return new Error(kBadRequest, "Missing or invalid 'value' parameter"); |
} |
+ |
// Flatten the given array of strings into one. |
string16 keys; |
for (size_t i = 0; i < key_list->GetSize(); ++i) { |
@@ -511,17 +592,14 @@ void ElementValueCommand::ExecutePost(Response* const response) { |
key_list->GetString(i, &keys_list_part); |
for (size_t j = 0; j < keys_list_part.size(); ++j) { |
if (CBU16_IS_SURROGATE(keys_list_part[j])) { |
- response->SetError(new Error( |
- kBadRequest, "ChromeDriver only supports characters in the BMP")); |
- return; |
+ return new Error(kBadRequest, |
+ "ChromeDriver only supports characters in the BMP"); |
} |
} |
keys.append(keys_list_part); |
} |
- Error* error = session_->SendKeys(element, keys); |
- if (error) |
- response->SetError(error); |
+ return session_->SendKeys(element, keys); |
} |
///////////////////// ElementTextCommand //////////////////// |