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 "core/dom/DOMArrayBuffer.h" | 7 #include "core/dom/DOMArrayBuffer.h" |
8 #include "core/dom/Document.h" | 8 #include "core/dom/Document.h" |
9 #include "core/fileapi/Blob.h" | 9 #include "core/fileapi/Blob.h" |
10 #include "core/frame/ConsoleTypes.h" | 10 #include "core/frame/ConsoleTypes.h" |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 { | 341 { |
342 connect(); | 342 connect(); |
343 { | 343 { |
344 InSequence s; | 344 InSequence s; |
345 EXPECT_CALL(*handle(), send(true, WebSocketHandle::MessageTypeBinary, Me
mEq("foo", 3), 3)); | 345 EXPECT_CALL(*handle(), send(true, WebSocketHandle::MessageTypeBinary, Me
mEq("foo", 3), 3)); |
346 } | 346 } |
347 | 347 |
348 handleClient()->didReceiveFlowControl(handle(), 16); | 348 handleClient()->didReceiveFlowControl(handle(), 16); |
349 EXPECT_CALL(*channelClient(), didConsumeBufferedAmount(_)).Times(AnyNumber()
); | 349 EXPECT_CALL(*channelClient(), didConsumeBufferedAmount(_)).Times(AnyNumber()
); |
350 | 350 |
351 DOMArrayBuffer* fooBuffer = DOMArrayBuffer::create("foo", 3); | 351 RefPtr<DOMArrayBuffer> fooBuffer = DOMArrayBuffer::create("foo", 3); |
352 channel()->send(*fooBuffer, 0, 3); | 352 channel()->send(*fooBuffer, 0, 3); |
353 | 353 |
354 EXPECT_EQ(3ul, m_sumOfConsumedBufferedAmount); | 354 EXPECT_EQ(3ul, m_sumOfConsumedBufferedAmount); |
355 } | 355 } |
356 | 356 |
357 TEST_F(DocumentWebSocketChannelTest, sendBinaryInArrayBufferPartial) | 357 TEST_F(DocumentWebSocketChannelTest, sendBinaryInArrayBufferPartial) |
358 { | 358 { |
359 connect(); | 359 connect(); |
360 { | 360 { |
361 InSequence s; | 361 InSequence s; |
362 EXPECT_CALL(*handle(), send(true, WebSocketHandle::MessageTypeBinary, Me
mEq("foo", 3), 3)); | 362 EXPECT_CALL(*handle(), send(true, WebSocketHandle::MessageTypeBinary, Me
mEq("foo", 3), 3)); |
363 EXPECT_CALL(*handle(), send(true, WebSocketHandle::MessageTypeBinary, Me
mEq("bar", 3), 3)); | 363 EXPECT_CALL(*handle(), send(true, WebSocketHandle::MessageTypeBinary, Me
mEq("bar", 3), 3)); |
364 EXPECT_CALL(*handle(), send(true, WebSocketHandle::MessageTypeBinary, Me
mEq("baz", 3), 3)); | 364 EXPECT_CALL(*handle(), send(true, WebSocketHandle::MessageTypeBinary, Me
mEq("baz", 3), 3)); |
365 EXPECT_CALL(*handle(), send(true, WebSocketHandle::MessageTypeBinary, Me
mEq("a", 1), 1)); | 365 EXPECT_CALL(*handle(), send(true, WebSocketHandle::MessageTypeBinary, Me
mEq("a", 1), 1)); |
366 } | 366 } |
367 | 367 |
368 handleClient()->didReceiveFlowControl(handle(), 16); | 368 handleClient()->didReceiveFlowControl(handle(), 16); |
369 EXPECT_CALL(*channelClient(), didConsumeBufferedAmount(_)).Times(AnyNumber()
); | 369 EXPECT_CALL(*channelClient(), didConsumeBufferedAmount(_)).Times(AnyNumber()
); |
370 | 370 |
371 DOMArrayBuffer* foobarBuffer = DOMArrayBuffer::create("foobar", 6); | 371 RefPtr<DOMArrayBuffer> foobarBuffer = DOMArrayBuffer::create("foobar", 6); |
372 DOMArrayBuffer* qbazuxBuffer = DOMArrayBuffer::create("qbazux", 6); | 372 RefPtr<DOMArrayBuffer> qbazuxBuffer = DOMArrayBuffer::create("qbazux", 6); |
373 channel()->send(*foobarBuffer, 0, 3); | 373 channel()->send(*foobarBuffer, 0, 3); |
374 channel()->send(*foobarBuffer, 3, 3); | 374 channel()->send(*foobarBuffer, 3, 3); |
375 channel()->send(*qbazuxBuffer, 1, 3); | 375 channel()->send(*qbazuxBuffer, 1, 3); |
376 channel()->send(*qbazuxBuffer, 2, 1); | 376 channel()->send(*qbazuxBuffer, 2, 1); |
377 | 377 |
378 EXPECT_EQ(10ul, m_sumOfConsumedBufferedAmount); | 378 EXPECT_EQ(10ul, m_sumOfConsumedBufferedAmount); |
379 } | 379 } |
380 | 380 |
381 TEST_F(DocumentWebSocketChannelTest, sendBinaryInArrayBufferWithNullBytes) | 381 TEST_F(DocumentWebSocketChannelTest, sendBinaryInArrayBufferWithNullBytes) |
382 { | 382 { |
383 connect(); | 383 connect(); |
384 { | 384 { |
385 InSequence s; | 385 InSequence s; |
386 EXPECT_CALL(*handle(), send(true, WebSocketHandle::MessageTypeBinary, Me
mEq("\0ar", 3), 3)); | 386 EXPECT_CALL(*handle(), send(true, WebSocketHandle::MessageTypeBinary, Me
mEq("\0ar", 3), 3)); |
387 EXPECT_CALL(*handle(), send(true, WebSocketHandle::MessageTypeBinary, Me
mEq("b\0z", 3), 3)); | 387 EXPECT_CALL(*handle(), send(true, WebSocketHandle::MessageTypeBinary, Me
mEq("b\0z", 3), 3)); |
388 EXPECT_CALL(*handle(), send(true, WebSocketHandle::MessageTypeBinary, Me
mEq("qu\0", 3), 3)); | 388 EXPECT_CALL(*handle(), send(true, WebSocketHandle::MessageTypeBinary, Me
mEq("qu\0", 3), 3)); |
389 EXPECT_CALL(*handle(), send(true, WebSocketHandle::MessageTypeBinary, Me
mEq("\0\0\0", 3), 3)); | 389 EXPECT_CALL(*handle(), send(true, WebSocketHandle::MessageTypeBinary, Me
mEq("\0\0\0", 3), 3)); |
390 } | 390 } |
391 | 391 |
392 handleClient()->didReceiveFlowControl(handle(), 16); | 392 handleClient()->didReceiveFlowControl(handle(), 16); |
393 EXPECT_CALL(*channelClient(), didConsumeBufferedAmount(_)).Times(AnyNumber()
); | 393 EXPECT_CALL(*channelClient(), didConsumeBufferedAmount(_)).Times(AnyNumber()
); |
394 | 394 |
395 { | 395 { |
396 DOMArrayBuffer* b = DOMArrayBuffer::create("\0ar", 3); | 396 RefPtr<DOMArrayBuffer> b = DOMArrayBuffer::create("\0ar", 3); |
397 channel()->send(*b, 0, 3); | 397 channel()->send(*b, 0, 3); |
398 } | 398 } |
399 { | 399 { |
400 DOMArrayBuffer* b = DOMArrayBuffer::create("b\0z", 3); | 400 RefPtr<DOMArrayBuffer> b = DOMArrayBuffer::create("b\0z", 3); |
401 channel()->send(*b, 0, 3); | 401 channel()->send(*b, 0, 3); |
402 } | 402 } |
403 { | 403 { |
404 DOMArrayBuffer* b = DOMArrayBuffer::create("qu\0", 3); | 404 RefPtr<DOMArrayBuffer> b = DOMArrayBuffer::create("qu\0", 3); |
405 channel()->send(*b, 0, 3); | 405 channel()->send(*b, 0, 3); |
406 } | 406 } |
407 { | 407 { |
408 DOMArrayBuffer* b = DOMArrayBuffer::create("\0\0\0", 3); | 408 RefPtr<DOMArrayBuffer> b = DOMArrayBuffer::create("\0\0\0", 3); |
409 channel()->send(*b, 0, 3); | 409 channel()->send(*b, 0, 3); |
410 } | 410 } |
411 | 411 |
412 EXPECT_EQ(12ul, m_sumOfConsumedBufferedAmount); | 412 EXPECT_EQ(12ul, m_sumOfConsumedBufferedAmount); |
413 } | 413 } |
414 | 414 |
415 TEST_F(DocumentWebSocketChannelTest, sendBinaryInArrayBufferNonLatin1UTF8) | 415 TEST_F(DocumentWebSocketChannelTest, sendBinaryInArrayBufferNonLatin1UTF8) |
416 { | 416 { |
417 connect(); | 417 connect(); |
418 EXPECT_CALL(*handle(), send(true, WebSocketHandle::MessageTypeBinary, MemEq(
"\xe7\x8b\x90", 3), 3)); | 418 EXPECT_CALL(*handle(), send(true, WebSocketHandle::MessageTypeBinary, MemEq(
"\xe7\x8b\x90", 3), 3)); |
419 | 419 |
420 handleClient()->didReceiveFlowControl(handle(), 16); | 420 handleClient()->didReceiveFlowControl(handle(), 16); |
421 EXPECT_CALL(*channelClient(), didConsumeBufferedAmount(_)).Times(AnyNumber()
); | 421 EXPECT_CALL(*channelClient(), didConsumeBufferedAmount(_)).Times(AnyNumber()
); |
422 | 422 |
423 DOMArrayBuffer* b = DOMArrayBuffer::create("\xe7\x8b\x90", 3); | 423 RefPtr<DOMArrayBuffer> b = DOMArrayBuffer::create("\xe7\x8b\x90", 3); |
424 channel()->send(*b, 0, 3); | 424 channel()->send(*b, 0, 3); |
425 | 425 |
426 EXPECT_EQ(3ul, m_sumOfConsumedBufferedAmount); | 426 EXPECT_EQ(3ul, m_sumOfConsumedBufferedAmount); |
427 } | 427 } |
428 | 428 |
429 TEST_F(DocumentWebSocketChannelTest, sendBinaryInArrayBufferNonUTF8) | 429 TEST_F(DocumentWebSocketChannelTest, sendBinaryInArrayBufferNonUTF8) |
430 { | 430 { |
431 connect(); | 431 connect(); |
432 EXPECT_CALL(*handle(), send(true, WebSocketHandle::MessageTypeBinary, MemEq(
"\x80\xff\xe7", 3), 3)); | 432 EXPECT_CALL(*handle(), send(true, WebSocketHandle::MessageTypeBinary, MemEq(
"\x80\xff\xe7", 3), 3)); |
433 | 433 |
434 handleClient()->didReceiveFlowControl(handle(), 16); | 434 handleClient()->didReceiveFlowControl(handle(), 16); |
435 EXPECT_CALL(*channelClient(), didConsumeBufferedAmount(_)).Times(AnyNumber()
); | 435 EXPECT_CALL(*channelClient(), didConsumeBufferedAmount(_)).Times(AnyNumber()
); |
436 | 436 |
437 DOMArrayBuffer* b = DOMArrayBuffer::create("\x80\xff\xe7", 3); | 437 RefPtr<DOMArrayBuffer> b = DOMArrayBuffer::create("\x80\xff\xe7", 3); |
438 channel()->send(*b, 0, 3); | 438 channel()->send(*b, 0, 3); |
439 | 439 |
440 EXPECT_EQ(3ul, m_sumOfConsumedBufferedAmount); | 440 EXPECT_EQ(3ul, m_sumOfConsumedBufferedAmount); |
441 } | 441 } |
442 | 442 |
443 TEST_F(DocumentWebSocketChannelTest, sendBinaryInArrayBufferNonLatin1UTF8Continu
ation) | 443 TEST_F(DocumentWebSocketChannelTest, sendBinaryInArrayBufferNonLatin1UTF8Continu
ation) |
444 { | 444 { |
445 connect(); | 445 connect(); |
446 Checkpoint checkpoint; | 446 Checkpoint checkpoint; |
447 { | 447 { |
448 InSequence s; | 448 InSequence s; |
449 EXPECT_CALL(*handle(), send(false, WebSocketHandle::MessageTypeBinary, M
emEq("\xe7\x8b\x90\xe7\x8b\x90\xe7\x8b\x90\xe7\x8b\x90\xe7\x8b\x90\xe7", 16), 16
)); | 449 EXPECT_CALL(*handle(), send(false, WebSocketHandle::MessageTypeBinary, M
emEq("\xe7\x8b\x90\xe7\x8b\x90\xe7\x8b\x90\xe7\x8b\x90\xe7\x8b\x90\xe7", 16), 16
)); |
450 EXPECT_CALL(checkpoint, Call(1)); | 450 EXPECT_CALL(checkpoint, Call(1)); |
451 EXPECT_CALL(*handle(), send(true, WebSocketHandle::MessageTypeContinuati
on, MemEq("\x8b\x90", 2), 2)); | 451 EXPECT_CALL(*handle(), send(true, WebSocketHandle::MessageTypeContinuati
on, MemEq("\x8b\x90", 2), 2)); |
452 } | 452 } |
453 | 453 |
454 handleClient()->didReceiveFlowControl(handle(), 16); | 454 handleClient()->didReceiveFlowControl(handle(), 16); |
455 EXPECT_CALL(*channelClient(), didConsumeBufferedAmount(_)).Times(AnyNumber()
); | 455 EXPECT_CALL(*channelClient(), didConsumeBufferedAmount(_)).Times(AnyNumber()
); |
456 | 456 |
457 DOMArrayBuffer* b = DOMArrayBuffer::create("\xe7\x8b\x90\xe7\x8b\x90\xe7\x8b
\x90\xe7\x8b\x90\xe7\x8b\x90\xe7\x8b\x90", 18); | 457 RefPtr<DOMArrayBuffer> b = DOMArrayBuffer::create("\xe7\x8b\x90\xe7\x8b\x90\
xe7\x8b\x90\xe7\x8b\x90\xe7\x8b\x90\xe7\x8b\x90", 18); |
458 channel()->send(*b, 0, 18); | 458 channel()->send(*b, 0, 18); |
459 checkpoint.Call(1); | 459 checkpoint.Call(1); |
460 | 460 |
461 handleClient()->didReceiveFlowControl(handle(), 16); | 461 handleClient()->didReceiveFlowControl(handle(), 16); |
462 | 462 |
463 EXPECT_EQ(18ul, m_sumOfConsumedBufferedAmount); | 463 EXPECT_EQ(18ul, m_sumOfConsumedBufferedAmount); |
464 } | 464 } |
465 | 465 |
466 // FIXME: Add tests for WebSocketChannel::send(PassRefPtr<BlobDataHandle>) | 466 // FIXME: Add tests for WebSocketChannel::send(PassRefPtr<BlobDataHandle>) |
467 | 467 |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
679 EXPECT_CALL(*channelClient(), didError()); | 679 EXPECT_CALL(*channelClient(), didError()); |
680 EXPECT_CALL(*channelClient(), didClose(WebSocketChannelClient::ClosingHa
ndshakeIncomplete, WebSocketChannel::CloseEventCodeAbnormalClosure, String())); | 680 EXPECT_CALL(*channelClient(), didClose(WebSocketChannelClient::ClosingHa
ndshakeIncomplete, WebSocketChannel::CloseEventCodeAbnormalClosure, String())); |
681 } | 681 } |
682 | 682 |
683 channel()->fail("fail message from WebSocket", ErrorMessageLevel, "sourceURL
", 1234); | 683 channel()->fail("fail message from WebSocket", ErrorMessageLevel, "sourceURL
", 1234); |
684 } | 684 } |
685 | 685 |
686 } // namespace | 686 } // namespace |
687 | 687 |
688 } // namespace blink | 688 } // namespace blink |
OLD | NEW |