| 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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 implicit_wait_(0), | 70 implicit_wait_(0), |
| 71 has_alert_prompt_text_(false), | 71 has_alert_prompt_text_(false), |
| 72 options_(options) { | 72 options_(options) { |
| 73 SessionManager::GetInstance()->Add(this); | 73 SessionManager::GetInstance()->Add(this); |
| 74 } | 74 } |
| 75 | 75 |
| 76 Session::~Session() { | 76 Session::~Session() { |
| 77 SessionManager::GetInstance()->Remove(id_); | 77 SessionManager::GetInstance()->Remove(id_); |
| 78 } | 78 } |
| 79 | 79 |
| 80 Error* Session::Init(const FilePath& browser_exe, | 80 Error* Session::Init(const Automation::BrowserOptions& options) { |
| 81 const FilePath& user_data_dir, | |
| 82 const CommandLine& options) { | |
| 83 if (!thread_.Start()) { | 81 if (!thread_.Start()) { |
| 84 delete this; | 82 delete this; |
| 85 return new Error(kUnknownError, "Cannot start session thread"); | 83 return new Error(kUnknownError, "Cannot start session thread"); |
| 86 } | 84 } |
| 87 | 85 |
| 88 Error* error = NULL; | 86 Error* error = NULL; |
| 89 RunSessionTask(NewRunnableMethod( | 87 RunSessionTask(NewRunnableMethod( |
| 90 this, | 88 this, |
| 91 &Session::InitOnSessionThread, | 89 &Session::InitOnSessionThread, |
| 92 browser_exe, | |
| 93 user_data_dir, | |
| 94 options, | 90 options, |
| 95 &error)); | 91 &error)); |
| 96 if (error) | 92 if (error) |
| 97 Terminate(); | 93 Terminate(); |
| 98 return error; | 94 return error; |
| 99 } | 95 } |
| 100 | 96 |
| 101 Error* Session::BeforeExecuteCommand() { | 97 Error* Session::BeforeExecuteCommand() { |
| 102 Error* error = NULL; | 98 Error* error = NULL; |
| 103 if (!options_.load_async) { | 99 if (!options_.load_async) { |
| (...skipping 1013 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1117 done_event.Wait(); | 1113 done_event.Wait(); |
| 1118 } | 1114 } |
| 1119 | 1115 |
| 1120 void Session::RunSessionTaskOnSessionThread(Task* task, | 1116 void Session::RunSessionTaskOnSessionThread(Task* task, |
| 1121 base::WaitableEvent* done_event) { | 1117 base::WaitableEvent* done_event) { |
| 1122 task->Run(); | 1118 task->Run(); |
| 1123 delete task; | 1119 delete task; |
| 1124 done_event->Signal(); | 1120 done_event->Signal(); |
| 1125 } | 1121 } |
| 1126 | 1122 |
| 1127 void Session::InitOnSessionThread(const FilePath& browser_exe, | 1123 |
| 1128 const FilePath& user_data_dir, | 1124 void Session::InitOnSessionThread(const Automation::BrowserOptions& options, |
| 1129 const CommandLine& options, | |
| 1130 Error** error) { | 1125 Error** error) { |
| 1131 automation_.reset(new Automation()); | 1126 automation_.reset(new Automation()); |
| 1132 if (browser_exe.empty()) { | 1127 automation_->Init(options, error); |
| 1133 automation_->Init(options, user_data_dir, error); | |
| 1134 } else { | |
| 1135 automation_->InitWithBrowserPath( | |
| 1136 browser_exe, user_data_dir, options, error); | |
| 1137 } | |
| 1138 | |
| 1139 if (*error) | 1128 if (*error) |
| 1140 return; | 1129 return; |
| 1141 | 1130 |
| 1142 std::vector<int> tab_ids; | 1131 std::vector<int> tab_ids; |
| 1143 automation_->GetTabIds(&tab_ids, error); | 1132 automation_->GetTabIds(&tab_ids, error); |
| 1144 if (*error) | 1133 if (*error) |
| 1145 return; | 1134 return; |
| 1146 if (tab_ids.empty()) { | 1135 if (tab_ids.empty()) { |
| 1147 *error = new Error(kUnknownError, "No tab ids after initialization"); | 1136 *error = new Error(kUnknownError, "No tab ids after initialization"); |
| 1148 return; | 1137 return; |
| (...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1527 if (error) | 1516 if (error) |
| 1528 return error; | 1517 return error; |
| 1529 if (!value->GetAsInteger(status)) | 1518 if (!value->GetAsInteger(status)) |
| 1530 return new Error(kUnknownError, | 1519 return new Error(kUnknownError, |
| 1531 "GET_APPCACHE_STATUS script returned non-integer: " + | 1520 "GET_APPCACHE_STATUS script returned non-integer: " + |
| 1532 JsonStringify(value.get())); | 1521 JsonStringify(value.get())); |
| 1533 return NULL; | 1522 return NULL; |
| 1534 } | 1523 } |
| 1535 | 1524 |
| 1536 } // namespace webdriver | 1525 } // namespace webdriver |
| OLD | NEW |