| 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/target_locator_commands.h" | 5 #include "chrome/test/webdriver/commands/target_locator_commands.h" |
| 6 | 6 |
| 7 #include "base/string_number_conversions.h" | 7 #include "base/string_number_conversions.h" |
| 8 #include "base/values.h" | 8 #include "base/values.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 | 13 |
| 13 namespace webdriver { | 14 namespace webdriver { |
| 14 | 15 |
| 15 WindowHandleCommand::WindowHandleCommand( | 16 WindowHandleCommand::WindowHandleCommand( |
| 16 const std::vector<std::string>& path_segments, | 17 const std::vector<std::string>& path_segments, |
| 17 DictionaryValue* parameters) | 18 DictionaryValue* parameters) |
| 18 : WebDriverCommand(path_segments, parameters) {} | 19 : WebDriverCommand(path_segments, parameters) {} |
| 19 | 20 |
| 20 WindowHandleCommand::~WindowHandleCommand() {} | 21 WindowHandleCommand::~WindowHandleCommand() {} |
| 21 | 22 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 | 102 |
| 102 SwitchFrameCommand::~SwitchFrameCommand() {} | 103 SwitchFrameCommand::~SwitchFrameCommand() {} |
| 103 | 104 |
| 104 bool SwitchFrameCommand::DoesPost() { | 105 bool SwitchFrameCommand::DoesPost() { |
| 105 return true; | 106 return true; |
| 106 } | 107 } |
| 107 | 108 |
| 108 void SwitchFrameCommand::ExecutePost(Response* const response) { | 109 void SwitchFrameCommand::ExecutePost(Response* const response) { |
| 109 std::string id; | 110 std::string id; |
| 110 int index = 0; | 111 int index = 0; |
| 112 WebElementId element; |
| 111 if (GetStringParameter("id", &id)) { | 113 if (GetStringParameter("id", &id)) { |
| 112 ErrorCode code = session_->SwitchToFrameWithNameOrId(id); | 114 ErrorCode code = session_->SwitchToFrameWithNameOrId(id); |
| 113 if (code != kSuccess) { | 115 if (code != kSuccess) { |
| 114 SET_WEBDRIVER_ERROR(response, "Could not switch to frame", code); | 116 SET_WEBDRIVER_ERROR(response, "Could not switch to frame", code); |
| 115 return; | 117 return; |
| 116 } | 118 } |
| 117 } else if (GetIntegerParameter("id", &index)) { | 119 } else if (GetIntegerParameter("id", &index)) { |
| 118 ErrorCode code = session_->SwitchToFrameWithIndex(index); | 120 ErrorCode code = session_->SwitchToFrameWithIndex(index); |
| 119 if (code != kSuccess) { | 121 if (code != kSuccess) { |
| 120 SET_WEBDRIVER_ERROR(response, "Could not switch to frame", code); | 122 SET_WEBDRIVER_ERROR(response, "Could not switch to frame", code); |
| 121 return; | 123 return; |
| 122 } | 124 } |
| 125 } else if (GetWebElementParameter("id", &element)) { |
| 126 ErrorCode code = session_->SwitchToFrameWithElement(element); |
| 127 if (code != kSuccess) { |
| 128 SET_WEBDRIVER_ERROR(response, "Could not switch to frame", code); |
| 129 return; |
| 130 } |
| 123 } else if (IsNullParameter("id")) { | 131 } else if (IsNullParameter("id")) { |
| 124 session_->SwitchToTopFrame(); | 132 session_->SwitchToTopFrame(); |
| 125 } else { | 133 } else { |
| 126 SET_WEBDRIVER_ERROR( | 134 SET_WEBDRIVER_ERROR( |
| 127 response, "Missing or invalid 'id' parameter", kBadRequest); | 135 response, "Missing or invalid 'id' parameter", kBadRequest); |
| 128 return; | 136 return; |
| 129 } | 137 } |
| 130 response->SetStatus(kSuccess); | 138 response->SetStatus(kSuccess); |
| 131 } | 139 } |
| 132 | 140 |
| 141 bool SwitchFrameCommand::GetWebElementParameter(const std::string& key, |
| 142 WebElementId* out) const { |
| 143 DictionaryValue* value; |
| 144 if (!GetDictionaryParameter(key, &value)) |
| 145 return false; |
| 146 |
| 147 WebElementId id(value); |
| 148 if (!id.is_valid()) |
| 149 return false; |
| 150 |
| 151 *out = id; |
| 152 return true; |
| 153 } |
| 154 |
| 133 ActiveElementCommand::ActiveElementCommand( | 155 ActiveElementCommand::ActiveElementCommand( |
| 134 const std::vector<std::string>& path_segments, | 156 const std::vector<std::string>& path_segments, |
| 135 DictionaryValue* parameters) | 157 DictionaryValue* parameters) |
| 136 : WebDriverCommand(path_segments, parameters) {} | 158 : WebDriverCommand(path_segments, parameters) {} |
| 137 | 159 |
| 138 ActiveElementCommand::~ActiveElementCommand() {} | 160 ActiveElementCommand::~ActiveElementCommand() {} |
| 139 | 161 |
| 140 bool ActiveElementCommand::DoesPost() { | 162 bool ActiveElementCommand::DoesPost() { |
| 141 return true; | 163 return true; |
| 142 } | 164 } |
| 143 | 165 |
| 144 void ActiveElementCommand::ExecutePost(Response* const response) { | 166 void ActiveElementCommand::ExecutePost(Response* const response) { |
| 145 ListValue args; | 167 ListValue args; |
| 146 Value* result = NULL; | 168 Value* result = NULL; |
| 147 ErrorCode status = session_->ExecuteScript( | 169 ErrorCode status = session_->ExecuteScript( |
| 148 "return document.activeElement || document.body", &args, &result); | 170 "return document.activeElement || document.body", &args, &result); |
| 149 response->SetStatus(status); | 171 response->SetStatus(status); |
| 150 response->SetValue(result); | 172 response->SetValue(result); |
| 151 } | 173 } |
| 152 | 174 |
| 153 } // namespace webdriver | 175 } // namespace webdriver |
| OLD | NEW |