OLD | NEW |
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 #include "chrome/test/chromedriver/net/test_http_server.h" | 5 #include "chrome/test/chromedriver/net/test_http_server.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/message_loop/message_loop_proxy.h" | 10 #include "base/message_loop/message_loop_proxy.h" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 void TestHttpServer::SetMessageAction(WebSocketMessageAction action) { | 68 void TestHttpServer::SetMessageAction(WebSocketMessageAction action) { |
69 base::AutoLock lock(action_lock_); | 69 base::AutoLock lock(action_lock_); |
70 message_action_ = action; | 70 message_action_ = action; |
71 } | 71 } |
72 | 72 |
73 GURL TestHttpServer::web_socket_url() const { | 73 GURL TestHttpServer::web_socket_url() const { |
74 base::AutoLock lock(url_lock_); | 74 base::AutoLock lock(url_lock_); |
75 return web_socket_url_; | 75 return web_socket_url_; |
76 } | 76 } |
77 | 77 |
78 void TestHttpServer::OnHttpRequest( | 78 void TestHttpServer::OnConnect(int connection_id) { |
79 int connection_id, | |
80 const net::HttpServerRequestInfo& info) { | |
81 server_->SetSendBufferSize(connection_id, kBufferSize); | 79 server_->SetSendBufferSize(connection_id, kBufferSize); |
82 server_->SetReceiveBufferSize(connection_id, kBufferSize); | 80 server_->SetReceiveBufferSize(connection_id, kBufferSize); |
83 } | 81 } |
84 | 82 |
85 void TestHttpServer::OnWebSocketRequest( | 83 void TestHttpServer::OnWebSocketRequest( |
86 int connection_id, | 84 int connection_id, |
87 const net::HttpServerRequestInfo& info) { | 85 const net::HttpServerRequestInfo& info) { |
88 server_->SetSendBufferSize(connection_id, kBufferSize); | |
89 server_->SetReceiveBufferSize(connection_id, kBufferSize); | |
90 | |
91 WebSocketRequestAction action; | 86 WebSocketRequestAction action; |
92 { | 87 { |
93 base::AutoLock lock(action_lock_); | 88 base::AutoLock lock(action_lock_); |
94 action = request_action_; | 89 action = request_action_; |
95 } | 90 } |
96 connections_.insert(connection_id); | 91 connections_.insert(connection_id); |
97 all_closed_event_.Reset(); | 92 all_closed_event_.Reset(); |
98 | 93 |
99 switch (action) { | 94 switch (action) { |
100 case kAccept: | 95 case kAccept: |
101 server_->AcceptWebSocket(connection_id, info); | 96 server_->AcceptWebSocket(connection_id, info); |
102 break; | 97 break; |
103 case kNotFound: | 98 case kNotFound: |
104 server_->Send404(connection_id); | 99 server_->Send404(connection_id); |
105 break; | 100 break; |
106 case kClose: | 101 case kClose: |
107 server_->Close(connection_id); | 102 server_->Close(connection_id); |
108 break; | 103 break; |
109 } | 104 } |
110 } | 105 } |
111 | 106 |
112 void TestHttpServer::OnWebSocketMessage(int connection_id, | 107 void TestHttpServer::OnWebSocketMessage(int connection_id, |
113 const std::string& data) { | 108 const std::string& data) { |
114 server_->SetSendBufferSize(connection_id, kBufferSize); | |
115 server_->SetReceiveBufferSize(connection_id, kBufferSize); | |
116 WebSocketMessageAction action; | 109 WebSocketMessageAction action; |
117 { | 110 { |
118 base::AutoLock lock(action_lock_); | 111 base::AutoLock lock(action_lock_); |
119 action = message_action_; | 112 action = message_action_; |
120 } | 113 } |
121 switch (action) { | 114 switch (action) { |
122 case kEchoMessage: | 115 case kEchoMessage: |
123 server_->SendOverWebSocket(connection_id, data); | 116 server_->SendOverWebSocket(connection_id, data); |
124 break; | 117 break; |
125 case kCloseOnMessage: | 118 case kCloseOnMessage: |
(...skipping 26 matching lines...) Expand all Loading... |
152 server_.reset(NULL); | 145 server_.reset(NULL); |
153 } | 146 } |
154 *success = server_.get(); | 147 *success = server_.get(); |
155 event->Signal(); | 148 event->Signal(); |
156 } | 149 } |
157 | 150 |
158 void TestHttpServer::StopOnServerThread(base::WaitableEvent* event) { | 151 void TestHttpServer::StopOnServerThread(base::WaitableEvent* event) { |
159 server_.reset(NULL); | 152 server_.reset(NULL); |
160 event->Signal(); | 153 event->Signal(); |
161 } | 154 } |
OLD | NEW |