|
| 1 | +#include "touch_commands.h" |
| 2 | +#include "chrome/test/webdriver/commands/response.h" |
| 3 | +#include "chrome/test/webdriver/webdriver_session.h" |
| 4 | + |
| 5 | +namespace webdriver { |
| 6 | + |
| 7 | + |
| 8 | +TouchCommand::TouchCommand( |
| 9 | + const std::vector<std::string>& path_segments, |
| 10 | + const DictionaryValue* const parameters) |
| 11 | + : WebDriverCommand(path_segments, parameters) {} |
| 12 | + |
| 13 | +TouchCommand::~TouchCommand() {} |
| 14 | + |
| 15 | +bool TouchCommand::DoesPost() { |
| 16 | + return true; |
| 17 | +} |
| 18 | + |
| 19 | +TouchClickCommand::TouchClickCommand(const std::vector<std::string>& path_segments, |
| 20 | + const DictionaryValue* const parameters) |
| 21 | + : TouchCommand(path_segments, parameters) { |
| 22 | +} |
| 23 | + |
| 24 | +TouchClickCommand::~TouchClickCommand() {} |
| 25 | + |
| 26 | +bool TouchClickCommand::Init(Response* const response) { |
| 27 | + if (!TouchCommand::Init(response)) |
| 28 | + return false; |
| 29 | + |
| 30 | + std::string element_name; |
| 31 | + has_element_ = GetStringParameter("element", &element_name); |
| 32 | + |
| 33 | + if (has_element_) { |
| 34 | + element_ = ElementId(element_name); |
| 35 | + } |
| 36 | + |
| 37 | + if (!has_element_ ) { |
| 38 | + response->SetError(new Error( |
| 39 | + kBadRequest, "Invalid command arguments")); |
| 40 | + } |
| 41 | + |
| 42 | + return true; |
| 43 | +} |
| 44 | + |
| 45 | +void TouchClickCommand::ExecutePost(Response* const response) { |
| 46 | + Point location; |
| 47 | + Error* error; |
| 48 | + printf("Execute Touch Click Comman post\n"); |
| 49 | + |
| 50 | + error = session_->GetElementLocationInView(element_, &location); |
| 51 | + if (error) { |
| 52 | + response->SetError(error); |
| 53 | + return; |
| 54 | + } |
| 55 | + |
| 56 | + error = session_->TouchClick(location); |
| 57 | + if (error) { |
| 58 | + response->SetError(error); |
| 59 | + return; |
| 60 | + } |
| 61 | +} |
| 62 | + |
| 63 | +TouchDoubleClickCommand::TouchDoubleClickCommand(const std::vector<std::string>& path_segments, |
| 64 | + const DictionaryValue* const parameters) |
| 65 | + : TouchCommand(path_segments, parameters) { |
| 66 | +} |
| 67 | + |
| 68 | +TouchDoubleClickCommand::~TouchDoubleClickCommand() {} |
| 69 | + |
| 70 | +bool TouchDoubleClickCommand::Init(Response* const response) { |
| 71 | + if (!TouchCommand::Init(response)) |
| 72 | + return false; |
| 73 | + |
| 74 | + std::string element_name; |
| 75 | + has_element_ = GetStringParameter("element", &element_name); |
| 76 | + |
| 77 | + if (has_element_) { |
| 78 | + element_ = ElementId(element_name); |
| 79 | + } |
| 80 | + |
| 81 | + if (!has_element_ ) { |
| 82 | + response->SetError(new Error( |
| 83 | + kBadRequest, "Invalid command arguments")); |
| 84 | + } |
| 85 | + |
| 86 | + return true; |
| 87 | +} |
| 88 | + |
| 89 | +void TouchDoubleClickCommand::ExecutePost(Response *const response) |
| 90 | +{ |
| 91 | + Point location; |
| 92 | + Error* error; |
| 93 | + printf("Execute Touch Double Click Comman post\n"); |
| 94 | + |
| 95 | + error = session_->GetElementLocationInView(element_, &location); |
| 96 | + if (error) { |
| 97 | + response->SetError(error); |
| 98 | + return; |
| 99 | + } |
| 100 | + |
| 101 | + error = session_->TouchDoubleClick(location); |
| 102 | + if (error) { |
| 103 | + response->SetError(error); |
| 104 | + return; |
| 105 | + } |
| 106 | +} |
| 107 | + |
| 108 | +TouchDownCommand::TouchDownCommand(const std::vector<std::string>& path_segments, |
| 109 | + const DictionaryValue* const parameters) |
| 110 | + : TouchCommand(path_segments, parameters) { |
| 111 | +} |
| 112 | + |
| 113 | +TouchDownCommand::~TouchDownCommand() {} |
| 114 | + |
| 115 | +void TouchDownCommand::ExecutePost(Response *const response) |
| 116 | +{ |
| 117 | + Error* error; |
| 118 | + printf("Execute Touch Down Comman post\n"); |
| 119 | + |
| 120 | + int x, y; |
| 121 | + if (!GetIntegerParameter("x", &x) || |
| 122 | + !GetIntegerParameter("y", &y)) { |
| 123 | + response->SetError(new Error( |
| 124 | + kBadRequest, |
| 125 | + "Missing or invalid 'x' or 'y' parameters")); |
| 126 | + return; |
| 127 | + } |
| 128 | + |
| 129 | + Point location(x, y); |
| 130 | + |
| 131 | + |
| 132 | + error = session_->TouchDown(location); |
| 133 | + if (error) { |
| 134 | + response->SetError(error); |
| 135 | + return; |
| 136 | + } |
| 137 | +} |
| 138 | + |
| 139 | +TouchUpCommand::TouchUpCommand(const std::vector<std::string>& path_segments, |
| 140 | + const DictionaryValue* const parameters) |
| 141 | + : TouchCommand(path_segments, parameters) { |
| 142 | +} |
| 143 | + |
| 144 | +TouchUpCommand::~TouchUpCommand() {} |
| 145 | + |
| 146 | +void TouchUpCommand::ExecutePost(Response *const response) |
| 147 | +{ |
| 148 | + Error* error; |
| 149 | + printf("Execute Touch Up Comman post\n"); |
| 150 | + |
| 151 | + int x, y; |
| 152 | + if (!GetIntegerParameter("x", &x) || |
| 153 | + !GetIntegerParameter("y", &y)) { |
| 154 | + response->SetError(new Error( |
| 155 | + kBadRequest, |
| 156 | + "Missing or invalid 'x' or 'y' parameters")); |
| 157 | + return; |
| 158 | + } |
| 159 | + |
| 160 | + Point location(x, y); |
| 161 | + |
| 162 | + |
| 163 | + error = session_->TouchUp(location); |
| 164 | + if (error) { |
| 165 | + response->SetError(error); |
| 166 | + return; |
| 167 | + } |
| 168 | +} |
| 169 | + |
| 170 | +TouchMoveCommand::TouchMoveCommand(const std::vector<std::string>& path_segments, |
| 171 | + const DictionaryValue* const parameters) |
| 172 | + : TouchCommand(path_segments, parameters) { |
| 173 | +} |
| 174 | + |
| 175 | +TouchMoveCommand::~TouchMoveCommand() {} |
| 176 | + |
| 177 | +void TouchMoveCommand::ExecutePost(Response *const response) |
| 178 | +{ |
| 179 | + Error* error; |
| 180 | + printf("Execute Touch Move Comman post\n"); |
| 181 | + |
| 182 | + int x, y; |
| 183 | + if (!GetIntegerParameter("x", &x) || |
| 184 | + !GetIntegerParameter("y", &y)) { |
| 185 | + response->SetError(new Error( |
| 186 | + kBadRequest, |
| 187 | + "Missing or invalid 'x' or 'y' parameters")); |
| 188 | + return; |
| 189 | + } |
| 190 | + |
| 191 | + Point location(x, y); |
| 192 | + |
| 193 | + |
| 194 | + error = session_->TouchDown(location); |
| 195 | + if (error) { |
| 196 | + response->SetError(error); |
| 197 | + return; |
| 198 | + } |
| 199 | +} |
| 200 | + |
| 201 | +TouchScrollCommand::TouchScrollCommand(const std::vector<std::string>& path_segments, |
| 202 | + const DictionaryValue* const parameters) |
| 203 | + : TouchCommand(path_segments, parameters) { |
| 204 | +} |
| 205 | + |
| 206 | +TouchScrollCommand::~TouchScrollCommand() {} |
| 207 | + |
| 208 | +void TouchScrollCommand::ExecutePost(Response *const response) |
| 209 | +{ |
| 210 | + Error* error; |
| 211 | + printf("Execute Touch Scroll Comman post\n"); |
| 212 | + |
| 213 | +} |
| 214 | + |
| 215 | +TouchLongClickCommand::TouchLongClickCommand(const std::vector<std::string>& path_segments, |
| 216 | + const DictionaryValue* const parameters) |
| 217 | + : TouchCommand(path_segments, parameters) { |
| 218 | +} |
| 219 | + |
| 220 | +TouchLongClickCommand::~TouchLongClickCommand() {} |
| 221 | + |
| 222 | +void TouchLongClickCommand::ExecutePost(Response *const response) |
| 223 | +{ |
| 224 | + Error* error; |
| 225 | + printf("Execute Touch LongClick post\n"); |
| 226 | + |
| 227 | +} |
| 228 | + |
| 229 | +TouchFlickCommand::TouchFlickCommand(const std::vector<std::string>& path_segments, |
| 230 | + const DictionaryValue* const parameters) |
| 231 | + : TouchCommand(path_segments, parameters) { |
| 232 | +} |
| 233 | + |
| 234 | +TouchFlickCommand::~TouchFlickCommand() {} |
| 235 | + |
| 236 | +void TouchFlickCommand::ExecutePost(Response *const response) |
| 237 | +{ |
| 238 | + Error* error; |
| 239 | + printf("Execute Touch Flick post\n"); |
| 240 | + |
| 241 | +} |
| 242 | + |
| 243 | + |
| 244 | +} |
| 245 | + |
0 commit comments