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

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, 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 unified diff | Download patch | Annotate | Revision Log
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_manager.h" 5 #include "chrome/test/webdriver/session_manager.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 29 matching lines...) Expand all
40 #include "third_party/webdriver/atoms.h" 40 #include "third_party/webdriver/atoms.h"
41 #include "ui/gfx/point.h" 41 #include "ui/gfx/point.h"
42 42
43 namespace webdriver { 43 namespace webdriver {
44 44
45 Session::Session() 45 Session::Session()
46 : id_(GenerateRandomID()), 46 : id_(GenerateRandomID()),
47 thread_(id_.c_str()), 47 thread_(id_.c_str()),
48 implicit_wait_(0), 48 implicit_wait_(0),
49 current_frame_xpath_(""), 49 current_frame_xpath_(""),
50 current_window_id_(0) { 50 current_window_id_(0),
51 use_native_events_(false) {
51 SessionManager::GetInstance()->Add(this); 52 SessionManager::GetInstance()->Add(this);
52 } 53 }
53 54
54 Session::~Session() { 55 Session::~Session() {
55 SessionManager::GetInstance()->Remove(id_); 56 SessionManager::GetInstance()->Remove(id_);
56 } 57 }
57 58
58 bool Session::Init(const FilePath& browser_dir) { 59 bool Session::Init(const FilePath& browser_dir) {
59 bool success = false; 60 bool success = false;
60 if (thread_.Start()) { 61 if (thread_.Start()) {
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 } 157 }
157 158
158 ErrorCode Session::ExecuteScript(const std::string& script, 159 ErrorCode Session::ExecuteScript(const std::string& script,
159 const ListValue* const args, 160 const ListValue* const args,
160 Value** value) { 161 Value** value) {
161 return ExecuteScript( 162 return ExecuteScript(
162 current_window_id_, current_frame_xpath_, script, args, value); 163 current_window_id_, current_frame_xpath_, script, args, value);
163 } 164 }
164 165
165 ErrorCode Session::SendKeys(const WebElementId& element, const string16& keys) { 166 ErrorCode Session::SendKeys(const WebElementId& element, const string16& keys) {
167 // This method will first check if the element we want to send the keys to is
168 // already focused, if not it will try to focus on it first.
166 ListValue args; 169 ListValue args;
167 args.Append(element.ToValue()); 170 args.Append(element.ToValue());
168 // TODO(jleyba): Update this to use the correct atom. 171 // TODO(jleyba): Update this to use the correct atom.
169 std::string script = "document.activeElement.blur();arguments[0].focus();"; 172 std::string script = "if(document.activeElement!=arguments[0]){"
173 " if(document.activeElement)"
174 " document.activeElement.blur();"
175 " arguments[0].focus();"
176 "}";
170 Value* unscoped_result = NULL; 177 Value* unscoped_result = NULL;
171 ErrorCode code = ExecuteScript(script, &args, &unscoped_result); 178 ErrorCode code = ExecuteScript(script, &args, &unscoped_result);
172 scoped_ptr<Value> result(unscoped_result);
173 if (code != kSuccess) { 179 if (code != kSuccess) {
174 LOG(ERROR) << "Failed to focus element before sending keys"; 180 LOG(ERROR) << "Failed to get or set focus element before sending keys";
175 return code; 181 return code;
176 } 182 }
177
178 bool success = false; 183 bool success = false;
179 RunSessionTask(NewRunnableMethod( 184 RunSessionTask(NewRunnableMethod(
180 this, 185 this,
181 &Session::SendKeysOnSessionThread, 186 &Session::SendKeysOnSessionThread,
182 keys, 187 keys,
183 &success)); 188 &success));
184 if (!success) 189 if (!success)
185 return kUnknownError; 190 return kUnknownError;
186 return kSuccess; 191 return kSuccess;
187 } 192 }
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after
615 automation_.reset(); 620 automation_.reset();
616 } 621 }
617 622
618 void Session::SendKeysOnSessionThread(const string16& keys, 623 void Session::SendKeysOnSessionThread(const string16& keys,
619 bool* success) { 624 bool* success) {
620 *success = true; 625 *success = true;
621 std::vector<WebKeyEvent> key_events; 626 std::vector<WebKeyEvent> key_events;
622 ConvertKeysToWebKeyEvents(keys, &key_events); 627 ConvertKeysToWebKeyEvents(keys, &key_events);
623 for (size_t i = 0; i < key_events.size(); ++i) { 628 for (size_t i = 0; i < key_events.size(); ++i) {
624 bool key_success = false; 629 bool key_success = false;
625 automation_->SendWebKeyEvent( 630 if (use_native_events_) {
626 current_window_id_, key_events[i], &key_success); 631 // 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.
632 // only need to call it once as compared to the WebKeyEvent method.
633 // Hence we filter events by their types, keeping only rawkeydown.
634 if (key_events[i].type != automation::kRawKeyDownType)
635 continue;
636 automation_->SendNativeKeyEvent(
637 current_window_id_,
638 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.
639 key_events[i].modifiers,
640 &key_success);
641 } else {
642 automation_->SendWebKeyEvent(
643 current_window_id_, key_events[i], &key_success);
644 }
627 if (!key_success) { 645 if (!key_success) {
628 LOG(ERROR) << "Failed to send key event. Event details:\n" 646 LOG(ERROR) << "Failed to send key event. Event details:\n"
629 << "Type: " << key_events[i].type << "\n" 647 << "Type: " << key_events[i].type << "\n"
630 << "KeyCode: " << key_events[i].key_code << "\n" 648 << "KeyCode: " << key_events[i].key_code << "\n"
631 << "UnmodifiedText: " << key_events[i].unmodified_text << "\n" 649 << "UnmodifiedText: " << key_events[i].unmodified_text << "\n"
632 << "ModifiedText: " << key_events[i].modified_text << "\n" 650 << "ModifiedText: " << key_events[i].modified_text << "\n"
633 << "Modifiers: " << key_events[i].modifiers << "\n"; 651 << "Modifiers: " << key_events[i].modifiers << "\n"
634 *success = false; 652 << "Was a native event: " << use_native_events_ << "\n";
653 *success = false;
kkania 2011/03/11 16:32:13 indentation
timothe 2011/03/21 18:02:05 Done.
635 } 654 }
636 } 655 }
637 } 656 }
638 657
639 ErrorCode Session::SwitchToFrameWithJavaScriptLocatedFrame( 658 ErrorCode Session::SwitchToFrameWithJavaScriptLocatedFrame(
640 const std::string& script, 659 const std::string& script,
641 ListValue* args) { 660 ListValue* args) {
642 Value* unscoped_result = NULL; 661 Value* unscoped_result = NULL;
643 ErrorCode code = ExecuteScript(script, args, &unscoped_result); 662 ErrorCode code = ExecuteScript(script, args, &unscoped_result);
644 scoped_ptr<Value> result(unscoped_result); 663 scoped_ptr<Value> result(unscoped_result);
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
772 } 791 }
773 } else { 792 } else {
774 LOG(ERROR) << "Location atom returned non-dictionary type"; 793 LOG(ERROR) << "Location atom returned non-dictionary type";
775 code = kUnknownError; 794 code = kUnknownError;
776 } 795 }
777 } 796 }
778 return code; 797 return code;
779 } 798 }
780 799
781 } // namespace webdriver 800 } // namespace webdriver
OLDNEW
« chrome/test/webdriver/chromedriver_tests.py ('K') | « chrome/test/webdriver/session.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698