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 | |
kkania
2011/02/09 16:53:13
no newline here
| |
20 #include "chrome/app/chrome_command_ids.h" | 21 #include "chrome/app/chrome_command_ids.h" |
21 #include "chrome/common/chrome_constants.h" | 22 #include "chrome/common/chrome_constants.h" |
22 #include "chrome/common/chrome_switches.h" | 23 #include "chrome/common/chrome_switches.h" |
23 #include "chrome/test/test_launcher_utils.h" | 24 #include "chrome/test/test_launcher_utils.h" |
24 #include "chrome/test/webdriver/utility_functions.h" | 25 #include "chrome/test/webdriver/utility_functions.h" |
26 | |
kkania
2011/02/09 16:53:13
no newline here
| |
27 #include "googleurl/src/gurl.h" | |
25 #include "third_party/webdriver/atoms.h" | 28 #include "third_party/webdriver/atoms.h" |
26 | 29 |
27 namespace webdriver { | 30 namespace webdriver { |
28 | 31 |
29 Session::Session(const std::string& id) | 32 Session::Session(const std::string& id) |
30 : thread_(id.c_str()), | 33 : thread_(id.c_str()), |
31 id_(id), | 34 id_(id), |
32 window_num_(0), | 35 window_num_(0), |
33 implicit_wait_(0), | 36 implicit_wait_(0), |
34 current_frame_xpath_("") { | 37 current_frame_xpath_("") { |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
165 bool Session::GetURL(std::string* url) { | 168 bool Session::GetURL(std::string* url) { |
166 bool success = false; | 169 bool success = false; |
167 RunSessionTask(NewRunnableMethod( | 170 RunSessionTask(NewRunnableMethod( |
168 automation_.get(), | 171 automation_.get(), |
169 &Automation::GetURL, | 172 &Automation::GetURL, |
170 url, | 173 url, |
171 &success)); | 174 &success)); |
172 return success; | 175 return success; |
173 } | 176 } |
174 | 177 |
178 bool Session::GetURL(GURL* gurl) { | |
179 bool success = false; | |
180 RunSessionTask(NewRunnableMethod( | |
181 automation_.get(), | |
kkania
2011/02/09 16:53:13
4 spaces not 2 here
| |
182 &Automation::GetGURL, | |
183 gurl, | |
184 &success)); | |
185 return success; | |
186 } | |
187 | |
175 bool Session::GetTabTitle(std::string* tab_title) { | 188 bool Session::GetTabTitle(std::string* tab_title) { |
176 bool success = false; | 189 bool success = false; |
177 RunSessionTask(NewRunnableMethod( | 190 RunSessionTask(NewRunnableMethod( |
178 automation_.get(), | 191 automation_.get(), |
179 &Automation::GetTabTitle, | 192 &Automation::GetTabTitle, |
180 tab_title, | 193 tab_title, |
181 &success)); | 194 &success)); |
182 return success; | 195 return success; |
183 } | 196 } |
184 | 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(), | |
kkania
2011/02/09 16:53:13
4 spaces not 2 here
| |
238 &Automation::SetCookie, | |
239 url, | |
240 cookie, | |
241 &success)); | |
242 return success; | |
243 } | |
244 | |
185 void Session::RunSessionTask(Task* task) { | 245 void Session::RunSessionTask(Task* task) { |
186 base::WaitableEvent done_event(false, false); | 246 base::WaitableEvent done_event(false, false); |
187 thread_.message_loop_proxy()->PostTask(FROM_HERE, NewRunnableMethod( | 247 thread_.message_loop_proxy()->PostTask(FROM_HERE, NewRunnableMethod( |
188 this, | 248 this, |
189 &Session::RunSessionTaskOnSessionThread, | 249 &Session::RunSessionTaskOnSessionThread, |
190 task, | 250 task, |
191 &done_event)); | 251 &done_event)); |
192 done_event.Wait(); | 252 done_event.Wait(); |
193 } | 253 } |
194 | 254 |
195 void Session::RunSessionTaskOnSessionThread(Task* task, | 255 void Session::RunSessionTaskOnSessionThread(Task* task, |
196 base::WaitableEvent* done_event) { | 256 base::WaitableEvent* done_event) { |
197 task->Run(); | 257 task->Run(); |
198 delete task; | 258 delete task; |
199 done_event->Signal(); | 259 done_event->Signal(); |
200 } | 260 } |
201 | 261 |
202 void Session::InitOnSessionThread(bool* success) { | 262 void Session::InitOnSessionThread(bool* success) { |
203 automation_.reset(new Automation()); | 263 automation_.reset(new Automation()); |
204 automation_->Init(success); | 264 automation_->Init(success); |
205 } | 265 } |
206 | 266 |
207 void Session::TerminateOnSessionThread() { | 267 void Session::TerminateOnSessionThread() { |
208 automation_->Terminate(); | 268 automation_->Terminate(); |
209 automation_.reset(); | 269 automation_.reset(); |
210 } | 270 } |
211 | 271 |
212 } // namespace webdriver | 272 } // namespace webdriver |
OLD | NEW |