| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/test/webdriver/commands/value_command.h" |
| 6 |
| 7 #include "base/scoped_ptr.h" |
| 8 #include "base/third_party/icu/icu_utf.h" |
| 9 #include "base/values.h" |
| 10 #include "chrome/test/webdriver/commands/response.h" |
| 11 #include "chrome/test/webdriver/error_codes.h" |
| 12 #include "chrome/test/webdriver/session.h" |
| 13 #include "chrome/test/webdriver/utility_functions.h" |
| 14 #include "third_party/webdriver/atoms.h" |
| 15 |
| 16 namespace webdriver { |
| 17 |
| 18 void ValueCommand::ExecuteGet(Response* const response) { |
| 19 Value* unscoped_result = NULL; |
| 20 ListValue args; |
| 21 std::string script = "return arguments[0]['value']"; |
| 22 args.Append(GetElementIdAsDictionaryValue(element_id)); |
| 23 ErrorCode code = |
| 24 session_->ExecuteScript(script, &args, &unscoped_result); |
| 25 scoped_ptr<Value> result(unscoped_result); |
| 26 if (code != kSuccess) { |
| 27 SET_WEBDRIVER_ERROR(response, "Failed to execute script", code); |
| 28 return; |
| 29 } |
| 30 if (!result->IsType(Value::TYPE_STRING) && |
| 31 !result->IsType(Value::TYPE_NULL)) { |
| 32 SET_WEBDRIVER_ERROR(response, |
| 33 "Result is not string or null type", |
| 34 kInternalServerError); |
| 35 return; |
| 36 } |
| 37 response->set_status(kSuccess); |
| 38 response->set_value(result.release()); |
| 39 } |
| 40 |
| 41 void ValueCommand::ExecutePost(Response* const response) { |
| 42 ListValue* key_list; |
| 43 if (!GetListParameter("value", &key_list)) { |
| 44 SET_WEBDRIVER_ERROR(response, |
| 45 "Missing or invalid 'value' parameter", |
| 46 kBadRequest); |
| 47 return; |
| 48 } |
| 49 // Flatten the given array of strings into one. |
| 50 string16 keys; |
| 51 for (size_t i = 0; i < key_list->GetSize(); ++i) { |
| 52 string16 keys_list_part; |
| 53 key_list->GetString(i, &keys_list_part); |
| 54 for (size_t j = 0; j < keys_list_part.size(); ++j) { |
| 55 if (CBU16_IS_SURROGATE(keys_list_part[j])) { |
| 56 SET_WEBDRIVER_ERROR( |
| 57 response, |
| 58 "ChromeDriver only supports characters in the BMP", |
| 59 kBadRequest); |
| 60 return; |
| 61 } |
| 62 } |
| 63 keys.append(keys_list_part); |
| 64 } |
| 65 |
| 66 ErrorCode code = |
| 67 session_->SendKeys(GetElementIdAsDictionaryValue(element_id), keys); |
| 68 if (code != kSuccess) { |
| 69 SET_WEBDRIVER_ERROR(response, |
| 70 "Internal SendKeys error", |
| 71 code); |
| 72 return; |
| 73 } |
| 74 response->set_status(kSuccess); |
| 75 } |
| 76 |
| 77 } // namespace webdriver |
| OLD | NEW |