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

Side by Side Diff: chrome/test/webdriver/session.cc

Issue 6694007: Small test and ChromeDriver fixes to enable additional tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase 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 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 return static_cast<ErrorCode>(status); 166 return static_cast<ErrorCode>(status);
167 } 167 }
168 168
169 ErrorCode Session::ExecuteScript(const std::string& script, 169 ErrorCode Session::ExecuteScript(const std::string& script,
170 const ListValue* const args, 170 const ListValue* const args,
171 Value** value) { 171 Value** value) {
172 return ExecuteScript(current_target_, script, args, value); 172 return ExecuteScript(current_target_, script, args, value);
173 } 173 }
174 174
175 ErrorCode Session::SendKeys(const WebElementId& element, const string16& keys) { 175 ErrorCode Session::SendKeys(const WebElementId& element, const string16& keys) {
176 bool is_displayed;
177 ErrorCode code = IsElementDisplayed(current_target_, element, &is_displayed);
dennis_jeffrey 2011/03/23 16:57:02 It looks like we're assuming that the IsElementDis
kkania 2011/03/26 01:58:32 Done.
178 if (code != kSuccess)
179 return code;
180 if (!is_displayed)
181 return kElementNotVisible;
182
176 ListValue args; 183 ListValue args;
177 args.Append(element.ToValue()); 184 args.Append(element.ToValue());
178 // TODO(jleyba): Update this to use the correct atom. 185 // TODO(jleyba): Update this to use the correct atom.
179 std::string script = "document.activeElement.blur();arguments[0].focus();"; 186 std::string script = "document.activeElement.blur();arguments[0].focus();";
180 Value* unscoped_result = NULL; 187 Value* unscoped_result = NULL;
181 ErrorCode code = ExecuteScript(script, &args, &unscoped_result); 188 code = ExecuteScript(script, &args, &unscoped_result);
182 scoped_ptr<Value> result(unscoped_result); 189 scoped_ptr<Value> result(unscoped_result);
183 if (code != kSuccess) { 190 if (code != kSuccess) {
184 LOG(ERROR) << "Failed to focus element before sending keys"; 191 LOG(ERROR) << "Failed to focus element before sending keys";
185 return code; 192 return code;
186 } 193 }
187 194
188 bool success = false; 195 bool success = false;
189 RunSessionTask(NewRunnableMethod( 196 RunSessionTask(NewRunnableMethod(
190 this, 197 this,
191 &Session::SendKeysOnSessionThread, 198 &Session::SendKeysOnSessionThread,
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 bool success = false; 278 bool success = false;
272 RunSessionTask(NewRunnableMethod( 279 RunSessionTask(NewRunnableMethod(
273 automation_.get(), 280 automation_.get(),
274 &Automation::GetTabTitle, 281 &Automation::GetTabTitle,
275 current_target_.window_id, 282 current_target_.window_id,
276 tab_title, 283 tab_title,
277 &success)); 284 &success));
278 return success; 285 return success;
279 } 286 }
280 287
281 void Session::MouseClick(const gfx::Point& click, 288 bool Session::MouseClick(const gfx::Point& click,
282 automation::MouseButton button) { 289 automation::MouseButton button) {
283 bool success = false; 290 bool success = false;
284 RunSessionTask(NewRunnableMethod( 291 RunSessionTask(NewRunnableMethod(
285 automation_.get(), 292 automation_.get(),
286 &Automation::MouseClick, 293 &Automation::MouseClick,
287 current_target_.window_id, 294 current_target_.window_id,
288 click, 295 click,
289 button, 296 button,
290 &success)); 297 &success));
298 return success;
291 } 299 }
292 300
293 bool Session::MouseMove(const gfx::Point& location) { 301 bool Session::MouseMove(const gfx::Point& location) {
294 bool success = false; 302 bool success = false;
295 RunSessionTask(NewRunnableMethod( 303 RunSessionTask(NewRunnableMethod(
296 automation_.get(), 304 automation_.get(),
297 &Automation::MouseMove, 305 &Automation::MouseMove,
298 current_target_.window_id, 306 current_target_.window_id,
299 location, 307 location,
300 &success)); 308 &success));
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 ErrorCode code_top = GetElementEffectiveStyle( 650 ErrorCode code_top = GetElementEffectiveStyle(
643 frame_id, element, "border-top-width", &border_top_str); 651 frame_id, element, "border-top-width", &border_top_str);
644 if (code_left != kSuccess || code_top != kSuccess) 652 if (code_left != kSuccess || code_top != kSuccess)
645 return code_left; 653 return code_left;
646 654
647 base::StringToInt(border_left_str, border_left); 655 base::StringToInt(border_left_str, border_left);
648 base::StringToInt(border_top_str, border_top); 656 base::StringToInt(border_top_str, border_top);
649 return kSuccess; 657 return kSuccess;
650 } 658 }
651 659
660 ErrorCode Session::IsElementDisplayed(const FrameId& frame_id,
661 const WebElementId& element,
662 bool* is_displayed) {
663 std::string script = base::StringPrintf(
664 "return (%s).apply(null, arguments);", atoms::IS_DISPLAYED);
665 ListValue args;
666 args.Append(element.ToValue());
667
668 Value* unscoped_result = NULL;
669 ErrorCode code = ExecuteScript(frame_id, script, &args, &unscoped_result);
670 scoped_ptr<Value> result(unscoped_result);
671 if (code != kSuccess)
672 return code;
673 if (!result->GetAsBoolean(is_displayed)) {
674 LOG(ERROR) << "IsDisplayed atom returned non boolean";
675 return kUnknownError;
676 }
677 return kSuccess;
678 }
679
652 bool Session::WaitForAllTabsToStopLoading() { 680 bool Session::WaitForAllTabsToStopLoading() {
653 if (!automation_.get()) 681 if (!automation_.get())
654 return true; 682 return true;
655 bool success = false; 683 bool success = false;
656 RunSessionTask(NewRunnableMethod( 684 RunSessionTask(NewRunnableMethod(
657 automation_.get(), 685 automation_.get(),
658 &Automation::WaitForAllTabsToStopLoading, 686 &Automation::WaitForAllTabsToStopLoading,
659 &success)); 687 &success));
660 return success; 688 return success;
661 } 689 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
700 current_target_ = FrameId(tab_ids[0], FramePath()); 728 current_target_ = FrameId(tab_ids[0], FramePath());
701 } 729 }
702 } 730 }
703 731
704 void Session::TerminateOnSessionThread() { 732 void Session::TerminateOnSessionThread() {
705 if (automation_.get()) 733 if (automation_.get())
706 automation_->Terminate(); 734 automation_->Terminate();
707 automation_.reset(); 735 automation_.reset();
708 } 736 }
709 737
710 void Session::SendKeysOnSessionThread(const string16& keys, 738 void Session::SendKeysOnSessionThread(const string16& keys, bool* success) {
711 bool* success) {
712 *success = true; 739 *success = true;
713 std::vector<WebKeyEvent> key_events; 740 std::vector<WebKeyEvent> key_events;
714 ConvertKeysToWebKeyEvents(keys, &key_events); 741 std::string error_msg;
742 if (!ConvertKeysToWebKeyEvents(keys, &key_events, &error_msg)) {
743 // TODO(kkania): Return this message to the user.
744 LOG(ERROR) << error_msg;
745 *success = false;
746 return;
747 }
715 for (size_t i = 0; i < key_events.size(); ++i) { 748 for (size_t i = 0; i < key_events.size(); ++i) {
716 bool key_success = false; 749 bool key_success = false;
717 automation_->SendWebKeyEvent( 750 automation_->SendWebKeyEvent(
718 current_target_.window_id, key_events[i], &key_success); 751 current_target_.window_id, key_events[i], &key_success);
719 if (!key_success) { 752 if (!key_success) {
720 LOG(ERROR) << "Failed to send key event. Event details:\n" 753 LOG(ERROR) << "Failed to send key event. Event details:\n"
721 << "Type: " << key_events[i].type << "\n" 754 << "Type: " << key_events[i].type << "\n"
722 << "KeyCode: " << key_events[i].key_code << "\n" 755 << "KeyCode: " << key_events[i].key_code << "\n"
723 << "UnmodifiedText: " << key_events[i].unmodified_text << "\n" 756 << "UnmodifiedText: " << key_events[i].unmodified_text << "\n"
724 << "ModifiedText: " << key_events[i].modified_text << "\n" 757 << "ModifiedText: " << key_events[i].modified_text << "\n"
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
862 if (!loc_dict->GetInteger("x", &x) || 895 if (!loc_dict->GetInteger("x", &x) ||
863 !loc_dict->GetInteger("y", &y)) { 896 !loc_dict->GetInteger("y", &y)) {
864 LOG(ERROR) << "Location atom returned bad coordinate dictionary"; 897 LOG(ERROR) << "Location atom returned bad coordinate dictionary";
865 code = kUnknownError; 898 code = kUnknownError;
866 } 899 }
867 *location = gfx::Point(x, y); 900 *location = gfx::Point(x, y);
868 return kSuccess; 901 return kSuccess;
869 } 902 }
870 903
871 } // namespace webdriver 904 } // namespace webdriver
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698