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

Side by Side Diff: trunk/src/net/websockets/websocket_throttle_test.cc

Issue 197463003: Revert 256579 "Allow the content browser client to specify a spe..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 6 years, 9 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 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 "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/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "net/base/address_list.h" 10 #include "net/base/address_list.h"
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 // configuration. 66 // configuration.
67 WebSocketJob::set_websocket_over_spdy_enabled(true); 67 WebSocketJob::set_websocket_over_spdy_enabled(true);
68 68
69 // For host1: 1.2.3.4, 1.2.3.5, 1.2.3.6 69 // For host1: 1.2.3.4, 1.2.3.5, 1.2.3.6
70 AddressList addr; 70 AddressList addr;
71 addr.push_back(MakeAddr(1, 2, 3, 4)); 71 addr.push_back(MakeAddr(1, 2, 3, 4));
72 addr.push_back(MakeAddr(1, 2, 3, 5)); 72 addr.push_back(MakeAddr(1, 2, 3, 5));
73 addr.push_back(MakeAddr(1, 2, 3, 6)); 73 addr.push_back(MakeAddr(1, 2, 3, 6));
74 scoped_refptr<WebSocketJob> w1(new WebSocketJob(&delegate)); 74 scoped_refptr<WebSocketJob> w1(new WebSocketJob(&delegate));
75 scoped_refptr<SocketStream> s1( 75 scoped_refptr<SocketStream> s1(
76 new SocketStream(GURL("ws://host1/"), w1.get(), &context, NULL)); 76 new SocketStream(GURL("ws://host1/"), w1.get()));
77 s1->set_context(&context);
77 w1->InitSocketStream(s1.get()); 78 w1->InitSocketStream(s1.get());
78 WebSocketThrottleTest::MockSocketStreamConnect(s1.get(), addr); 79 WebSocketThrottleTest::MockSocketStreamConnect(s1.get(), addr);
79 80
80 DVLOG(1) << "socket1"; 81 DVLOG(1) << "socket1";
81 TestCompletionCallback callback_s1; 82 TestCompletionCallback callback_s1;
82 // Trying to open connection to host1 will start without wait. 83 // Trying to open connection to host1 will start without wait.
83 EXPECT_EQ(OK, w1->OnStartOpenConnection(s1.get(), callback_s1.callback())); 84 EXPECT_EQ(OK, w1->OnStartOpenConnection(s1.get(), callback_s1.callback()));
84 85
85 // Now connecting to host1, so waiting queue looks like 86 // Now connecting to host1, so waiting queue looks like
86 // Address | head -> tail 87 // Address | head -> tail
87 // 1.2.3.4 | w1 88 // 1.2.3.4 | w1
88 // 1.2.3.5 | w1 89 // 1.2.3.5 | w1
89 // 1.2.3.6 | w1 90 // 1.2.3.6 | w1
90 91
91 // For host2: 1.2.3.4 92 // For host2: 1.2.3.4
92 addr.clear(); 93 addr.clear();
93 addr.push_back(MakeAddr(1, 2, 3, 4)); 94 addr.push_back(MakeAddr(1, 2, 3, 4));
94 scoped_refptr<WebSocketJob> w2(new WebSocketJob(&delegate)); 95 scoped_refptr<WebSocketJob> w2(new WebSocketJob(&delegate));
95 scoped_refptr<SocketStream> s2( 96 scoped_refptr<SocketStream> s2(
96 new SocketStream(GURL("ws://host2/"), w2.get(), &context, NULL)); 97 new SocketStream(GURL("ws://host2/"), w2.get()));
98 s2->set_context(&context);
97 w2->InitSocketStream(s2.get()); 99 w2->InitSocketStream(s2.get());
98 WebSocketThrottleTest::MockSocketStreamConnect(s2.get(), addr); 100 WebSocketThrottleTest::MockSocketStreamConnect(s2.get(), addr);
99 101
100 DVLOG(1) << "socket2"; 102 DVLOG(1) << "socket2";
101 TestCompletionCallback callback_s2; 103 TestCompletionCallback callback_s2;
102 // Trying to open connection to host2 will wait for w1. 104 // Trying to open connection to host2 will wait for w1.
103 EXPECT_EQ(ERR_IO_PENDING, 105 EXPECT_EQ(ERR_IO_PENDING,
104 w2->OnStartOpenConnection(s2.get(), callback_s2.callback())); 106 w2->OnStartOpenConnection(s2.get(), callback_s2.callback()));
105 // Now waiting queue looks like 107 // Now waiting queue looks like
106 // Address | head -> tail 108 // Address | head -> tail
107 // 1.2.3.4 | w1 w2 109 // 1.2.3.4 | w1 w2
108 // 1.2.3.5 | w1 110 // 1.2.3.5 | w1
109 // 1.2.3.6 | w1 111 // 1.2.3.6 | w1
110 112
111 // For host3: 1.2.3.5 113 // For host3: 1.2.3.5
112 addr.clear(); 114 addr.clear();
113 addr.push_back(MakeAddr(1, 2, 3, 5)); 115 addr.push_back(MakeAddr(1, 2, 3, 5));
114 scoped_refptr<WebSocketJob> w3(new WebSocketJob(&delegate)); 116 scoped_refptr<WebSocketJob> w3(new WebSocketJob(&delegate));
115 scoped_refptr<SocketStream> s3( 117 scoped_refptr<SocketStream> s3(
116 new SocketStream(GURL("ws://host3/"), w3.get(), &context, NULL)); 118 new SocketStream(GURL("ws://host3/"), w3.get()));
119 s3->set_context(&context);
117 w3->InitSocketStream(s3.get()); 120 w3->InitSocketStream(s3.get());
118 WebSocketThrottleTest::MockSocketStreamConnect(s3.get(), addr); 121 WebSocketThrottleTest::MockSocketStreamConnect(s3.get(), addr);
119 122
120 DVLOG(1) << "socket3"; 123 DVLOG(1) << "socket3";
121 TestCompletionCallback callback_s3; 124 TestCompletionCallback callback_s3;
122 // Trying to open connection to host3 will wait for w1. 125 // Trying to open connection to host3 will wait for w1.
123 EXPECT_EQ(ERR_IO_PENDING, 126 EXPECT_EQ(ERR_IO_PENDING,
124 w3->OnStartOpenConnection(s3.get(), callback_s3.callback())); 127 w3->OnStartOpenConnection(s3.get(), callback_s3.callback()));
125 // Address | head -> tail 128 // Address | head -> tail
126 // 1.2.3.4 | w1 w2 129 // 1.2.3.4 | w1 w2
127 // 1.2.3.5 | w1 w3 130 // 1.2.3.5 | w1 w3
128 // 1.2.3.6 | w1 131 // 1.2.3.6 | w1
129 132
130 // For host4: 1.2.3.4, 1.2.3.6 133 // For host4: 1.2.3.4, 1.2.3.6
131 addr.clear(); 134 addr.clear();
132 addr.push_back(MakeAddr(1, 2, 3, 4)); 135 addr.push_back(MakeAddr(1, 2, 3, 4));
133 addr.push_back(MakeAddr(1, 2, 3, 6)); 136 addr.push_back(MakeAddr(1, 2, 3, 6));
134 scoped_refptr<WebSocketJob> w4(new WebSocketJob(&delegate)); 137 scoped_refptr<WebSocketJob> w4(new WebSocketJob(&delegate));
135 scoped_refptr<SocketStream> s4( 138 scoped_refptr<SocketStream> s4(
136 new SocketStream(GURL("ws://host4/"), w4.get(), &context, NULL)); 139 new SocketStream(GURL("ws://host4/"), w4.get()));
140 s4->set_context(&context);
137 w4->InitSocketStream(s4.get()); 141 w4->InitSocketStream(s4.get());
138 WebSocketThrottleTest::MockSocketStreamConnect(s4.get(), addr); 142 WebSocketThrottleTest::MockSocketStreamConnect(s4.get(), addr);
139 143
140 DVLOG(1) << "socket4"; 144 DVLOG(1) << "socket4";
141 TestCompletionCallback callback_s4; 145 TestCompletionCallback callback_s4;
142 // Trying to open connection to host4 will wait for w1, w2. 146 // Trying to open connection to host4 will wait for w1, w2.
143 EXPECT_EQ(ERR_IO_PENDING, 147 EXPECT_EQ(ERR_IO_PENDING,
144 w4->OnStartOpenConnection(s4.get(), callback_s4.callback())); 148 w4->OnStartOpenConnection(s4.get(), callback_s4.callback()));
145 // Address | head -> tail 149 // Address | head -> tail
146 // 1.2.3.4 | w1 w2 w4 150 // 1.2.3.4 | w1 w2 w4
147 // 1.2.3.5 | w1 w3 151 // 1.2.3.5 | w1 w3
148 // 1.2.3.6 | w1 w4 152 // 1.2.3.6 | w1 w4
149 153
150 // For host5: 1.2.3.6 154 // For host5: 1.2.3.6
151 addr.clear(); 155 addr.clear();
152 addr.push_back(MakeAddr(1, 2, 3, 6)); 156 addr.push_back(MakeAddr(1, 2, 3, 6));
153 scoped_refptr<WebSocketJob> w5(new WebSocketJob(&delegate)); 157 scoped_refptr<WebSocketJob> w5(new WebSocketJob(&delegate));
154 scoped_refptr<SocketStream> s5( 158 scoped_refptr<SocketStream> s5(
155 new SocketStream(GURL("ws://host5/"), w5.get(), &context, NULL)); 159 new SocketStream(GURL("ws://host5/"), w5.get()));
160 s5->set_context(&context);
156 w5->InitSocketStream(s5.get()); 161 w5->InitSocketStream(s5.get());
157 WebSocketThrottleTest::MockSocketStreamConnect(s5.get(), addr); 162 WebSocketThrottleTest::MockSocketStreamConnect(s5.get(), addr);
158 163
159 DVLOG(1) << "socket5"; 164 DVLOG(1) << "socket5";
160 TestCompletionCallback callback_s5; 165 TestCompletionCallback callback_s5;
161 // Trying to open connection to host5 will wait for w1, w4 166 // Trying to open connection to host5 will wait for w1, w4
162 EXPECT_EQ(ERR_IO_PENDING, 167 EXPECT_EQ(ERR_IO_PENDING,
163 w5->OnStartOpenConnection(s5.get(), callback_s5.callback())); 168 w5->OnStartOpenConnection(s5.get(), callback_s5.callback()));
164 // Address | head -> tail 169 // Address | head -> tail
165 // 1.2.3.4 | w1 w2 w4 170 // 1.2.3.4 | w1 w2 w4
166 // 1.2.3.5 | w1 w3 171 // 1.2.3.5 | w1 w3
167 // 1.2.3.6 | w1 w4 w5 172 // 1.2.3.6 | w1 w4 w5
168 173
169 // For host6: 1.2.3.6 174 // For host6: 1.2.3.6
170 addr.clear(); 175 addr.clear();
171 addr.push_back(MakeAddr(1, 2, 3, 6)); 176 addr.push_back(MakeAddr(1, 2, 3, 6));
172 scoped_refptr<WebSocketJob> w6(new WebSocketJob(&delegate)); 177 scoped_refptr<WebSocketJob> w6(new WebSocketJob(&delegate));
173 scoped_refptr<SocketStream> s6( 178 scoped_refptr<SocketStream> s6(
174 new SocketStream(GURL("ws://host6/"), w6.get(), &context, NULL)); 179 new SocketStream(GURL("ws://host6/"), w6.get()));
180 s6->set_context(&context);
175 w6->InitSocketStream(s6.get()); 181 w6->InitSocketStream(s6.get());
176 WebSocketThrottleTest::MockSocketStreamConnect(s6.get(), addr); 182 WebSocketThrottleTest::MockSocketStreamConnect(s6.get(), addr);
177 183
178 DVLOG(1) << "socket6"; 184 DVLOG(1) << "socket6";
179 TestCompletionCallback callback_s6; 185 TestCompletionCallback callback_s6;
180 // Trying to open connection to host6 will wait for w1, w4, w5 186 // Trying to open connection to host6 will wait for w1, w4, w5
181 EXPECT_EQ(ERR_IO_PENDING, 187 EXPECT_EQ(ERR_IO_PENDING,
182 w6->OnStartOpenConnection(s6.get(), callback_s6.callback())); 188 w6->OnStartOpenConnection(s6.get(), callback_s6.callback()));
183 // Address | head -> tail 189 // Address | head -> tail
184 // 1.2.3.4 | w1 w2 w4 190 // 1.2.3.4 | w1 w2 w4
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 TestURLRequestContext context; 282 TestURLRequestContext context;
277 DummySocketStreamDelegate delegate; 283 DummySocketStreamDelegate delegate;
278 WebSocketJob::set_websocket_over_spdy_enabled(true); 284 WebSocketJob::set_websocket_over_spdy_enabled(true);
279 285
280 // For localhost: 127.0.0.1, 127.0.0.1 286 // For localhost: 127.0.0.1, 127.0.0.1
281 AddressList addr; 287 AddressList addr;
282 addr.push_back(MakeAddr(127, 0, 0, 1)); 288 addr.push_back(MakeAddr(127, 0, 0, 1));
283 addr.push_back(MakeAddr(127, 0, 0, 1)); 289 addr.push_back(MakeAddr(127, 0, 0, 1));
284 scoped_refptr<WebSocketJob> w1(new WebSocketJob(&delegate)); 290 scoped_refptr<WebSocketJob> w1(new WebSocketJob(&delegate));
285 scoped_refptr<SocketStream> s1( 291 scoped_refptr<SocketStream> s1(
286 new SocketStream(GURL("ws://localhost/"), w1.get(), &context, NULL)); 292 new SocketStream(GURL("ws://localhost/"), w1.get()));
293 s1->set_context(&context);
287 w1->InitSocketStream(s1.get()); 294 w1->InitSocketStream(s1.get());
288 WebSocketThrottleTest::MockSocketStreamConnect(s1.get(), addr); 295 WebSocketThrottleTest::MockSocketStreamConnect(s1.get(), addr);
289 296
290 DVLOG(1) << "socket1"; 297 DVLOG(1) << "socket1";
291 TestCompletionCallback callback_s1; 298 TestCompletionCallback callback_s1;
292 // Trying to open connection to localhost will start without wait. 299 // Trying to open connection to localhost will start without wait.
293 EXPECT_EQ(OK, w1->OnStartOpenConnection(s1.get(), callback_s1.callback())); 300 EXPECT_EQ(OK, w1->OnStartOpenConnection(s1.get(), callback_s1.callback()));
294 301
295 DVLOG(1) << "socket1 close"; 302 DVLOG(1) << "socket1 close";
296 w1->OnClose(s1.get()); 303 w1->OnClose(s1.get());
297 s1->DetachDelegate(); 304 s1->DetachDelegate();
298 DVLOG(1) << "Done"; 305 DVLOG(1) << "Done";
299 base::MessageLoopForIO::current()->RunUntilIdle(); 306 base::MessageLoopForIO::current()->RunUntilIdle();
300 } 307 }
301 308
302 // A connection should not be blocked by another connection to the same IP 309 // A connection should not be blocked by another connection to the same IP
303 // with a different port. 310 // with a different port.
304 TEST_F(WebSocketThrottleTest, NoThrottleForDistinctPort) { 311 TEST_F(WebSocketThrottleTest, NoThrottleForDistinctPort) {
305 TestURLRequestContext context; 312 TestURLRequestContext context;
306 DummySocketStreamDelegate delegate; 313 DummySocketStreamDelegate delegate;
307 IPAddressNumber localhost; 314 IPAddressNumber localhost;
308 ParseIPLiteralToNumber("127.0.0.1", &localhost); 315 ParseIPLiteralToNumber("127.0.0.1", &localhost);
309 WebSocketJob::set_websocket_over_spdy_enabled(false); 316 WebSocketJob::set_websocket_over_spdy_enabled(false);
310 317
311 // socket1: 127.0.0.1:80 318 // socket1: 127.0.0.1:80
312 scoped_refptr<WebSocketJob> w1(new WebSocketJob(&delegate)); 319 scoped_refptr<WebSocketJob> w1(new WebSocketJob(&delegate));
313 scoped_refptr<SocketStream> s1( 320 scoped_refptr<SocketStream> s1(
314 new SocketStream(GURL("ws://localhost:80/"), w1.get(), &context, NULL)); 321 new SocketStream(GURL("ws://localhost:80/"), w1.get()));
322 s1->set_context(&context);
315 w1->InitSocketStream(s1.get()); 323 w1->InitSocketStream(s1.get());
316 MockSocketStreamConnect(s1.get(), 324 MockSocketStreamConnect(s1.get(),
317 AddressList::CreateFromIPAddress(localhost, 80)); 325 AddressList::CreateFromIPAddress(localhost, 80));
318 326
319 DVLOG(1) << "connecting socket1"; 327 DVLOG(1) << "connecting socket1";
320 TestCompletionCallback callback_s1; 328 TestCompletionCallback callback_s1;
321 // Trying to open connection to localhost:80 will start without waiting. 329 // Trying to open connection to localhost:80 will start without waiting.
322 EXPECT_EQ(OK, w1->OnStartOpenConnection(s1.get(), callback_s1.callback())); 330 EXPECT_EQ(OK, w1->OnStartOpenConnection(s1.get(), callback_s1.callback()));
323 331
324 // socket2: 127.0.0.1:81 332 // socket2: 127.0.0.1:81
325 scoped_refptr<WebSocketJob> w2(new WebSocketJob(&delegate)); 333 scoped_refptr<WebSocketJob> w2(new WebSocketJob(&delegate));
326 scoped_refptr<SocketStream> s2( 334 scoped_refptr<SocketStream> s2(
327 new SocketStream(GURL("ws://localhost:81/"), w2.get(), &context, NULL)); 335 new SocketStream(GURL("ws://localhost:81/"), w2.get()));
336 s2->set_context(&context);
328 w2->InitSocketStream(s2.get()); 337 w2->InitSocketStream(s2.get());
329 MockSocketStreamConnect(s2.get(), 338 MockSocketStreamConnect(s2.get(),
330 AddressList::CreateFromIPAddress(localhost, 81)); 339 AddressList::CreateFromIPAddress(localhost, 81));
331 340
332 DVLOG(1) << "connecting socket2"; 341 DVLOG(1) << "connecting socket2";
333 TestCompletionCallback callback_s2; 342 TestCompletionCallback callback_s2;
334 // Trying to open connection to localhost:81 will start without waiting. 343 // Trying to open connection to localhost:81 will start without waiting.
335 EXPECT_EQ(OK, w2->OnStartOpenConnection(s2.get(), callback_s2.callback())); 344 EXPECT_EQ(OK, w2->OnStartOpenConnection(s2.get(), callback_s2.callback()));
336 345
337 DVLOG(1) << "closing socket1"; 346 DVLOG(1) << "closing socket1";
338 w1->OnClose(s1.get()); 347 w1->OnClose(s1.get());
339 s1->DetachDelegate(); 348 s1->DetachDelegate();
340 349
341 DVLOG(1) << "closing socket2"; 350 DVLOG(1) << "closing socket2";
342 w2->OnClose(s2.get()); 351 w2->OnClose(s2.get());
343 s2->DetachDelegate(); 352 s2->DetachDelegate();
344 DVLOG(1) << "Done"; 353 DVLOG(1) << "Done";
345 base::MessageLoopForIO::current()->RunUntilIdle(); 354 base::MessageLoopForIO::current()->RunUntilIdle();
346 } 355 }
347 356
348 } 357 }
OLDNEW
« no previous file with comments | « trunk/src/net/websockets/websocket_job_test.cc ('k') | trunk/src/remoting/host/token_validator_factory_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698