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.h" | 5 #include "chrome/test/webdriver/session.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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 screenshot_on_error_(false), | 63 screenshot_on_error_(false), |
64 use_native_events_(false), | 64 use_native_events_(false), |
65 has_alert_prompt_text_(false) { | 65 has_alert_prompt_text_(false) { |
66 SessionManager::GetInstance()->Add(this); | 66 SessionManager::GetInstance()->Add(this); |
67 } | 67 } |
68 | 68 |
69 Session::~Session() { | 69 Session::~Session() { |
70 SessionManager::GetInstance()->Remove(id_); | 70 SessionManager::GetInstance()->Remove(id_); |
71 } | 71 } |
72 | 72 |
73 Error* Session::Init(const FilePath& browser_exe, | 73 Error* Session::Init(const Automation::InitOptions& options) { |
74 const FilePath& user_data_dir, | |
75 const CommandLine& options) { | |
76 if (!thread_.Start()) { | 74 if (!thread_.Start()) { |
77 delete this; | 75 delete this; |
78 return new Error(kUnknownError, "Cannot start session thread"); | 76 return new Error(kUnknownError, "Cannot start session thread"); |
79 } | 77 } |
80 | 78 |
81 Error* error = NULL; | 79 Error* error = NULL; |
82 RunSessionTask(NewRunnableMethod( | 80 RunSessionTask(NewRunnableMethod( |
83 this, | 81 this, |
84 &Session::InitOnSessionThread, | 82 &Session::InitOnSessionThread, |
85 browser_exe, | |
86 user_data_dir, | |
87 options, | 83 options, |
88 &error)); | 84 &error)); |
89 if (error) | 85 if (error) |
90 Terminate(); | 86 Terminate(); |
91 return error; | 87 return error; |
92 } | 88 } |
93 | 89 |
94 void Session::Terminate() { | 90 void Session::Terminate() { |
95 RunSessionTask(NewRunnableMethod( | 91 RunSessionTask(NewRunnableMethod( |
96 this, | 92 this, |
(...skipping 961 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1058 done_event.Wait(); | 1054 done_event.Wait(); |
1059 } | 1055 } |
1060 | 1056 |
1061 void Session::RunSessionTaskOnSessionThread(Task* task, | 1057 void Session::RunSessionTaskOnSessionThread(Task* task, |
1062 base::WaitableEvent* done_event) { | 1058 base::WaitableEvent* done_event) { |
1063 task->Run(); | 1059 task->Run(); |
1064 delete task; | 1060 delete task; |
1065 done_event->Signal(); | 1061 done_event->Signal(); |
1066 } | 1062 } |
1067 | 1063 |
1068 void Session::InitOnSessionThread(const FilePath& browser_exe, | 1064 |
1069 const FilePath& user_data_dir, | 1065 void Session::InitOnSessionThread(const Automation::InitOptions& options, |
1070 const CommandLine& options, | |
1071 Error** error) { | 1066 Error** error) { |
1072 automation_.reset(new Automation()); | 1067 automation_.reset(new Automation()); |
1073 if (browser_exe.empty()) { | 1068 automation_->Init(options, error); |
1074 automation_->Init(options, user_data_dir, error); | |
1075 } else { | |
1076 automation_->InitWithBrowserPath( | |
1077 browser_exe, user_data_dir, options, error); | |
1078 } | |
1079 | |
1080 if (*error) | 1069 if (*error) |
1081 return; | 1070 return; |
1082 | 1071 |
1083 std::vector<int> tab_ids; | 1072 std::vector<int> tab_ids; |
1084 automation_->GetTabIds(&tab_ids, error); | 1073 automation_->GetTabIds(&tab_ids, error); |
1085 if (*error) | 1074 if (*error) |
1086 return; | 1075 return; |
1087 if (tab_ids.empty()) { | 1076 if (tab_ids.empty()) { |
1088 *error = new Error(kUnknownError, "No tab ids after initialization"); | 1077 *error = new Error(kUnknownError, "No tab ids after initialization"); |
1089 return; | 1078 return; |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1432 path, | 1421 path, |
1433 &error)); | 1422 &error)); |
1434 if (error) | 1423 if (error) |
1435 return error; | 1424 return error; |
1436 if (!file_util::ReadFileToString(path, png)) | 1425 if (!file_util::ReadFileToString(path, png)) |
1437 return new Error(kUnknownError, "Could not read screenshot file"); | 1426 return new Error(kUnknownError, "Could not read screenshot file"); |
1438 return NULL; | 1427 return NULL; |
1439 } | 1428 } |
1440 | 1429 |
1441 } // namespace webdriver | 1430 } // namespace webdriver |
OLD | NEW |