| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/webelement_commands.h" | 5 #include "chrome/test/webdriver/commands/webelement_commands.h" |
| 6 | 6 |
| 7 #include "base/scoped_ptr.h" | 7 #include "base/scoped_ptr.h" |
| 8 #include "base/third_party/icu/icu_utf.h" | 8 #include "base/third_party/icu/icu_utf.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "chrome/test/webdriver/commands/response.h" | 10 #include "chrome/test/webdriver/commands/response.h" |
| 11 #include "chrome/test/webdriver/error_codes.h" | 11 #include "chrome/test/webdriver/error_codes.h" |
| 12 #include "chrome/test/webdriver/session.h" | 12 #include "chrome/test/webdriver/session.h" |
| 13 #include "chrome/test/webdriver/utility_functions.h" | 13 #include "chrome/test/webdriver/utility_functions.h" |
| 14 #include "third_party/webdriver/atoms.h" | 14 #include "third_party/webdriver/atoms.h" |
| 15 | 15 |
| 16 namespace webdriver { | 16 namespace webdriver { |
| 17 | 17 |
| 18 WebElementCommand::WebElementCommand( |
| 19 const std::vector<std::string>& path_segments, |
| 20 const DictionaryValue* const parameters) |
| 21 : WebDriverCommand(path_segments, parameters), |
| 22 path_segments_(path_segments) {} |
| 23 |
| 24 WebElementCommand::~WebElementCommand() {} |
| 25 |
| 18 bool WebElementCommand::Init(Response* const response) { | 26 bool WebElementCommand::Init(Response* const response) { |
| 19 if (!WebDriverCommand::Init(response)) | 27 if (!WebDriverCommand::Init(response)) |
| 20 return false; | 28 return false; |
| 21 | 29 |
| 22 // There should be at least 5 segments to match | 30 // There should be at least 5 segments to match |
| 23 // "/session/$session/element/$id" | 31 // "/session/$session/element/$id" |
| 24 if (path_segments_.size() < 5) { | 32 if (path_segments_.size() < 5) { |
| 25 SET_WEBDRIVER_ERROR(response, "Path segments is less than 5", | 33 SET_WEBDRIVER_ERROR(response, "Path segments is less than 5", |
| 26 kBadRequest); | 34 kBadRequest); |
| 27 return false; | 35 return false; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 LOG(ERROR) << "Expected JavaScript atom to return " | 85 LOG(ERROR) << "Expected JavaScript atom to return " |
| 78 << "{width:number, height:number} dictionary." << std::endl; | 86 << "{width:number, height:number} dictionary." << std::endl; |
| 79 return false; | 87 return false; |
| 80 } | 88 } |
| 81 | 89 |
| 82 DictionaryValue* dict = static_cast<DictionaryValue*>(result); | 90 DictionaryValue* dict = static_cast<DictionaryValue*>(result); |
| 83 return dict->GetInteger("width", width) && | 91 return dict->GetInteger("width", width) && |
| 84 dict->GetInteger("height", height); | 92 dict->GetInteger("height", height); |
| 85 } | 93 } |
| 86 | 94 |
| 95 bool WebElementCommand::RequiresValidTab() { |
| 96 return true; |
| 97 } |
| 98 |
| 99 ElementValueCommand::ElementValueCommand( |
| 100 const std::vector<std::string>& path_segments, |
| 101 DictionaryValue* parameters) |
| 102 : WebElementCommand(path_segments, parameters) {} |
| 103 |
| 104 ElementValueCommand::~ElementValueCommand() {} |
| 105 |
| 106 bool ElementValueCommand::DoesGet() { |
| 107 return true; |
| 108 } |
| 109 |
| 110 bool ElementValueCommand::DoesPost() { |
| 111 return true; |
| 112 } |
| 113 |
| 87 void ElementValueCommand::ExecuteGet(Response* const response) { | 114 void ElementValueCommand::ExecuteGet(Response* const response) { |
| 88 Value* unscoped_result = NULL; | 115 Value* unscoped_result = NULL; |
| 89 ListValue args; | 116 ListValue args; |
| 90 std::string script = "return arguments[0]['value']"; | 117 std::string script = "return arguments[0]['value']"; |
| 91 args.Append(GetElementIdAsDictionaryValue(element_id)); | 118 args.Append(GetElementIdAsDictionaryValue(element_id)); |
| 92 ErrorCode code = | 119 ErrorCode code = |
| 93 session_->ExecuteScript(script, &args, &unscoped_result); | 120 session_->ExecuteScript(script, &args, &unscoped_result); |
| 94 scoped_ptr<Value> result(unscoped_result); | 121 scoped_ptr<Value> result(unscoped_result); |
| 95 if (code != kSuccess) { | 122 if (code != kSuccess) { |
| 96 SET_WEBDRIVER_ERROR(response, "Failed to execute script", code); | 123 SET_WEBDRIVER_ERROR(response, "Failed to execute script", code); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 session_->SendKeys(GetElementIdAsDictionaryValue(element_id), keys); | 163 session_->SendKeys(GetElementIdAsDictionaryValue(element_id), keys); |
| 137 if (code != kSuccess) { | 164 if (code != kSuccess) { |
| 138 SET_WEBDRIVER_ERROR(response, | 165 SET_WEBDRIVER_ERROR(response, |
| 139 "Internal SendKeys error", | 166 "Internal SendKeys error", |
| 140 code); | 167 code); |
| 141 return; | 168 return; |
| 142 } | 169 } |
| 143 response->set_status(kSuccess); | 170 response->set_status(kSuccess); |
| 144 } | 171 } |
| 145 | 172 |
| 173 ElementTextCommand::ElementTextCommand( |
| 174 const std::vector<std::string>& path_segments, |
| 175 DictionaryValue* parameters) |
| 176 : WebElementCommand(path_segments, parameters) {} |
| 177 |
| 178 ElementTextCommand::~ElementTextCommand() {} |
| 179 |
| 180 bool ElementTextCommand::DoesGet() { |
| 181 return true; |
| 182 } |
| 183 |
| 146 void ElementTextCommand::ExecuteGet(Response* const response) { | 184 void ElementTextCommand::ExecuteGet(Response* const response) { |
| 147 Value* unscoped_result = NULL; | 185 Value* unscoped_result = NULL; |
| 148 ListValue args; | 186 ListValue args; |
| 149 // TODO(jleyba): Use a real javascript atom. | 187 // TODO(jleyba): Use a real javascript atom. |
| 150 std::string script = | 188 std::string script = |
| 151 "function getText(element) {" | 189 "function getText(element) {" |
| 152 " if (element instanceof Text) {" | 190 " if (element instanceof Text) {" |
| 153 " return element.textContent.replace(/^\\s+|\\s+$/g, '');" | 191 " return element.textContent.replace(/^\\s+|\\s+$/g, '');" |
| 154 " }" | 192 " }" |
| 155 " var childrenText = '';" | 193 " var childrenText = '';" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 171 SET_WEBDRIVER_ERROR(response, | 209 SET_WEBDRIVER_ERROR(response, |
| 172 "Result is not string type", | 210 "Result is not string type", |
| 173 kInternalServerError); | 211 kInternalServerError); |
| 174 return; | 212 return; |
| 175 } | 213 } |
| 176 response->set_status(kSuccess); | 214 response->set_status(kSuccess); |
| 177 response->set_value(result.release()); | 215 response->set_value(result.release()); |
| 178 } | 216 } |
| 179 | 217 |
| 180 } // namespace webdriver | 218 } // namespace webdriver |
| OLD | NEW |