| OLD | NEW |
| 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/session.h" | 10 #include "chrome/test/webdriver/session.h" |
| 11 #include "chrome/test/webdriver/web_element_id.h" | 11 #include "chrome/test/webdriver/web_element_id.h" |
| 12 #include "chrome/test/webdriver/webdriver_basic_types.h" |
| 12 #include "chrome/test/webdriver/webdriver_error.h" | 13 #include "chrome/test/webdriver/webdriver_error.h" |
| 13 #include "ui/gfx/point.h" | |
| 14 #include "ui/gfx/size.h" | |
| 15 | 14 |
| 16 namespace { | 15 namespace { |
| 17 | 16 |
| 18 const int kLeftButton = 0; | 17 const int kLeftButton = 0; |
| 19 const int kMiddleButton = 1; | 18 const int kMiddleButton = 1; |
| 20 const int kRightButton = 2; | 19 const int kRightButton = 2; |
| 21 | 20 |
| 22 } // namespace | 21 } // namespace |
| 23 | 22 |
| 24 namespace webdriver { | 23 namespace webdriver { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 39 Error* error = session_->GetElementTagName( | 38 Error* error = session_->GetElementTagName( |
| 40 session_->current_target(), element, &tag_name); | 39 session_->current_target(), element, &tag_name); |
| 41 if (error) { | 40 if (error) { |
| 42 response->SetError(error); | 41 response->SetError(error); |
| 43 return; | 42 return; |
| 44 } | 43 } |
| 45 | 44 |
| 46 if (tag_name == "option") { | 45 if (tag_name == "option") { |
| 47 error = session_->SelectOptionElement(session_->current_target(), element); | 46 error = session_->SelectOptionElement(session_->current_target(), element); |
| 48 } else { | 47 } else { |
| 49 gfx::Point location; | 48 Point location; |
| 50 error = session_->GetClickableLocation(element, &location); | 49 error = session_->GetClickableLocation(element, &location); |
| 51 if (!error) | 50 if (!error) |
| 52 error = session_->MouseMoveAndClick(location, automation::kLeftButton); | 51 error = session_->MouseMoveAndClick(location, automation::kLeftButton); |
| 53 } | 52 } |
| 54 if (error) { | 53 if (error) { |
| 55 response->SetError(error); | 54 response->SetError(error); |
| 56 return; | 55 return; |
| 57 } | 56 } |
| 58 } | 57 } |
| 59 | 58 |
| 60 HoverCommand::HoverCommand(const std::vector<std::string>& path_segments, | 59 HoverCommand::HoverCommand(const std::vector<std::string>& path_segments, |
| 61 const DictionaryValue* const parameters) | 60 const DictionaryValue* const parameters) |
| 62 : WebElementCommand(path_segments, parameters) {} | 61 : WebElementCommand(path_segments, parameters) {} |
| 63 | 62 |
| 64 HoverCommand::~HoverCommand() {} | 63 HoverCommand::~HoverCommand() {} |
| 65 | 64 |
| 66 bool HoverCommand::DoesPost() { | 65 bool HoverCommand::DoesPost() { |
| 67 return true; | 66 return true; |
| 68 } | 67 } |
| 69 | 68 |
| 70 void HoverCommand::ExecutePost(Response* response) { | 69 void HoverCommand::ExecutePost(Response* response) { |
| 71 Error* error = NULL; | 70 Error* error = NULL; |
| 72 gfx::Point location; | 71 Point location; |
| 73 error = session_->GetClickableLocation(element, &location); | 72 error = session_->GetClickableLocation(element, &location); |
| 74 if (!error) | 73 if (!error) |
| 75 error = session_->MouseMove(location); | 74 error = session_->MouseMove(location); |
| 76 if (error) { | 75 if (error) { |
| 77 response->SetError(error); | 76 response->SetError(error); |
| 78 return; | 77 return; |
| 79 } | 78 } |
| 80 } | 79 } |
| 81 | 80 |
| 82 DragCommand::DragCommand(const std::vector<std::string>& path_segments, | 81 DragCommand::DragCommand(const std::vector<std::string>& path_segments, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 97 | 96 |
| 98 return true; | 97 return true; |
| 99 } | 98 } |
| 100 | 99 |
| 101 bool DragCommand::DoesPost() { | 100 bool DragCommand::DoesPost() { |
| 102 return true; | 101 return true; |
| 103 } | 102 } |
| 104 | 103 |
| 105 void DragCommand::ExecutePost(Response* response) { | 104 void DragCommand::ExecutePost(Response* response) { |
| 106 Error* error = NULL; | 105 Error* error = NULL; |
| 107 gfx::Point drag_from; | 106 Point drag_from; |
| 108 error = session_->GetClickableLocation(element, &drag_from); | 107 error = session_->GetClickableLocation(element, &drag_from); |
| 109 if (error) { | 108 if (error) { |
| 110 response->SetError(error); | 109 response->SetError(error); |
| 111 return; | 110 return; |
| 112 } | 111 } |
| 113 | 112 |
| 114 gfx::Point drag_to(drag_from); | 113 Point drag_to(drag_from); |
| 115 drag_to.Offset(drag_x_, drag_y_); | 114 drag_to.Offset(drag_x_, drag_y_); |
| 116 if (drag_to.x() < 0 || drag_to.y() < 0) | 115 if (drag_to.x() < 0 || drag_to.y() < 0) |
| 117 error = new Error(kBadRequest, "Invalid (x,y) coordinates"); | 116 error = new Error(kBadRequest, "Invalid (x,y) coordinates"); |
| 118 if (!error) | 117 if (!error) |
| 119 error = session_->MouseDrag(drag_from, drag_to); | 118 error = session_->MouseDrag(drag_from, drag_to); |
| 120 | 119 |
| 121 if (error) { | 120 if (error) { |
| 122 response->SetError(error); | 121 response->SetError(error); |
| 123 return; | 122 return; |
| 124 } | 123 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 if (!has_element_ && !has_offset_) { | 159 if (!has_element_ && !has_offset_) { |
| 161 response->SetError(new Error( | 160 response->SetError(new Error( |
| 162 kBadRequest, "Invalid command arguments")); | 161 kBadRequest, "Invalid command arguments")); |
| 163 return false; | 162 return false; |
| 164 } | 163 } |
| 165 | 164 |
| 166 return true; | 165 return true; |
| 167 } | 166 } |
| 168 | 167 |
| 169 void MoveToCommand::ExecutePost(Response* const response) { | 168 void MoveToCommand::ExecutePost(Response* const response) { |
| 170 gfx::Point location; | 169 Point location; |
| 171 Error* error; | 170 Error* error; |
| 172 | 171 |
| 173 if (has_element_) { | 172 if (has_element_) { |
| 174 // If an element is specified, calculate the coordinate. | 173 // If an element is specified, calculate the coordinate. |
| 175 error = session_->GetElementLocationInView(element_, &location); | 174 error = session_->GetElementLocationInView(element_, &location); |
| 176 if (error) { | 175 if (error) { |
| 177 response->SetError(error); | 176 response->SetError(error); |
| 178 return; | 177 return; |
| 179 } | 178 } |
| 180 } else { | 179 } else { |
| 181 // If not, use the current mouse position. | 180 // If not, use the current mouse position. |
| 182 location = session_->get_mouse_position(); | 181 location = session_->get_mouse_position(); |
| 183 } | 182 } |
| 184 | 183 |
| 185 if (has_offset_) { | 184 if (has_offset_) { |
| 186 // If an offset is specified, translate by the offset. | 185 // If an offset is specified, translate by the offset. |
| 187 location.Offset(x_offset_, y_offset_); | 186 location.Offset(x_offset_, y_offset_); |
| 188 } else { | 187 } else { |
| 189 DCHECK(has_element_); | 188 DCHECK(has_element_); |
| 190 | 189 |
| 191 // If not, calculate the half of the element size and translate by it. | 190 // If not, calculate the half of the element size and translate by it. |
| 192 gfx::Size size; | 191 Size size; |
| 193 error = session_->GetElementSize(session_->current_target(), | 192 error = session_->GetElementSize(session_->current_target(), |
| 194 element_, &size); | 193 element_, &size); |
| 195 if (error) { | 194 if (error) { |
| 196 response->SetError(error); | 195 response->SetError(error); |
| 197 return; | 196 return; |
| 198 } | 197 } |
| 199 | 198 |
| 200 location.Offset(size.width() / 2, size.height() / 2); | 199 location.Offset(size.width() / 2, size.height() / 2); |
| 201 } | 200 } |
| 202 | 201 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 | 275 |
| 277 void DoubleClickCommand::ExecutePost(Response* const response) { | 276 void DoubleClickCommand::ExecutePost(Response* const response) { |
| 278 Error* error = session_->MouseDoubleClick(); | 277 Error* error = session_->MouseDoubleClick(); |
| 279 if (error) { | 278 if (error) { |
| 280 response->SetError(error); | 279 response->SetError(error); |
| 281 return; | 280 return; |
| 282 } | 281 } |
| 283 } | 282 } |
| 284 | 283 |
| 285 } // namespace webdriver | 284 } // namespace webdriver |
| OLD | NEW |