OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "modules/websockets/WebSocketChannel.h" | 5 #include "modules/websockets/WebSocketChannel.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <memory> | 8 #include <memory> |
9 #include "core/dom/DOMArrayBuffer.h" | 9 #include "core/dom/DOMArrayBuffer.h" |
10 #include "core/dom/Document.h" | 10 #include "core/dom/Document.h" |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 MockWebSocketHandle* handle() { return m_handle; } | 120 MockWebSocketHandle* handle() { return m_handle; } |
121 | 121 |
122 void didConsumeBufferedAmount(unsigned long a) { | 122 void didConsumeBufferedAmount(unsigned long a) { |
123 m_sumOfConsumedBufferedAmount += a; | 123 m_sumOfConsumedBufferedAmount += a; |
124 } | 124 } |
125 | 125 |
126 void connect() { | 126 void connect() { |
127 { | 127 { |
128 InSequence s; | 128 InSequence s; |
129 EXPECT_CALL(*handle(), initialize(_)); | 129 EXPECT_CALL(*handle(), initialize(_)); |
130 EXPECT_CALL(*handle(), connect(KURL(KURL(), "ws://localhost/"), _, _, _, | 130 EXPECT_CALL( |
131 _, handleClient())); | 131 *handle(), |
| 132 connect(KURL(KURL(), "ws://localhost/"), _, _, _, _, handleClient())); |
132 EXPECT_CALL(*handle(), flowControl(65536)); | 133 EXPECT_CALL(*handle(), flowControl(65536)); |
133 EXPECT_CALL(*channelClient(), didConnect(String("a"), String("b"))); | 134 EXPECT_CALL(*channelClient(), didConnect(String("a"), String("b"))); |
134 } | 135 } |
135 EXPECT_TRUE(channel()->connect(KURL(KURL(), "ws://localhost/"), "x")); | 136 EXPECT_TRUE(channel()->connect(KURL(KURL(), "ws://localhost/"), "x")); |
136 handleClient()->didConnect(handle(), String("a"), String("b")); | 137 handleClient()->didConnect(handle(), String("a"), String("b")); |
137 ::testing::Mock::VerifyAndClearExpectations(this); | 138 ::testing::Mock::VerifyAndClearExpectations(this); |
138 } | 139 } |
139 | 140 |
140 std::unique_ptr<DummyPageHolder> m_pageHolder; | 141 std::unique_ptr<DummyPageHolder> m_pageHolder; |
141 Persistent<MockWebSocketChannelClient> m_channelClient; | 142 Persistent<MockWebSocketChannelClient> m_channelClient; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 EXPECT_STREQ("http://example.com", origin->toString().utf8().data()); | 202 EXPECT_STREQ("http://example.com", origin->toString().utf8().data()); |
202 | 203 |
203 checkpoint.Call(1); | 204 checkpoint.Call(1); |
204 handleClient()->didConnect(handle(), String("a"), String("b")); | 205 handleClient()->didConnect(handle(), String("a"), String("b")); |
205 } | 206 } |
206 | 207 |
207 TEST_F(DocumentWebSocketChannelTest, sendText) { | 208 TEST_F(DocumentWebSocketChannelTest, sendText) { |
208 connect(); | 209 connect(); |
209 { | 210 { |
210 InSequence s; | 211 InSequence s; |
211 EXPECT_CALL(*handle(), send(true, WebSocketHandle::MessageTypeText, | 212 EXPECT_CALL( |
212 MemEq("foo", 3), 3)); | 213 *handle(), |
213 EXPECT_CALL(*handle(), send(true, WebSocketHandle::MessageTypeText, | 214 send(true, WebSocketHandle::MessageTypeText, MemEq("foo", 3), 3)); |
214 MemEq("bar", 3), 3)); | 215 EXPECT_CALL( |
215 EXPECT_CALL(*handle(), send(true, WebSocketHandle::MessageTypeText, | 216 *handle(), |
216 MemEq("baz", 3), 3)); | 217 send(true, WebSocketHandle::MessageTypeText, MemEq("bar", 3), 3)); |
| 218 EXPECT_CALL( |
| 219 *handle(), |
| 220 send(true, WebSocketHandle::MessageTypeText, MemEq("baz", 3), 3)); |
217 } | 221 } |
218 | 222 |
219 handleClient()->didReceiveFlowControl(handle(), 16); | 223 handleClient()->didReceiveFlowControl(handle(), 16); |
220 EXPECT_CALL(*channelClient(), didConsumeBufferedAmount(_)).Times(AnyNumber()); | 224 EXPECT_CALL(*channelClient(), didConsumeBufferedAmount(_)).Times(AnyNumber()); |
221 | 225 |
222 channel()->send("foo"); | 226 channel()->send("foo"); |
223 channel()->send("bar"); | 227 channel()->send("bar"); |
224 channel()->send("baz"); | 228 channel()->send("baz"); |
225 | 229 |
226 EXPECT_EQ(9ul, m_sumOfConsumedBufferedAmount); | 230 EXPECT_EQ(9ul, m_sumOfConsumedBufferedAmount); |
227 } | 231 } |
228 | 232 |
229 TEST_F(DocumentWebSocketChannelTest, sendTextContinuation) { | 233 TEST_F(DocumentWebSocketChannelTest, sendTextContinuation) { |
230 connect(); | 234 connect(); |
231 Checkpoint checkpoint; | 235 Checkpoint checkpoint; |
232 { | 236 { |
233 InSequence s; | 237 InSequence s; |
234 EXPECT_CALL(*handle(), send(false, WebSocketHandle::MessageTypeText, | 238 EXPECT_CALL(*handle(), |
235 MemEq("0123456789abcdef", 16), 16)); | 239 send(false, WebSocketHandle::MessageTypeText, |
| 240 MemEq("0123456789abcdef", 16), 16)); |
236 EXPECT_CALL(checkpoint, Call(1)); | 241 EXPECT_CALL(checkpoint, Call(1)); |
237 EXPECT_CALL(*handle(), send(true, WebSocketHandle::MessageTypeContinuation, | 242 EXPECT_CALL( |
238 MemEq("g", 1), 1)); | 243 *handle(), |
239 EXPECT_CALL(*handle(), send(true, WebSocketHandle::MessageTypeText, | 244 send(true, WebSocketHandle::MessageTypeContinuation, MemEq("g", 1), 1)); |
240 MemEq("hijk", 4), 4)); | 245 EXPECT_CALL( |
241 EXPECT_CALL(*handle(), send(false, WebSocketHandle::MessageTypeText, | 246 *handle(), |
242 MemEq("lmnopqrstuv", 11), 11)); | 247 send(true, WebSocketHandle::MessageTypeText, MemEq("hijk", 4), 4)); |
| 248 EXPECT_CALL(*handle(), |
| 249 send(false, WebSocketHandle::MessageTypeText, |
| 250 MemEq("lmnopqrstuv", 11), 11)); |
243 EXPECT_CALL(checkpoint, Call(2)); | 251 EXPECT_CALL(checkpoint, Call(2)); |
244 EXPECT_CALL(*handle(), send(false, WebSocketHandle::MessageTypeContinuation, | 252 EXPECT_CALL(*handle(), |
245 MemEq("wxyzABCDEFGHIJKL", 16), 16)); | 253 send(false, WebSocketHandle::MessageTypeContinuation, |
| 254 MemEq("wxyzABCDEFGHIJKL", 16), 16)); |
246 EXPECT_CALL(checkpoint, Call(3)); | 255 EXPECT_CALL(checkpoint, Call(3)); |
247 EXPECT_CALL(*handle(), send(true, WebSocketHandle::MessageTypeContinuation, | 256 EXPECT_CALL(*handle(), |
248 MemEq("MNOPQRSTUVWXYZ", 14), 14)); | 257 send(true, WebSocketHandle::MessageTypeContinuation, |
| 258 MemEq("MNOPQRSTUVWXYZ", 14), 14)); |
249 } | 259 } |
250 | 260 |
251 handleClient()->didReceiveFlowControl(handle(), 16); | 261 handleClient()->didReceiveFlowControl(handle(), 16); |
252 EXPECT_CALL(*channelClient(), didConsumeBufferedAmount(_)).Times(AnyNumber()); | 262 EXPECT_CALL(*channelClient(), didConsumeBufferedAmount(_)).Times(AnyNumber()); |
253 | 263 |
254 channel()->send("0123456789abcdefg"); | 264 channel()->send("0123456789abcdefg"); |
255 channel()->send("hijk"); | 265 channel()->send("hijk"); |
256 channel()->send("lmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"); | 266 channel()->send("lmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"); |
257 checkpoint.Call(1); | 267 checkpoint.Call(1); |
258 handleClient()->didReceiveFlowControl(handle(), 16); | 268 handleClient()->didReceiveFlowControl(handle(), 16); |
259 checkpoint.Call(2); | 269 checkpoint.Call(2); |
260 handleClient()->didReceiveFlowControl(handle(), 16); | 270 handleClient()->didReceiveFlowControl(handle(), 16); |
261 checkpoint.Call(3); | 271 checkpoint.Call(3); |
262 handleClient()->didReceiveFlowControl(handle(), 16); | 272 handleClient()->didReceiveFlowControl(handle(), 16); |
263 | 273 |
264 EXPECT_EQ(62ul, m_sumOfConsumedBufferedAmount); | 274 EXPECT_EQ(62ul, m_sumOfConsumedBufferedAmount); |
265 } | 275 } |
266 | 276 |
267 TEST_F(DocumentWebSocketChannelTest, sendBinaryInVector) { | 277 TEST_F(DocumentWebSocketChannelTest, sendBinaryInVector) { |
268 connect(); | 278 connect(); |
269 { | 279 { |
270 InSequence s; | 280 InSequence s; |
271 EXPECT_CALL(*handle(), send(true, WebSocketHandle::MessageTypeBinary, | 281 EXPECT_CALL( |
272 MemEq("foo", 3), 3)); | 282 *handle(), |
| 283 send(true, WebSocketHandle::MessageTypeBinary, MemEq("foo", 3), 3)); |
273 } | 284 } |
274 | 285 |
275 handleClient()->didReceiveFlowControl(handle(), 16); | 286 handleClient()->didReceiveFlowControl(handle(), 16); |
276 EXPECT_CALL(*channelClient(), didConsumeBufferedAmount(_)).Times(AnyNumber()); | 287 EXPECT_CALL(*channelClient(), didConsumeBufferedAmount(_)).Times(AnyNumber()); |
277 | 288 |
278 Vector<char> fooVector; | 289 Vector<char> fooVector; |
279 fooVector.append("foo", 3); | 290 fooVector.append("foo", 3); |
280 channel()->sendBinaryAsCharVector(WTF::makeUnique<Vector<char>>(fooVector)); | 291 channel()->sendBinaryAsCharVector(WTF::makeUnique<Vector<char>>(fooVector)); |
281 | 292 |
282 EXPECT_EQ(3ul, m_sumOfConsumedBufferedAmount); | 293 EXPECT_EQ(3ul, m_sumOfConsumedBufferedAmount); |
283 } | 294 } |
284 | 295 |
285 TEST_F(DocumentWebSocketChannelTest, sendBinaryInVectorWithNullBytes) { | 296 TEST_F(DocumentWebSocketChannelTest, sendBinaryInVectorWithNullBytes) { |
286 connect(); | 297 connect(); |
287 { | 298 { |
288 InSequence s; | 299 InSequence s; |
289 EXPECT_CALL(*handle(), send(true, WebSocketHandle::MessageTypeBinary, | 300 EXPECT_CALL( |
290 MemEq("\0ar", 3), 3)); | 301 *handle(), |
291 EXPECT_CALL(*handle(), send(true, WebSocketHandle::MessageTypeBinary, | 302 send(true, WebSocketHandle::MessageTypeBinary, MemEq("\0ar", 3), 3)); |
292 MemEq("b\0z", 3), 3)); | 303 EXPECT_CALL( |
293 EXPECT_CALL(*handle(), send(true, WebSocketHandle::MessageTypeBinary, | 304 *handle(), |
294 MemEq("qu\0", 3), 3)); | 305 send(true, WebSocketHandle::MessageTypeBinary, MemEq("b\0z", 3), 3)); |
295 EXPECT_CALL(*handle(), send(true, WebSocketHandle::MessageTypeBinary, | 306 EXPECT_CALL( |
296 MemEq("\0\0\0", 3), 3)); | 307 *handle(), |
| 308 send(true, WebSocketHandle::MessageTypeBinary, MemEq("qu\0", 3), 3)); |
| 309 EXPECT_CALL( |
| 310 *handle(), |
| 311 send(true, WebSocketHandle::MessageTypeBinary, MemEq("\0\0\0", 3), 3)); |
297 } | 312 } |
298 | 313 |
299 handleClient()->didReceiveFlowControl(handle(), 16); | 314 handleClient()->didReceiveFlowControl(handle(), 16); |
300 EXPECT_CALL(*channelClient(), didConsumeBufferedAmount(_)).Times(AnyNumber()); | 315 EXPECT_CALL(*channelClient(), didConsumeBufferedAmount(_)).Times(AnyNumber()); |
301 | 316 |
302 { | 317 { |
303 Vector<char> v; | 318 Vector<char> v; |
304 v.append("\0ar", 3); | 319 v.append("\0ar", 3); |
305 channel()->sendBinaryAsCharVector(WTF::makeUnique<Vector<char>>(v)); | 320 channel()->sendBinaryAsCharVector(WTF::makeUnique<Vector<char>>(v)); |
306 } | 321 } |
(...skipping 11 matching lines...) Expand all Loading... |
318 Vector<char> v; | 333 Vector<char> v; |
319 v.append("\0\0\0", 3); | 334 v.append("\0\0\0", 3); |
320 channel()->sendBinaryAsCharVector(WTF::makeUnique<Vector<char>>(v)); | 335 channel()->sendBinaryAsCharVector(WTF::makeUnique<Vector<char>>(v)); |
321 } | 336 } |
322 | 337 |
323 EXPECT_EQ(12ul, m_sumOfConsumedBufferedAmount); | 338 EXPECT_EQ(12ul, m_sumOfConsumedBufferedAmount); |
324 } | 339 } |
325 | 340 |
326 TEST_F(DocumentWebSocketChannelTest, sendBinaryInVectorNonLatin1UTF8) { | 341 TEST_F(DocumentWebSocketChannelTest, sendBinaryInVectorNonLatin1UTF8) { |
327 connect(); | 342 connect(); |
328 EXPECT_CALL(*handle(), send(true, WebSocketHandle::MessageTypeBinary, | 343 EXPECT_CALL(*handle(), |
329 MemEq("\xe7\x8b\x90", 3), 3)); | 344 send(true, WebSocketHandle::MessageTypeBinary, |
| 345 MemEq("\xe7\x8b\x90", 3), 3)); |
330 | 346 |
331 handleClient()->didReceiveFlowControl(handle(), 16); | 347 handleClient()->didReceiveFlowControl(handle(), 16); |
332 EXPECT_CALL(*channelClient(), didConsumeBufferedAmount(_)).Times(AnyNumber()); | 348 EXPECT_CALL(*channelClient(), didConsumeBufferedAmount(_)).Times(AnyNumber()); |
333 | 349 |
334 Vector<char> v; | 350 Vector<char> v; |
335 v.append("\xe7\x8b\x90", 3); | 351 v.append("\xe7\x8b\x90", 3); |
336 channel()->sendBinaryAsCharVector(WTF::makeUnique<Vector<char>>(v)); | 352 channel()->sendBinaryAsCharVector(WTF::makeUnique<Vector<char>>(v)); |
337 | 353 |
338 EXPECT_EQ(3ul, m_sumOfConsumedBufferedAmount); | 354 EXPECT_EQ(3ul, m_sumOfConsumedBufferedAmount); |
339 } | 355 } |
340 | 356 |
341 TEST_F(DocumentWebSocketChannelTest, sendBinaryInVectorNonUTF8) { | 357 TEST_F(DocumentWebSocketChannelTest, sendBinaryInVectorNonUTF8) { |
342 connect(); | 358 connect(); |
343 EXPECT_CALL(*handle(), send(true, WebSocketHandle::MessageTypeBinary, | 359 EXPECT_CALL(*handle(), |
344 MemEq("\x80\xff\xe7", 3), 3)); | 360 send(true, WebSocketHandle::MessageTypeBinary, |
| 361 MemEq("\x80\xff\xe7", 3), 3)); |
345 | 362 |
346 handleClient()->didReceiveFlowControl(handle(), 16); | 363 handleClient()->didReceiveFlowControl(handle(), 16); |
347 EXPECT_CALL(*channelClient(), didConsumeBufferedAmount(_)).Times(AnyNumber()); | 364 EXPECT_CALL(*channelClient(), didConsumeBufferedAmount(_)).Times(AnyNumber()); |
348 | 365 |
349 Vector<char> v; | 366 Vector<char> v; |
350 v.append("\x80\xff\xe7", 3); | 367 v.append("\x80\xff\xe7", 3); |
351 channel()->sendBinaryAsCharVector(WTF::makeUnique<Vector<char>>(v)); | 368 channel()->sendBinaryAsCharVector(WTF::makeUnique<Vector<char>>(v)); |
352 | 369 |
353 EXPECT_EQ(3ul, m_sumOfConsumedBufferedAmount); | 370 EXPECT_EQ(3ul, m_sumOfConsumedBufferedAmount); |
354 } | 371 } |
355 | 372 |
356 TEST_F(DocumentWebSocketChannelTest, | 373 TEST_F(DocumentWebSocketChannelTest, |
357 sendBinaryInVectorNonLatin1UTF8Continuation) { | 374 sendBinaryInVectorNonLatin1UTF8Continuation) { |
358 connect(); | 375 connect(); |
359 Checkpoint checkpoint; | 376 Checkpoint checkpoint; |
360 { | 377 { |
361 InSequence s; | 378 InSequence s; |
362 EXPECT_CALL(*handle(), send(false, WebSocketHandle::MessageTypeBinary, | 379 EXPECT_CALL(*handle(), |
363 MemEq("\xe7\x8b\x90\xe7\x8b\x90\xe7\x8b\x90\xe7" | 380 send(false, WebSocketHandle::MessageTypeBinary, |
364 "\x8b\x90\xe7\x8b\x90\xe7", | 381 MemEq("\xe7\x8b\x90\xe7\x8b\x90\xe7\x8b\x90\xe7" |
365 16), | 382 "\x8b\x90\xe7\x8b\x90\xe7", |
366 16)); | 383 16), |
| 384 16)); |
367 EXPECT_CALL(checkpoint, Call(1)); | 385 EXPECT_CALL(checkpoint, Call(1)); |
368 EXPECT_CALL(*handle(), send(true, WebSocketHandle::MessageTypeContinuation, | 386 EXPECT_CALL(*handle(), |
369 MemEq("\x8b\x90", 2), 2)); | 387 send(true, WebSocketHandle::MessageTypeContinuation, |
| 388 MemEq("\x8b\x90", 2), 2)); |
370 } | 389 } |
371 | 390 |
372 handleClient()->didReceiveFlowControl(handle(), 16); | 391 handleClient()->didReceiveFlowControl(handle(), 16); |
373 EXPECT_CALL(*channelClient(), didConsumeBufferedAmount(_)).Times(AnyNumber()); | 392 EXPECT_CALL(*channelClient(), didConsumeBufferedAmount(_)).Times(AnyNumber()); |
374 | 393 |
375 Vector<char> v; | 394 Vector<char> v; |
376 v.append( | 395 v.append( |
377 "\xe7\x8b\x90\xe7\x8b\x90\xe7\x8b\x90\xe7\x8b\x90\xe7\x8b\x90\xe7\x8b" | 396 "\xe7\x8b\x90\xe7\x8b\x90\xe7\x8b\x90\xe7\x8b\x90\xe7\x8b\x90\xe7\x8b" |
378 "\x90", | 397 "\x90", |
379 18); | 398 18); |
380 channel()->sendBinaryAsCharVector(WTF::makeUnique<Vector<char>>(v)); | 399 channel()->sendBinaryAsCharVector(WTF::makeUnique<Vector<char>>(v)); |
381 checkpoint.Call(1); | 400 checkpoint.Call(1); |
382 | 401 |
383 handleClient()->didReceiveFlowControl(handle(), 16); | 402 handleClient()->didReceiveFlowControl(handle(), 16); |
384 | 403 |
385 EXPECT_EQ(18ul, m_sumOfConsumedBufferedAmount); | 404 EXPECT_EQ(18ul, m_sumOfConsumedBufferedAmount); |
386 } | 405 } |
387 | 406 |
388 TEST_F(DocumentWebSocketChannelTest, sendBinaryInArrayBuffer) { | 407 TEST_F(DocumentWebSocketChannelTest, sendBinaryInArrayBuffer) { |
389 connect(); | 408 connect(); |
390 { | 409 { |
391 InSequence s; | 410 InSequence s; |
392 EXPECT_CALL(*handle(), send(true, WebSocketHandle::MessageTypeBinary, | 411 EXPECT_CALL( |
393 MemEq("foo", 3), 3)); | 412 *handle(), |
| 413 send(true, WebSocketHandle::MessageTypeBinary, MemEq("foo", 3), 3)); |
394 } | 414 } |
395 | 415 |
396 handleClient()->didReceiveFlowControl(handle(), 16); | 416 handleClient()->didReceiveFlowControl(handle(), 16); |
397 EXPECT_CALL(*channelClient(), didConsumeBufferedAmount(_)).Times(AnyNumber()); | 417 EXPECT_CALL(*channelClient(), didConsumeBufferedAmount(_)).Times(AnyNumber()); |
398 | 418 |
399 DOMArrayBuffer* fooBuffer = DOMArrayBuffer::create("foo", 3); | 419 DOMArrayBuffer* fooBuffer = DOMArrayBuffer::create("foo", 3); |
400 channel()->send(*fooBuffer, 0, 3); | 420 channel()->send(*fooBuffer, 0, 3); |
401 | 421 |
402 EXPECT_EQ(3ul, m_sumOfConsumedBufferedAmount); | 422 EXPECT_EQ(3ul, m_sumOfConsumedBufferedAmount); |
403 } | 423 } |
404 | 424 |
405 TEST_F(DocumentWebSocketChannelTest, sendBinaryInArrayBufferPartial) { | 425 TEST_F(DocumentWebSocketChannelTest, sendBinaryInArrayBufferPartial) { |
406 connect(); | 426 connect(); |
407 { | 427 { |
408 InSequence s; | 428 InSequence s; |
409 EXPECT_CALL(*handle(), send(true, WebSocketHandle::MessageTypeBinary, | 429 EXPECT_CALL( |
410 MemEq("foo", 3), 3)); | 430 *handle(), |
411 EXPECT_CALL(*handle(), send(true, WebSocketHandle::MessageTypeBinary, | 431 send(true, WebSocketHandle::MessageTypeBinary, MemEq("foo", 3), 3)); |
412 MemEq("bar", 3), 3)); | 432 EXPECT_CALL( |
413 EXPECT_CALL(*handle(), send(true, WebSocketHandle::MessageTypeBinary, | 433 *handle(), |
414 MemEq("baz", 3), 3)); | 434 send(true, WebSocketHandle::MessageTypeBinary, MemEq("bar", 3), 3)); |
415 EXPECT_CALL(*handle(), send(true, WebSocketHandle::MessageTypeBinary, | 435 EXPECT_CALL( |
416 MemEq("a", 1), 1)); | 436 *handle(), |
| 437 send(true, WebSocketHandle::MessageTypeBinary, MemEq("baz", 3), 3)); |
| 438 EXPECT_CALL( |
| 439 *handle(), |
| 440 send(true, WebSocketHandle::MessageTypeBinary, MemEq("a", 1), 1)); |
417 } | 441 } |
418 | 442 |
419 handleClient()->didReceiveFlowControl(handle(), 16); | 443 handleClient()->didReceiveFlowControl(handle(), 16); |
420 EXPECT_CALL(*channelClient(), didConsumeBufferedAmount(_)).Times(AnyNumber()); | 444 EXPECT_CALL(*channelClient(), didConsumeBufferedAmount(_)).Times(AnyNumber()); |
421 | 445 |
422 DOMArrayBuffer* foobarBuffer = DOMArrayBuffer::create("foobar", 6); | 446 DOMArrayBuffer* foobarBuffer = DOMArrayBuffer::create("foobar", 6); |
423 DOMArrayBuffer* qbazuxBuffer = DOMArrayBuffer::create("qbazux", 6); | 447 DOMArrayBuffer* qbazuxBuffer = DOMArrayBuffer::create("qbazux", 6); |
424 channel()->send(*foobarBuffer, 0, 3); | 448 channel()->send(*foobarBuffer, 0, 3); |
425 channel()->send(*foobarBuffer, 3, 3); | 449 channel()->send(*foobarBuffer, 3, 3); |
426 channel()->send(*qbazuxBuffer, 1, 3); | 450 channel()->send(*qbazuxBuffer, 1, 3); |
427 channel()->send(*qbazuxBuffer, 2, 1); | 451 channel()->send(*qbazuxBuffer, 2, 1); |
428 | 452 |
429 EXPECT_EQ(10ul, m_sumOfConsumedBufferedAmount); | 453 EXPECT_EQ(10ul, m_sumOfConsumedBufferedAmount); |
430 } | 454 } |
431 | 455 |
432 TEST_F(DocumentWebSocketChannelTest, sendBinaryInArrayBufferWithNullBytes) { | 456 TEST_F(DocumentWebSocketChannelTest, sendBinaryInArrayBufferWithNullBytes) { |
433 connect(); | 457 connect(); |
434 { | 458 { |
435 InSequence s; | 459 InSequence s; |
436 EXPECT_CALL(*handle(), send(true, WebSocketHandle::MessageTypeBinary, | 460 EXPECT_CALL( |
437 MemEq("\0ar", 3), 3)); | 461 *handle(), |
438 EXPECT_CALL(*handle(), send(true, WebSocketHandle::MessageTypeBinary, | 462 send(true, WebSocketHandle::MessageTypeBinary, MemEq("\0ar", 3), 3)); |
439 MemEq("b\0z", 3), 3)); | 463 EXPECT_CALL( |
440 EXPECT_CALL(*handle(), send(true, WebSocketHandle::MessageTypeBinary, | 464 *handle(), |
441 MemEq("qu\0", 3), 3)); | 465 send(true, WebSocketHandle::MessageTypeBinary, MemEq("b\0z", 3), 3)); |
442 EXPECT_CALL(*handle(), send(true, WebSocketHandle::MessageTypeBinary, | 466 EXPECT_CALL( |
443 MemEq("\0\0\0", 3), 3)); | 467 *handle(), |
| 468 send(true, WebSocketHandle::MessageTypeBinary, MemEq("qu\0", 3), 3)); |
| 469 EXPECT_CALL( |
| 470 *handle(), |
| 471 send(true, WebSocketHandle::MessageTypeBinary, MemEq("\0\0\0", 3), 3)); |
444 } | 472 } |
445 | 473 |
446 handleClient()->didReceiveFlowControl(handle(), 16); | 474 handleClient()->didReceiveFlowControl(handle(), 16); |
447 EXPECT_CALL(*channelClient(), didConsumeBufferedAmount(_)).Times(AnyNumber()); | 475 EXPECT_CALL(*channelClient(), didConsumeBufferedAmount(_)).Times(AnyNumber()); |
448 | 476 |
449 { | 477 { |
450 DOMArrayBuffer* b = DOMArrayBuffer::create("\0ar", 3); | 478 DOMArrayBuffer* b = DOMArrayBuffer::create("\0ar", 3); |
451 channel()->send(*b, 0, 3); | 479 channel()->send(*b, 0, 3); |
452 } | 480 } |
453 { | 481 { |
454 DOMArrayBuffer* b = DOMArrayBuffer::create("b\0z", 3); | 482 DOMArrayBuffer* b = DOMArrayBuffer::create("b\0z", 3); |
455 channel()->send(*b, 0, 3); | 483 channel()->send(*b, 0, 3); |
456 } | 484 } |
457 { | 485 { |
458 DOMArrayBuffer* b = DOMArrayBuffer::create("qu\0", 3); | 486 DOMArrayBuffer* b = DOMArrayBuffer::create("qu\0", 3); |
459 channel()->send(*b, 0, 3); | 487 channel()->send(*b, 0, 3); |
460 } | 488 } |
461 { | 489 { |
462 DOMArrayBuffer* b = DOMArrayBuffer::create("\0\0\0", 3); | 490 DOMArrayBuffer* b = DOMArrayBuffer::create("\0\0\0", 3); |
463 channel()->send(*b, 0, 3); | 491 channel()->send(*b, 0, 3); |
464 } | 492 } |
465 | 493 |
466 EXPECT_EQ(12ul, m_sumOfConsumedBufferedAmount); | 494 EXPECT_EQ(12ul, m_sumOfConsumedBufferedAmount); |
467 } | 495 } |
468 | 496 |
469 TEST_F(DocumentWebSocketChannelTest, sendBinaryInArrayBufferNonLatin1UTF8) { | 497 TEST_F(DocumentWebSocketChannelTest, sendBinaryInArrayBufferNonLatin1UTF8) { |
470 connect(); | 498 connect(); |
471 EXPECT_CALL(*handle(), send(true, WebSocketHandle::MessageTypeBinary, | 499 EXPECT_CALL(*handle(), |
472 MemEq("\xe7\x8b\x90", 3), 3)); | 500 send(true, WebSocketHandle::MessageTypeBinary, |
| 501 MemEq("\xe7\x8b\x90", 3), 3)); |
473 | 502 |
474 handleClient()->didReceiveFlowControl(handle(), 16); | 503 handleClient()->didReceiveFlowControl(handle(), 16); |
475 EXPECT_CALL(*channelClient(), didConsumeBufferedAmount(_)).Times(AnyNumber()); | 504 EXPECT_CALL(*channelClient(), didConsumeBufferedAmount(_)).Times(AnyNumber()); |
476 | 505 |
477 DOMArrayBuffer* b = DOMArrayBuffer::create("\xe7\x8b\x90", 3); | 506 DOMArrayBuffer* b = DOMArrayBuffer::create("\xe7\x8b\x90", 3); |
478 channel()->send(*b, 0, 3); | 507 channel()->send(*b, 0, 3); |
479 | 508 |
480 EXPECT_EQ(3ul, m_sumOfConsumedBufferedAmount); | 509 EXPECT_EQ(3ul, m_sumOfConsumedBufferedAmount); |
481 } | 510 } |
482 | 511 |
483 TEST_F(DocumentWebSocketChannelTest, sendBinaryInArrayBufferNonUTF8) { | 512 TEST_F(DocumentWebSocketChannelTest, sendBinaryInArrayBufferNonUTF8) { |
484 connect(); | 513 connect(); |
485 EXPECT_CALL(*handle(), send(true, WebSocketHandle::MessageTypeBinary, | 514 EXPECT_CALL(*handle(), |
486 MemEq("\x80\xff\xe7", 3), 3)); | 515 send(true, WebSocketHandle::MessageTypeBinary, |
| 516 MemEq("\x80\xff\xe7", 3), 3)); |
487 | 517 |
488 handleClient()->didReceiveFlowControl(handle(), 16); | 518 handleClient()->didReceiveFlowControl(handle(), 16); |
489 EXPECT_CALL(*channelClient(), didConsumeBufferedAmount(_)).Times(AnyNumber()); | 519 EXPECT_CALL(*channelClient(), didConsumeBufferedAmount(_)).Times(AnyNumber()); |
490 | 520 |
491 DOMArrayBuffer* b = DOMArrayBuffer::create("\x80\xff\xe7", 3); | 521 DOMArrayBuffer* b = DOMArrayBuffer::create("\x80\xff\xe7", 3); |
492 channel()->send(*b, 0, 3); | 522 channel()->send(*b, 0, 3); |
493 | 523 |
494 EXPECT_EQ(3ul, m_sumOfConsumedBufferedAmount); | 524 EXPECT_EQ(3ul, m_sumOfConsumedBufferedAmount); |
495 } | 525 } |
496 | 526 |
497 TEST_F(DocumentWebSocketChannelTest, | 527 TEST_F(DocumentWebSocketChannelTest, |
498 sendBinaryInArrayBufferNonLatin1UTF8Continuation) { | 528 sendBinaryInArrayBufferNonLatin1UTF8Continuation) { |
499 connect(); | 529 connect(); |
500 Checkpoint checkpoint; | 530 Checkpoint checkpoint; |
501 { | 531 { |
502 InSequence s; | 532 InSequence s; |
503 EXPECT_CALL(*handle(), send(false, WebSocketHandle::MessageTypeBinary, | 533 EXPECT_CALL(*handle(), |
504 MemEq("\xe7\x8b\x90\xe7\x8b\x90\xe7\x8b\x90\xe7" | 534 send(false, WebSocketHandle::MessageTypeBinary, |
505 "\x8b\x90\xe7\x8b\x90\xe7", | 535 MemEq("\xe7\x8b\x90\xe7\x8b\x90\xe7\x8b\x90\xe7" |
506 16), | 536 "\x8b\x90\xe7\x8b\x90\xe7", |
507 16)); | 537 16), |
| 538 16)); |
508 EXPECT_CALL(checkpoint, Call(1)); | 539 EXPECT_CALL(checkpoint, Call(1)); |
509 EXPECT_CALL(*handle(), send(true, WebSocketHandle::MessageTypeContinuation, | 540 EXPECT_CALL(*handle(), |
510 MemEq("\x8b\x90", 2), 2)); | 541 send(true, WebSocketHandle::MessageTypeContinuation, |
| 542 MemEq("\x8b\x90", 2), 2)); |
511 } | 543 } |
512 | 544 |
513 handleClient()->didReceiveFlowControl(handle(), 16); | 545 handleClient()->didReceiveFlowControl(handle(), 16); |
514 EXPECT_CALL(*channelClient(), didConsumeBufferedAmount(_)).Times(AnyNumber()); | 546 EXPECT_CALL(*channelClient(), didConsumeBufferedAmount(_)).Times(AnyNumber()); |
515 | 547 |
516 DOMArrayBuffer* b = DOMArrayBuffer::create( | 548 DOMArrayBuffer* b = DOMArrayBuffer::create( |
517 "\xe7\x8b\x90\xe7\x8b\x90\xe7\x8b\x90\xe7\x8b\x90\xe7\x8b\x90\xe7\x8b" | 549 "\xe7\x8b\x90\xe7\x8b\x90\xe7\x8b\x90\xe7\x8b\x90\xe7\x8b\x90\xe7\x8b" |
518 "\x90", | 550 "\x90", |
519 18); | 551 18); |
520 channel()->send(*b, 0, 18); | 552 channel()->send(*b, 0, 18); |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
677 | 709 |
678 TEST_F(DocumentWebSocketChannelTest, closeFromBrowser) { | 710 TEST_F(DocumentWebSocketChannelTest, closeFromBrowser) { |
679 connect(); | 711 connect(); |
680 Checkpoint checkpoint; | 712 Checkpoint checkpoint; |
681 { | 713 { |
682 InSequence s; | 714 InSequence s; |
683 | 715 |
684 EXPECT_CALL(*channelClient(), didStartClosingHandshake()); | 716 EXPECT_CALL(*channelClient(), didStartClosingHandshake()); |
685 EXPECT_CALL(checkpoint, Call(1)); | 717 EXPECT_CALL(checkpoint, Call(1)); |
686 | 718 |
687 EXPECT_CALL(*handle(), close(WebSocketChannel::CloseEventCodeNormalClosure, | 719 EXPECT_CALL(*handle(), |
688 String("close reason"))); | 720 close(WebSocketChannel::CloseEventCodeNormalClosure, |
| 721 String("close reason"))); |
689 EXPECT_CALL(checkpoint, Call(2)); | 722 EXPECT_CALL(checkpoint, Call(2)); |
690 | 723 |
691 EXPECT_CALL(*channelClient(), | 724 EXPECT_CALL(*channelClient(), |
692 didClose(WebSocketChannelClient::ClosingHandshakeComplete, | 725 didClose(WebSocketChannelClient::ClosingHandshakeComplete, |
693 WebSocketChannel::CloseEventCodeNormalClosure, | 726 WebSocketChannel::CloseEventCodeNormalClosure, |
694 String("close reason"))); | 727 String("close reason"))); |
695 EXPECT_CALL(checkpoint, Call(3)); | 728 EXPECT_CALL(checkpoint, Call(3)); |
696 } | 729 } |
697 | 730 |
698 handleClient()->didStartClosingHandshake(handle()); | 731 handleClient()->didStartClosingHandshake(handle()); |
(...skipping 10 matching lines...) Expand all Loading... |
709 | 742 |
710 channel()->disconnect(); | 743 channel()->disconnect(); |
711 } | 744 } |
712 | 745 |
713 TEST_F(DocumentWebSocketChannelTest, closeFromWebSocket) { | 746 TEST_F(DocumentWebSocketChannelTest, closeFromWebSocket) { |
714 connect(); | 747 connect(); |
715 Checkpoint checkpoint; | 748 Checkpoint checkpoint; |
716 { | 749 { |
717 InSequence s; | 750 InSequence s; |
718 | 751 |
719 EXPECT_CALL(*handle(), close(WebSocketChannel::CloseEventCodeNormalClosure, | 752 EXPECT_CALL(*handle(), |
720 String("close reason"))); | 753 close(WebSocketChannel::CloseEventCodeNormalClosure, |
| 754 String("close reason"))); |
721 EXPECT_CALL(checkpoint, Call(1)); | 755 EXPECT_CALL(checkpoint, Call(1)); |
722 | 756 |
723 EXPECT_CALL(*channelClient(), | 757 EXPECT_CALL(*channelClient(), |
724 didClose(WebSocketChannelClient::ClosingHandshakeComplete, | 758 didClose(WebSocketChannelClient::ClosingHandshakeComplete, |
725 WebSocketChannel::CloseEventCodeNormalClosure, | 759 WebSocketChannel::CloseEventCodeNormalClosure, |
726 String("close reason"))); | 760 String("close reason"))); |
727 EXPECT_CALL(checkpoint, Call(2)); | 761 EXPECT_CALL(checkpoint, Call(2)); |
728 } | 762 } |
729 | 763 |
730 channel()->close(WebSocketChannel::CloseEventCodeNormalClosure, | 764 channel()->close(WebSocketChannel::CloseEventCodeNormalClosure, |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
766 WebSocketChannel::CloseEventCodeAbnormalClosure, String())); | 800 WebSocketChannel::CloseEventCodeAbnormalClosure, String())); |
767 } | 801 } |
768 | 802 |
769 channel()->fail("fail message from WebSocket", ErrorMessageLevel, | 803 channel()->fail("fail message from WebSocket", ErrorMessageLevel, |
770 SourceLocation::create(String(), 0, 0, nullptr)); | 804 SourceLocation::create(String(), 0, 0, nullptr)); |
771 } | 805 } |
772 | 806 |
773 } // namespace | 807 } // namespace |
774 | 808 |
775 } // namespace blink | 809 } // namespace blink |
OLD | NEW |