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

Side by Side Diff: net/websockets/websocket_throttle_unittest.cc

Issue 12033072: Include destination port for websocket throttling. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fix things caught by toyoshim. Created 7 years, 10 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 | « net/websockets/websocket_throttle.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "net/websockets/websocket_throttle.h" 5 #include "net/websockets/websocket_throttle.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "googleurl/src/gurl.h" 10 #include "googleurl/src/gurl.h"
(...skipping 14 matching lines...) Expand all
25 virtual void OnSentData(net::SocketStream* socket, int amount_sent) {} 25 virtual void OnSentData(net::SocketStream* socket, int amount_sent) {}
26 virtual void OnReceivedData(net::SocketStream* socket, 26 virtual void OnReceivedData(net::SocketStream* socket,
27 const char* data, int len) {} 27 const char* data, int len) {}
28 virtual void OnClose(net::SocketStream* socket) {} 28 virtual void OnClose(net::SocketStream* socket) {}
29 }; 29 };
30 30
31 namespace net { 31 namespace net {
32 32
33 class WebSocketThrottleTest : public PlatformTest { 33 class WebSocketThrottleTest : public PlatformTest {
34 protected: 34 protected:
35 IPEndPoint MakeAddr(int a1, int a2, int a3, int a4) { 35 static IPEndPoint MakeAddr(int a1, int a2, int a3, int a4) {
36 IPAddressNumber ip; 36 IPAddressNumber ip;
37 ip.push_back(a1); 37 ip.push_back(a1);
38 ip.push_back(a2); 38 ip.push_back(a2);
39 ip.push_back(a3); 39 ip.push_back(a3);
40 ip.push_back(a4); 40 ip.push_back(a4);
41 return IPEndPoint(ip, 0); 41 return IPEndPoint(ip, 0);
42 } 42 }
43 43
44 static void MockSocketStreamConnect( 44 static void MockSocketStreamConnect(
45 SocketStream* socket, const AddressList& list) { 45 SocketStream* socket, const AddressList& list) {
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 // Trying to open connection to localhost will start without wait. 298 // Trying to open connection to localhost will start without wait.
299 EXPECT_EQ(OK, w1->OnStartOpenConnection(s1, callback_s1.callback())); 299 EXPECT_EQ(OK, w1->OnStartOpenConnection(s1, callback_s1.callback()));
300 300
301 DVLOG(1) << "socket1 close"; 301 DVLOG(1) << "socket1 close";
302 w1->OnClose(s1.get()); 302 w1->OnClose(s1.get());
303 s1->DetachDelegate(); 303 s1->DetachDelegate();
304 DVLOG(1) << "Done"; 304 DVLOG(1) << "Done";
305 MessageLoopForIO::current()->RunUntilIdle(); 305 MessageLoopForIO::current()->RunUntilIdle();
306 } 306 }
307 307
308 // A connection should not be blocked by another connection to the same IP
309 // with a different port.
310 TEST_F(WebSocketThrottleTest, NoThrottleForDistinctPort) {
311 TestURLRequestContext context;
312 DummySocketStreamDelegate delegate;
313 IPAddressNumber localhost;
314 ParseIPLiteralToNumber("127.0.0.1", &localhost);
315 WebSocketJob::set_websocket_over_spdy_enabled(false);
316
317 // socket1: 127.0.0.1:80
318 scoped_refptr<WebSocketJob> w1(new WebSocketJob(&delegate));
319 scoped_refptr<SocketStream> s1(
320 new SocketStream(GURL("ws://localhost:80/"), w1.get()));
321 s1->set_context(&context);
322 w1->InitSocketStream(s1.get());
323 MockSocketStreamConnect(s1, AddressList::CreateFromIPAddress(localhost, 80));
324
325 DVLOG(1) << "connecting socket1";
326 TestCompletionCallback callback_s1;
327 // Trying to open connection to localhost:80 will start without waiting.
328 EXPECT_EQ(OK, w1->OnStartOpenConnection(s1, callback_s1.callback()));
329
330 // socket2: 127.0.0.1:81
331 scoped_refptr<WebSocketJob> w2(new WebSocketJob(&delegate));
332 scoped_refptr<SocketStream> s2(
333 new SocketStream(GURL("ws://localhost:81/"), w2.get()));
334 s2->set_context(&context);
335 w2->InitSocketStream(s2.get());
336 MockSocketStreamConnect(s2, AddressList::CreateFromIPAddress(localhost, 81));
337
338 DVLOG(1) << "connecting socket2";
339 TestCompletionCallback callback_s2;
340 // Trying to open connection to localhost:81 will start without waiting.
341 EXPECT_EQ(OK, w2->OnStartOpenConnection(s2, callback_s2.callback()));
342
343 DVLOG(1) << "closing socket1";
344 w1->OnClose(s1.get());
345 s1->DetachDelegate();
346
347 DVLOG(1) << "closing socket2";
348 w2->OnClose(s2.get());
349 s2->DetachDelegate();
350 DVLOG(1) << "Done";
351 MessageLoopForIO::current()->RunUntilIdle();
352 }
353
308 } 354 }
OLDNEW
« no previous file with comments | « net/websockets/websocket_throttle.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698