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 "config.h" | 5 #include "config.h" |
6 #include "modules/websockets/DOMWebSocket.h" | 6 #include "modules/websockets/DOMWebSocket.h" |
7 | 7 |
8 #include "bindings/core/v8/ExceptionState.h" | 8 #include "bindings/core/v8/ExceptionState.h" |
9 #include "bindings/core/v8/V8Binding.h" | 9 #include "bindings/core/v8/V8Binding.h" |
10 #include "bindings/core/v8/V8BindingForTesting.h" | 10 #include "bindings/core/v8/V8BindingForTesting.h" |
(...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
592 0x0000 | 592 0x0000 |
593 }; | 593 }; |
594 m_websocket->send(nonLatin1String, m_exceptionState); | 594 m_websocket->send(nonLatin1String, m_exceptionState); |
595 | 595 |
596 EXPECT_FALSE(m_exceptionState.hadException()); | 596 EXPECT_FALSE(m_exceptionState.hadException()); |
597 EXPECT_EQ(DOMWebSocket::OPEN, m_websocket->readyState()); | 597 EXPECT_EQ(DOMWebSocket::OPEN, m_websocket->readyState()); |
598 } | 598 } |
599 | 599 |
600 TEST_F(DOMWebSocketTest, sendArrayBufferWhenConnecting) | 600 TEST_F(DOMWebSocketTest, sendArrayBufferWhenConnecting) |
601 { | 601 { |
602 RefPtr<DOMArrayBufferView> view = DOMUint8Array::create(8); | 602 RefPtr<DOMArrayBufferView> view = DOMUint8Array::deprecatedCreateOrCrash(8); |
603 { | 603 { |
604 InSequence s; | 604 InSequence s; |
605 EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String
())).WillOnce(Return(true)); | 605 EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String
())).WillOnce(Return(true)); |
606 } | 606 } |
607 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState
); | 607 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState
); |
608 | 608 |
609 EXPECT_FALSE(m_exceptionState.hadException()); | 609 EXPECT_FALSE(m_exceptionState.hadException()); |
610 | 610 |
611 m_websocket->send(view->buffer().get(), m_exceptionState); | 611 RefPtr<DOMArrayBuffer> buffer = view->buffer(); |
| 612 m_websocket->send(buffer.get(), m_exceptionState); |
612 | 613 |
613 EXPECT_TRUE(m_exceptionState.hadException()); | 614 EXPECT_TRUE(m_exceptionState.hadException()); |
614 EXPECT_EQ(InvalidStateError, m_exceptionState.code()); | 615 EXPECT_EQ(InvalidStateError, m_exceptionState.code()); |
615 EXPECT_EQ("Still in CONNECTING state.", m_exceptionState.message()); | 616 EXPECT_EQ("Still in CONNECTING state.", m_exceptionState.message()); |
616 EXPECT_EQ(DOMWebSocket::CONNECTING, m_websocket->readyState()); | 617 EXPECT_EQ(DOMWebSocket::CONNECTING, m_websocket->readyState()); |
617 } | 618 } |
618 | 619 |
619 TEST_F(DOMWebSocketTest, sendArrayBufferWhenClosing) | 620 TEST_F(DOMWebSocketTest, sendArrayBufferWhenClosing) |
620 { | 621 { |
621 RefPtr<DOMArrayBufferView> view = DOMUint8Array::create(8); | 622 RefPtr<DOMArrayBufferView> view = DOMUint8Array::deprecatedCreateOrCrash(8); |
622 { | 623 { |
623 InSequence s; | 624 InSequence s; |
624 EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String
())).WillOnce(Return(true)); | 625 EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String
())).WillOnce(Return(true)); |
625 EXPECT_CALL(channel(), fail(_, _, _, _)); | 626 EXPECT_CALL(channel(), fail(_, _, _, _)); |
626 } | 627 } |
627 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState
); | 628 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState
); |
628 | 629 |
629 EXPECT_FALSE(m_exceptionState.hadException()); | 630 EXPECT_FALSE(m_exceptionState.hadException()); |
630 | 631 |
631 m_websocket->close(m_exceptionState); | 632 m_websocket->close(m_exceptionState); |
632 EXPECT_FALSE(m_exceptionState.hadException()); | 633 EXPECT_FALSE(m_exceptionState.hadException()); |
633 | 634 |
634 m_websocket->send(view->buffer().get(), m_exceptionState); | 635 RefPtr<DOMArrayBuffer> buffer = view->buffer(); |
| 636 m_websocket->send(buffer.get(), m_exceptionState); |
635 | 637 |
636 EXPECT_FALSE(m_exceptionState.hadException()); | 638 EXPECT_FALSE(m_exceptionState.hadException()); |
637 EXPECT_EQ(DOMWebSocket::CLOSING, m_websocket->readyState()); | 639 EXPECT_EQ(DOMWebSocket::CLOSING, m_websocket->readyState()); |
638 } | 640 } |
639 | 641 |
640 TEST_F(DOMWebSocketTest, sendArrayBufferWhenClosed) | 642 TEST_F(DOMWebSocketTest, sendArrayBufferWhenClosed) |
641 { | 643 { |
642 Checkpoint checkpoint; | 644 Checkpoint checkpoint; |
643 RefPtr<DOMArrayBufferView> view = DOMUint8Array::create(8); | 645 RefPtr<DOMArrayBufferView> view = DOMUint8Array::deprecatedCreateOrCrash(8); |
644 { | 646 { |
645 InSequence s; | 647 InSequence s; |
646 EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String
())).WillOnce(Return(true)); | 648 EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String
())).WillOnce(Return(true)); |
647 EXPECT_CALL(channel(), disconnect()); | 649 EXPECT_CALL(channel(), disconnect()); |
648 EXPECT_CALL(checkpoint, Call(1)); | 650 EXPECT_CALL(checkpoint, Call(1)); |
649 } | 651 } |
650 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState
); | 652 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState
); |
651 | 653 |
652 EXPECT_FALSE(m_exceptionState.hadException()); | 654 EXPECT_FALSE(m_exceptionState.hadException()); |
653 | 655 |
654 m_websocket->didClose(WebSocketChannelClient::ClosingHandshakeIncomplete, 10
06, ""); | 656 m_websocket->didClose(WebSocketChannelClient::ClosingHandshakeIncomplete, 10
06, ""); |
655 checkpoint.Call(1); | 657 checkpoint.Call(1); |
656 | 658 |
657 m_websocket->send(view->buffer().get(), m_exceptionState); | 659 RefPtr<DOMArrayBuffer> buffer = view->buffer(); |
| 660 m_websocket->send(buffer.get(), m_exceptionState); |
658 | 661 |
659 EXPECT_FALSE(m_exceptionState.hadException()); | 662 EXPECT_FALSE(m_exceptionState.hadException()); |
660 EXPECT_EQ(DOMWebSocket::CLOSED, m_websocket->readyState()); | 663 EXPECT_EQ(DOMWebSocket::CLOSED, m_websocket->readyState()); |
661 } | 664 } |
662 | 665 |
663 TEST_F(DOMWebSocketTest, sendArrayBufferSuccess) | 666 TEST_F(DOMWebSocketTest, sendArrayBufferSuccess) |
664 { | 667 { |
665 RefPtr<DOMArrayBufferView> view = DOMUint8Array::create(8); | 668 RefPtr<DOMArrayBufferView> view = DOMUint8Array::deprecatedCreateOrCrash(8); |
666 { | 669 { |
667 InSequence s; | 670 InSequence s; |
668 EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String
())).WillOnce(Return(true)); | 671 EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String
())).WillOnce(Return(true)); |
669 EXPECT_CALL(channel(), send(Ref(*view->buffer()), 0, 8)); | 672 RefPtr<DOMArrayBuffer> buffer = view->buffer(); |
| 673 EXPECT_CALL(channel(), send(Ref(*buffer), 0, 8)); |
670 } | 674 } |
671 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState
); | 675 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState
); |
672 | 676 |
673 EXPECT_FALSE(m_exceptionState.hadException()); | 677 EXPECT_FALSE(m_exceptionState.hadException()); |
674 | 678 |
675 m_websocket->didConnect("", ""); | 679 m_websocket->didConnect("", ""); |
676 m_websocket->send(view->buffer().get(), m_exceptionState); | 680 RefPtr<DOMArrayBuffer> buffer = view->buffer(); |
| 681 m_websocket->send(buffer.get(), m_exceptionState); |
677 | 682 |
678 EXPECT_FALSE(m_exceptionState.hadException()); | 683 EXPECT_FALSE(m_exceptionState.hadException()); |
679 EXPECT_EQ(DOMWebSocket::OPEN, m_websocket->readyState()); | 684 EXPECT_EQ(DOMWebSocket::OPEN, m_websocket->readyState()); |
680 } | 685 } |
681 | 686 |
682 // FIXME: We should have Blob tests here. | 687 // FIXME: We should have Blob tests here. |
683 // We can't create a Blob because the blob registration cannot be mocked yet. | 688 // We can't create a Blob because the blob registration cannot be mocked yet. |
684 | 689 |
685 // FIXME: We should add tests for bufferedAmount. | 690 // FIXME: We should add tests for bufferedAmount. |
686 | 691 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
746 EXPECT_EQ(InvalidAccessError, m_exceptionState.code()); | 751 EXPECT_EQ(InvalidAccessError, m_exceptionState.code()); |
747 EXPECT_EQ(String::format("The code must be either 1000, or between 3000 and
4999. %d is neither.", GetParam()), m_exceptionState.message()); | 752 EXPECT_EQ(String::format("The code must be either 1000, or between 3000 and
4999. %d is neither.", GetParam()), m_exceptionState.message()); |
748 EXPECT_EQ(DOMWebSocket::CONNECTING, m_websocket->readyState()); | 753 EXPECT_EQ(DOMWebSocket::CONNECTING, m_websocket->readyState()); |
749 } | 754 } |
750 | 755 |
751 INSTANTIATE_TEST_CASE_P(DOMWebSocketInvalidClosingCode, DOMWebSocketInvalidClosi
ngCodeTest, ::testing::Values(0, 1, 998, 999, 1001, 2999, 5000, 9999, 65535)); | 756 INSTANTIATE_TEST_CASE_P(DOMWebSocketInvalidClosingCode, DOMWebSocketInvalidClosi
ngCodeTest, ::testing::Values(0, 1, 998, 999, 1001, 2999, 5000, 9999, 65535)); |
752 | 757 |
753 } // namespace | 758 } // namespace |
754 | 759 |
755 } // namespace blink | 760 } // namespace blink |
OLD | NEW |