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

Unified Diff: chrome/test/webdriver/session.cc

Issue 6630001: Allow webdriver users to choose between sending the key events when... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 9 years, 10 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
Index: chrome/test/webdriver/session.cc
===================================================================
--- chrome/test/webdriver/session.cc (revision 76851)
+++ chrome/test/webdriver/session.cc (working copy)
@@ -162,18 +162,41 @@
}
ErrorCode Session::SendKeys(const WebElementId& element, const string16& keys) {
- ListValue args;
- args.Append(element.ToValue());
- // TODO(jleyba): Update this to use the correct atom.
- std::string script = "document.activeElement.blur();arguments[0].focus();";
- Value* unscoped_result = NULL;
- ErrorCode code = ExecuteScript(script, &args, &unscoped_result);
- scoped_ptr<Value> result(unscoped_result);
- if (code != kSuccess) {
- LOG(ERROR) << "Failed to focus element before sending keys";
- return code;
+ // This method will first check if the element we want to send the keys to is
+ // already focused, if not it will try to focus on it first.
+ scoped_ptr<ListValue> nullArgs(new ListValue);
Jason Leyba 2011/03/04 19:25:12 This would be much simpler if you did it all with
timothe faudot 2011/03/07 02:45:26 Done.
+ Value* active_element = NULL;
+ ErrorCode status = ExecuteScript(
+ "return document.activeElement;", nullArgs.get(), &active_element);
+ if (status != kSuccess) {
+ LOG(ERROR) << "Failed to get which element was focused before sending keys";
+ return status;
}
-
+ if (active_element == NULL ||
+ active_element->GetType() != Value::TYPE_DICTIONARY) {
+ LOG(ERROR) << "Expected Japascript to return a dictionary";
+ return kUnknownError;
+ }
+ std::string active_elem_str;
+ static_cast<DictionaryValue*>(active_element)->GetString("ELEMENT",
+ &active_elem_str);
+ std::string wanted_element;
+ DictionaryValue* element_id =
+ static_cast<DictionaryValue*>(element.ToValue());
+ element_id->GetString("ELEMENT", &wanted_element);
+ // We focus on the element only if necessary.
+ if (active_elem_str != wanted_element) {
+ scoped_ptr<ListValue> args(new ListValue);
+ args->Append(element.ToValue());
+ // TODO(jleyba): Update this to use the correct atom.
+ std::string script = "document.activeElement.blur();arguments[0].focus();";
+ Value* unscoped_result = NULL;
+ ErrorCode code = ExecuteScript(script, args.get(), &unscoped_result);
+ if (code != kSuccess) {
+ LOG(ERROR) << "Failed to focus element before sending keys";
+ return code;
+ }
+ }
bool success = false;
RunSessionTask(NewRunnableMethod(
this,
@@ -611,8 +634,9 @@
for (size_t i = 0; i < key_events.size(); ++i) {
bool key_success = false;
automation_->SendWebKeyEvent(
- current_window_id_, key_events[i], &key_success);
- if (!key_success) {
+ current_window_id_, key_events[i],
+ SessionManager::GetInstance()->use_native_events(), &key_success);
+ if (!key_success) {
LOG(ERROR) << "Failed to send key event. Event details:\n"
<< "Type: " << key_events[i].type << "\n"
<< "KeyCode: " << key_events[i].key_code << "\n"

Powered by Google App Engine
This is Rietveld 408576698