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 #ifndef CHROME_TEST_WEBDRIVER_DISPATCH_H_ | 5 #ifndef CHROME_TEST_WEBDRIVER_DISPATCH_H_ |
6 #define CHROME_TEST_WEBDRIVER_DISPATCH_H_ | 6 #define CHROME_TEST_WEBDRIVER_DISPATCH_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/logging.h" |
12 #include "chrome/test/webdriver/commands/response.h" | 13 #include "chrome/test/webdriver/commands/response.h" |
13 #include "third_party/mongoose/mongoose.h" | 14 #include "third_party/mongoose/mongoose.h" |
14 | 15 |
15 class DictionaryValue; | 16 class DictionaryValue; |
16 | 17 |
17 namespace base { | 18 namespace base { |
18 class WaitableEvent; | 19 class WaitableEvent; |
19 } | 20 } |
20 | 21 |
21 namespace webdriver { | 22 namespace webdriver { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 void* user_data) { | 62 void* user_data) { |
62 std::string method; | 63 std::string method; |
63 std::vector<std::string> path_segments; | 64 std::vector<std::string> path_segments; |
64 DictionaryValue* parameters = NULL; | 65 DictionaryValue* parameters = NULL; |
65 Response response; | 66 Response response; |
66 if (internal::ParseRequestInfo(request_info, | 67 if (internal::ParseRequestInfo(request_info, |
67 &method, | 68 &method, |
68 &path_segments, | 69 &path_segments, |
69 ¶meters, | 70 ¶meters, |
70 &response)) { | 71 &response)) { |
| 72 std::string post_data(request_info->post_data, request_info->post_data_len); |
| 73 LOG(INFO) << "Received command, url: " << request_info->uri |
| 74 << ", method: " << request_info->request_method |
| 75 << ", postd data: " << post_data; |
71 internal::DispatchHelper( | 76 internal::DispatchHelper( |
72 new CommandType(path_segments, parameters), | 77 new CommandType(path_segments, parameters), |
73 method, | 78 method, |
74 &response); | 79 &response); |
75 } | 80 } |
76 | |
77 internal::SendResponse(connection, | 81 internal::SendResponse(connection, |
78 request_info->request_method, | 82 request_info->request_method, |
79 response); | 83 response); |
| 84 LOG(INFO) << "Sent command response, url: " << request_info->uri; |
80 } | 85 } |
81 | 86 |
82 class Dispatcher { | 87 class Dispatcher { |
83 public: | 88 public: |
84 // Creates a new dispatcher that will register all URL callbacks with the | 89 // Creates a new dispatcher that will register all URL callbacks with the |
85 // given |context|. Each callback's pattern will be prefixed with the provided | 90 // given |context|. Each callback's pattern will be prefixed with the provided |
86 // |root|. | 91 // |root|. |
87 Dispatcher(struct mg_context* context, const std::string& root); | 92 Dispatcher(struct mg_context* context, const std::string& root); |
88 ~Dispatcher(); | 93 ~Dispatcher(); |
89 | 94 |
90 // Registers a callback for a WebDriver command using the given URL |pattern|. | 95 // Registers a callback for a WebDriver command using the given URL |pattern|. |
91 // The |CommandType| must be a subtype of |webdriver::Command|. | 96 // The |CommandType| must be a subtype of |webdriver::Command|. |
92 template<typename CommandType> | 97 template<typename CommandType> |
93 void Add(const std::string& pattern); | 98 void Add(const std::string& pattern); |
94 | 99 |
95 // Registers a callback that will shutdown the server. When any HTTP request | 100 // Registers a callback that will shutdown the server. When any HTTP request |
96 // is received at this URL |pattern|, the |shutdown_event| will be signaled. | 101 // is received at this URL |pattern|, the |shutdown_event| will be signaled. |
97 void AddShutdown(const std::string& pattern, | 102 void AddShutdown(const std::string& pattern, |
98 base::WaitableEvent* shutdown_event); | 103 base::WaitableEvent* shutdown_event); |
99 | 104 |
100 // Registers a callback for the given pattern that will return a simple | 105 // Registers a callback for the given pattern that will return a simple |
101 // "HTTP/1.1 200 OK" message with "ok" in the body. Used for checking the | 106 // "HTTP/1.1 200 OK" message with "ok" in the body. Used for checking the |
102 // status of the server. | 107 // status of the server. |
103 void AddStatus(const std::string& pattern); | 108 void AddHealthz(const std::string& pattern); |
| 109 |
| 110 // Registers a callback for the given pattern that will return the current |
| 111 // WebDriver log contents. |
| 112 void AddLog(const std::string& pattern); |
104 | 113 |
105 // Registers a callback that will always respond with a | 114 // Registers a callback that will always respond with a |
106 // "HTTP/1.1 501 Not Implemented" message. | 115 // "HTTP/1.1 501 Not Implemented" message. |
107 void SetNotImplemented(const std::string& pattern); | 116 void SetNotImplemented(const std::string& pattern); |
108 | 117 |
109 // Registers a callback that will respond for all other requests with a | 118 // Registers a callback that will respond for all other requests with a |
110 // "HTTP/1.1 403 Forbidden" message. Should be called only after registering | 119 // "HTTP/1.1 403 Forbidden" message. Should be called only after registering |
111 // other callbacks. | 120 // other callbacks. |
112 void ForbidAllOtherRequests(); | 121 void ForbidAllOtherRequests(); |
113 | 122 |
114 private: | 123 private: |
115 struct mg_context* context_; | 124 struct mg_context* context_; |
116 const std::string root_; | 125 const std::string root_; |
117 | 126 |
118 DISALLOW_COPY_AND_ASSIGN(Dispatcher); | 127 DISALLOW_COPY_AND_ASSIGN(Dispatcher); |
119 }; | 128 }; |
120 | 129 |
121 | 130 |
122 template <typename CommandType> | 131 template <typename CommandType> |
123 void Dispatcher::Add(const std::string& pattern) { | 132 void Dispatcher::Add(const std::string& pattern) { |
124 mg_set_uri_callback(context_, (root_ + pattern).c_str(), | 133 mg_set_uri_callback(context_, (root_ + pattern).c_str(), |
125 &Dispatch<CommandType>, NULL); | 134 &Dispatch<CommandType>, NULL); |
126 } | 135 } |
127 | 136 |
128 } // namespace webdriver | 137 } // namespace webdriver |
129 | 138 |
130 #endif // CHROME_TEST_WEBDRIVER_DISPATCH_H_ | 139 #endif // CHROME_TEST_WEBDRIVER_DISPATCH_H_ |
OLD | NEW |