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

Side by Side Diff: chrome/test/webdriver/commands/webelement_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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/test/webdriver/commands/webelement_command.h"
6
7 #include "third_party/webdriver/atoms.h"
8 #include "chrome/test/webdriver/error_codes.h"
9 #include "chrome/test/webdriver/utility_functions.h"
10
11 namespace webdriver {
12
13 bool WebElementCommand::Init(Response* const response) {
14 if (WebDriverCommand::Init(response)) {
15 SET_WEBDRIVER_ERROR(response, "Failure on Init for web element command",
16 kInternalServerError);
17 return false;
18 }
19
20 // There should be at least 5 segments to match
21 // "/session/$session/element/$id"
22 if (path_segments_.size() < 5) {
23 SET_WEBDRIVER_ERROR(response, "Path segments is less than 5",
24 kBadRequest);
25 return false;
26 }
27
28 // We cannot verify the ID is valid until we execute the command and
29 // inject the ID into the in-page cache.
30 element_id = path_segments_.at(4);
31 return true;
32 }
33
34 bool WebElementCommand::GetElementLocation(bool in_view, int* x, int* y) {
35 scoped_ptr<ListValue> args(new ListValue());
36 Value* result = NULL;
37
38 std::string jscript = build_atom(GET_LOCATION, sizeof GET_LOCATION);
39 if (in_view) {
40 jscript.append("arguments[0].scrollIntoView();");
41 }
42 jscript.append("return getLocation(arguments[0]);");
43
44 args->Append(GetElementIdAsDictionaryValue(element_id));
45
46 ErrorCode error = session_->ExecuteScript(jscript, args.get(), &result);
47 if (error != kSuccess) {
48 LOG(INFO) << "Javascript failed to execute" << std::endl;
49 return false;
50 }
51
52 if (result == NULL || result->GetType() != Value::TYPE_DICTIONARY) {
53 LOG(ERROR) << "Expected JavaScript atom to return a dictionary";
54 return false;
55 }
56
57 DictionaryValue* dict = static_cast<DictionaryValue*>(result);
58 return dict->GetInteger("x", x) && dict->GetInteger("y", y);
59 }
60
61 bool WebElementCommand::GetElementSize(int* width, int* height) {
62 scoped_ptr<ListValue> args(new ListValue());
63 Value* result = NULL;
64
65 std::string jscript = build_atom(GET_SIZE, sizeof GET_LOCATION);
66 args->Append(GetElementIdAsDictionaryValue(element_id));
67
68 ErrorCode error = session_->ExecuteScript(jscript, args.get(), &result);
69 if (error != kSuccess) {
70 LOG(ERROR) << "Javascript failed to execute" << std::endl;
71 return false;
72 }
73
74 if (result == NULL || result->GetType() != Value::TYPE_DICTIONARY) {
75 LOG(ERROR) << "Expected JavaScript atom to return "
76 << "{width:number, height:number} dictionary." << std::endl;
77 return false;
78 }
79
80 DictionaryValue* dict = static_cast<DictionaryValue*>(result);
81 return dict->GetInteger("width", width) &&
82 dict->GetInteger("height", height);
83 }
84
85 } // namespace webdriver
OLDNEW
« no previous file with comments | « chrome/test/webdriver/commands/webelement_command.h ('k') | chrome/test/webdriver/commands/webelement_commands.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698