| OLD | NEW |
| 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 "googleurl/src/gurl.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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 bool Session::GetURL(std::string* url) { | 168 bool Session::GetURL(std::string* url) { |
| 168 bool success = false; | 169 bool success = false; |
| 169 RunSessionTask(NewRunnableMethod( | 170 RunSessionTask(NewRunnableMethod( |
| 170 automation_.get(), | 171 automation_.get(), |
| 171 &Automation::GetURL, | 172 &Automation::GetURL, |
| 172 url, | 173 url, |
| 173 &success)); | 174 &success)); |
| 174 return success; | 175 return success; |
| 175 } | 176 } |
| 176 | 177 |
| 178 bool Session::GetURL(GURL* gurl) { |
| 179 bool success = false; |
| 180 RunSessionTask(NewRunnableMethod( |
| 181 automation_.get(), |
| 182 &Automation::GetGURL, |
| 183 gurl, |
| 184 &success)); |
| 185 return success; |
| 186 } |
| 187 |
| 177 bool Session::GetTabTitle(std::string* tab_title) { | 188 bool Session::GetTabTitle(std::string* tab_title) { |
| 178 bool success = false; | 189 bool success = false; |
| 179 RunSessionTask(NewRunnableMethod( | 190 RunSessionTask(NewRunnableMethod( |
| 180 automation_.get(), | 191 automation_.get(), |
| 181 &Automation::GetTabTitle, | 192 &Automation::GetTabTitle, |
| 182 tab_title, | 193 tab_title, |
| 183 &success)); | 194 &success)); |
| 184 return success; | 195 return success; |
| 185 } | 196 } |
| 186 | 197 |
| 198 bool Session::GetCookies(const GURL& url, std::string* cookies) { |
| 199 bool success = false; |
| 200 RunSessionTask(NewRunnableMethod( |
| 201 automation_.get(), |
| 202 &Automation::GetCookies, |
| 203 url, |
| 204 cookies, |
| 205 &success)); |
| 206 return success; |
| 207 } |
| 208 |
| 209 bool Session::GetCookieByName(const GURL& url, |
| 210 const std::string& cookie_name, |
| 211 std::string* cookie) { |
| 212 bool success = false; |
| 213 RunSessionTask(NewRunnableMethod( |
| 214 automation_.get(), |
| 215 &Automation::GetCookieByName, |
| 216 url, |
| 217 cookie_name, |
| 218 cookie, |
| 219 &success)); |
| 220 return success; |
| 221 } |
| 222 |
| 223 bool Session::DeleteCookie(const GURL& url, const std::string& cookie_name) { |
| 224 bool success = false; |
| 225 RunSessionTask(NewRunnableMethod( |
| 226 automation_.get(), |
| 227 &Automation::DeleteCookie, |
| 228 url, |
| 229 cookie_name, |
| 230 &success)); |
| 231 return success; |
| 232 } |
| 233 |
| 234 bool Session::SetCookie(const GURL& url, const std::string& cookie) { |
| 235 bool success = false; |
| 236 RunSessionTask(NewRunnableMethod( |
| 237 automation_.get(), |
| 238 &Automation::SetCookie, |
| 239 url, |
| 240 cookie, |
| 241 &success)); |
| 242 return success; |
| 243 } |
| 244 |
| 187 void Session::RunSessionTask(Task* task) { | 245 void Session::RunSessionTask(Task* task) { |
| 188 base::WaitableEvent done_event(false, false); | 246 base::WaitableEvent done_event(false, false); |
| 189 thread_.message_loop_proxy()->PostTask(FROM_HERE, NewRunnableMethod( | 247 thread_.message_loop_proxy()->PostTask(FROM_HERE, NewRunnableMethod( |
| 190 this, | 248 this, |
| 191 &Session::RunSessionTaskOnSessionThread, | 249 &Session::RunSessionTaskOnSessionThread, |
| 192 task, | 250 task, |
| 193 &done_event)); | 251 &done_event)); |
| 194 done_event.Wait(); | 252 done_event.Wait(); |
| 195 } | 253 } |
| 196 | 254 |
| 197 void Session::RunSessionTaskOnSessionThread(Task* task, | 255 void Session::RunSessionTaskOnSessionThread(Task* task, |
| 198 base::WaitableEvent* done_event) { | 256 base::WaitableEvent* done_event) { |
| 199 task->Run(); | 257 task->Run(); |
| 200 delete task; | 258 delete task; |
| 201 done_event->Signal(); | 259 done_event->Signal(); |
| 202 } | 260 } |
| 203 | 261 |
| 204 void Session::InitOnSessionThread(bool* success) { | 262 void Session::InitOnSessionThread(bool* success) { |
| 205 automation_.reset(new Automation()); | 263 automation_.reset(new Automation()); |
| 206 automation_->Init(success); | 264 automation_->Init(success); |
| 207 } | 265 } |
| 208 | 266 |
| 209 void Session::TerminateOnSessionThread() { | 267 void Session::TerminateOnSessionThread() { |
| 210 automation_->Terminate(); | 268 automation_->Terminate(); |
| 211 automation_.reset(); | 269 automation_.reset(); |
| 212 } | 270 } |
| 213 | 271 |
| 214 } // namespace webdriver | 272 } // namespace webdriver |
| OLD | NEW |