| 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/chromedriver/logging.h" | 5 #include "chrome/test/chromedriver/logging.h" |
| 6 | 6 |
| 7 #include <stdio.h> | 7 #include <stdio.h> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/json/json_reader.h" | 11 #include "base/json/json_reader.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
| 14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
| 15 #include "chrome/test/chromedriver/capabilities.h" | 15 #include "chrome/test/chromedriver/capabilities.h" |
| 16 #include "chrome/test/chromedriver/chrome/console_logger.h" | 16 #include "chrome/test/chromedriver/chrome/console_logger.h" |
| 17 #include "chrome/test/chromedriver/chrome/performance_logger.h" |
| 17 #include "chrome/test/chromedriver/chrome/status.h" | 18 #include "chrome/test/chromedriver/chrome/status.h" |
| 18 #include "chrome/test/chromedriver/command_listener_proxy.h" | |
| 19 #include "chrome/test/chromedriver/performance_logger.h" | |
| 20 #include "chrome/test/chromedriver/session.h" | 19 #include "chrome/test/chromedriver/session.h" |
| 21 | 20 |
| 22 #if defined(OS_POSIX) | 21 #if defined(OS_POSIX) |
| 23 #include <fcntl.h> | 22 #include <fcntl.h> |
| 24 #include <unistd.h> | 23 #include <unistd.h> |
| 25 #endif | 24 #endif |
| 26 | 25 |
| 27 | 26 |
| 28 namespace { | 27 namespace { |
| 29 | 28 |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 false); // enable_tickcount | 232 false); // enable_tickcount |
| 234 logging::SetLogMessageHandler(&HandleLogMessage); | 233 logging::SetLogMessageHandler(&HandleLogMessage); |
| 235 | 234 |
| 236 logging::LoggingSettings logging_settings; | 235 logging::LoggingSettings logging_settings; |
| 237 logging_settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; | 236 logging_settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; |
| 238 return logging::InitLogging(logging_settings); | 237 return logging::InitLogging(logging_settings); |
| 239 } | 238 } |
| 240 | 239 |
| 241 Status CreateLogs(const Capabilities& capabilities, | 240 Status CreateLogs(const Capabilities& capabilities, |
| 242 ScopedVector<WebDriverLog>* out_logs, | 241 ScopedVector<WebDriverLog>* out_logs, |
| 243 ScopedVector<DevToolsEventListener>* out_devtools_listeners, | 242 ScopedVector<DevToolsEventListener>* out_listeners) { |
| 244 ScopedVector<CommandListener>* out_command_listeners) { | |
| 245 ScopedVector<WebDriverLog> logs; | 243 ScopedVector<WebDriverLog> logs; |
| 246 ScopedVector<DevToolsEventListener> devtools_listeners; | 244 ScopedVector<DevToolsEventListener> listeners; |
| 247 ScopedVector<CommandListener> command_listeners; | |
| 248 Log::Level browser_log_level = Log::kWarning; | 245 Log::Level browser_log_level = Log::kWarning; |
| 249 const LoggingPrefs& prefs = capabilities.logging_prefs; | 246 const LoggingPrefs& prefs = capabilities.logging_prefs; |
| 250 | 247 |
| 251 for (LoggingPrefs::const_iterator iter = prefs.begin(); | 248 for (LoggingPrefs::const_iterator iter = prefs.begin(); |
| 252 iter != prefs.end(); | 249 iter != prefs.end(); |
| 253 ++iter) { | 250 ++iter) { |
| 254 std::string type = iter->first; | 251 std::string type = iter->first; |
| 255 Log::Level level = iter->second; | 252 Log::Level level = iter->second; |
| 256 if (type == WebDriverLog::kPerformanceType) { | 253 if (type == WebDriverLog::kPerformanceType) { |
| 257 if (level != Log::kOff) { | 254 if (level != Log::kOff) { |
| 258 WebDriverLog* log = new WebDriverLog(type, Log::kAll); | 255 WebDriverLog* log = new WebDriverLog(type, Log::kAll); |
| 259 logs.push_back(log); | 256 logs.push_back(log); |
| 260 PerformanceLogger* perf_log = new PerformanceLogger(log); | 257 listeners.push_back(new PerformanceLogger(log)); |
| 261 // We use a proxy for |perf_log|'s |CommandListener| interface. | |
| 262 // session->chrome will own |perf_log|, and |session| will own |proxy|. | |
| 263 // session->command_listeners (the proxy) will be destroyed first. | |
| 264 CommandListenerProxy* proxy = new CommandListenerProxy(perf_log); | |
| 265 devtools_listeners.push_back(perf_log); | |
| 266 command_listeners.push_back(proxy); | |
| 267 } | 258 } |
| 268 } else if (type == WebDriverLog::kBrowserType) { | 259 } else if (type == WebDriverLog::kBrowserType) { |
| 269 browser_log_level = level; | 260 browser_log_level = level; |
| 270 } else if (type != WebDriverLog::kDriverType) { | 261 } else if (type != WebDriverLog::kDriverType) { |
| 271 // Driver "should" ignore unrecognized log types, per Selenium tests. | 262 // Driver "should" ignore unrecognized log types, per Selenium tests. |
| 272 // For example the Java client passes the "client" log type in the caps, | 263 // For example the Java client passes the "client" log type in the caps, |
| 273 // which the server should never provide. | 264 // which the server should never provide. |
| 274 LOG(WARNING) << "Ignoring unrecognized log type: " << type; | 265 LOG(WARNING) << "Ignoring unrecognized log type: " << type; |
| 275 } | 266 } |
| 276 } | 267 } |
| 277 // Create "browser" log -- should always exist. | 268 // Create "browser" log -- should always exist. |
| 278 WebDriverLog* browser_log = | 269 WebDriverLog* browser_log = |
| 279 new WebDriverLog(WebDriverLog::kBrowserType, browser_log_level); | 270 new WebDriverLog(WebDriverLog::kBrowserType, browser_log_level); |
| 280 logs.push_back(browser_log); | 271 logs.push_back(browser_log); |
| 281 // If the level is OFF, don't even bother listening for DevTools events. | 272 // If the level is OFF, don't even bother listening for DevTools events. |
| 282 if (browser_log_level != Log::kOff) | 273 if (browser_log_level != Log::kOff) |
| 283 devtools_listeners.push_back(new ConsoleLogger(browser_log)); | 274 listeners.push_back(new ConsoleLogger(browser_log)); |
| 284 | 275 |
| 285 out_logs->swap(logs); | 276 out_logs->swap(logs); |
| 286 out_devtools_listeners->swap(devtools_listeners); | 277 out_listeners->swap(listeners); |
| 287 out_command_listeners->swap(command_listeners); | |
| 288 return Status(kOk); | 278 return Status(kOk); |
| 289 } | 279 } |
| OLD | NEW |