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/webdriver_session.h" | 5 #include "chrome/test/webdriver/webdriver_session.h" |
6 | 6 |
7 #include <sstream> | 7 #include <sstream> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 } | 49 } |
50 | 50 |
51 FrameId& FrameId::operator=(const FrameId& other) { | 51 FrameId& FrameId::operator=(const FrameId& other) { |
52 window_id = other.window_id; | 52 window_id = other.window_id; |
53 frame_path = other.frame_path; | 53 frame_path = other.frame_path; |
54 return *this; | 54 return *this; |
55 } | 55 } |
56 | 56 |
57 Session::Options::Options() | 57 Session::Options::Options() |
58 : use_native_events(false), | 58 : use_native_events(false), |
59 load_async(false) { | 59 load_async(false), |
| 60 no_website_testing_defaults(false) { |
60 } | 61 } |
61 | 62 |
62 Session::Options::~Options() { | 63 Session::Options::~Options() { |
63 } | 64 } |
64 | 65 |
65 Session::Session(const Options& options) | 66 Session::Session(const Options& options) |
66 : id_(GenerateRandomID()), | 67 : id_(GenerateRandomID()), |
67 current_target_(FrameId(0, FramePath())), | 68 current_target_(FrameId(0, FramePath())), |
68 thread_(id_.c_str()), | 69 thread_(id_.c_str()), |
69 async_script_timeout_(0), | 70 async_script_timeout_(0), |
70 implicit_wait_(0), | 71 implicit_wait_(0), |
71 has_alert_prompt_text_(false), | 72 has_alert_prompt_text_(false), |
72 options_(options) { | 73 options_(options) { |
73 SessionManager::GetInstance()->Add(this); | 74 SessionManager::GetInstance()->Add(this); |
74 } | 75 } |
75 | 76 |
76 Session::~Session() { | 77 Session::~Session() { |
77 SessionManager::GetInstance()->Remove(id_); | 78 SessionManager::GetInstance()->Remove(id_); |
78 } | 79 } |
79 | 80 |
80 Error* Session::Init(const Automation::BrowserOptions& options) { | 81 Error* Session::Init(const Automation::BrowserOptions& options) { |
81 if (!thread_.Start()) { | 82 if (!thread_.Start()) { |
82 delete this; | 83 delete this; |
83 return new Error(kUnknownError, "Cannot start session thread"); | 84 return new Error(kUnknownError, "Cannot start session thread"); |
84 } | 85 } |
85 | 86 |
86 Error* error = NULL; | 87 Error* error = NULL; |
87 RunSessionTask(NewRunnableMethod( | 88 RunSessionTask(base::Bind( |
88 this, | |
89 &Session::InitOnSessionThread, | 89 &Session::InitOnSessionThread, |
| 90 base::Unretained(this), |
90 options, | 91 options, |
91 &error)); | 92 &error)); |
| 93 |
| 94 if (!error) |
| 95 error = PostBrowserStartInit(); |
| 96 |
92 if (error) | 97 if (error) |
93 Terminate(); | 98 Terminate(); |
94 return error; | 99 return error; |
95 } | 100 } |
96 | 101 |
97 Error* Session::BeforeExecuteCommand() { | 102 Error* Session::BeforeExecuteCommand() { |
98 Error* error = AfterExecuteCommand(); | 103 Error* error = AfterExecuteCommand(); |
99 if (!error) { | 104 if (!error) { |
100 scoped_ptr<Error> switch_error(SwitchToTopFrameIfCurrentFrameInvalid()); | 105 scoped_ptr<Error> switch_error(SwitchToTopFrameIfCurrentFrameInvalid()); |
101 if (switch_error.get()) { | 106 if (switch_error.get()) { |
(...skipping 13 matching lines...) Expand all Loading... |
115 Error* error = NULL; | 120 Error* error = NULL; |
116 if (!options_.load_async) { | 121 if (!options_.load_async) { |
117 LOG(INFO) << "Waiting for the page to stop loading"; | 122 LOG(INFO) << "Waiting for the page to stop loading"; |
118 error = WaitForAllTabsToStopLoading(); | 123 error = WaitForAllTabsToStopLoading(); |
119 LOG(INFO) << "Done waiting for the page to stop loading"; | 124 LOG(INFO) << "Done waiting for the page to stop loading"; |
120 } | 125 } |
121 return error; | 126 return error; |
122 } | 127 } |
123 | 128 |
124 void Session::Terminate() { | 129 void Session::Terminate() { |
125 RunSessionTask(NewRunnableMethod( | 130 RunSessionTask(base::Bind( |
126 this, | 131 &Session::TerminateOnSessionThread, |
127 &Session::TerminateOnSessionThread)); | 132 base::Unretained(this))); |
128 delete this; | 133 delete this; |
129 } | 134 } |
130 | 135 |
131 Error* Session::ExecuteScript(const FrameId& frame_id, | 136 Error* Session::ExecuteScript(const FrameId& frame_id, |
132 const std::string& script, | 137 const std::string& script, |
133 const ListValue* const args, | 138 const ListValue* const args, |
134 Value** value) { | 139 Value** value) { |
135 std::string args_as_json; | 140 std::string args_as_json; |
136 base::JSONWriter::Write(static_cast<const Value* const>(args), | 141 base::JSONWriter::Write(static_cast<const Value* const>(args), |
137 /*pretty_print=*/false, | 142 /*pretty_print=*/false, |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 " throw new Error('Failed to send keys because cannot focus element');" | 260 " throw new Error('Failed to send keys because cannot focus element');" |
256 "}"; | 261 "}"; |
257 error = ExecuteScriptAndParse(current_target_, | 262 error = ExecuteScriptAndParse(current_target_, |
258 kFocusScript, | 263 kFocusScript, |
259 "focusElement", | 264 "focusElement", |
260 CreateListValueFrom(element), | 265 CreateListValueFrom(element), |
261 CreateDirectValueParser(kSkipParsing)); | 266 CreateDirectValueParser(kSkipParsing)); |
262 if (error) | 267 if (error) |
263 return error; | 268 return error; |
264 | 269 |
265 RunSessionTask(NewRunnableMethod( | 270 RunSessionTask(base::Bind( |
266 this, | |
267 &Session::SendKeysOnSessionThread, | 271 &Session::SendKeysOnSessionThread, |
| 272 base::Unretained(this), |
268 keys, | 273 keys, |
269 &error)); | 274 &error)); |
270 return error; | 275 return error; |
271 } | 276 } |
272 | 277 |
273 Error* Session::DragAndDropFilePaths( | 278 Error* Session::DragAndDropFilePaths( |
274 const Point& location, | 279 const Point& location, |
275 const std::vector<FilePath::StringType>& paths) { | 280 const std::vector<FilePath::StringType>& paths) { |
276 Error* error = NULL; | 281 Error* error = NULL; |
277 RunSessionTask(NewRunnableMethod( | 282 RunSessionTask(base::Bind( |
278 automation_.get(), | |
279 &Automation::DragAndDropFilePaths, | 283 &Automation::DragAndDropFilePaths, |
| 284 base::Unretained(automation_.get()), |
280 current_target_.window_id, | 285 current_target_.window_id, |
281 location, | 286 location, |
282 paths, | 287 paths, |
283 &error)); | 288 &error)); |
284 return error; | 289 return error; |
285 } | 290 } |
286 | 291 |
287 Error* Session::NavigateToURL(const std::string& url) { | 292 Error* Session::NavigateToURL(const std::string& url) { |
288 Error* error = NULL; | 293 Error* error = NULL; |
289 if (options_.load_async) { | 294 if (options_.load_async) { |
290 RunSessionTask(NewRunnableMethod( | 295 RunSessionTask(base::Bind( |
291 automation_.get(), | |
292 &Automation::NavigateToURLAsync, | 296 &Automation::NavigateToURLAsync, |
| 297 base::Unretained(automation_.get()), |
293 current_target_.window_id, | 298 current_target_.window_id, |
294 url, | 299 url, |
295 &error)); | 300 &error)); |
296 } else { | 301 } else { |
297 RunSessionTask(NewRunnableMethod( | 302 RunSessionTask(base::Bind( |
298 automation_.get(), | |
299 &Automation::NavigateToURL, | 303 &Automation::NavigateToURL, |
| 304 base::Unretained(automation_.get()), |
300 current_target_.window_id, | 305 current_target_.window_id, |
301 url, | 306 url, |
302 &error)); | 307 &error)); |
303 } | 308 } |
304 return error; | 309 return error; |
305 } | 310 } |
306 | 311 |
307 Error* Session::GoForward() { | 312 Error* Session::GoForward() { |
308 Error* error = NULL; | 313 Error* error = NULL; |
309 RunSessionTask(NewRunnableMethod( | 314 RunSessionTask(base::Bind( |
310 automation_.get(), | |
311 &Automation::GoForward, | 315 &Automation::GoForward, |
| 316 base::Unretained(automation_.get()), |
312 current_target_.window_id, | 317 current_target_.window_id, |
313 &error)); | 318 &error)); |
314 return error; | 319 return error; |
315 } | 320 } |
316 | 321 |
317 Error* Session::GoBack() { | 322 Error* Session::GoBack() { |
318 Error* error = NULL; | 323 Error* error = NULL; |
319 RunSessionTask(NewRunnableMethod( | 324 RunSessionTask(base::Bind( |
320 automation_.get(), | |
321 &Automation::GoBack, | 325 &Automation::GoBack, |
| 326 base::Unretained(automation_.get()), |
322 current_target_.window_id, | 327 current_target_.window_id, |
323 &error)); | 328 &error)); |
324 return error; | 329 return error; |
325 } | 330 } |
326 | 331 |
327 Error* Session::Reload() { | 332 Error* Session::Reload() { |
328 Error* error = NULL; | 333 Error* error = NULL; |
329 RunSessionTask(NewRunnableMethod( | 334 RunSessionTask(base::Bind( |
330 automation_.get(), | |
331 &Automation::Reload, | 335 &Automation::Reload, |
| 336 base::Unretained(automation_.get()), |
332 current_target_.window_id, | 337 current_target_.window_id, |
333 &error)); | 338 &error)); |
334 return error; | 339 return error; |
335 } | 340 } |
336 | 341 |
337 Error* Session::GetURL(std::string* url) { | 342 Error* Session::GetURL(std::string* url) { |
338 return ExecuteScriptAndParse(current_target_, | 343 return ExecuteScriptAndParse(current_target_, |
339 "function() { return document.URL }", | 344 "function() { return document.URL }", |
340 "getUrl", | 345 "getUrl", |
341 new ListValue(), | 346 new ListValue(), |
(...skipping 11 matching lines...) Expand all Loading... |
353 return ExecuteScriptAndParse(FrameId(current_target_.window_id, FramePath()), | 358 return ExecuteScriptAndParse(FrameId(current_target_.window_id, FramePath()), |
354 kGetTitleScript, | 359 kGetTitleScript, |
355 "getTitle", | 360 "getTitle", |
356 new ListValue(), | 361 new ListValue(), |
357 CreateDirectValueParser(tab_title)); | 362 CreateDirectValueParser(tab_title)); |
358 } | 363 } |
359 | 364 |
360 Error* Session::MouseMoveAndClick(const Point& location, | 365 Error* Session::MouseMoveAndClick(const Point& location, |
361 automation::MouseButton button) { | 366 automation::MouseButton button) { |
362 Error* error = NULL; | 367 Error* error = NULL; |
363 RunSessionTask(NewRunnableMethod( | 368 RunSessionTask(base::Bind( |
364 automation_.get(), | |
365 &Automation::MouseClick, | 369 &Automation::MouseClick, |
| 370 base::Unretained(automation_.get()), |
366 current_target_.window_id, | 371 current_target_.window_id, |
367 location, | 372 location, |
368 button, | 373 button, |
369 &error)); | 374 &error)); |
370 if (!error) | 375 if (!error) |
371 mouse_position_ = location; | 376 mouse_position_ = location; |
372 return error; | 377 return error; |
373 } | 378 } |
374 | 379 |
375 Error* Session::MouseMove(const Point& location) { | 380 Error* Session::MouseMove(const Point& location) { |
376 Error* error = NULL; | 381 Error* error = NULL; |
377 RunSessionTask(NewRunnableMethod( | 382 RunSessionTask(base::Bind( |
378 automation_.get(), | |
379 &Automation::MouseMove, | 383 &Automation::MouseMove, |
| 384 base::Unretained(automation_.get()), |
380 current_target_.window_id, | 385 current_target_.window_id, |
381 location, | 386 location, |
382 &error)); | 387 &error)); |
383 if (!error) | 388 if (!error) |
384 mouse_position_ = location; | 389 mouse_position_ = location; |
385 return error; | 390 return error; |
386 } | 391 } |
387 | 392 |
388 Error* Session::MouseDrag(const Point& start, | 393 Error* Session::MouseDrag(const Point& start, |
389 const Point& end) { | 394 const Point& end) { |
390 Error* error = NULL; | 395 Error* error = NULL; |
391 RunSessionTask(NewRunnableMethod( | 396 RunSessionTask(base::Bind( |
392 automation_.get(), | |
393 &Automation::MouseDrag, | 397 &Automation::MouseDrag, |
| 398 base::Unretained(automation_.get()), |
394 current_target_.window_id, | 399 current_target_.window_id, |
395 start, | 400 start, |
396 end, | 401 end, |
397 &error)); | 402 &error)); |
398 if (!error) | 403 if (!error) |
399 mouse_position_ = end; | 404 mouse_position_ = end; |
400 return error; | 405 return error; |
401 } | 406 } |
402 | 407 |
403 Error* Session::MouseClick(automation::MouseButton button) { | 408 Error* Session::MouseClick(automation::MouseButton button) { |
404 return MouseMoveAndClick(mouse_position_, button); | 409 return MouseMoveAndClick(mouse_position_, button); |
405 } | 410 } |
406 | 411 |
407 Error* Session::MouseButtonDown() { | 412 Error* Session::MouseButtonDown() { |
408 Error* error = NULL; | 413 Error* error = NULL; |
409 RunSessionTask(NewRunnableMethod( | 414 RunSessionTask(base::Bind( |
410 automation_.get(), | |
411 &Automation::MouseButtonDown, | 415 &Automation::MouseButtonDown, |
| 416 base::Unretained(automation_.get()), |
412 current_target_.window_id, | 417 current_target_.window_id, |
413 mouse_position_, | 418 mouse_position_, |
414 &error)); | 419 &error)); |
415 return error; | 420 return error; |
416 } | 421 } |
417 | 422 |
418 Error* Session::MouseButtonUp() { | 423 Error* Session::MouseButtonUp() { |
419 Error* error = NULL; | 424 Error* error = NULL; |
420 RunSessionTask(NewRunnableMethod( | 425 RunSessionTask(base::Bind( |
421 automation_.get(), | |
422 &Automation::MouseButtonUp, | 426 &Automation::MouseButtonUp, |
| 427 base::Unretained(automation_.get()), |
423 current_target_.window_id, | 428 current_target_.window_id, |
424 mouse_position_, | 429 mouse_position_, |
425 &error)); | 430 &error)); |
426 return error; | 431 return error; |
427 } | 432 } |
428 | 433 |
429 Error* Session::MouseDoubleClick() { | 434 Error* Session::MouseDoubleClick() { |
430 Error* error = NULL; | 435 Error* error = NULL; |
431 RunSessionTask(NewRunnableMethod( | 436 RunSessionTask(base::Bind( |
432 automation_.get(), | |
433 &Automation::MouseDoubleClick, | 437 &Automation::MouseDoubleClick, |
| 438 base::Unretained(automation_.get()), |
434 current_target_.window_id, | 439 current_target_.window_id, |
435 mouse_position_, | 440 mouse_position_, |
436 &error)); | 441 &error)); |
437 return error; | 442 return error; |
438 } | 443 } |
439 | 444 |
440 Error* Session::GetCookies(const std::string& url, ListValue** cookies) { | 445 Error* Session::GetCookies(const std::string& url, ListValue** cookies) { |
441 Error* error = NULL; | 446 Error* error = NULL; |
442 RunSessionTask(NewRunnableMethod( | 447 RunSessionTask(base::Bind( |
443 automation_.get(), | |
444 &Automation::GetCookies, | 448 &Automation::GetCookies, |
| 449 base::Unretained(automation_.get()), |
445 url, | 450 url, |
446 cookies, | 451 cookies, |
447 &error)); | 452 &error)); |
448 return error; | 453 return error; |
449 } | 454 } |
450 | 455 |
451 Error* Session::DeleteCookie(const std::string& url, | 456 Error* Session::DeleteCookie(const std::string& url, |
452 const std::string& cookie_name) { | 457 const std::string& cookie_name) { |
453 Error* error = NULL; | 458 Error* error = NULL; |
454 RunSessionTask(NewRunnableMethod( | 459 RunSessionTask(base::Bind( |
455 automation_.get(), | |
456 &Automation::DeleteCookie, | 460 &Automation::DeleteCookie, |
| 461 base::Unretained(automation_.get()), |
457 url, | 462 url, |
458 cookie_name, | 463 cookie_name, |
459 &error)); | 464 &error)); |
460 return error; | 465 return error; |
461 } | 466 } |
462 | 467 |
463 Error* Session::SetCookie(const std::string& url, | 468 Error* Session::SetCookie(const std::string& url, |
464 DictionaryValue* cookie_dict) { | 469 DictionaryValue* cookie_dict) { |
465 Error* error = NULL; | 470 Error* error = NULL; |
466 RunSessionTask(NewRunnableMethod( | 471 RunSessionTask(base::Bind( |
467 automation_.get(), | |
468 &Automation::SetCookie, | 472 &Automation::SetCookie, |
| 473 base::Unretained(automation_.get()), |
469 url, | 474 url, |
470 cookie_dict, | 475 cookie_dict, |
471 &error)); | 476 &error)); |
472 return error; | 477 return error; |
473 } | 478 } |
474 | 479 |
475 Error* Session::GetWindowIds(std::vector<int>* window_ids) { | 480 Error* Session::GetWindowIds(std::vector<int>* window_ids) { |
476 Error* error = NULL; | 481 Error* error = NULL; |
477 RunSessionTask(NewRunnableMethod( | 482 RunSessionTask(base::Bind( |
478 automation_.get(), | |
479 &Automation::GetTabIds, | 483 &Automation::GetTabIds, |
| 484 base::Unretained(automation_.get()), |
480 window_ids, | 485 window_ids, |
481 &error)); | 486 &error)); |
482 return error; | 487 return error; |
483 } | 488 } |
484 | 489 |
485 Error* Session::SwitchToWindow(const std::string& name) { | 490 Error* Session::SwitchToWindow(const std::string& name) { |
486 int switch_to_id = 0; | 491 int switch_to_id = 0; |
487 int name_no = 0; | 492 int name_no = 0; |
488 if (base::StringToInt(name, &name_no)) { | 493 if (base::StringToInt(name, &name_no)) { |
489 Error* error = NULL; | 494 Error* error = NULL; |
490 bool does_exist = false; | 495 bool does_exist = false; |
491 RunSessionTask(NewRunnableMethod( | 496 RunSessionTask(base::Bind( |
492 automation_.get(), | |
493 &Automation::DoesTabExist, | 497 &Automation::DoesTabExist, |
| 498 base::Unretained(automation_.get()), |
494 name_no, | 499 name_no, |
495 &does_exist, | 500 &does_exist, |
496 &error)); | 501 &error)); |
497 if (error) | 502 if (error) |
498 return error; | 503 return error; |
499 if (does_exist) | 504 if (does_exist) |
500 switch_to_id = name_no; | 505 switch_to_id = name_no; |
501 } | 506 } |
502 | 507 |
503 if (!switch_to_id) { | 508 if (!switch_to_id) { |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
623 } else if (error.get()) { | 628 } else if (error.get()) { |
624 return error.release(); | 629 return error.release(); |
625 } | 630 } |
626 frame_path = frame_path.Append(components[i]); | 631 frame_path = frame_path.Append(components[i]); |
627 } | 632 } |
628 return NULL; | 633 return NULL; |
629 } | 634 } |
630 | 635 |
631 Error* Session::CloseWindow() { | 636 Error* Session::CloseWindow() { |
632 Error* error = NULL; | 637 Error* error = NULL; |
633 RunSessionTask(NewRunnableMethod( | 638 RunSessionTask(base::Bind( |
634 automation_.get(), | |
635 &Automation::CloseTab, | 639 &Automation::CloseTab, |
| 640 base::Unretained(automation_.get()), |
636 current_target_.window_id, | 641 current_target_.window_id, |
637 &error)); | 642 &error)); |
638 | 643 |
639 if (!error) { | 644 if (!error) { |
640 std::vector<int> window_ids; | 645 std::vector<int> window_ids; |
641 scoped_ptr<Error> error(GetWindowIds(&window_ids)); | 646 scoped_ptr<Error> error(GetWindowIds(&window_ids)); |
642 if (error.get() || window_ids.empty()) { | 647 if (error.get() || window_ids.empty()) { |
643 // The automation connection will soon be closed, if not already, | 648 // The automation connection will soon be closed, if not already, |
644 // because we supposedly just closed the last window. Terminate the | 649 // because we supposedly just closed the last window. Terminate the |
645 // session. | 650 // session. |
646 // TODO(kkania): This will cause us problems if GetWindowIds fails for a | 651 // TODO(kkania): This will cause us problems if GetWindowIds fails for a |
647 // reason other than the channel is disconnected. Look into having | 652 // reason other than the channel is disconnected. Look into having |
648 // |GetWindowIds| tell us if it just closed the last window. | 653 // |GetWindowIds| tell us if it just closed the last window. |
649 Terminate(); | 654 Terminate(); |
650 } | 655 } |
651 } | 656 } |
652 return error; | 657 return error; |
653 } | 658 } |
654 | 659 |
655 Error* Session::GetAlertMessage(std::string* text) { | 660 Error* Session::GetAlertMessage(std::string* text) { |
656 Error* error = NULL; | 661 Error* error = NULL; |
657 RunSessionTask(NewRunnableMethod( | 662 RunSessionTask(base::Bind( |
658 automation_.get(), | |
659 &Automation::GetAppModalDialogMessage, | 663 &Automation::GetAppModalDialogMessage, |
| 664 base::Unretained(automation_.get()), |
660 text, | 665 text, |
661 &error)); | 666 &error)); |
662 return error; | 667 return error; |
663 } | 668 } |
664 | 669 |
665 Error* Session::SetAlertPromptText(const std::string& alert_prompt_text) { | 670 Error* Session::SetAlertPromptText(const std::string& alert_prompt_text) { |
666 std::string message_text; | 671 std::string message_text; |
667 // Only set the alert prompt text if an alert is actually active. | 672 // Only set the alert prompt text if an alert is actually active. |
668 Error* error = GetAlertMessage(&message_text); | 673 Error* error = GetAlertMessage(&message_text); |
669 if (!error) { | 674 if (!error) { |
670 has_alert_prompt_text_ = true; | 675 has_alert_prompt_text_ = true; |
671 alert_prompt_text_ = alert_prompt_text; | 676 alert_prompt_text_ = alert_prompt_text; |
672 } | 677 } |
673 return error; | 678 return error; |
674 } | 679 } |
675 | 680 |
676 Error* Session::AcceptOrDismissAlert(bool accept) { | 681 Error* Session::AcceptOrDismissAlert(bool accept) { |
677 Error* error = NULL; | 682 Error* error = NULL; |
678 if (accept && has_alert_prompt_text_) { | 683 if (accept && has_alert_prompt_text_) { |
679 RunSessionTask(NewRunnableMethod( | 684 RunSessionTask(base::Bind( |
680 automation_.get(), | |
681 &Automation::AcceptPromptAppModalDialog, | 685 &Automation::AcceptPromptAppModalDialog, |
| 686 base::Unretained(automation_.get()), |
682 alert_prompt_text_, | 687 alert_prompt_text_, |
683 &error)); | 688 &error)); |
684 } else { | 689 } else { |
685 RunSessionTask(NewRunnableMethod( | 690 RunSessionTask(base::Bind( |
686 automation_.get(), | |
687 &Automation::AcceptOrDismissAppModalDialog, | 691 &Automation::AcceptOrDismissAppModalDialog, |
| 692 base::Unretained(automation_.get()), |
688 accept, | 693 accept, |
689 &error)); | 694 &error)); |
690 } | 695 } |
691 has_alert_prompt_text_ = false; | 696 has_alert_prompt_text_ = false; |
692 return error; | 697 return error; |
693 } | 698 } |
694 | 699 |
695 std::string Session::GetBrowserVersion() { | 700 std::string Session::GetBrowserVersion() { |
696 std::string version; | 701 std::string version; |
697 RunSessionTask(NewRunnableMethod( | 702 RunSessionTask(base::Bind( |
698 automation_.get(), | |
699 &Automation::GetBrowserVersion, | 703 &Automation::GetBrowserVersion, |
| 704 base::Unretained(automation_.get()), |
700 &version)); | 705 &version)); |
701 return version; | 706 return version; |
702 } | 707 } |
703 | 708 |
704 Error* Session::CompareBrowserVersion(int client_build_no, | 709 Error* Session::CompareBrowserVersion(int client_build_no, |
705 int client_patch_no, | 710 int client_patch_no, |
706 bool* is_newer_or_equal) { | 711 bool* is_newer_or_equal) { |
707 std::string version = GetBrowserVersion(); | 712 std::string version = GetBrowserVersion(); |
708 std::vector<std::string> split_version; | 713 std::vector<std::string> split_version; |
709 base::SplitString(version, '.', &split_version); | 714 base::SplitString(version, '.', &split_version); |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
985 atoms::asString(atoms::GET_ATTRIBUTE), | 990 atoms::asString(atoms::GET_ATTRIBUTE), |
986 "getAttribute", | 991 "getAttribute", |
987 CreateListValueFrom(element, key), | 992 CreateListValueFrom(element, key), |
988 CreateDirectValueParser(value)); | 993 CreateDirectValueParser(value)); |
989 } | 994 } |
990 | 995 |
991 Error* Session::WaitForAllTabsToStopLoading() { | 996 Error* Session::WaitForAllTabsToStopLoading() { |
992 if (!automation_.get()) | 997 if (!automation_.get()) |
993 return NULL; | 998 return NULL; |
994 Error* error = NULL; | 999 Error* error = NULL; |
995 RunSessionTask(NewRunnableMethod( | 1000 RunSessionTask(base::Bind( |
996 automation_.get(), | |
997 &Automation::WaitForAllTabsToStopLoading, | 1001 &Automation::WaitForAllTabsToStopLoading, |
| 1002 base::Unretained(automation_.get()), |
998 &error)); | 1003 &error)); |
999 return error; | 1004 return error; |
1000 } | 1005 } |
1001 | 1006 |
1002 Error* Session::InstallExtensionDeprecated(const FilePath& path) { | 1007 Error* Session::InstallExtensionDeprecated(const FilePath& path) { |
1003 Error* error = NULL; | 1008 Error* error = NULL; |
1004 RunSessionTask(NewRunnableMethod( | 1009 RunSessionTask(base::Bind( |
1005 automation_.get(), | |
1006 &Automation::InstallExtensionDeprecated, | 1010 &Automation::InstallExtensionDeprecated, |
| 1011 base::Unretained(automation_.get()), |
1007 path, | 1012 path, |
1008 &error)); | 1013 &error)); |
1009 return error; | 1014 return error; |
1010 } | 1015 } |
1011 | 1016 |
1012 Error* Session::GetInstalledExtensions( | 1017 Error* Session::GetInstalledExtensions( |
1013 std::vector<std::string>* extension_ids) { | 1018 std::vector<std::string>* extension_ids) { |
1014 Error* error = NULL; | 1019 Error* error = NULL; |
1015 RunSessionTask(base::Bind( | 1020 RunSessionTask(base::Bind( |
1016 &Automation::GetInstalledExtensions, | 1021 &Automation::GetInstalledExtensions, |
1017 base::Unretained(automation_.get()), | 1022 base::Unretained(automation_.get()), |
1018 extension_ids, | 1023 extension_ids, |
1019 &error)); | 1024 &error)); |
1020 return error; | 1025 return error; |
1021 } | 1026 } |
1022 | 1027 |
1023 Error* Session::InstallExtension( | 1028 Error* Session::InstallExtension( |
1024 const FilePath& path, std::string* extension_id) { | 1029 const FilePath& path, std::string* extension_id) { |
1025 Error* error = NULL; | 1030 Error* error = NULL; |
1026 RunSessionTask(base::Bind( | 1031 RunSessionTask(base::Bind( |
1027 &Automation::InstallExtension, | 1032 &Automation::InstallExtension, |
1028 base::Unretained(automation_.get()), | 1033 base::Unretained(automation_.get()), |
1029 path, | 1034 path, |
1030 extension_id, | 1035 extension_id, |
1031 &error)); | 1036 &error)); |
1032 return error; | 1037 return error; |
1033 } | 1038 } |
1034 | 1039 |
| 1040 Error* Session::SetPreference( |
| 1041 const std::string& pref, |
| 1042 bool is_user_pref, |
| 1043 base::Value* value) { |
| 1044 Error* error = NULL; |
| 1045 if (is_user_pref) { |
| 1046 RunSessionTask(base::Bind( |
| 1047 &Automation::SetPreference, |
| 1048 base::Unretained(automation_.get()), |
| 1049 pref, |
| 1050 value, |
| 1051 &error)); |
| 1052 } else { |
| 1053 RunSessionTask(base::Bind( |
| 1054 &Automation::SetLocalStatePreference, |
| 1055 base::Unretained(automation_.get()), |
| 1056 pref, |
| 1057 value, |
| 1058 &error)); |
| 1059 } |
| 1060 return error; |
| 1061 } |
| 1062 |
1035 const std::string& Session::id() const { | 1063 const std::string& Session::id() const { |
1036 return id_; | 1064 return id_; |
1037 } | 1065 } |
1038 | 1066 |
1039 const FrameId& Session::current_target() const { | 1067 const FrameId& Session::current_target() const { |
1040 return current_target_; | 1068 return current_target_; |
1041 } | 1069 } |
1042 | 1070 |
1043 void Session::set_async_script_timeout(int timeout_ms) { | 1071 void Session::set_async_script_timeout(int timeout_ms) { |
1044 async_script_timeout_ = timeout_ms; | 1072 async_script_timeout_ = timeout_ms; |
(...skipping 14 matching lines...) Expand all Loading... |
1059 const Point& Session::get_mouse_position() const { | 1087 const Point& Session::get_mouse_position() const { |
1060 return mouse_position_; | 1088 return mouse_position_; |
1061 } | 1089 } |
1062 | 1090 |
1063 const Session::Options& Session::options() const { | 1091 const Session::Options& Session::options() const { |
1064 return options_; | 1092 return options_; |
1065 } | 1093 } |
1066 | 1094 |
1067 void Session::RunSessionTask(Task* task) { | 1095 void Session::RunSessionTask(Task* task) { |
1068 base::WaitableEvent done_event(false, false); | 1096 base::WaitableEvent done_event(false, false); |
1069 thread_.message_loop_proxy()->PostTask(FROM_HERE, NewRunnableMethod( | 1097 thread_.message_loop_proxy()->PostTask(FROM_HERE, base::Bind( |
1070 this, | |
1071 &Session::RunSessionTaskOnSessionThread, | 1098 &Session::RunSessionTaskOnSessionThread, |
| 1099 base::Unretained(this), |
1072 task, | 1100 task, |
1073 &done_event)); | 1101 &done_event)); |
1074 done_event.Wait(); | 1102 done_event.Wait(); |
1075 } | 1103 } |
1076 | 1104 |
1077 void Session::RunSessionTaskOnSessionThread(Task* task, | 1105 void Session::RunSessionTaskOnSessionThread(Task* task, |
1078 base::WaitableEvent* done_event) { | 1106 base::WaitableEvent* done_event) { |
1079 task->Run(); | 1107 task->Run(); |
1080 delete task; | 1108 delete task; |
1081 done_event->Signal(); | 1109 done_event->Signal(); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1119 if (automation_.get()) | 1147 if (automation_.get()) |
1120 automation_->Terminate(); | 1148 automation_->Terminate(); |
1121 automation_.reset(); | 1149 automation_.reset(); |
1122 } | 1150 } |
1123 | 1151 |
1124 Error* Session::ExecuteScriptAndParseValue(const FrameId& frame_id, | 1152 Error* Session::ExecuteScriptAndParseValue(const FrameId& frame_id, |
1125 const std::string& script, | 1153 const std::string& script, |
1126 Value** script_result) { | 1154 Value** script_result) { |
1127 std::string response_json; | 1155 std::string response_json; |
1128 Error* error = NULL; | 1156 Error* error = NULL; |
1129 RunSessionTask(NewRunnableMethod( | 1157 RunSessionTask(base::Bind( |
1130 automation_.get(), | |
1131 &Automation::ExecuteScript, | 1158 &Automation::ExecuteScript, |
| 1159 base::Unretained(automation_.get()), |
1132 frame_id.window_id, | 1160 frame_id.window_id, |
1133 frame_id.frame_path, | 1161 frame_id.frame_path, |
1134 script, | 1162 script, |
1135 &response_json, | 1163 &response_json, |
1136 &error)); | 1164 &error)); |
1137 if (error) | 1165 if (error) |
1138 return error; | 1166 return error; |
1139 | 1167 |
1140 scoped_ptr<Value> value(base::JSONReader::ReadAndReturnError( | 1168 scoped_ptr<Value> value(base::JSONReader::ReadAndReturnError( |
1141 response_json, true, NULL, NULL)); | 1169 response_json, true, NULL, NULL)); |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1438 | 1466 |
1439 Error* Session::GetScreenShot(std::string* png) { | 1467 Error* Session::GetScreenShot(std::string* png) { |
1440 Error* error = NULL; | 1468 Error* error = NULL; |
1441 ScopedTempDir screenshots_dir; | 1469 ScopedTempDir screenshots_dir; |
1442 if (!screenshots_dir.CreateUniqueTempDir()) { | 1470 if (!screenshots_dir.CreateUniqueTempDir()) { |
1443 return new Error(kUnknownError, | 1471 return new Error(kUnknownError, |
1444 "Could not create temp directory for screenshot"); | 1472 "Could not create temp directory for screenshot"); |
1445 } | 1473 } |
1446 | 1474 |
1447 FilePath path = screenshots_dir.path().AppendASCII("screen"); | 1475 FilePath path = screenshots_dir.path().AppendASCII("screen"); |
1448 RunSessionTask(NewRunnableMethod( | 1476 RunSessionTask(base::Bind( |
1449 automation_.get(), | |
1450 &Automation::CaptureEntirePageAsPNG, | 1477 &Automation::CaptureEntirePageAsPNG, |
| 1478 base::Unretained(automation_.get()), |
1451 current_target_.window_id, | 1479 current_target_.window_id, |
1452 path, | 1480 path, |
1453 &error)); | 1481 &error)); |
1454 if (error) | 1482 if (error) |
1455 return error; | 1483 return error; |
1456 if (!file_util::ReadFileToString(path, png)) | 1484 if (!file_util::ReadFileToString(path, png)) |
1457 return new Error(kUnknownError, "Could not read screenshot file"); | 1485 return new Error(kUnknownError, "Could not read screenshot file"); |
1458 return NULL; | 1486 return NULL; |
1459 } | 1487 } |
1460 | 1488 |
1461 Error* Session::GetBrowserConnectionState(bool* online) { | 1489 Error* Session::GetBrowserConnectionState(bool* online) { |
1462 return ExecuteScriptAndParse( | 1490 return ExecuteScriptAndParse( |
1463 current_target_, | 1491 current_target_, |
1464 atoms::asString(atoms::IS_ONLINE), | 1492 atoms::asString(atoms::IS_ONLINE), |
1465 "isOnline", | 1493 "isOnline", |
1466 new ListValue(), | 1494 new ListValue(), |
1467 CreateDirectValueParser(online)); | 1495 CreateDirectValueParser(online)); |
1468 } | 1496 } |
1469 | 1497 |
1470 Error* Session::GetAppCacheStatus(int* status) { | 1498 Error* Session::GetAppCacheStatus(int* status) { |
1471 return ExecuteScriptAndParse( | 1499 return ExecuteScriptAndParse( |
1472 current_target_, | 1500 current_target_, |
1473 atoms::asString(atoms::GET_APPCACHE_STATUS), | 1501 atoms::asString(atoms::GET_APPCACHE_STATUS), |
1474 "getAppcacheStatus", | 1502 "getAppcacheStatus", |
1475 new ListValue(), | 1503 new ListValue(), |
1476 CreateDirectValueParser(status)); | 1504 CreateDirectValueParser(status)); |
1477 } | 1505 } |
1478 | 1506 |
| 1507 Error* Session::PostBrowserStartInit() { |
| 1508 Error* error = NULL; |
| 1509 if (!options_.no_website_testing_defaults) |
| 1510 error = InitForWebsiteTesting(); |
| 1511 if (error) |
| 1512 return error; |
| 1513 |
| 1514 // Install extensions. |
| 1515 for (size_t i = 0; i < options_.extensions.size(); ++i) { |
| 1516 error = InstallExtensionDeprecated(options_.extensions[i]); |
| 1517 if (error) |
| 1518 return error; |
| 1519 } |
| 1520 return NULL; |
| 1521 } |
| 1522 |
| 1523 Error* Session::InitForWebsiteTesting() { |
| 1524 // Disable checking for SSL certificate revocation. |
| 1525 Error* error = SetPreference( |
| 1526 "ssl.rev_checking.enabled", |
| 1527 false /* is_user_pref */, |
| 1528 Value::CreateBooleanValue(false)); |
| 1529 if (error) |
| 1530 return error; |
| 1531 |
| 1532 // Allow certain content by default. |
| 1533 const int kAllowContent = 1; |
| 1534 DictionaryValue* default_content_settings = new DictionaryValue(); |
| 1535 default_content_settings->SetInteger("geolocation", kAllowContent); |
| 1536 default_content_settings->SetInteger("notifications", kAllowContent); |
| 1537 return SetPreference( |
| 1538 "profile.default_content_settings", |
| 1539 true /* is_user_pref */, |
| 1540 default_content_settings); |
| 1541 } |
| 1542 |
1479 } // namespace webdriver | 1543 } // namespace webdriver |
OLD | NEW |