| 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 <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 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 #include "chrome/test/webdriver/error_codes.h" | 30 #include "chrome/test/webdriver/error_codes.h" |
| 31 #include "chrome/test/webdriver/session_manager.h" | 31 #include "chrome/test/webdriver/session_manager.h" |
| 32 #include "chrome/test/webdriver/utility_functions.h" | 32 #include "chrome/test/webdriver/utility_functions.h" |
| 33 #include "chrome/test/webdriver/commands/cookie_commands.h" | 33 #include "chrome/test/webdriver/commands/cookie_commands.h" |
| 34 #include "chrome/test/webdriver/commands/create_session.h" | 34 #include "chrome/test/webdriver/commands/create_session.h" |
| 35 #include "chrome/test/webdriver/commands/execute_command.h" | 35 #include "chrome/test/webdriver/commands/execute_command.h" |
| 36 #include "chrome/test/webdriver/commands/find_element_commands.h" | 36 #include "chrome/test/webdriver/commands/find_element_commands.h" |
| 37 #include "chrome/test/webdriver/commands/implicit_wait_command.h" | 37 #include "chrome/test/webdriver/commands/implicit_wait_command.h" |
| 38 #include "chrome/test/webdriver/commands/navigate_commands.h" | 38 #include "chrome/test/webdriver/commands/navigate_commands.h" |
| 39 #include "chrome/test/webdriver/commands/mouse_commands.h" | 39 #include "chrome/test/webdriver/commands/mouse_commands.h" |
| 40 #include "chrome/test/webdriver/commands/screenshot_command.h" |
| 40 #include "chrome/test/webdriver/commands/session_with_id.h" | 41 #include "chrome/test/webdriver/commands/session_with_id.h" |
| 41 #include "chrome/test/webdriver/commands/source_command.h" | 42 #include "chrome/test/webdriver/commands/source_command.h" |
| 42 #include "chrome/test/webdriver/commands/speed_command.h" | 43 #include "chrome/test/webdriver/commands/speed_command.h" |
| 43 #include "chrome/test/webdriver/commands/target_locator_commands.h" | 44 #include "chrome/test/webdriver/commands/target_locator_commands.h" |
| 44 #include "chrome/test/webdriver/commands/title_command.h" | 45 #include "chrome/test/webdriver/commands/title_command.h" |
| 45 #include "chrome/test/webdriver/commands/url_command.h" | 46 #include "chrome/test/webdriver/commands/url_command.h" |
| 46 #include "chrome/test/webdriver/commands/webelement_commands.h" | 47 #include "chrome/test/webdriver/commands/webelement_commands.h" |
| 47 #include "third_party/mongoose/mongoose.h" | 48 #include "third_party/mongoose/mongoose.h" |
| 48 | 49 |
| 49 #if defined(OS_WIN) | 50 #if defined(OS_WIN) |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 dispatcher->Add<ElementLocationInViewCommand>( | 96 dispatcher->Add<ElementLocationInViewCommand>( |
| 96 "/session/*/element/*/location_in_view"); | 97 "/session/*/element/*/location_in_view"); |
| 97 dispatcher->Add<ElementNameCommand>( "/session/*/element/*/name"); | 98 dispatcher->Add<ElementNameCommand>( "/session/*/element/*/name"); |
| 98 dispatcher->Add<ElementSelectedCommand>("/session/*/element/*/selected"); | 99 dispatcher->Add<ElementSelectedCommand>("/session/*/element/*/selected"); |
| 99 dispatcher->Add<ElementSizeCommand>( "/session/*/element/*/size"); | 100 dispatcher->Add<ElementSizeCommand>( "/session/*/element/*/size"); |
| 100 dispatcher->Add<ElementSubmitCommand>( "/session/*/element/*/submit"); | 101 dispatcher->Add<ElementSubmitCommand>( "/session/*/element/*/submit"); |
| 101 dispatcher->Add<ElementTextCommand>( "/session/*/element/*/text"); | 102 dispatcher->Add<ElementTextCommand>( "/session/*/element/*/text"); |
| 102 dispatcher->Add<ElementToggleCommand>( "/session/*/element/*/toggle"); | 103 dispatcher->Add<ElementToggleCommand>( "/session/*/element/*/toggle"); |
| 103 dispatcher->Add<ElementValueCommand>( "/session/*/element/*/value"); | 104 dispatcher->Add<ElementValueCommand>( "/session/*/element/*/value"); |
| 104 | 105 |
| 106 dispatcher->Add<ScreenshotCommand>("/session/*/screenshot"); |
| 107 |
| 105 // Mouse Commands | 108 // Mouse Commands |
| 106 dispatcher->Add<ClickCommand>("/session/*/element/*/click"); | 109 dispatcher->Add<ClickCommand>("/session/*/element/*/click"); |
| 107 dispatcher->Add<DragCommand>( "/session/*/element/*/drag"); | 110 dispatcher->Add<DragCommand>( "/session/*/element/*/drag"); |
| 108 dispatcher->Add<HoverCommand>("/session/*/element/*/hover"); | 111 dispatcher->Add<HoverCommand>("/session/*/element/*/hover"); |
| 109 | 112 |
| 110 // All session based commands should be listed after the element based | 113 // All session based commands should be listed after the element based |
| 111 // commands to avoid potential mapping conflicts from an overzealous | 114 // commands to avoid potential mapping conflicts from an overzealous |
| 112 // wildcard match. For example, /session/*/title maps to the handler to | 115 // wildcard match. For example, /session/*/title maps to the handler to |
| 113 // fetch the page title. If mapped first, this would overwrite the handler | 116 // fetch the page title. If mapped first, this would overwrite the handler |
| 114 // for /session/*/element/*/attribute/title, which should fetch the title | 117 // for /session/*/element/*/attribute/title, which should fetch the title |
| (...skipping 13 matching lines...) Expand all Loading... |
| 128 dispatcher->Add<ImplicitWaitCommand>( "/session/*/timeouts/implicit_wait"); | 131 dispatcher->Add<ImplicitWaitCommand>( "/session/*/timeouts/implicit_wait"); |
| 129 | 132 |
| 130 // Cookie functions. | 133 // Cookie functions. |
| 131 dispatcher->Add<CookieCommand>( "/session/*/cookie"); | 134 dispatcher->Add<CookieCommand>( "/session/*/cookie"); |
| 132 dispatcher->Add<NamedCookieCommand>("/session/*/cookie/*"); | 135 dispatcher->Add<NamedCookieCommand>("/session/*/cookie/*"); |
| 133 | 136 |
| 134 // Commands that have not been implemented yet. We list these out explicitly | 137 // Commands that have not been implemented yet. We list these out explicitly |
| 135 // so that tests that attempt to use them fail with a meaningful error. | 138 // so that tests that attempt to use them fail with a meaningful error. |
| 136 dispatcher->SetNotImplemented("/session/*/execute_async"); | 139 dispatcher->SetNotImplemented("/session/*/execute_async"); |
| 137 dispatcher->SetNotImplemented("/session/*/timeouts/async_script"); | 140 dispatcher->SetNotImplemented("/session/*/timeouts/async_script"); |
| 138 dispatcher->SetNotImplemented("/session/*/screenshot"); | |
| 139 | 141 |
| 140 // Since the /session/* is a wild card that would match the above URIs, this | 142 // Since the /session/* is a wild card that would match the above URIs, this |
| 141 // line MUST be the last registered URI with the server. | 143 // line MUST be the last registered URI with the server. |
| 142 dispatcher->Add<SessionWithID>("/session/*"); | 144 dispatcher->Add<SessionWithID>("/session/*"); |
| 143 } | 145 } |
| 144 | 146 |
| 145 } // namespace webdriver | 147 } // namespace webdriver |
| 146 | 148 |
| 147 // Configures mongoose according to the given command line flags. | 149 // Configures mongoose according to the given command line flags. |
| 148 // Returns true on success. | 150 // Returns true on success. |
| 149 bool SetMongooseOptions(struct mg_context* ctx, | 151 bool SetMongooseOptions(struct mg_context* ctx, |
| 150 const std::string& port, | 152 const std::string& port, |
| 151 const std::string& root) { | 153 const std::string& root) { |
| 152 if (!mg_set_option(ctx, "ports", port.c_str())) { | 154 if (!mg_set_option(ctx, "ports", port.c_str())) { |
| 153 std::cout << "ChromeDriver cannot bind to port (" | 155 std::cout << "ChromeDriver cannot bind to port (" |
| 154 << port.c_str() << ")" << std::endl; | 156 << port.c_str() << ")" << std::endl; |
| 155 return false; | 157 return false; |
| 156 } | 158 } |
| 157 if (root.length()) | 159 if (root.length()) |
| 158 mg_set_option(ctx, "root", root.c_str()); | 160 mg_set_option(ctx, "root", root.c_str()); |
| 159 // Lower the default idle time to 1 second. Idle time refers to how long a | 161 // Lower the default idle time to 1 second. Idle time refers to how long a |
| 160 // worker thread will wait for new connections before exiting. | 162 // worker thread will wait for new connections before exiting. |
| 161 // This is so mongoose quits in a reasonable amount of time. | 163 // This is so mongoose quits in a reasonable amount of time. |
| 162 mg_set_option(ctx, "idle_time", "1"); | 164 mg_set_option(ctx, "idle_time", "1"); |
| 163 return true; | 165 return true; |
| 164 } | 166 } |
| 165 | 167 |
| 168 |
| 166 // Sets up and runs the Mongoose HTTP server for the JSON over HTTP | 169 // Sets up and runs the Mongoose HTTP server for the JSON over HTTP |
| 167 // protcol of webdriver. The spec is located at: | 170 // protcol of webdriver. The spec is located at: |
| 168 // http://code.google.com/p/selenium/wiki/JsonWireProtocol. | 171 // http://code.google.com/p/selenium/wiki/JsonWireProtocol. |
| 169 int main(int argc, char *argv[]) { | 172 int main(int argc, char *argv[]) { |
| 170 struct mg_context *ctx; | 173 struct mg_context *ctx; |
| 171 base::AtExitManager exit; | 174 base::AtExitManager exit; |
| 172 base::WaitableEvent shutdown_event(false, false); | 175 base::WaitableEvent shutdown_event(false, false); |
| 173 CommandLine::Init(argc, argv); | 176 CommandLine::Init(argc, argv); |
| 174 CommandLine* cmd_line = CommandLine::ForCurrentProcess(); | 177 CommandLine* cmd_line = CommandLine::ForCurrentProcess(); |
| 175 | 178 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 | 249 |
| 247 // Run until we receive command to shutdown. | 250 // Run until we receive command to shutdown. |
| 248 shutdown_event.Wait(); | 251 shutdown_event.Wait(); |
| 249 | 252 |
| 250 // We should not reach here since the service should never quit. | 253 // We should not reach here since the service should never quit. |
| 251 // TODO(jmikhail): register a listener for SIGTERM and break the | 254 // TODO(jmikhail): register a listener for SIGTERM and break the |
| 252 // message loop gracefully. | 255 // message loop gracefully. |
| 253 mg_stop(ctx); | 256 mg_stop(ctx); |
| 254 return (EXIT_SUCCESS); | 257 return (EXIT_SUCCESS); |
| 255 } | 258 } |
| OLD | NEW |