| Index: chrome/test/webdriver/commands/value_command.cc
|
| ===================================================================
|
| --- chrome/test/webdriver/commands/value_command.cc (revision 0)
|
| +++ chrome/test/webdriver/commands/value_command.cc (revision 0)
|
| @@ -0,0 +1,77 @@
|
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "chrome/test/webdriver/commands/value_command.h"
|
| +
|
| +#include "base/scoped_ptr.h"
|
| +#include "base/third_party/icu/icu_utf.h"
|
| +#include "base/values.h"
|
| +#include "chrome/test/webdriver/commands/response.h"
|
| +#include "chrome/test/webdriver/error_codes.h"
|
| +#include "chrome/test/webdriver/session.h"
|
| +#include "chrome/test/webdriver/utility_functions.h"
|
| +#include "third_party/webdriver/atoms.h"
|
| +
|
| +namespace webdriver {
|
| +
|
| +void ValueCommand::ExecuteGet(Response* const response) {
|
| + Value* unscoped_result = NULL;
|
| + ListValue args;
|
| + std::string script = "return arguments[0]['value']";
|
| + args.Append(GetElementIdAsDictionaryValue(element_id));
|
| + ErrorCode code =
|
| + session_->ExecuteScript(script, &args, &unscoped_result);
|
| + scoped_ptr<Value> result(unscoped_result);
|
| + if (code != kSuccess) {
|
| + SET_WEBDRIVER_ERROR(response, "Failed to execute script", code);
|
| + return;
|
| + }
|
| + if (!result->IsType(Value::TYPE_STRING) &&
|
| + !result->IsType(Value::TYPE_NULL)) {
|
| + SET_WEBDRIVER_ERROR(response,
|
| + "Result is not string or null type",
|
| + kInternalServerError);
|
| + return;
|
| + }
|
| + response->set_status(kSuccess);
|
| + response->set_value(result.release());
|
| +}
|
| +
|
| +void ValueCommand::ExecutePost(Response* const response) {
|
| + ListValue* key_list;
|
| + if (!GetListParameter("value", &key_list)) {
|
| + SET_WEBDRIVER_ERROR(response,
|
| + "Missing or invalid 'value' parameter",
|
| + kBadRequest);
|
| + return;
|
| + }
|
| + // Flatten the given array of strings into one.
|
| + string16 keys;
|
| + for (size_t i = 0; i < key_list->GetSize(); ++i) {
|
| + string16 keys_list_part;
|
| + key_list->GetString(i, &keys_list_part);
|
| + for (size_t j = 0; j < keys_list_part.size(); ++j) {
|
| + if (CBU16_IS_SURROGATE(keys_list_part[j])) {
|
| + SET_WEBDRIVER_ERROR(
|
| + response,
|
| + "ChromeDriver only supports characters in the BMP",
|
| + kBadRequest);
|
| + return;
|
| + }
|
| + }
|
| + keys.append(keys_list_part);
|
| + }
|
| +
|
| + ErrorCode code =
|
| + session_->SendKeys(GetElementIdAsDictionaryValue(element_id), keys);
|
| + if (code != kSuccess) {
|
| + SET_WEBDRIVER_ERROR(response,
|
| + "Internal SendKeys error",
|
| + code);
|
| + return;
|
| + }
|
| + response->set_status(kSuccess);
|
| +}
|
| +
|
| +} // namespace webdriver
|
|
|
| Property changes on: chrome\test\webdriver\commands\value_command.cc
|
| ___________________________________________________________________
|
| Added: svn:eol-style
|
| + LF
|
|
|
|
|