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

Side by Side Diff: content/browser/renderer_host/websocket_dispatcher_host_unittest.cc

Issue 2003253002: [Devtools] Allow User-Agent header override for Websockets (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: tests Created 4 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
« no previous file with comments | « content/browser/bad_message.h ('k') | content/browser/renderer_host/websocket_host.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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 "content/browser/renderer_host/websocket_dispatcher_host.h" 5 #include "content/browser/renderer_host/websocket_dispatcher_host.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 url::Origin origin(GURL("http://example.com")); 122 url::Origin origin(GURL("http://example.com"));
123 int render_frame_id = -3; 123 int render_frame_id = -3;
124 124
125 for (int i = 0; i < number_of_channels; ++i) { 125 for (int i = 0; i < number_of_channels; ++i) {
126 int routing_id = next_routing_id_++; 126 int routing_id = next_routing_id_++;
127 WebSocketHostMsg_AddChannelRequest message( 127 WebSocketHostMsg_AddChannelRequest message(
128 routing_id, 128 routing_id,
129 socket_url, 129 socket_url,
130 requested_protocols, 130 requested_protocols,
131 origin, 131 origin,
132 "",
132 render_frame_id); 133 render_frame_id);
133 if (!dispatcher_host_->OnMessageReceived(message)) 134 if (!dispatcher_host_->OnMessageReceived(message))
134 return false; 135 return false;
135 } 136 }
136 137
137 return true; 138 return true;
138 } 139 }
139 140
140 // Adds and cancels |n| connections. Returns true if succeeded. 141 // Adds and cancels |n| connections. Returns true if succeeded.
141 bool AddAndCancelMultipleChannels(int number_of_channels) { 142 bool AddAndCancelMultipleChannels(int number_of_channels) {
142 GURL socket_url("ws://example.com/test"); 143 GURL socket_url("ws://example.com/test");
143 std::vector<std::string> requested_protocols; 144 std::vector<std::string> requested_protocols;
144 url::Origin origin(GURL("http://example.com")); 145 url::Origin origin(GURL("http://example.com"));
145 int render_frame_id = -3; 146 int render_frame_id = -3;
146 147
147 for (int i = 0; i < number_of_channels; ++i) { 148 for (int i = 0; i < number_of_channels; ++i) {
148 int routing_id = next_routing_id_++; 149 int routing_id = next_routing_id_++;
149 WebSocketHostMsg_AddChannelRequest messageAddChannelRequest( 150 WebSocketHostMsg_AddChannelRequest messageAddChannelRequest(
150 routing_id, 151 routing_id,
151 socket_url, 152 socket_url,
152 requested_protocols, 153 requested_protocols,
153 origin, 154 origin,
155 "",
154 render_frame_id); 156 render_frame_id);
155 if (!dispatcher_host_->OnMessageReceived(messageAddChannelRequest)) 157 if (!dispatcher_host_->OnMessageReceived(messageAddChannelRequest))
156 return false; 158 return false;
157 159
158 WebSocketMsg_DropChannel messageDropChannel( 160 WebSocketMsg_DropChannel messageDropChannel(
159 routing_id, false, net::kWebSocketErrorAbnormalClosure, ""); 161 routing_id, false, net::kWebSocketErrorAbnormalClosure, "");
160 if (!dispatcher_host_->OnMessageReceived(messageDropChannel)) 162 if (!dispatcher_host_->OnMessageReceived(messageDropChannel))
161 return false; 163 return false;
162 } 164 }
163 165
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 } 221 }
220 222
221 TEST_F(WebSocketDispatcherHostTest, AddChannelRequest) { 223 TEST_F(WebSocketDispatcherHostTest, AddChannelRequest) {
222 int routing_id = 123; 224 int routing_id = 123;
223 GURL socket_url("ws://example.com/test"); 225 GURL socket_url("ws://example.com/test");
224 std::vector<std::string> requested_protocols; 226 std::vector<std::string> requested_protocols;
225 requested_protocols.push_back("hello"); 227 requested_protocols.push_back("hello");
226 url::Origin origin(GURL("http://example.com")); 228 url::Origin origin(GURL("http://example.com"));
227 int render_frame_id = -2; 229 int render_frame_id = -2;
228 WebSocketHostMsg_AddChannelRequest message( 230 WebSocketHostMsg_AddChannelRequest message(
229 routing_id, socket_url, requested_protocols, origin, render_frame_id); 231 routing_id, socket_url, requested_protocols, origin, "", render_frame_id);
230 232
231 ASSERT_TRUE(dispatcher_host_->OnMessageReceived(message)); 233 ASSERT_TRUE(dispatcher_host_->OnMessageReceived(message));
232 234
233 ASSERT_EQ(1U, mock_hosts_.size()); 235 ASSERT_EQ(1U, mock_hosts_.size());
234 MockWebSocketHost* host = mock_hosts_[0]; 236 MockWebSocketHost* host = mock_hosts_[0];
235 237
236 ASSERT_EQ(1U, host->received_messages_.size()); 238 ASSERT_EQ(1U, host->received_messages_.size());
237 const IPC::Message& forwarded_message = host->received_messages_[0]; 239 const IPC::Message& forwarded_message = host->received_messages_[0];
238 EXPECT_EQ(WebSocketHostMsg_AddChannelRequest::ID, forwarded_message.type()); 240 EXPECT_EQ(WebSocketHostMsg_AddChannelRequest::ID, forwarded_message.type());
239 EXPECT_EQ(routing_id, forwarded_message.routing_id()); 241 EXPECT_EQ(routing_id, forwarded_message.routing_id());
(...skipping 13 matching lines...) Expand all
253 255
254 TEST_F(WebSocketDispatcherHostTest, SendFrame) { 256 TEST_F(WebSocketDispatcherHostTest, SendFrame) {
255 int routing_id = 123; 257 int routing_id = 123;
256 258
257 GURL socket_url("ws://example.com/test"); 259 GURL socket_url("ws://example.com/test");
258 std::vector<std::string> requested_protocols; 260 std::vector<std::string> requested_protocols;
259 requested_protocols.push_back("hello"); 261 requested_protocols.push_back("hello");
260 url::Origin origin(GURL("http://example.com")); 262 url::Origin origin(GURL("http://example.com"));
261 int render_frame_id = -2; 263 int render_frame_id = -2;
262 WebSocketHostMsg_AddChannelRequest add_channel_message( 264 WebSocketHostMsg_AddChannelRequest add_channel_message(
263 routing_id, socket_url, requested_protocols, origin, render_frame_id); 265 routing_id, socket_url, requested_protocols, origin, "", render_frame_id);
264 266
265 ASSERT_TRUE(dispatcher_host_->OnMessageReceived(add_channel_message)); 267 ASSERT_TRUE(dispatcher_host_->OnMessageReceived(add_channel_message));
266 268
267 std::vector<char> data; 269 std::vector<char> data;
268 WebSocketMsg_SendFrame send_frame_message( 270 WebSocketMsg_SendFrame send_frame_message(
269 routing_id, true, WEB_SOCKET_MESSAGE_TYPE_TEXT, data); 271 routing_id, true, WEB_SOCKET_MESSAGE_TYPE_TEXT, data);
270 272
271 EXPECT_TRUE(dispatcher_host_->OnMessageReceived(send_frame_message)); 273 EXPECT_TRUE(dispatcher_host_->OnMessageReceived(send_frame_message));
272 274
273 ASSERT_EQ(1U, mock_hosts_.size()); 275 ASSERT_EQ(1U, mock_hosts_.size());
274 MockWebSocketHost* host = mock_hosts_[0]; 276 MockWebSocketHost* host = mock_hosts_[0];
275 277
276 ASSERT_EQ(2U, host->received_messages_.size()); 278 ASSERT_EQ(2U, host->received_messages_.size());
277 { 279 {
278 const IPC::Message& forwarded_message = host->received_messages_[0]; 280 const IPC::Message& forwarded_message = host->received_messages_[0];
279 EXPECT_EQ(WebSocketHostMsg_AddChannelRequest::ID, forwarded_message.type()); 281 EXPECT_EQ(WebSocketHostMsg_AddChannelRequest::ID, forwarded_message.type());
280 EXPECT_EQ(routing_id, forwarded_message.routing_id()); 282 EXPECT_EQ(routing_id, forwarded_message.routing_id());
281 } 283 }
282 { 284 {
283 const IPC::Message& forwarded_message = host->received_messages_[1]; 285 const IPC::Message& forwarded_message = host->received_messages_[1];
284 EXPECT_EQ(WebSocketMsg_SendFrame::ID, forwarded_message.type()); 286 EXPECT_EQ(WebSocketMsg_SendFrame::ID, forwarded_message.type());
285 EXPECT_EQ(routing_id, forwarded_message.routing_id()); 287 EXPECT_EQ(routing_id, forwarded_message.routing_id());
286 } 288 }
287 } 289 }
288 290
289 TEST_F(WebSocketDispatcherHostTest, Destruct) { 291 TEST_F(WebSocketDispatcherHostTest, Destruct) {
290 WebSocketHostMsg_AddChannelRequest message1( 292 WebSocketHostMsg_AddChannelRequest message1(
291 123, GURL("ws://example.com/test"), std::vector<std::string>(), 293 123, GURL("ws://example.com/test"), std::vector<std::string>(),
292 url::Origin(GURL("http://example.com")), -1); 294 url::Origin(GURL("http://example.com")), "", -1);
293 WebSocketHostMsg_AddChannelRequest message2( 295 WebSocketHostMsg_AddChannelRequest message2(
294 456, GURL("ws://example.com/test2"), std::vector<std::string>(), 296 456, GURL("ws://example.com/test2"), std::vector<std::string>(),
295 url::Origin(GURL("http://example.com")), -1); 297 url::Origin(GURL("http://example.com")), "", -1);
296 298
297 ASSERT_TRUE(dispatcher_host_->OnMessageReceived(message1)); 299 ASSERT_TRUE(dispatcher_host_->OnMessageReceived(message1));
298 ASSERT_TRUE(dispatcher_host_->OnMessageReceived(message2)); 300 ASSERT_TRUE(dispatcher_host_->OnMessageReceived(message2));
299 301
300 ASSERT_EQ(2u, mock_hosts_.size()); 302 ASSERT_EQ(2u, mock_hosts_.size());
301 303
302 mock_hosts_.clear(); 304 mock_hosts_.clear();
303 dispatcher_host_ = NULL; 305 dispatcher_host_ = NULL;
304 306
305 ASSERT_EQ(2u, gone_hosts_.size()); 307 ASSERT_EQ(2u, gone_hosts_.size());
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 414
413 // This is a regression test for https://crrev.com/998173003/. 415 // This is a regression test for https://crrev.com/998173003/.
414 TEST_F(WebSocketDispatcherHostTest, InvalidScheme) { 416 TEST_F(WebSocketDispatcherHostTest, InvalidScheme) {
415 int routing_id = 123; 417 int routing_id = 123;
416 GURL socket_url("http://example.com/test"); 418 GURL socket_url("http://example.com/test");
417 std::vector<std::string> requested_protocols; 419 std::vector<std::string> requested_protocols;
418 requested_protocols.push_back("hello"); 420 requested_protocols.push_back("hello");
419 url::Origin origin(GURL("http://example.com")); 421 url::Origin origin(GURL("http://example.com"));
420 int render_frame_id = -2; 422 int render_frame_id = -2;
421 WebSocketHostMsg_AddChannelRequest message( 423 WebSocketHostMsg_AddChannelRequest message(
422 routing_id, socket_url, requested_protocols, origin, render_frame_id); 424 routing_id, socket_url, requested_protocols, origin, "", render_frame_id);
423 425
424 ASSERT_TRUE(dispatcher_host_->OnMessageReceived(message)); 426 ASSERT_TRUE(dispatcher_host_->OnMessageReceived(message));
425 427
426 ASSERT_EQ(1U, mock_hosts_.size()); 428 ASSERT_EQ(1U, mock_hosts_.size());
427 MockWebSocketHost* host = mock_hosts_[0]; 429 MockWebSocketHost* host = mock_hosts_[0];
428 430
429 // Tests that WebSocketHost::OnMessageReceived() doesn't cause a crash and 431 // Tests that WebSocketHost::OnMessageReceived() doesn't cause a crash and
430 // the connection with an invalid scheme fails here. 432 // the connection with an invalid scheme fails here.
431 // We call WebSocketHost::OnMessageReceived() here explicitly because 433 // We call WebSocketHost::OnMessageReceived() here explicitly because
432 // MockWebSocketHost does not call WebSocketHost::OnMessageReceived() for 434 // MockWebSocketHost does not call WebSocketHost::OnMessageReceived() for
433 // WebSocketHostMsg_AddChannelRequest. 435 // WebSocketHostMsg_AddChannelRequest.
434 host->WebSocketHost::OnMessageReceived(message); 436 host->WebSocketHost::OnMessageReceived(message);
435 437
436 EXPECT_EQ(0, dispatcher_host_->num_pending_connections()); 438 EXPECT_EQ(0, dispatcher_host_->num_pending_connections());
437 EXPECT_EQ(1, dispatcher_host_->num_failed_connections()); 439 EXPECT_EQ(1, dispatcher_host_->num_failed_connections());
438 EXPECT_EQ(0, dispatcher_host_->num_succeeded_connections()); 440 EXPECT_EQ(0, dispatcher_host_->num_succeeded_connections());
439 } 441 }
440 442
441 } // namespace 443 } // namespace
442 } // namespace content 444 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/bad_message.h ('k') | content/browser/renderer_host/websocket_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698