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

Side by Side Diff: chrome/test/chromedriver/net/test_http_server.cc

Issue 590653002: [chromedriver] Remove extra call to HttpServer::Close() and increase TestHttpServer buffer limit (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add comment Created 6 years, 3 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
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 #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"
11 #include "base/strings/stringprintf.h" 11 #include "base/strings/stringprintf.h"
12 #include "base/time/time.h" 12 #include "base/time/time.h"
13 #include "net/base/ip_endpoint.h" 13 #include "net/base/ip_endpoint.h"
14 #include "net/base/net_errors.h" 14 #include "net/base/net_errors.h"
15 #include "net/server/http_server_request_info.h" 15 #include "net/server/http_server_request_info.h"
16 #include "net/socket/tcp_server_socket.h" 16 #include "net/socket/tcp_server_socket.h"
17 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
18 18
19 const int kBufferSize = 100 * 1024 * 1024; // 100 MB
20
19 TestHttpServer::TestHttpServer() 21 TestHttpServer::TestHttpServer()
20 : thread_("ServerThread"), 22 : thread_("ServerThread"),
21 all_closed_event_(false, true), 23 all_closed_event_(false, true),
22 request_action_(kAccept), 24 request_action_(kAccept),
23 message_action_(kEchoMessage) { 25 message_action_(kEchoMessage) {
24 } 26 }
25 27
26 TestHttpServer::~TestHttpServer() { 28 TestHttpServer::~TestHttpServer() {
27 } 29 }
28 30
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 void TestHttpServer::SetMessageAction(WebSocketMessageAction action) { 68 void TestHttpServer::SetMessageAction(WebSocketMessageAction action) {
67 base::AutoLock lock(action_lock_); 69 base::AutoLock lock(action_lock_);
68 message_action_ = action; 70 message_action_ = action;
69 } 71 }
70 72
71 GURL TestHttpServer::web_socket_url() const { 73 GURL TestHttpServer::web_socket_url() const {
72 base::AutoLock lock(url_lock_); 74 base::AutoLock lock(url_lock_);
73 return web_socket_url_; 75 return web_socket_url_;
74 } 76 }
75 77
78 void TestHttpServer::OnHttpRequest(
79 int connection_id,
80 const net::HttpServerRequestInfo& info) {
81 server_->SetSendBufferSize(connection_id, kBufferSize);
82 server_->SetReceiveBufferSize(connection_id, kBufferSize);
83 }
84
76 void TestHttpServer::OnWebSocketRequest( 85 void TestHttpServer::OnWebSocketRequest(
77 int connection_id, 86 int connection_id,
78 const net::HttpServerRequestInfo& info) { 87 const net::HttpServerRequestInfo& info) {
88 server_->SetSendBufferSize(connection_id, kBufferSize);
89 server_->SetReceiveBufferSize(connection_id, kBufferSize);
90
79 WebSocketRequestAction action; 91 WebSocketRequestAction action;
80 { 92 {
81 base::AutoLock lock(action_lock_); 93 base::AutoLock lock(action_lock_);
82 action = request_action_; 94 action = request_action_;
83 } 95 }
84 connections_.insert(connection_id); 96 connections_.insert(connection_id);
85 all_closed_event_.Reset(); 97 all_closed_event_.Reset();
86 98
87 switch (action) { 99 switch (action) {
88 case kAccept: 100 case kAccept:
89 server_->AcceptWebSocket(connection_id, info); 101 server_->AcceptWebSocket(connection_id, info);
90 break; 102 break;
91 case kNotFound: 103 case kNotFound:
92 server_->Send404(connection_id); 104 server_->Send404(connection_id);
93 break; 105 break;
94 case kClose: 106 case kClose:
95 server_->Close(connection_id); 107 server_->Close(connection_id);
96 break; 108 break;
97 } 109 }
98 } 110 }
99 111
100 void TestHttpServer::OnWebSocketMessage(int connection_id, 112 void TestHttpServer::OnWebSocketMessage(int connection_id,
101 const std::string& data) { 113 const std::string& data) {
114 server_->SetSendBufferSize(connection_id, kBufferSize);
115 server_->SetReceiveBufferSize(connection_id, kBufferSize);
102 WebSocketMessageAction action; 116 WebSocketMessageAction action;
103 { 117 {
104 base::AutoLock lock(action_lock_); 118 base::AutoLock lock(action_lock_);
105 action = message_action_; 119 action = message_action_;
106 } 120 }
107 switch (action) { 121 switch (action) {
108 case kEchoMessage: 122 case kEchoMessage:
109 server_->SendOverWebSocket(connection_id, data); 123 server_->SendOverWebSocket(connection_id, data);
110 break; 124 break;
111 case kCloseOnMessage: 125 case kCloseOnMessage:
(...skipping 26 matching lines...) Expand all
138 server_.reset(NULL); 152 server_.reset(NULL);
139 } 153 }
140 *success = server_.get(); 154 *success = server_.get();
141 event->Signal(); 155 event->Signal();
142 } 156 }
143 157
144 void TestHttpServer::StopOnServerThread(base::WaitableEvent* event) { 158 void TestHttpServer::StopOnServerThread(base::WaitableEvent* event) {
145 server_.reset(NULL); 159 server_.reset(NULL);
146 event->Signal(); 160 event->Signal();
147 } 161 }
OLDNEW
« no previous file with comments | « chrome/test/chromedriver/net/test_http_server.h ('k') | chrome/test/chromedriver/server/chromedriver_server.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698