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

Side by Side Diff: chrome/test/webdriver/session.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
« no previous file with comments | « chrome/test/webdriver/session.h ('k') | chrome/test/webdriver/webdriver_key_converter.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 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/session_manager.h" 5 #include "chrome/test/webdriver/session_manager.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/message_loop_proxy.h" 12 #include "base/message_loop_proxy.h"
13 #include "base/process.h" 13 #include "base/process.h"
14 #include "base/process_util.h" 14 #include "base/process_util.h"
15 #include "base/string_util.h" 15 #include "base/string_util.h"
16 #include "base/json/json_reader.h" 16 #include "base/json/json_reader.h"
17 #include "base/json/json_writer.h" 17 #include "base/json/json_writer.h"
18 #include "base/test/test_timeouts.h" 18 #include "base/test/test_timeouts.h"
19 #include "base/utf_string_conversions.h" 19 #include "base/utf_string_conversions.h"
20 #include "chrome/app/chrome_command_ids.h" 20 #include "chrome/app/chrome_command_ids.h"
21 #include "chrome/common/chrome_constants.h" 21 #include "chrome/common/chrome_constants.h"
22 #include "chrome/common/chrome_switches.h" 22 #include "chrome/common/chrome_switches.h"
23 #include "chrome/test/test_launcher_utils.h" 23 #include "chrome/test/test_launcher_utils.h"
24 #include "chrome/test/webdriver/utility_functions.h" 24 #include "chrome/test/webdriver/utility_functions.h"
25 #include "chrome/test/webdriver/webdriver_key_converter.h"
25 #include "third_party/webdriver/atoms.h" 26 #include "third_party/webdriver/atoms.h"
26 27
27 namespace webdriver { 28 namespace webdriver {
28 29
29 Session::Session(const std::string& id) 30 Session::Session(const std::string& id)
30 : thread_(id.c_str()), 31 : thread_(id.c_str()),
31 id_(id), 32 id_(id),
32 window_num_(0), 33 window_num_(0),
33 implicit_wait_(0), 34 implicit_wait_(0),
34 current_frame_xpath_("") { 35 current_frame_xpath_("") {
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 *value = Value::CreateNullValue(); 121 *value = Value::CreateNullValue();
121 } 122 }
122 123
123 int status; 124 int status;
124 if (!result_dict->GetInteger("status", &status)) { 125 if (!result_dict->GetInteger("status", &status)) {
125 NOTREACHED() << "...script did not return a status flag."; 126 NOTREACHED() << "...script did not return a status flag.";
126 } 127 }
127 return static_cast<ErrorCode>(status); 128 return static_cast<ErrorCode>(status);
128 } 129 }
129 130
131 ErrorCode Session::SendKeys(DictionaryValue* element, const string16& keys) {
132 ListValue args;
133 args.Append(element);
134 // TODO(jleyba): Update this to use the correct atom.
135 std::string script = "document.activeElement.blur();arguments[0].focus();";
136 Value* unscoped_result = NULL;
137 ErrorCode code = ExecuteScript(script, &args, &unscoped_result);
138 scoped_ptr<Value> result(unscoped_result);
139 if (code != kSuccess)
140 return code;
141
142 bool success = false;
143 RunSessionTask(NewRunnableMethod(
144 this,
145 &Session::SendKeysOnSessionThread,
146 keys,
147 &success));
148 if (!success)
149 return kUnknownError;
150 return kSuccess;
151 }
152
130 bool Session::NavigateToURL(const std::string& url) { 153 bool Session::NavigateToURL(const std::string& url) {
131 bool success = false; 154 bool success = false;
132 RunSessionTask(NewRunnableMethod( 155 RunSessionTask(NewRunnableMethod(
133 automation_.get(), 156 automation_.get(),
134 &Automation::NavigateToURL, 157 &Automation::NavigateToURL,
135 url, 158 url,
136 &success)); 159 &success));
137 return success; 160 return success;
138 } 161 }
139 162
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 void Session::InitOnSessionThread(bool* success) { 227 void Session::InitOnSessionThread(bool* success) {
205 automation_.reset(new Automation()); 228 automation_.reset(new Automation());
206 automation_->Init(success); 229 automation_->Init(success);
207 } 230 }
208 231
209 void Session::TerminateOnSessionThread() { 232 void Session::TerminateOnSessionThread() {
210 automation_->Terminate(); 233 automation_->Terminate();
211 automation_.reset(); 234 automation_.reset();
212 } 235 }
213 236
237 void Session::SendKeysOnSessionThread(const string16& keys,
238 bool* success) {
239 *success = true;
240 std::vector<WebKeyEvent> key_events;
241 ConvertKeysToWebKeyEvents(keys, &key_events);
242 for (size_t i = 0; i < key_events.size(); ++i) {
243 bool key_success = false;
244 automation_->SendWebKeyEvent(key_events[i], &key_success);
245 if (!key_success) {
246 LOG(ERROR) << "Failed to send key event. Event details:\n"
247 << "Type: " << key_events[i].type << "\n"
248 << "KeyCode: " << key_events[i].key_code << "\n"
249 << "UnmodifiedText: " << key_events[i].unmodified_text << "\n"
250 << "ModifiedText: " << key_events[i].modified_text << "\n"
251 << "Modifiers: " << key_events[i].modifiers << "\n";
252 *success = false;
253 }
254 }
255 }
256
214 } // namespace webdriver 257 } // namespace webdriver
OLDNEW
« no previous file with comments | « chrome/test/webdriver/session.h ('k') | chrome/test/webdriver/webdriver_key_converter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698