Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(331)

Side by Side Diff: chrome/test/webdriver/server.cc

Issue 7104085: In chromedriver, add /log handler (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ... Created 9 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/test/webdriver/keymap.cc ('k') | chrome/test/webdriver/session_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <signal.h> 5 #include <signal.h>
6 #include <stdlib.h> 6 #include <stdlib.h>
7 7
8 #if defined(OS_WIN) 8 #if defined(OS_WIN)
9 #include <windows.h> 9 #include <windows.h>
10 #endif 10 #endif
11 11
12 #include <iostream> 12 #include <iostream>
13 #include <fstream> 13 #include <fstream>
14 14
15 #include "base/at_exit.h" 15 #include "base/at_exit.h"
16 #include "base/command_line.h" 16 #include "base/command_line.h"
17 #include "base/file_path.h" 17 #include "base/file_path.h"
18 #include "base/file_util.h" 18 #include "base/file_util.h"
19 #include "base/logging.h" 19 #include "base/logging.h"
20 #include "base/memory/scoped_ptr.h" 20 #include "base/memory/scoped_ptr.h"
21 #include "base/string_number_conversions.h" 21 #include "base/string_number_conversions.h"
22 #include "base/string_split.h" 22 #include "base/string_split.h"
23 #include "base/string_util.h" 23 #include "base/string_util.h"
24 #include "base/synchronization/waitable_event.h" 24 #include "base/synchronization/waitable_event.h"
25 #include "base/test/test_timeouts.h" 25 #include "base/test/test_timeouts.h"
26 #include "base/threading/platform_thread.h" 26 #include "base/threading/platform_thread.h"
27 #include "base/utf_string_conversions.h" 27 #include "base/utf_string_conversions.h"
28 #include "chrome/common/chrome_paths.h" 28 #include "chrome/common/chrome_paths.h"
29 #include "chrome/common/chrome_switches.h" 29 #include "chrome/common/chrome_switches.h"
30 #include "chrome/test/webdriver/dispatch.h"
31 #include "chrome/test/webdriver/session_manager.h"
32 #include "chrome/test/webdriver/utility_functions.h"
33 #include "chrome/test/webdriver/commands/alert_commands.h" 30 #include "chrome/test/webdriver/commands/alert_commands.h"
34 #include "chrome/test/webdriver/commands/cookie_commands.h" 31 #include "chrome/test/webdriver/commands/cookie_commands.h"
35 #include "chrome/test/webdriver/commands/create_session.h" 32 #include "chrome/test/webdriver/commands/create_session.h"
36 #include "chrome/test/webdriver/commands/execute_async_script_command.h" 33 #include "chrome/test/webdriver/commands/execute_async_script_command.h"
37 #include "chrome/test/webdriver/commands/execute_command.h" 34 #include "chrome/test/webdriver/commands/execute_command.h"
38 #include "chrome/test/webdriver/commands/find_element_commands.h" 35 #include "chrome/test/webdriver/commands/find_element_commands.h"
39 #include "chrome/test/webdriver/commands/navigate_commands.h" 36 #include "chrome/test/webdriver/commands/navigate_commands.h"
40 #include "chrome/test/webdriver/commands/mouse_commands.h" 37 #include "chrome/test/webdriver/commands/mouse_commands.h"
41 #include "chrome/test/webdriver/commands/screenshot_command.h" 38 #include "chrome/test/webdriver/commands/screenshot_command.h"
42 #include "chrome/test/webdriver/commands/session_with_id.h" 39 #include "chrome/test/webdriver/commands/session_with_id.h"
43 #include "chrome/test/webdriver/commands/set_timeout_commands.h" 40 #include "chrome/test/webdriver/commands/set_timeout_commands.h"
44 #include "chrome/test/webdriver/commands/source_command.h" 41 #include "chrome/test/webdriver/commands/source_command.h"
45 #include "chrome/test/webdriver/commands/target_locator_commands.h" 42 #include "chrome/test/webdriver/commands/target_locator_commands.h"
46 #include "chrome/test/webdriver/commands/title_command.h" 43 #include "chrome/test/webdriver/commands/title_command.h"
47 #include "chrome/test/webdriver/commands/url_command.h" 44 #include "chrome/test/webdriver/commands/url_command.h"
48 #include "chrome/test/webdriver/commands/webelement_commands.h" 45 #include "chrome/test/webdriver/commands/webelement_commands.h"
46 #include "chrome/test/webdriver/dispatch.h"
47 #include "chrome/test/webdriver/session_manager.h"
48 #include "chrome/test/webdriver/utility_functions.h"
49 #include "chrome/test/webdriver/webdriver_logging.h"
49 #include "third_party/mongoose/mongoose.h" 50 #include "third_party/mongoose/mongoose.h"
50 51
51 #if defined(OS_WIN) 52 #if defined(OS_WIN)
52 #include <time.h> 53 #include <time.h>
53 #elif defined(OS_POSIX) 54 #elif defined(OS_POSIX)
54 #include <errno.h> 55 #include <errno.h>
55 #include <sys/time.h> 56 #include <sys/time.h>
56 #include <sys/types.h> 57 #include <sys/types.h>
57 #include <sys/wait.h> 58 #include <sys/wait.h>
58 #endif 59 #endif
59 60
60 namespace webdriver { 61 namespace webdriver {
61 62
62 void InitCallbacks(struct mg_context* ctx, Dispatcher* dispatcher, 63 void InitCallbacks(struct mg_context* ctx, Dispatcher* dispatcher,
63 base::WaitableEvent* shutdown_event, 64 base::WaitableEvent* shutdown_event,
64 bool forbid_other_requests) { 65 bool forbid_other_requests) {
65 dispatcher->AddShutdown("/shutdown", shutdown_event); 66 dispatcher->AddShutdown("/shutdown", shutdown_event);
66 dispatcher->AddStatus("/healthz"); 67 dispatcher->AddHealthz("/healthz");
68 dispatcher->AddLog("/log");
67 69
68 dispatcher->Add<CreateSession>("/session"); 70 dispatcher->Add<CreateSession>("/session");
69 71
70 // WebElement commands 72 // WebElement commands
71 dispatcher->Add<FindOneElementCommand>( "/session/*/element"); 73 dispatcher->Add<FindOneElementCommand>( "/session/*/element");
72 dispatcher->Add<FindManyElementsCommand>("/session/*/elements"); 74 dispatcher->Add<FindManyElementsCommand>("/session/*/elements");
73 dispatcher->Add<ActiveElementCommand>( "/session/*/element/active"); 75 dispatcher->Add<ActiveElementCommand>( "/session/*/element/active");
74 dispatcher->Add<FindOneElementCommand>( "/session/*/element/*/element"); 76 dispatcher->Add<FindOneElementCommand>( "/session/*/element/*/element");
75 dispatcher->Add<FindManyElementsCommand>("/session/*/elements/*/elements"); 77 dispatcher->Add<FindManyElementsCommand>("/session/*/elements/*/elements");
76 dispatcher->Add<ElementAttributeCommand>("/session/*/element/*/attribute/*"); 78 dispatcher->Add<ElementAttributeCommand>("/session/*/element/*/attribute/*");
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 // Since the /session/* is a wild card that would match the above URIs, this 138 // Since the /session/* is a wild card that would match the above URIs, this
137 // line MUST be after all other webdriver command callbacks. 139 // line MUST be after all other webdriver command callbacks.
138 dispatcher->Add<SessionWithID>("/session/*"); 140 dispatcher->Add<SessionWithID>("/session/*");
139 141
140 if (forbid_other_requests) 142 if (forbid_other_requests)
141 dispatcher->ForbidAllOtherRequests(); 143 dispatcher->ForbidAllOtherRequests();
142 } 144 }
143 145
144 } // namespace webdriver 146 } // namespace webdriver
145 147
146 // Initializes logging for ChromeDriver.
147 void InitChromeDriverLogging(const CommandLine& command_line) {
148 bool success = InitLogging(
149 FILE_PATH_LITERAL("chromedriver.log"),
150 logging::LOG_TO_BOTH_FILE_AND_SYSTEM_DEBUG_LOG,
151 logging::LOCK_LOG_FILE,
152 logging::DELETE_OLD_LOG_FILE,
153 logging::DISABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS);
154 if (!success) {
155 PLOG(ERROR) << "Unable to initialize logging";
156 }
157 logging::SetLogItems(false, // enable_process_id
158 false, // enable_thread_id
159 true, // enable_timestamp
160 false); // enable_tickcount
161 if (command_line.HasSwitch(switches::kLoggingLevel)) {
162 std::string log_level = command_line.GetSwitchValueASCII(
163 switches::kLoggingLevel);
164 int level = 0;
165 if (base::StringToInt(log_level, &level)) {
166 logging::SetMinLogLevel(level);
167 } else {
168 LOG(WARNING) << "Bad log level: " << log_level;
169 }
170 }
171 }
172
173 // Configures mongoose according to the given command line flags. 148 // Configures mongoose according to the given command line flags.
174 // Returns true on success. 149 // Returns true on success.
175 bool SetMongooseOptions(struct mg_context* ctx, 150 bool SetMongooseOptions(struct mg_context* ctx,
176 const std::string& port, 151 const std::string& port,
177 const std::string& root) { 152 const std::string& root) {
178 if (!mg_set_option(ctx, "ports", port.c_str())) { 153 if (!mg_set_option(ctx, "ports", port.c_str())) {
179 std::cout << "ChromeDriver cannot bind to port (" 154 std::cout << "ChromeDriver cannot bind to port ("
180 << port.c_str() << ")" << std::endl; 155 << port.c_str() << ")" << std::endl;
181 return false; 156 return false;
182 } 157 }
(...skipping 19 matching lines...) Expand all
202 177
203 #if defined(OS_POSIX) 178 #if defined(OS_POSIX)
204 signal(SIGPIPE, SIG_IGN); 179 signal(SIGPIPE, SIG_IGN);
205 #endif 180 #endif
206 srand((unsigned int)time(NULL)); 181 srand((unsigned int)time(NULL));
207 182
208 // Register Chrome's path provider so that the AutomationProxy will find our 183 // Register Chrome's path provider so that the AutomationProxy will find our
209 // built Chrome. 184 // built Chrome.
210 chrome::RegisterPathProvider(); 185 chrome::RegisterPathProvider();
211 TestTimeouts::Initialize(); 186 TestTimeouts::Initialize();
212 InitChromeDriverLogging(*cmd_line);
213 187
214 // Parse command line flags. 188 // Parse command line flags.
215 std::string port = "9515"; 189 std::string port = "9515";
216 std::string root; 190 std::string root;
217 std::string url_base; 191 std::string url_base;
192 bool verbose = false;
218 if (cmd_line->HasSwitch("port")) 193 if (cmd_line->HasSwitch("port"))
219 port = cmd_line->GetSwitchValueASCII("port"); 194 port = cmd_line->GetSwitchValueASCII("port");
220 // The 'root' flag allows the user to specify a location to serve files from. 195 // The 'root' flag allows the user to specify a location to serve files from.
221 // If it is not given, a callback will be registered to forbid all file 196 // If it is not given, a callback will be registered to forbid all file
222 // requests. 197 // requests.
223 if (cmd_line->HasSwitch("root")) 198 if (cmd_line->HasSwitch("root"))
224 root = cmd_line->GetSwitchValueASCII("root"); 199 root = cmd_line->GetSwitchValueASCII("root");
225 if (cmd_line->HasSwitch("url-base")) 200 if (cmd_line->HasSwitch("url-base"))
226 url_base = cmd_line->GetSwitchValueASCII("url-base"); 201 url_base = cmd_line->GetSwitchValueASCII("url-base");
202 // Whether or not to do verbose logging.
203 if (cmd_line->HasSwitch("verbose"))
204 verbose = true;
205
206 webdriver::InitWebDriverLogging(
207 verbose ? logging::LOG_INFO : logging::LOG_WARNING);
227 208
228 webdriver::SessionManager* manager = webdriver::SessionManager::GetInstance(); 209 webdriver::SessionManager* manager = webdriver::SessionManager::GetInstance();
229 manager->set_port(port); 210 manager->set_port(port);
230 manager->set_url_base(url_base); 211 manager->set_url_base(url_base);
231 212
232 // Initialize SHTTPD context. 213 // Initialize SHTTPD context.
233 // Listen on port 9515 or port specified on command line. 214 // Listen on port 9515 or port specified on command line.
234 // TODO(jmikhail) Maybe add port 9516 as a secure connection. 215 // TODO(jmikhail) Maybe add port 9516 as a secure connection.
235 ctx = mg_start(); 216 ctx = mg_start();
236 if (!SetMongooseOptions(ctx, port, root)) { 217 if (!SetMongooseOptions(ctx, port, root)) {
(...skipping 19 matching lines...) Expand all
256 237
257 // Run until we receive command to shutdown. 238 // Run until we receive command to shutdown.
258 shutdown_event.Wait(); 239 shutdown_event.Wait();
259 240
260 // We should not reach here since the service should never quit. 241 // We should not reach here since the service should never quit.
261 // TODO(jmikhail): register a listener for SIGTERM and break the 242 // TODO(jmikhail): register a listener for SIGTERM and break the
262 // message loop gracefully. 243 // message loop gracefully.
263 mg_stop(ctx); 244 mg_stop(ctx);
264 return (EXIT_SUCCESS); 245 return (EXIT_SUCCESS);
265 } 246 }
OLDNEW
« no previous file with comments | « chrome/test/webdriver/keymap.cc ('k') | chrome/test/webdriver/session_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698