OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #ifndef _WIN32 | 7 #ifndef _WIN32 |
8 #include <sys/time.h> | 8 #include <sys/time.h> |
9 #include <sys/types.h> | 9 #include <sys/types.h> |
10 #include <sys/wait.h> | 10 #include <sys/wait.h> |
11 #else | 11 #else |
12 #include <time.h> | 12 #include <time.h> |
13 #endif | 13 #endif |
14 #include <iostream> | 14 #include <iostream> |
15 #include <fstream> | 15 #include <fstream> |
16 | 16 |
17 #include "base/at_exit.h" | 17 #include "base/at_exit.h" |
18 #include "base/command_line.h" | 18 #include "base/command_line.h" |
19 #include "base/logging.h" | 19 #include "base/logging.h" |
20 #include "base/scoped_ptr.h" | 20 #include "base/scoped_ptr.h" |
21 #include "base/string_util.h" | 21 #include "base/string_util.h" |
22 #include "base/utf_string_conversions.h" | 22 #include "base/utf_string_conversions.h" |
23 | 23 |
24 #include "chrome/test/webdriver/dispatch.h" | 24 #include "chrome/test/webdriver/dispatch.h" |
25 #include "chrome/test/webdriver/session_manager.h" | 25 #include "chrome/test/webdriver/session_manager.h" |
26 #include "chrome/test/webdriver/utility_functions.h" | 26 #include "chrome/test/webdriver/utility_functions.h" |
27 #include "chrome/test/webdriver/commands/create_session.h" | 27 #include "chrome/test/webdriver/commands/create_session.h" |
28 #include "chrome/test/webdriver/commands/execute_command.h" | 28 #include "chrome/test/webdriver/commands/execute_command.h" |
| 29 #include "chrome/test/webdriver/commands/find_element_commands.h" |
| 30 #include "chrome/test/webdriver/commands/implicit_wait_command.h" |
29 #include "chrome/test/webdriver/commands/navigate_commands.h" | 31 #include "chrome/test/webdriver/commands/navigate_commands.h" |
30 #include "chrome/test/webdriver/commands/session_with_id.h" | 32 #include "chrome/test/webdriver/commands/session_with_id.h" |
31 #include "chrome/test/webdriver/commands/source_command.h" | 33 #include "chrome/test/webdriver/commands/source_command.h" |
32 #include "chrome/test/webdriver/commands/title_command.h" | 34 #include "chrome/test/webdriver/commands/title_command.h" |
33 #include "chrome/test/webdriver/commands/url_command.h" | 35 #include "chrome/test/webdriver/commands/url_command.h" |
34 | 36 |
35 #include "third_party/mongoose/mongoose.h" | 37 #include "third_party/mongoose/mongoose.h" |
36 | 38 |
37 // Make sure we have ho zombies from CGIs. | 39 // Make sure we have ho zombies from CGIs. |
38 static void | 40 static void |
(...skipping 20 matching lines...) Expand all Loading... |
59 void InitCallbacks(struct mg_context* ctx) { | 61 void InitCallbacks(struct mg_context* ctx) { |
60 SetCallback<CreateSession>(ctx, "/session"); | 62 SetCallback<CreateSession>(ctx, "/session"); |
61 SetCallback<BackCommand>(ctx, "/session/*/back"); | 63 SetCallback<BackCommand>(ctx, "/session/*/back"); |
62 SetCallback<ExecuteCommand>(ctx, "/session/*/execute"); | 64 SetCallback<ExecuteCommand>(ctx, "/session/*/execute"); |
63 SetCallback<ForwardCommand>(ctx, "/session/*/forward"); | 65 SetCallback<ForwardCommand>(ctx, "/session/*/forward"); |
64 SetCallback<RefreshCommand>(ctx, "/session/*/refresh"); | 66 SetCallback<RefreshCommand>(ctx, "/session/*/refresh"); |
65 SetCallback<SourceCommand>(ctx, "/session/*/source"); | 67 SetCallback<SourceCommand>(ctx, "/session/*/source"); |
66 SetCallback<TitleCommand>(ctx, "/session/*/title"); | 68 SetCallback<TitleCommand>(ctx, "/session/*/title"); |
67 SetCallback<URLCommand>(ctx, "/session/*/url"); | 69 SetCallback<URLCommand>(ctx, "/session/*/url"); |
68 | 70 |
| 71 // WebElement commands |
| 72 SetCallback<ImplicitWaitCommand>(ctx, "/session/*/timeouts/implicit_wait"); |
| 73 SetCallback<FindOneElementCommand>(ctx, "/session/*/element"); |
| 74 SetCallback<FindManyElementsCommand>(ctx, "/session/*/elements"); |
| 75 SetCallback<FindOneElementCommand>(ctx, "/session/*/element/*/element"); |
| 76 SetCallback<FindManyElementsCommand>(ctx, "/session/*/elements/*/elements"); |
| 77 |
69 // Since the /session/* is a wild card that would match the above URIs, this | 78 // Since the /session/* is a wild card that would match the above URIs, this |
70 // line MUST be the last registered URI with the server. | 79 // line MUST be the last registered URI with the server. |
71 SetCallback<SessionWithID>(ctx, "/session/*"); | 80 SetCallback<SessionWithID>(ctx, "/session/*"); |
72 } | 81 } |
73 } // namespace webdriver | 82 } // namespace webdriver |
74 | 83 |
75 // Sets up and runs the Mongoose HTTP server for the JSON over HTTP | 84 // Sets up and runs the Mongoose HTTP server for the JSON over HTTP |
76 // protcol of webdriver. The spec is located at: | 85 // protcol of webdriver. The spec is located at: |
77 // http://code.google.com/p/selenium/wiki/JsonWireProtocol. | 86 // http://code.google.com/p/selenium/wiki/JsonWireProtocol. |
78 int main(int argc, char *argv[]) { | 87 int main(int argc, char *argv[]) { |
79 struct mg_context *ctx; | 88 struct mg_context *ctx; |
80 base::AtExitManager exit; | 89 base::AtExitManager exit; |
81 std::string port = "8080"; | 90 std::string port = "9515"; |
82 #ifdef OS_POSIX | 91 #ifdef OS_POSIX |
83 CommandLine cmd_line = CommandLine(argc, argv); | 92 CommandLine cmd_line = CommandLine(argc, argv); |
84 #elif OS_WIN | 93 #elif OS_WIN |
85 std::string c; | 94 std::string c; |
86 | 95 |
87 for (int i = 0; i < argc; ++i) { | 96 for (int i = 0; i < argc; ++i) { |
88 c += std::string(argv[i]); | 97 c += std::string(argv[i]); |
89 } | 98 } |
90 CommandLine& cmd_line = CommandLine::FromString(ASCIIToWide(c)); | 99 CommandLine& cmd_line = CommandLine::FromString(ASCIIToWide(c)); |
91 #endif | 100 #endif |
(...skipping 10 matching lines...) Expand all Loading... |
102 if (cmd_line.HasSwitch(std::string("port"))) { | 111 if (cmd_line.HasSwitch(std::string("port"))) { |
103 port = cmd_line.GetSwitchValueASCII(std::string("port")); | 112 port = cmd_line.GetSwitchValueASCII(std::string("port")); |
104 } | 113 } |
105 | 114 |
106 VLOG(1) << "Using port: " << port; | 115 VLOG(1) << "Using port: " << port; |
107 webdriver::SessionManager* session = | 116 webdriver::SessionManager* session = |
108 Singleton<webdriver::SessionManager>::get(); | 117 Singleton<webdriver::SessionManager>::get(); |
109 session->SetIPAddress(port); | 118 session->SetIPAddress(port); |
110 | 119 |
111 // Initialize SHTTPD context. | 120 // Initialize SHTTPD context. |
112 // Listen on port 8080 or port specified on command line. | 121 // Listen on port 9515 or port specified on command line. |
113 // TODO(jmikhail) Maybe add port 8081 as a secure connection. | 122 // TODO(jmikhail) Maybe add port 9516 as a secure connection. |
114 ctx = mg_start(); | 123 ctx = mg_start(); |
115 mg_set_option(ctx, "ports", port.c_str()); | 124 mg_set_option(ctx, "ports", port.c_str()); |
116 | 125 |
117 webdriver::InitCallbacks(ctx); | 126 webdriver::InitCallbacks(ctx); |
118 | 127 |
119 std::cout << "Starting server" << std::endl; | 128 std::cout << "Starting server on port: " << port << std::endl; |
120 // The default behavior is to run this service forever. | 129 // The default behavior is to run this service forever. |
121 while (true) | 130 while (true) |
122 PlatformThread::Sleep(3600); | 131 PlatformThread::Sleep(3600); |
123 | 132 |
124 // We should not reach here since the service should never quit. | 133 // We should not reach here since the service should never quit. |
125 // TODO(jmikhail): register a listener for SIGTERM and break the | 134 // TODO(jmikhail): register a listener for SIGTERM and break the |
126 // message loop gracefully. | 135 // message loop gracefully. |
127 mg_stop(ctx); | 136 mg_stop(ctx); |
128 return (EXIT_SUCCESS); | 137 return (EXIT_SUCCESS); |
129 } | 138 } |
130 | 139 |
OLD | NEW |