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 <sstream> | 7 #include <sstream> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 12 matching lines...) Expand all Loading... | |
23 #include "base/string_util.h" | 23 #include "base/string_util.h" |
24 #include "base/synchronization/waitable_event.h" | 24 #include "base/synchronization/waitable_event.h" |
25 #include "base/test/test_timeouts.h" | 25 #include "base/test/test_timeouts.h" |
26 #include "base/threading/platform_thread.h" | 26 #include "base/threading/platform_thread.h" |
27 #include "base/time.h" | 27 #include "base/time.h" |
28 #include "base/utf_string_conversions.h" | 28 #include "base/utf_string_conversions.h" |
29 #include "base/values.h" | 29 #include "base/values.h" |
30 #include "chrome/app/chrome_command_ids.h" | 30 #include "chrome/app/chrome_command_ids.h" |
31 #include "chrome/common/chrome_constants.h" | 31 #include "chrome/common/chrome_constants.h" |
32 #include "chrome/common/chrome_switches.h" | 32 #include "chrome/common/chrome_switches.h" |
33 #include "chrome/test/automation/automation_json_requests.h" | |
33 #include "chrome/test/test_launcher_utils.h" | 34 #include "chrome/test/test_launcher_utils.h" |
34 #include "chrome/test/webdriver/session_manager.h" | 35 #include "chrome/test/webdriver/session_manager.h" |
35 #include "chrome/test/webdriver/utility_functions.h" | 36 #include "chrome/test/webdriver/utility_functions.h" |
36 #include "chrome/test/webdriver/webdriver_key_converter.h" | 37 #include "chrome/test/webdriver/webdriver_key_converter.h" |
37 #include "chrome/test/webdriver/web_element_id.h" | 38 #include "chrome/test/webdriver/web_element_id.h" |
38 #include "googleurl/src/gurl.h" | 39 #include "googleurl/src/gurl.h" |
39 #include "third_party/webdriver/atoms.h" | 40 #include "third_party/webdriver/atoms.h" |
40 #include "ui/gfx/point.h" | 41 #include "ui/gfx/point.h" |
41 | 42 |
42 namespace webdriver { | 43 namespace webdriver { |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
252 bool success = false; | 253 bool success = false; |
253 RunSessionTask(NewRunnableMethod( | 254 RunSessionTask(NewRunnableMethod( |
254 automation_.get(), | 255 automation_.get(), |
255 &Automation::GetTabTitle, | 256 &Automation::GetTabTitle, |
256 current_window_id_, | 257 current_window_id_, |
257 tab_title, | 258 tab_title, |
258 &success)); | 259 &success)); |
259 return success; | 260 return success; |
260 } | 261 } |
261 | 262 |
262 void Session::MouseClick(const gfx::Point& click, int flags) { | 263 void Session::MouseClick(const gfx::Point& click, |
264 automation::MouseButton button) { | |
263 bool success = false; | 265 bool success = false; |
264 RunSessionTask(NewRunnableMethod( | 266 RunSessionTask(NewRunnableMethod( |
265 automation_.get(), | 267 automation_.get(), |
266 &Automation::MouseClick, | 268 &Automation::MouseClick, |
267 current_window_id_, | 269 current_window_id_, |
268 click, | 270 click, |
269 flags, | 271 button, |
270 &success)); | 272 &success)); |
271 } | 273 } |
272 | 274 |
273 bool Session::MouseMove(const gfx::Point& location) { | 275 bool Session::MouseMove(const gfx::Point& location) { |
274 bool success = false; | 276 bool success = false; |
275 RunSessionTask(NewRunnableMethod( | 277 RunSessionTask(NewRunnableMethod( |
276 automation_.get(), | 278 automation_.get(), |
277 &Automation::MouseMove, | 279 &Automation::MouseMove, |
278 current_window_id_, | 280 current_window_id_, |
279 location, | 281 location, |
(...skipping 22 matching lines...) Expand all Loading... | |
302 current_window_id_, | 304 current_window_id_, |
303 url, | 305 url, |
304 cookies, | 306 cookies, |
305 &success)); | 307 &success)); |
306 return success; | 308 return success; |
307 } | 309 } |
308 | 310 |
309 bool Session::GetCookieByName(const GURL& url, | 311 bool Session::GetCookieByName(const GURL& url, |
310 const std::string& cookie_name, | 312 const std::string& cookie_name, |
311 std::string* cookie) { | 313 std::string* cookie) { |
312 bool success = false; | 314 std::string cookies; |
313 RunSessionTask(NewRunnableMethod( | 315 if (!GetCookies(url, &cookies)) |
314 automation_.get(), | 316 return false; |
315 &Automation::GetCookieByName, | 317 |
316 current_window_id_, | 318 std::string namestr = cookie_name + "="; |
317 url, | 319 std::string::size_type idx = cookies.find(namestr); |
318 cookie_name, | 320 if (idx != std::string::npos) { |
319 cookie, | 321 cookies.erase(0, idx + namestr.length()); |
320 &success)); | 322 *cookie = cookies.substr(0, cookies.find(";")); |
321 return success; | 323 } else { |
324 cookie->clear(); | |
325 } | |
326 | |
327 return true; | |
322 } | 328 } |
323 | 329 |
324 bool Session::DeleteCookie(const GURL& url, const std::string& cookie_name) { | 330 bool Session::DeleteCookie(const GURL& url, const std::string& cookie_name) { |
325 bool success = false; | 331 bool success = false; |
326 RunSessionTask(NewRunnableMethod( | 332 RunSessionTask(NewRunnableMethod( |
327 automation_.get(), | 333 automation_.get(), |
328 &Automation::DeleteCookie, | 334 &Automation::DeleteCookie, |
329 current_window_id_, | 335 current_window_id_, |
330 url, | 336 url, |
331 cookie_name, | 337 cookie_name, |
(...skipping 20 matching lines...) Expand all Loading... | |
352 &Automation::GetTabIds, | 358 &Automation::GetTabIds, |
353 window_ids, | 359 window_ids, |
354 &success)); | 360 &success)); |
355 return success; | 361 return success; |
356 } | 362 } |
357 | 363 |
358 ErrorCode Session::SwitchToWindow(const std::string& name) { | 364 ErrorCode Session::SwitchToWindow(const std::string& name) { |
359 int switch_to_id = 0; | 365 int switch_to_id = 0; |
360 int name_no = 0; | 366 int name_no = 0; |
361 if (base::StringToInt(name, &name_no)) { | 367 if (base::StringToInt(name, &name_no)) { |
362 bool does_exist = false; | 368 bool success = false, does_exist = false; |
Paweł Hajdan Jr.
2011/03/05 11:44:56
nit: I'd prefer to avoid declaring two variables w
kkania
2011/03/07 04:31:51
Done.
| |
363 RunSessionTask(NewRunnableMethod( | 369 RunSessionTask(NewRunnableMethod( |
364 automation_.get(), | 370 automation_.get(), |
365 &Automation::DoesTabExist, | 371 &Automation::DoesTabExist, |
366 name_no, | 372 name_no, |
367 &does_exist)); | 373 &does_exist, |
374 &success)); | |
375 if (!success) { | |
376 LOG(ERROR) << "Unable to determine if window exists"; | |
377 return kUnknownError; | |
378 } | |
368 if (does_exist) | 379 if (does_exist) |
369 switch_to_id = name_no; | 380 switch_to_id = name_no; |
370 } | 381 } |
371 | 382 |
372 if (!switch_to_id) { | 383 if (!switch_to_id) { |
373 std::vector<int> window_ids; | 384 std::vector<int> window_ids; |
374 GetWindowIds(&window_ids); | 385 GetWindowIds(&window_ids); |
375 // See if any of the window names match |name|. | 386 // See if any of the window names match |name|. |
376 for (size_t i = 0; i < window_ids.size(); ++i) { | 387 for (size_t i = 0; i < window_ids.size(); ++i) { |
377 ListValue empty_list; | 388 ListValue empty_list; |
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
760 } | 771 } |
761 } else { | 772 } else { |
762 LOG(ERROR) << "Location atom returned non-dictionary type"; | 773 LOG(ERROR) << "Location atom returned non-dictionary type"; |
763 code = kUnknownError; | 774 code = kUnknownError; |
764 } | 775 } |
765 } | 776 } |
766 return code; | 777 return code; |
767 } | 778 } |
768 | 779 |
769 } // namespace webdriver | 780 } // namespace webdriver |
OLD | NEW |