Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4277)

Unified Diff: chrome/test/webdriver/commands/value_command.cc

Issue 6482014: Implement sendKeys webdriver API in ChromeDriver. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698