 Chromium Code Reviews
 Chromium Code Reviews Issue 6630001:
  Allow webdriver users to choose between sending the key events when...  (Closed) 
  Base URL: http://src.chromium.org/svn/trunk/src/
    
  
    Issue 6630001:
  Allow webdriver users to choose between sending the key events when...  (Closed) 
  Base URL: http://src.chromium.org/svn/trunk/src/| Index: chrome/test/webdriver/session.cc | 
| =================================================================== | 
| --- chrome/test/webdriver/session.cc (revision 77771) | 
| +++ chrome/test/webdriver/session.cc (working copy) | 
| @@ -47,7 +47,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); | 
| } | 
| @@ -163,18 +164,22 @@ | 
| } | 
| ErrorCode Session::SendKeys(const WebElementId& element, const string16& keys) { | 
| + // 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. | 
| ListValue args; | 
| 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)" | 
| + " 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"; | 
| + LOG(ERROR) << "Failed to get or set focus element before sending keys"; | 
| return code; | 
| } | 
| - | 
| bool success = false; | 
| RunSessionTask(NewRunnableMethod( | 
| this, | 
| @@ -622,16 +627,30 @@ | 
| ConvertKeysToWebKeyEvents(keys, &key_events); | 
| 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 (use_native_events_) { | 
| + // The automation proxy will generate up/down events for us, we | 
| 
kkania
2011/03/11 16:32:13
proxy -> provider
 
timothe
2011/03/21 18:02:05
Done.
 | 
| + // only need to call it once as compared to the WebKeyEvent method. | 
| + // Hence we filter events by their types, keeping only rawkeydown. | 
| + if (key_events[i].type != automation::kRawKeyDownType) | 
| + continue; | 
| + automation_->SendNativeKeyEvent( | 
| + current_window_id_, | 
| + static_cast<ui::KeyboardCode>(key_events[i].key_code), | 
| 
kkania
2011/03/11 16:32:13
isn't key_code already a ui::KeyboardCode
 
timothe
2011/03/21 18:02:05
Done.
 | 
| + key_events[i].modifiers, | 
| + &key_success); | 
| + } else { | 
| + automation_->SendWebKeyEvent( | 
| + current_window_id_, key_events[i], &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; | 
| + << "Modifiers: " << key_events[i].modifiers << "\n" | 
| + << "Was a native event: " << use_native_events_ << "\n"; | 
| + *success = false; | 
| 
kkania
2011/03/11 16:32:13
indentation
 
timothe
2011/03/21 18:02:05
Done.
 | 
| } | 
| } | 
| } |