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/utility_functions.h" |
11 #include "chrome/test/webdriver/web_element_id.h" | 12 #include "chrome/test/webdriver/web_element_id.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/point.h" |
14 #include "ui/gfx/size.h" | 15 #include "ui/gfx/size.h" |
15 | 16 |
16 namespace { | 17 namespace { |
17 | 18 |
18 const int kLeftButton = 0; | 19 const int kLeftButton = 0; |
19 const int kMiddleButton = 1; | 20 const int kMiddleButton = 1; |
20 const int kRightButton = 2; | 21 const int kRightButton = 2; |
(...skipping 16 matching lines...) Expand all Loading... |
37 void MoveAndClickCommand::ExecutePost(Response* response) { | 38 void MoveAndClickCommand::ExecutePost(Response* response) { |
38 std::string tag_name; | 39 std::string tag_name; |
39 Error* error = session_->GetElementTagName( | 40 Error* error = session_->GetElementTagName( |
40 session_->current_target(), element, &tag_name); | 41 session_->current_target(), element, &tag_name); |
41 if (error) { | 42 if (error) { |
42 response->SetError(error); | 43 response->SetError(error); |
43 return; | 44 return; |
44 } | 45 } |
45 | 46 |
46 if (tag_name == "option") { | 47 if (tag_name == "option") { |
47 error = session_->SelectOptionElement(session_->current_target(), element); | 48 const char* kCanOptionBeToggledScript = |
| 49 "return (function(option) {" |
| 50 " var select = option.parentElement;" |
| 51 " if (!select || select.tagName.toLowerCase() != 'select')" |
| 52 " throw new Error('Option element is not in a select');" |
| 53 " return select.multiple;" |
| 54 "}).apply(null, arguments);"; |
| 55 ListValue args; |
| 56 args.Append(element.ToValue()); |
| 57 Value* value = NULL; |
| 58 error = session_->ExecuteScript( |
| 59 session_->current_target(), kCanOptionBeToggledScript, &args, &value); |
| 60 if (error) { |
| 61 response->SetError(error); |
| 62 return; |
| 63 } |
| 64 scoped_ptr<Value> scoped_value(value); |
| 65 bool can_be_toggled; |
| 66 if (!value->GetAsBoolean(&can_be_toggled)) { |
| 67 response->SetError( |
| 68 new Error(kUnknownError, "canOptionBeToggled returned non-boolean: " + |
| 69 JsonStringify(value))); |
| 70 return; |
| 71 } |
| 72 |
| 73 if (can_be_toggled) { |
| 74 error = session_->ToggleOptionElement( |
| 75 session_->current_target(), element); |
| 76 } else { |
| 77 error = session_->SetOptionElementSelected( |
| 78 session_->current_target(), element, true); |
| 79 } |
48 } else { | 80 } else { |
49 gfx::Point location; | 81 gfx::Point location; |
50 error = session_->GetClickableLocation(element, &location); | 82 error = session_->GetClickableLocation(element, &location); |
51 if (!error) | 83 if (!error) |
52 error = session_->MouseMoveAndClick(location, automation::kLeftButton); | 84 error = session_->MouseMoveAndClick(location, automation::kLeftButton); |
53 } | 85 } |
54 if (error) { | 86 if (error) { |
55 response->SetError(error); | 87 response->SetError(error); |
56 return; | 88 return; |
57 } | 89 } |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 | 308 |
277 void DoubleClickCommand::ExecutePost(Response* const response) { | 309 void DoubleClickCommand::ExecutePost(Response* const response) { |
278 Error* error = session_->MouseDoubleClick(); | 310 Error* error = session_->MouseDoubleClick(); |
279 if (error) { | 311 if (error) { |
280 response->SetError(error); | 312 response->SetError(error); |
281 return; | 313 return; |
282 } | 314 } |
283 } | 315 } |
284 | 316 |
285 } // namespace webdriver | 317 } // namespace webdriver |
OLD | NEW |