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

Side by Side 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, 8 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/test/webdriver/session.h ('k') | chrome/test/webdriver/test_page.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/test/webdriver/session.h" 5 #include "chrome/test/webdriver/session.h"
6 6
7 #include <sstream> 7 #include <sstream>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 window_id = other.window_id; 54 window_id = other.window_id;
55 frame_path = other.frame_path; 55 frame_path = other.frame_path;
56 return *this; 56 return *this;
57 } 57 }
58 58
59 Session::Session() 59 Session::Session()
60 : id_(GenerateRandomID()), 60 : id_(GenerateRandomID()),
61 thread_(id_.c_str()), 61 thread_(id_.c_str()),
62 implicit_wait_(0), 62 implicit_wait_(0),
63 screenshot_on_error_(false), 63 screenshot_on_error_(false),
64 current_target_(FrameId(0, FramePath())) { 64 current_target_(FrameId(0, FramePath())),
65 use_native_events_(false) {
65 SessionManager::GetInstance()->Add(this); 66 SessionManager::GetInstance()->Add(this);
66 } 67 }
67 68
68 Session::~Session() { 69 Session::~Session() {
69 SessionManager::GetInstance()->Remove(id_); 70 SessionManager::GetInstance()->Remove(id_);
70 } 71 }
71 72
72 bool Session::Init(const FilePath& browser_dir) { 73 bool Session::Init(const FilePath& browser_dir) {
73 bool success = false; 74 bool success = false;
74 if (thread_.Start()) { 75 if (thread_.Start()) {
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 } 176 }
176 177
177 ErrorCode Session::SendKeys(const WebElementId& element, const string16& keys) { 178 ErrorCode Session::SendKeys(const WebElementId& element, const string16& keys) {
178 bool is_displayed = false; 179 bool is_displayed = false;
179 ErrorCode code = IsElementDisplayed(current_target_, element, &is_displayed); 180 ErrorCode code = IsElementDisplayed(current_target_, element, &is_displayed);
180 if (code != kSuccess) 181 if (code != kSuccess)
181 return code; 182 return code;
182 if (!is_displayed) 183 if (!is_displayed)
183 return kElementNotVisible; 184 return kElementNotVisible;
184 185
186 // This method will first check if the element we want to send the keys to is
187 // already focused, if not it will try to focus on it first.
185 ListValue args; 188 ListValue args;
186 args.Append(element.ToValue()); 189 args.Append(element.ToValue());
187 // TODO(jleyba): Update this to use the correct atom. 190 // TODO(jleyba): Update this to use the correct atom.
188 std::string script = "document.activeElement.blur();arguments[0].focus();"; 191 std::string script = "if(document.activeElement!=arguments[0]){"
192 " if(document.activeElement)"
193 " document.activeElement.blur();"
194 " arguments[0].focus();"
195 "}";
189 Value* unscoped_result = NULL; 196 Value* unscoped_result = NULL;
190 code = ExecuteScript(script, &args, &unscoped_result); 197 code = ExecuteScript(script, &args, &unscoped_result);
191 scoped_ptr<Value> result(unscoped_result);
192 if (code != kSuccess) { 198 if (code != kSuccess) {
193 LOG(ERROR) << "Failed to focus element before sending keys"; 199 LOG(ERROR) << "Failed to get or set focus element before sending keys";
194 return code; 200 return code;
195 } 201 }
196
197 bool success = false; 202 bool success = false;
198 RunSessionTask(NewRunnableMethod( 203 RunSessionTask(NewRunnableMethod(
199 this, 204 this,
200 &Session::SendKeysOnSessionThread, 205 &Session::SendKeysOnSessionThread,
201 keys, 206 keys,
202 &success)); 207 &success));
203 if (!success) 208 if (!success)
204 return kUnknownError; 209 return kUnknownError;
205 return kSuccess; 210 return kSuccess;
206 } 211 }
(...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after
822 std::vector<WebKeyEvent> key_events; 827 std::vector<WebKeyEvent> key_events;
823 std::string error_msg; 828 std::string error_msg;
824 if (!ConvertKeysToWebKeyEvents(keys, &key_events, &error_msg)) { 829 if (!ConvertKeysToWebKeyEvents(keys, &key_events, &error_msg)) {
825 // TODO(kkania): Return this message to the user. 830 // TODO(kkania): Return this message to the user.
826 LOG(ERROR) << error_msg; 831 LOG(ERROR) << error_msg;
827 *success = false; 832 *success = false;
828 return; 833 return;
829 } 834 }
830 for (size_t i = 0; i < key_events.size(); ++i) { 835 for (size_t i = 0; i < key_events.size(); ++i) {
831 bool key_success = false; 836 bool key_success = false;
832 automation_->SendWebKeyEvent( 837 if (use_native_events_) {
833 current_target_.window_id, key_events[i], &key_success); 838 // The automation provider will generate up/down events for us, we
839 // only need to call it once as compared to the WebKeyEvent method.
840 // Hence we filter events by their types, keeping only rawkeydown.
841 if (key_events[i].type != automation::kRawKeyDownType)
842 continue;
843 automation_->SendNativeKeyEvent(
844 current_target_.window_id,
845 key_events[i].key_code,
846 key_events[i].modifiers,
847 &key_success);
848 } else {
849 automation_->SendWebKeyEvent(
850 current_target_.window_id, key_events[i], &key_success);
851 }
834 if (!key_success) { 852 if (!key_success) {
835 LOG(ERROR) << "Failed to send key event. Event details:\n" 853 LOG(ERROR) << "Failed to send key event. Event details:\n"
836 << "Type: " << key_events[i].type << "\n" 854 << "Type: " << key_events[i].type << "\n"
837 << "KeyCode: " << key_events[i].key_code << "\n" 855 << "KeyCode: " << key_events[i].key_code << "\n"
838 << "UnmodifiedText: " << key_events[i].unmodified_text << "\n" 856 << "UnmodifiedText: " << key_events[i].unmodified_text << "\n"
839 << "ModifiedText: " << key_events[i].modified_text << "\n" 857 << "ModifiedText: " << key_events[i].modified_text << "\n"
840 << "Modifiers: " << key_events[i].modifiers << "\n"; 858 << "Modifiers: " << key_events[i].modifiers << "\n";
841 *success = false; 859 *success = false;
842 } 860 }
843 } 861 }
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
1029 1047
1030 Session::Speed Session::speed() const { 1048 Session::Speed Session::speed() const {
1031 return speed_; 1049 return speed_;
1032 } 1050 }
1033 1051
1034 void Session::set_speed(Speed speed) { 1052 void Session::set_speed(Speed speed) {
1035 speed_ = speed; 1053 speed_ = speed;
1036 } 1054 }
1037 1055
1038 } // namespace webdriver 1056 } // namespace webdriver
OLDNEW
« 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