OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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" |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/file_path.h" | 13 #include "base/file_path.h" |
14 #include "base/file_util.h" | 14 #include "base/file_util.h" |
15 #include "base/json/json_reader.h" | 15 #include "base/json/json_reader.h" |
16 #include "base/json/json_writer.h" | 16 #include "base/json/json_writer.h" |
17 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
18 #include "base/message_loop_proxy.h" | 18 #include "base/message_loop_proxy.h" |
19 #include "base/process.h" | 19 #include "base/process.h" |
20 #include "base/process_util.h" | 20 #include "base/process_util.h" |
21 #include "base/scoped_temp_dir.h" | |
22 #include "base/string_number_conversions.h" | 21 #include "base/string_number_conversions.h" |
23 #include "base/string_split.h" | 22 #include "base/string_split.h" |
24 #include "base/string_util.h" | 23 #include "base/string_util.h" |
25 #include "base/stringprintf.h" | 24 #include "base/stringprintf.h" |
26 #include "base/synchronization/waitable_event.h" | 25 #include "base/synchronization/waitable_event.h" |
27 #include "base/test/test_timeouts.h" | 26 #include "base/test/test_timeouts.h" |
28 #include "base/threading/platform_thread.h" | 27 #include "base/threading/platform_thread.h" |
29 #include "base/time.h" | 28 #include "base/time.h" |
30 #include "base/utf_string_conversions.h" | 29 #include "base/utf_string_conversions.h" |
31 #include "base/values.h" | 30 #include "base/values.h" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 | 80 |
82 Session::~Session() { | 81 Session::~Session() { |
83 SessionManager::GetInstance()->Remove(id_); | 82 SessionManager::GetInstance()->Remove(id_); |
84 } | 83 } |
85 | 84 |
86 Error* Session::Init(const DictionaryValue* capabilities_dict) { | 85 Error* Session::Init(const DictionaryValue* capabilities_dict) { |
87 if (!thread_.Start()) { | 86 if (!thread_.Start()) { |
88 delete this; | 87 delete this; |
89 return new Error(kUnknownError, "Cannot start session thread"); | 88 return new Error(kUnknownError, "Cannot start session thread"); |
90 } | 89 } |
91 ScopedTempDir temp_dir; | 90 if (!temp_dir_.CreateUniqueTempDir()) { |
92 if (!temp_dir.CreateUniqueTempDir()) { | |
93 delete this; | 91 delete this; |
94 return new Error( | 92 return new Error( |
95 kUnknownError, "Unable to create temp directory for unpacking"); | 93 kUnknownError, "Unable to create temp directory for unpacking"); |
96 } | 94 } |
97 logger_.Log(kFineLogLevel, | 95 logger_.Log(kFineLogLevel, |
98 "Initializing session with capabilities " + | 96 "Initializing session with capabilities " + |
99 JsonStringifyForDisplay(capabilities_dict)); | 97 JsonStringifyForDisplay(capabilities_dict)); |
100 CapabilitiesParser parser( | 98 CapabilitiesParser parser( |
101 capabilities_dict, temp_dir.path(), logger_, &capabilities_); | 99 capabilities_dict, temp_dir_.path(), logger_, &capabilities_); |
102 Error* error = parser.Parse(); | 100 Error* error = parser.Parse(); |
103 if (error) { | 101 if (error) { |
104 delete this; | 102 delete this; |
105 return error; | 103 return error; |
106 } | 104 } |
107 logger_.set_min_log_level(capabilities_.log_levels[LogType::kDriver]); | 105 logger_.set_min_log_level(capabilities_.log_levels[LogType::kDriver]); |
108 | 106 |
109 Automation::BrowserOptions browser_options; | 107 Automation::BrowserOptions browser_options; |
110 browser_options.command = capabilities_.command; | 108 browser_options.command = capabilities_.command; |
111 browser_options.channel_id = capabilities_.channel; | 109 browser_options.channel_id = capabilities_.channel; |
(...skipping 1286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1398 } | 1396 } |
1399 | 1397 |
1400 const Point& Session::get_mouse_position() const { | 1398 const Point& Session::get_mouse_position() const { |
1401 return mouse_position_; | 1399 return mouse_position_; |
1402 } | 1400 } |
1403 | 1401 |
1404 const Logger& Session::logger() const { | 1402 const Logger& Session::logger() const { |
1405 return logger_; | 1403 return logger_; |
1406 } | 1404 } |
1407 | 1405 |
| 1406 const FilePath& Session::temp_dir() const { |
| 1407 return temp_dir_.path(); |
| 1408 } |
| 1409 |
1408 const Capabilities& Session::capabilities() const { | 1410 const Capabilities& Session::capabilities() const { |
1409 return capabilities_; | 1411 return capabilities_; |
1410 } | 1412 } |
1411 | 1413 |
1412 void Session::RunSessionTask(const base::Closure& task) { | 1414 void Session::RunSessionTask(const base::Closure& task) { |
1413 base::WaitableEvent done_event(false, false); | 1415 base::WaitableEvent done_event(false, false); |
1414 thread_.message_loop_proxy()->PostTask(FROM_HERE, base::Bind( | 1416 thread_.message_loop_proxy()->PostTask(FROM_HERE, base::Bind( |
1415 &Session::RunClosureOnSessionThread, | 1417 &Session::RunClosureOnSessionThread, |
1416 base::Unretained(this), | 1418 base::Unretained(this), |
1417 task, | 1419 task, |
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1857 DictionaryValue* default_content_settings = new DictionaryValue(); | 1859 DictionaryValue* default_content_settings = new DictionaryValue(); |
1858 default_content_settings->SetInteger("geolocation", kAllowContent); | 1860 default_content_settings->SetInteger("geolocation", kAllowContent); |
1859 default_content_settings->SetInteger("notifications", kAllowContent); | 1861 default_content_settings->SetInteger("notifications", kAllowContent); |
1860 return SetPreference( | 1862 return SetPreference( |
1861 "profile.default_content_settings", | 1863 "profile.default_content_settings", |
1862 true /* is_user_pref */, | 1864 true /* is_user_pref */, |
1863 default_content_settings); | 1865 default_content_settings); |
1864 } | 1866 } |
1865 | 1867 |
1866 } // namespace webdriver | 1868 } // namespace webdriver |
OLD | NEW |