Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 118 *value = Value::CreateNullValue(); | 119 *value = Value::CreateNullValue(); |
| 119 } | 120 } |
| 120 | 121 |
| 121 int status; | 122 int status; |
| 122 if (!result_dict->GetInteger("status", &status)) { | 123 if (!result_dict->GetInteger("status", &status)) { |
| 123 NOTREACHED() << "...script did not return a status flag."; | 124 NOTREACHED() << "...script did not return a status flag."; |
| 124 } | 125 } |
| 125 return static_cast<ErrorCode>(status); | 126 return static_cast<ErrorCode>(status); |
| 126 } | 127 } |
| 127 | 128 |
| 129 ErrorCode Session::SendKeys(DictionaryValue* element, const string16& keys) { | |
| 130 ListValue args; | |
| 131 args.Append(element); | |
| 132 // TODO(jleyba): Update this to use the correct atom. | |
| 133 std::string script = "document.activeElement.blur();arguments[0].focus();"; | |
| 134 Value* unscoped_result = NULL; | |
| 135 ErrorCode code = ExecuteScript(script, &args, &unscoped_result); | |
| 136 if (code != kSuccess) | |
| 137 return code; | |
| 138 delete unscoped_result; | |
|
jleyba
2011/02/10 05:52:19
You leak unscoped_result if code != kSuccess.
kkania
2011/02/10 18:17:48
Done.
| |
| 139 | |
| 140 bool success = false; | |
| 141 RunSessionTask(NewRunnableMethod( | |
| 142 this, | |
| 143 &Session::SendKeysOnSessionThread, | |
| 144 keys, | |
| 145 &success)); | |
| 146 if (!success) | |
| 147 return kUnknownError; | |
| 148 return kSuccess; | |
| 149 } | |
| 150 | |
| 128 bool Session::NavigateToURL(const std::string& url) { | 151 bool Session::NavigateToURL(const std::string& url) { |
| 129 bool success = false; | 152 bool success = false; |
| 130 RunSessionTask(NewRunnableMethod( | 153 RunSessionTask(NewRunnableMethod( |
| 131 automation_.get(), | 154 automation_.get(), |
| 132 &Automation::NavigateToURL, | 155 &Automation::NavigateToURL, |
| 133 url, | 156 url, |
| 134 &success)); | 157 &success)); |
| 135 return success; | 158 return success; |
| 136 } | 159 } |
| 137 | 160 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 202 void Session::InitOnSessionThread(bool* success) { | 225 void Session::InitOnSessionThread(bool* success) { |
| 203 automation_.reset(new Automation()); | 226 automation_.reset(new Automation()); |
| 204 automation_->Init(success); | 227 automation_->Init(success); |
| 205 } | 228 } |
| 206 | 229 |
| 207 void Session::TerminateOnSessionThread() { | 230 void Session::TerminateOnSessionThread() { |
| 208 automation_->Terminate(); | 231 automation_->Terminate(); |
| 209 automation_.reset(); | 232 automation_.reset(); |
| 210 } | 233 } |
| 211 | 234 |
| 235 void Session::SendKeysOnSessionThread(const string16& keys, | |
| 236 bool* success) { | |
| 237 *success = true; | |
| 238 std::vector<WebKeyEvent> key_events; | |
| 239 ConvertKeysToWebKeyEvents(keys, &key_events); | |
| 240 for (size_t i = 0; i < key_events.size(); ++i) { | |
| 241 bool key_success = false; | |
| 242 automation_->SendWebKeyEvent(key_events[i], &key_success); | |
| 243 if (!key_success) { | |
| 244 LOG(ERROR) << "Failed to send key event. Event details:\n" | |
| 245 << "Type: " << key_events[i].type << "\n" | |
| 246 << "KeyCode: " << key_events[i].key_code << "\n" | |
| 247 << "UnmodifiedText: " << key_events[i].unmodified_text << "\n" | |
| 248 << "ModifiedText: " << key_events[i].modified_text << "\n" | |
| 249 << "Modifiers: " << key_events[i].modifiers << "\n"; | |
| 250 *success = false; | |
| 251 } | |
| 252 } | |
| 253 } | |
| 254 | |
| 212 } // namespace webdriver | 255 } // namespace webdriver |
| OLD | NEW |