Chromium Code Reviews| Index: chrome/test/webdriver/session.cc |
| =================================================================== |
| --- chrome/test/webdriver/session.cc (revision 76851) |
| +++ chrome/test/webdriver/session.cc (working copy) |
| @@ -46,7 +46,8 @@ |
| thread_(id_.c_str()), |
| implicit_wait_(0), |
| current_frame_xpath_(""), |
| - current_window_id_(0) { |
| + current_window_id_(0), |
| + use_native_events_(false) { |
| SessionManager::GetInstance()->Add(this); |
| } |
| @@ -162,18 +163,20 @@ |
| } |
| ErrorCode Session::SendKeys(const WebElementId& element, const string16& keys) { |
| - ListValue args; |
| - args.Append(element.ToValue()); |
| + // 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> args(new ListValue); |
|
kkania
2011/03/10 00:28:58
why the change to scoped_ptr here?
timothe faudot
2011/03/10 05:34:32
A remnant of my previous struggles with the focus
|
| + args->Append(element.ToValue()); |
| // TODO(jleyba): Update this to use the correct atom. |
| - std::string script = "document.activeElement.blur();arguments[0].focus();"; |
| + std::string script = "if(document.activeElement!=arguments[0])" |
| + "{if(document.activeElement)" |
|
kkania
2011/03/10 00:28:58
can you make this a bit more readable
timothe faudot
2011/03/10 05:34:32
Done.
|
| + "document.activeElement.blur();arguments[0].focus();}"; |
| Value* unscoped_result = NULL; |
| - ErrorCode code = ExecuteScript(script, &args, &unscoped_result); |
| - scoped_ptr<Value> result(unscoped_result); |
| + ErrorCode code = ExecuteScript(script, args.get(), &unscoped_result); |
| if (code != kSuccess) { |
| - LOG(ERROR) << "Failed to focus element before sending keys"; |
| + LOG(ERROR) << "Failed to get or set focus element before sending keys"; |
| return code; |
| } |
| - |
| bool success = false; |
| RunSessionTask(NewRunnableMethod( |
| this, |
| @@ -611,15 +614,16 @@ |
| for (size_t i = 0; i < key_events.size(); ++i) { |
| bool key_success = false; |
| automation_->SendWebKeyEvent( |
| - current_window_id_, key_events[i], &key_success); |
| + current_window_id_, key_events[i], 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" |
| - << "UnmodifiedText: " << key_events[i].unmodified_text << "\n" |
| - << "ModifiedText: " << key_events[i].modified_text << "\n" |
| - << "Modifiers: " << key_events[i].modifiers << "\n"; |
| - *success = false; |
| + LOG(ERROR) << "Failed to send key event. Event details:\n" |
|
kkania
2011/03/10 00:28:58
looks like the indentation got messed up somehow
timothe faudot
2011/03/10 05:34:32
Done.
|
| + << "Type: " << key_events[i].type << "\n" |
| + << "KeyCode: " << key_events[i].key_code << "\n" |
| + << "UnmodifiedText: " << key_events[i].unmodified_text << "\n" |
| + << "ModifiedText: " << key_events[i].modified_text << "\n" |
| + << "Modifiers: " << key_events[i].modifiers << "\n" |
| + << "Was a native event: " << use_native_events_ << "\n"; |
| + *success = false; |
| } |
| } |
| } |