| 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" |
| 11 #include "base/callback.h" |
| 10 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 11 #include "base/file_path.h" | 13 #include "base/file_path.h" |
| 12 #include "base/file_util.h" | 14 #include "base/file_util.h" |
| 13 #include "base/json/json_reader.h" | 15 #include "base/json/json_reader.h" |
| 14 #include "base/json/json_writer.h" | 16 #include "base/json/json_writer.h" |
| 15 #include "base/logging.h" | 17 #include "base/logging.h" |
| 16 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
| 17 #include "base/message_loop_proxy.h" | 19 #include "base/message_loop_proxy.h" |
| 18 #include "base/process.h" | 20 #include "base/process.h" |
| 19 #include "base/process_util.h" | 21 #include "base/process_util.h" |
| (...skipping 970 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 990 if (!automation_.get()) | 992 if (!automation_.get()) |
| 991 return NULL; | 993 return NULL; |
| 992 Error* error = NULL; | 994 Error* error = NULL; |
| 993 RunSessionTask(NewRunnableMethod( | 995 RunSessionTask(NewRunnableMethod( |
| 994 automation_.get(), | 996 automation_.get(), |
| 995 &Automation::WaitForAllTabsToStopLoading, | 997 &Automation::WaitForAllTabsToStopLoading, |
| 996 &error)); | 998 &error)); |
| 997 return error; | 999 return error; |
| 998 } | 1000 } |
| 999 | 1001 |
| 1000 Error* Session::InstallExtension(const FilePath& path) { | 1002 Error* Session::InstallExtensionDeprecated(const FilePath& path) { |
| 1001 Error* error = NULL; | 1003 Error* error = NULL; |
| 1002 RunSessionTask(NewRunnableMethod( | 1004 RunSessionTask(NewRunnableMethod( |
| 1003 automation_.get(), | 1005 automation_.get(), |
| 1004 &Automation::InstallExtension, | 1006 &Automation::InstallExtensionDeprecated, |
| 1005 path, | 1007 path, |
| 1006 &error)); | 1008 &error)); |
| 1007 return error; | 1009 return error; |
| 1008 } | 1010 } |
| 1011 |
| 1012 Error* Session::GetInstalledExtensions( |
| 1013 std::vector<std::string>* extension_ids) { |
| 1014 Error* error = NULL; |
| 1015 RunSessionTask(base::Bind( |
| 1016 &Automation::GetInstalledExtensions, |
| 1017 base::Unretained(automation_.get()), |
| 1018 extension_ids, |
| 1019 &error)); |
| 1020 return error; |
| 1021 } |
| 1022 |
| 1023 Error* Session::InstallExtension( |
| 1024 const FilePath& path, std::string* extension_id) { |
| 1025 Error* error = NULL; |
| 1026 RunSessionTask(base::Bind( |
| 1027 &Automation::InstallExtension, |
| 1028 base::Unretained(automation_.get()), |
| 1029 path, |
| 1030 extension_id, |
| 1031 &error)); |
| 1032 return error; |
| 1033 } |
| 1009 | 1034 |
| 1010 const std::string& Session::id() const { | 1035 const std::string& Session::id() const { |
| 1011 return id_; | 1036 return id_; |
| 1012 } | 1037 } |
| 1013 | 1038 |
| 1014 const FrameId& Session::current_target() const { | 1039 const FrameId& Session::current_target() const { |
| 1015 return current_target_; | 1040 return current_target_; |
| 1016 } | 1041 } |
| 1017 | 1042 |
| 1018 void Session::set_async_script_timeout(int timeout_ms) { | 1043 void Session::set_async_script_timeout(int timeout_ms) { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1049 done_event.Wait(); | 1074 done_event.Wait(); |
| 1050 } | 1075 } |
| 1051 | 1076 |
| 1052 void Session::RunSessionTaskOnSessionThread(Task* task, | 1077 void Session::RunSessionTaskOnSessionThread(Task* task, |
| 1053 base::WaitableEvent* done_event) { | 1078 base::WaitableEvent* done_event) { |
| 1054 task->Run(); | 1079 task->Run(); |
| 1055 delete task; | 1080 delete task; |
| 1056 done_event->Signal(); | 1081 done_event->Signal(); |
| 1057 } | 1082 } |
| 1058 | 1083 |
| 1084 void Session::RunSessionTask(const base::Closure& task) { |
| 1085 base::WaitableEvent done_event(false, false); |
| 1086 thread_.message_loop_proxy()->PostTask(FROM_HERE, base::Bind( |
| 1087 &Session::RunClosureOnSessionThread, |
| 1088 base::Unretained(this), |
| 1089 task, |
| 1090 &done_event)); |
| 1091 done_event.Wait(); |
| 1092 } |
| 1093 |
| 1094 void Session::RunClosureOnSessionThread(const base::Closure& task, |
| 1095 base::WaitableEvent* done_event) { |
| 1096 task.Run(); |
| 1097 done_event->Signal(); |
| 1098 } |
| 1059 | 1099 |
| 1060 void Session::InitOnSessionThread(const Automation::BrowserOptions& options, | 1100 void Session::InitOnSessionThread(const Automation::BrowserOptions& options, |
| 1061 Error** error) { | 1101 Error** error) { |
| 1062 automation_.reset(new Automation()); | 1102 automation_.reset(new Automation()); |
| 1063 automation_->Init(options, error); | 1103 automation_->Init(options, error); |
| 1064 if (*error) | 1104 if (*error) |
| 1065 return; | 1105 return; |
| 1066 | 1106 |
| 1067 std::vector<int> tab_ids; | 1107 std::vector<int> tab_ids; |
| 1068 automation_->GetTabIds(&tab_ids, error); | 1108 automation_->GetTabIds(&tab_ids, error); |
| (...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1430 Error* Session::GetAppCacheStatus(int* status) { | 1470 Error* Session::GetAppCacheStatus(int* status) { |
| 1431 return ExecuteScriptAndParse( | 1471 return ExecuteScriptAndParse( |
| 1432 current_target_, | 1472 current_target_, |
| 1433 atoms::asString(atoms::GET_APPCACHE_STATUS), | 1473 atoms::asString(atoms::GET_APPCACHE_STATUS), |
| 1434 "getAppcacheStatus", | 1474 "getAppcacheStatus", |
| 1435 new ListValue(), | 1475 new ListValue(), |
| 1436 CreateDirectValueParser(status)); | 1476 CreateDirectValueParser(status)); |
| 1437 } | 1477 } |
| 1438 | 1478 |
| 1439 } // namespace webdriver | 1479 } // namespace webdriver |
| OLD | NEW |