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..24b1fb5a6c907084b8c1a4c4290bbd6f34b81e83 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,97 @@ 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; |
+ } |
+ |
+ response->SetStatus(kSuccess); |
kkania
2011/06/01 16:16:41
this is the default status of the response, so you
nodchip
2011/06/02 07:15:53
Done.
|
+} |
+ |
+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; |
+ } |
+ |
+ if (!scoped_value->IsType(Value::TYPE_STRING)) { |
+ return new Error(kUnknownError, |
+ "Could not get the attribute value as a string"); |
+ } |
+ |
+ std::string actual_value; |
+ if (!scoped_value->GetAsString(&actual_value)) { |
kkania
2011/06/01 16:16:41
I believe GetAsString will do the same check as yo
nodchip
2011/06/02 07:15:53
Done.
|
+ return new Error(kUnknownError, "Could not get the attribute value"); |
kkania
2011/06/01 16:16:41
change error message to "Attribute '%s' did not ha
nodchip
2011/06/02 07:15:53
Done.
|
+ } |
+ |
+ *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, "Invalid element in 'value' parameter"); |
kkania
2011/06/01 16:16:41
this is a bit unclear, how about including somethi
nodchip
2011/06/02 07:15:53
Done.
|
+ } |
+ |
+ if (!file_util::PathExists(FilePath(path))) { |
+ return new Error(kBadRequest, "Path does not exist"); |
kkania
2011/06/01 16:16:41
put the path in the error msg
nodchip
2011/06/02 07:15:53
Done.
|
+ } |
+ |
+ 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 +593,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 //////////////////// |