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

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, 9 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
« no previous file with comments | « chrome/test/webdriver/session.h ('k') | chrome/test/webdriver/test_page.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/webdriver/session.cc
===================================================================
--- chrome/test/webdriver/session.cc (revision 79882)
+++ chrome/test/webdriver/session.cc (working copy)
@@ -61,7 +61,8 @@
thread_(id_.c_str()),
implicit_wait_(0),
screenshot_on_error_(false),
- current_target_(FrameId(0, FramePath())) {
+ current_target_(FrameId(0, FramePath())),
+ use_native_events_(false) {
SessionManager::GetInstance()->Add(this);
}
@@ -182,18 +183,22 @@
if (!is_displayed)
return kElementNotVisible;
+ // 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;
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,
@@ -829,8 +834,21 @@
}
for (size_t i = 0; i < key_events.size(); ++i) {
bool key_success = false;
- automation_->SendWebKeyEvent(
- current_target_.window_id, key_events[i], &key_success);
+ if (use_native_events_) {
+ // The automation provider will generate up/down events for us, we
+ // 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_target_.window_id,
+ key_events[i].key_code,
+ key_events[i].modifiers,
+ &key_success);
+ } else {
+ automation_->SendWebKeyEvent(
+ current_target_.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"
« no previous file with comments | « chrome/test/webdriver/session.h ('k') | chrome/test/webdriver/test_page.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698