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

Side by Side Diff: chrome/test/webdriver/commands/mouse_commands.cc

Issue 6694007: Small test and ChromeDriver fixes to enable additional tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address Dennis' comments 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/commands/mouse_commands.h" 5 #include "chrome/test/webdriver/commands/mouse_commands.h"
6 6
7 #include "base/values.h" 7 #include "base/values.h"
8 #include "chrome/common/automation_constants.h" 8 #include "chrome/common/automation_constants.h"
9 #include "chrome/test/webdriver/commands/response.h" 9 #include "chrome/test/webdriver/commands/response.h"
10 #include "chrome/test/webdriver/error_codes.h" 10 #include "chrome/test/webdriver/error_codes.h"
11 #include "chrome/test/webdriver/session.h" 11 #include "chrome/test/webdriver/session.h"
12 #include "chrome/test/webdriver/web_element_id.h" 12 #include "chrome/test/webdriver/web_element_id.h"
13 #include "ui/gfx/point.h" 13 #include "ui/gfx/point.h"
14 #include "ui/gfx/size.h" 14 #include "ui/gfx/size.h"
15 15
16 namespace webdriver { 16 namespace webdriver {
17 17
18 MouseCommand::~MouseCommand() {} 18 MouseCommand::~MouseCommand() {}
19 19
20 bool MouseCommand::DoesPost() { 20 bool MouseCommand::DoesPost() {
21 return true; 21 return true;
22 } 22 }
23 23
24 void MouseCommand::ExecutePost(Response* response) { 24 void MouseCommand::ExecutePost(Response* response) {
25 // TODO(jmikhail): verify that the element is visible 25 bool is_displayed;
26 ErrorCode code = session_->IsElementDisplayed(
27 session_->current_target(), element, &is_displayed);
28 if (code != kSuccess) {
29 SET_WEBDRIVER_ERROR(response, "Failed to determine element visibility",
30 code);
31 return;
32 }
33 if (!is_displayed) {
34 SET_WEBDRIVER_ERROR(response, "Element must be displayed",
35 kElementNotVisible);
36 return;
37 }
38
26 gfx::Point location; 39 gfx::Point location;
27 ErrorCode code = session_->GetElementLocationInView(element, &location); 40 code = session_->GetElementLocationInView(element, &location);
28 if (code != kSuccess) { 41 if (code != kSuccess) {
29 SET_WEBDRIVER_ERROR(response, "Failed to compute element location.", 42 SET_WEBDRIVER_ERROR(response, "Failed to compute element location.",
30 code); 43 code);
31 return; 44 return;
32 } 45 }
33 46
34 gfx::Size size; 47 gfx::Size size;
35 code = session_->GetElementSize(session_->current_target(), element, &size); 48 code = session_->GetElementSize(session_->current_target(), element, &size);
36 if (code != kSuccess) { 49 if (code != kSuccess) {
37 SET_WEBDRIVER_ERROR(response, "Failed to compute element size.", code); 50 SET_WEBDRIVER_ERROR(response, "Failed to compute element size.", code);
38 return; 51 return;
39 } 52 }
40 53
41 location.Offset(size.width() / 2, size.height() / 2); 54 location.Offset(size.width() / 2, size.height() / 2);
55 bool success = false;
42 switch (cmd_) { 56 switch (cmd_) {
43 case kClick: 57 case kClick:
44 VLOG(1) << "Mouse click at: (" << location.x() << ", " 58 VLOG(1) << "Mouse click at: (" << location.x() << ", "
45 << location.y() << ")" << std::endl; 59 << location.y() << ")" << std::endl;
46 session_->MouseClick(location, automation::kLeftButton); 60 success = session_->MouseClick(location, automation::kLeftButton);
47 break; 61 break;
48 62
49 case kHover: 63 case kHover:
50 VLOG(1) << "Mouse hover at: (" << location.x() << ", " 64 VLOG(1) << "Mouse hover at: (" << location.x() << ", "
51 << location.y() << ")" << std::endl; 65 << location.y() << ")" << std::endl;
52 session_->MouseMove(location); 66 success = session_->MouseMove(location);
53 break; 67 break;
54 68
55 case kDrag: { 69 case kDrag: {
56 gfx::Point drag_to(location); 70 gfx::Point drag_to(location);
57 drag_to.Offset(drag_x_, drag_y_); 71 drag_to.Offset(drag_x_, drag_y_);
58 if (drag_to.x() < 0 || drag_to.y() < 0) { 72 if (drag_to.x() < 0 || drag_to.y() < 0) {
59 SET_WEBDRIVER_ERROR(response, "Invalid pos to drag to", kBadRequest); 73 SET_WEBDRIVER_ERROR(response, "Invalid pos to drag to", kBadRequest);
60 return; 74 return;
61 } 75 }
62 76
63 // click on the element 77 // click on the element
64 VLOG(1) << "Dragging mouse from: " 78 VLOG(1) << "Dragging mouse from: "
65 << "(" << location.x() << ", " << location.y() << ") " 79 << "(" << location.x() << ", " << location.y() << ") "
66 << "to: (" << drag_to.x() << ", " << drag_to.y() << ")" 80 << "to: (" << drag_to.x() << ", " << drag_to.y() << ")"
67 << std::endl; 81 << std::endl;
68 session_->MouseDrag(location, drag_to); 82 success = session_->MouseDrag(location, drag_to);
69 break; 83 break;
70 } 84 }
71 85
72 default: 86 default:
73 SET_WEBDRIVER_ERROR(response, "Unknown mouse request", kUnknownCommand); 87 SET_WEBDRIVER_ERROR(response, "Unknown mouse request", kUnknownCommand);
74 return; 88 return;
75 } 89 }
76 90
91 if (!success) {
92 SET_WEBDRIVER_ERROR(response, "Performing mouse operation failed",
93 kUnknownError);
94 return;
95 }
77 response->SetStatus(kSuccess); 96 response->SetStatus(kSuccess);
78 } 97 }
79 98
80 DragCommand::DragCommand(const std::vector<std::string>& path_segments, 99 DragCommand::DragCommand(const std::vector<std::string>& path_segments,
81 const DictionaryValue* const parameters) 100 const DictionaryValue* const parameters)
82 : MouseCommand(path_segments, parameters, kDrag) {} 101 : MouseCommand(path_segments, parameters, kDrag) {}
83 102
84 DragCommand::~DragCommand() {} 103 DragCommand::~DragCommand() {}
85 104
86 bool DragCommand::Init(Response* const response) { 105 bool DragCommand::Init(Response* const response) {
(...skipping 17 matching lines...) Expand all
104 123
105 ClickCommand::~ClickCommand() {} 124 ClickCommand::~ClickCommand() {}
106 125
107 HoverCommand::HoverCommand(const std::vector<std::string>& path_segments, 126 HoverCommand::HoverCommand(const std::vector<std::string>& path_segments,
108 const DictionaryValue* const parameters) 127 const DictionaryValue* const parameters)
109 : MouseCommand(path_segments, parameters, kHover) {} 128 : MouseCommand(path_segments, parameters, kHover) {}
110 129
111 HoverCommand::~HoverCommand() {} 130 HoverCommand::~HoverCommand() {}
112 131
113 } // namespace webdriver 132 } // namespace webdriver
OLDNEW
« no previous file with comments | « chrome/test/webdriver/WEBDRIVER_TESTS ('k') | chrome/test/webdriver/commands/webelement_commands.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698