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

Side by Side Diff: chrome/test/chromedriver/server/http_handler.h

Issue 18419003: [chromedriver] Remove dll build target. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix nits and update readme Created 7 years, 5 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
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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_CHROMEDRIVER_SERVER_HTTP_HANDLER_H_ 5 #ifndef CHROME_TEST_CHROMEDRIVER_SERVER_HTTP_HANDLER_H_
6 #define CHROME_TEST_CHROMEDRIVER_SERVER_HTTP_HANDLER_H_ 6 #define CHROME_TEST_CHROMEDRIVER_SERVER_HTTP_HANDLER_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/compiler_specific.h"
12 #include "base/gtest_prod_util.h"
11 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/threading/thread.h"
15 #include "chrome/test/chromedriver/command.h"
16 #include "chrome/test/chromedriver/element_commands.h"
17 #include "chrome/test/chromedriver/net/sync_websocket_factory.h"
18 #include "chrome/test/chromedriver/session_commands.h"
19 #include "chrome/test/chromedriver/session_map.h"
20 #include "chrome/test/chromedriver/window_commands.h"
12 21
13 namespace base { 22 namespace base {
14 class DictionaryValue; 23 class DictionaryValue;
15 } 24 }
16 25
17 class CommandExecutor; 26 class Adb;
27 class DeviceManager;
28 class Log;
18 class HttpResponse; 29 class HttpResponse;
19 class Log; 30 class URLRequestContextGetter;
20 31
21 enum HttpMethod { 32 enum HttpMethod {
22 kGet = 0, 33 kGet = 0,
23 kPost, 34 kPost,
24 kDelete, 35 kDelete,
25 }; 36 };
26 37
27 struct HttpRequest { 38 struct HttpRequest {
28 HttpRequest(HttpMethod method, 39 HttpRequest(HttpMethod method,
29 const std::string& path, 40 const std::string& path,
30 const std::string& body); 41 const std::string& body);
31 ~HttpRequest(); 42 ~HttpRequest();
32 43
33 HttpMethod method; 44 HttpMethod method;
34 std::string path; 45 std::string path;
35 std::string body; 46 std::string body;
36 }; 47 };
37 48
38 struct CommandMapping { 49 struct CommandMapping {
50 CommandMapping();
chrisgao (Use stgao instead) 2013/07/02 01:31:40 remove
chrisgao (Use stgao instead) 2013/07/02 18:13:04 Done.
39 CommandMapping(HttpMethod method, 51 CommandMapping(HttpMethod method,
40 const std::string& path_pattern, 52 const std::string& path_pattern,
41 const std::string& name); 53 const Command& command);
42 ~CommandMapping(); 54 ~CommandMapping();
43 55
44 HttpMethod method; 56 HttpMethod method;
45 std::string path_pattern; 57 std::string path_pattern;
46 std::string name; 58 Command command;
47 }; 59 };
48 60
49 class HttpHandler { 61 class HttpHandler {
50 public: 62 public:
51 typedef std::vector<CommandMapping> CommandMap; 63 HttpHandler(Log* log, const std::string& url_base);
52 static scoped_ptr<CommandMap> CreateCommandMap();
53
54 HttpHandler(Log* log,
55 scoped_ptr<CommandExecutor> executor,
56 scoped_ptr<std::vector<CommandMapping> > commands,
57 const std::string& url_base);
58 ~HttpHandler(); 64 ~HttpHandler();
59 65
60 void Handle(const HttpRequest& request, 66 void Init();
kkania 2013/07/02 01:57:08 can we remove the init and just do in the construc
chrisgao (Use stgao instead) 2013/07/02 18:13:04 Done.
61 HttpResponse* response); 67 void Handle(const HttpRequest& request, HttpResponse* response);
62
63 bool ShouldShutdown(const HttpRequest& request); 68 bool ShouldShutdown(const HttpRequest& request);
64 69
65 private: 70 private:
66 void HandleInternal(const HttpRequest& request, 71 FRIEND_TEST_ALL_PREFIXES(HttpHandlerTest, HandleUnknownCommand);
67 HttpResponse* response); 72 FRIEND_TEST_ALL_PREFIXES(HttpHandlerTest, HandleNewSession);
73 FRIEND_TEST_ALL_PREFIXES(HttpHandlerTest, HandleInvalidPost);
74 FRIEND_TEST_ALL_PREFIXES(HttpHandlerTest, HandleUnimplementedCommand);
75 FRIEND_TEST_ALL_PREFIXES(HttpHandlerTest, HandleCommand);
76 typedef std::vector<CommandMapping> CommandMap;
77
78 Command WrapToNonSessionCommand(const SessionCommand& session_command);
79 Command WrapToNonSessionCommand(const WindowCommand& window_command);
80 Command WrapToNonSessionCommand(const ElementCommand& element_command);
81 void HandleInternal(const HttpRequest& request, HttpResponse* response);
68 bool HandleWebDriverCommand( 82 bool HandleWebDriverCommand(
69 const HttpRequest& request, 83 const HttpRequest& request,
70 const std::string& trimmed_path, 84 const std::string& trimmed_path,
71 HttpResponse* response); 85 HttpResponse* response);
72 86
73 Log* log_; 87 Log* log_;
74 scoped_ptr<CommandExecutor> executor_; 88 base::Thread io_thread_;
89 std::string url_base_;
90 scoped_refptr<URLRequestContextGetter> context_getter_;
91 SyncWebSocketFactory socket_factory_;
92 SessionMap session_map_;
75 scoped_ptr<CommandMap> command_map_; 93 scoped_ptr<CommandMap> command_map_;
76 std::string url_base_; 94 scoped_ptr<Adb> adb_;
95 scoped_ptr<DeviceManager> device_manager_;
96
97 DISALLOW_COPY_AND_ASSIGN(HttpHandler);
77 }; 98 };
78 99
79 namespace internal { 100 namespace internal {
80 extern const char kNewSessionIdCommand[]; 101
102 extern const char kNewSessionPathPattern[];
103
81 bool MatchesCommand(HttpMethod method, 104 bool MatchesCommand(HttpMethod method,
82 const std::string& path, 105 const std::string& path,
83 const CommandMapping& command, 106 const CommandMapping& command,
84 std::string* session_id, 107 std::string* session_id,
85 base::DictionaryValue* out_params); 108 base::DictionaryValue* out_params);
109
86 } // namespace internal 110 } // namespace internal
87 111
88 #endif // CHROME_TEST_CHROMEDRIVER_SERVER_HTTP_HANDLER_H_ 112 #endif // CHROME_TEST_CHROMEDRIVER_SERVER_HTTP_HANDLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698