OLD | NEW |
---|---|
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_channel.h" | 5 #include "net/websockets/websocket_channel.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include <iostream> | 9 #include <iostream> |
10 #include <string> | 10 #include <string> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/bind.h" | 13 #include "base/bind.h" |
14 #include "base/bind_helpers.h" | 14 #include "base/bind_helpers.h" |
15 #include "base/callback.h" | 15 #include "base/callback.h" |
16 #include "base/location.h" | 16 #include "base/location.h" |
17 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
18 #include "base/memory/scoped_vector.h" | 18 #include "base/memory/scoped_vector.h" |
19 #include "base/memory/weak_ptr.h" | |
19 #include "base/message_loop/message_loop.h" | 20 #include "base/message_loop/message_loop.h" |
20 #include "base/safe_numerics.h" | 21 #include "base/safe_numerics.h" |
21 #include "base/strings/string_piece.h" | 22 #include "base/strings/string_piece.h" |
22 #include "net/base/net_errors.h" | 23 #include "net/base/net_errors.h" |
23 #include "net/url_request/url_request_context.h" | 24 #include "net/url_request/url_request_context.h" |
24 #include "net/websockets/websocket_errors.h" | 25 #include "net/websockets/websocket_errors.h" |
25 #include "net/websockets/websocket_event_interface.h" | 26 #include "net/websockets/websocket_event_interface.h" |
26 #include "net/websockets/websocket_mux.h" | 27 #include "net/websockets/websocket_mux.h" |
27 #include "testing/gmock/include/gmock/gmock.h" | 28 #include "testing/gmock/include/gmock/gmock.h" |
28 #include "testing/gtest/include/gtest/gtest.h" | 29 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
78 } | 79 } |
79 | 80 |
80 std::ostream& operator<<(std::ostream& os, | 81 std::ostream& operator<<(std::ostream& os, |
81 const ScopedVector<WebSocketFrame>* vector) { | 82 const ScopedVector<WebSocketFrame>* vector) { |
82 return os << '&' << *vector; | 83 return os << '&' << *vector; |
83 } | 84 } |
84 | 85 |
85 namespace { | 86 namespace { |
86 | 87 |
87 using ::testing::AnyNumber; | 88 using ::testing::AnyNumber; |
89 using ::testing::DefaultValue; | |
88 using ::testing::InSequence; | 90 using ::testing::InSequence; |
89 using ::testing::MockFunction; | 91 using ::testing::MockFunction; |
90 using ::testing::Return; | 92 using ::testing::Return; |
91 using ::testing::SaveArg; | 93 using ::testing::SaveArg; |
92 using ::testing::StrictMock; | 94 using ::testing::StrictMock; |
93 using ::testing::_; | 95 using ::testing::_; |
94 | 96 |
95 // A selection of characters that have traditionally been mangled in some | 97 // A selection of characters that have traditionally been mangled in some |
96 // environment or other, for testing 8-bit cleanliness. | 98 // environment or other, for testing 8-bit cleanliness. |
97 const char kBinaryBlob[] = {'\n', '\r', // BACKWARDS CRNL | 99 const char kBinaryBlob[] = {'\n', '\r', // BACKWARDS CRNL |
(...skipping 11 matching lines...) Expand all Loading... | |
109 | 111 |
110 // The amount of quota a new connection gets by default. | 112 // The amount of quota a new connection gets by default. |
111 // TODO(ricea): If kDefaultSendQuotaHighWaterMark changes, then this value will | 113 // TODO(ricea): If kDefaultSendQuotaHighWaterMark changes, then this value will |
112 // need to be updated. | 114 // need to be updated. |
113 const size_t kDefaultInitialQuota = 1 << 17; | 115 const size_t kDefaultInitialQuota = 1 << 17; |
114 // The amount of bytes we need to send after the initial connection to trigger a | 116 // The amount of bytes we need to send after the initial connection to trigger a |
115 // quota refresh. TODO(ricea): Change this if kDefaultSendQuotaHighWaterMark or | 117 // quota refresh. TODO(ricea): Change this if kDefaultSendQuotaHighWaterMark or |
116 // kDefaultSendQuotaLowWaterMark change. | 118 // kDefaultSendQuotaLowWaterMark change. |
117 const size_t kDefaultQuotaRefreshTrigger = (1 << 16) + 1; | 119 const size_t kDefaultQuotaRefreshTrigger = (1 << 16) + 1; |
118 | 120 |
121 typedef WebSocketEventInterface::ChannelState ChannelState; | |
122 const ChannelState CHANNEL_ALIVE = WebSocketEventInterface::CHANNEL_ALIVE; | |
123 const ChannelState CHANNEL_DELETED = WebSocketEventInterface::CHANNEL_DELETED; | |
124 | |
125 // This typedef mainly exists to avoid having to repeat the "NOLINT" incantation | |
126 // all over the place. | |
127 typedef MockFunction<void(int)> Checkpoint; // NOLINT | |
128 | |
119 // This mock is for testing expectations about how the EventInterface is used. | 129 // This mock is for testing expectations about how the EventInterface is used. |
120 class MockWebSocketEventInterface : public WebSocketEventInterface { | 130 class MockWebSocketEventInterface : public WebSocketEventInterface { |
121 public: | 131 public: |
122 MOCK_METHOD2(OnAddChannelResponse, void(bool, const std::string&)); | 132 MOCK_METHOD2(OnAddChannelResponse, |
133 ChannelState(bool, const std::string&)); // NOLINT | |
123 MOCK_METHOD3(OnDataFrame, | 134 MOCK_METHOD3(OnDataFrame, |
124 void(bool, WebSocketMessageType, const std::vector<char>&)); | 135 ChannelState(bool, |
125 MOCK_METHOD1(OnFlowControl, void(int64)); | 136 WebSocketMessageType, |
126 MOCK_METHOD0(OnClosingHandshake, void(void)); | 137 const std::vector<char>&)); // NOLINT |
127 MOCK_METHOD2(OnDropChannel, void(uint16, const std::string&)); | 138 MOCK_METHOD1(OnFlowControl, ChannelState(int64)); // NOLINT |
139 MOCK_METHOD0(OnClosingHandshake, ChannelState(void)); // NOLINT | |
140 MOCK_METHOD2(OnDropChannel, | |
141 ChannelState(uint16, const std::string&)); // NOLINT | |
128 }; | 142 }; |
129 | 143 |
130 // This fake EventInterface is for tests which need a WebSocketEventInterface | 144 // This fake EventInterface is for tests which need a WebSocketEventInterface |
131 // implementation but are not verifying how it is used. | 145 // implementation but are not verifying how it is used. |
132 class FakeWebSocketEventInterface : public WebSocketEventInterface { | 146 class FakeWebSocketEventInterface : public WebSocketEventInterface { |
133 virtual void OnAddChannelResponse( | 147 virtual ChannelState OnAddChannelResponse( |
134 bool fail, | 148 bool fail, |
135 const std::string& selected_protocol) OVERRIDE {} | 149 const std::string& selected_protocol) OVERRIDE { |
136 virtual void OnDataFrame(bool fin, | 150 return fail ? CHANNEL_DELETED : CHANNEL_ALIVE; |
137 WebSocketMessageType type, | 151 } |
138 const std::vector<char>& data) OVERRIDE {} | 152 virtual ChannelState OnDataFrame(bool fin, |
139 virtual void OnFlowControl(int64 quota) OVERRIDE {} | 153 WebSocketMessageType type, |
140 virtual void OnClosingHandshake() OVERRIDE {} | 154 const std::vector<char>& data) OVERRIDE { |
141 virtual void OnDropChannel(uint16 code, const std::string& reason) OVERRIDE {} | 155 return CHANNEL_ALIVE; |
156 } | |
157 virtual ChannelState OnFlowControl(int64 quota) OVERRIDE { | |
158 return CHANNEL_ALIVE; | |
159 } | |
160 virtual ChannelState OnClosingHandshake() OVERRIDE { return CHANNEL_ALIVE; } | |
161 virtual ChannelState OnDropChannel(uint16 code, | |
162 const std::string& reason) OVERRIDE { | |
163 return CHANNEL_DELETED; | |
164 } | |
142 }; | 165 }; |
143 | 166 |
144 // This fake WebSocketStream is for tests that require a WebSocketStream but are | 167 // This fake WebSocketStream is for tests that require a WebSocketStream but are |
145 // not testing the way it is used. It has minimal functionality to return | 168 // not testing the way it is used. It has minimal functionality to return |
146 // the |protocol| and |extensions| that it was constructed with. | 169 // the |protocol| and |extensions| that it was constructed with. |
147 class FakeWebSocketStream : public WebSocketStream { | 170 class FakeWebSocketStream : public WebSocketStream { |
148 public: | 171 public: |
149 // Constructs with empty protocol and extensions. | 172 // Constructs with empty protocol and extensions. |
150 FakeWebSocketStream() {} | 173 FakeWebSocketStream() {} |
151 | 174 |
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
542 CompletionCallback read_callback_; | 565 CompletionCallback read_callback_; |
543 // Owned by the caller of ReadFrames(). | 566 // Owned by the caller of ReadFrames(). |
544 ScopedVector<WebSocketFrame>* read_frames_; | 567 ScopedVector<WebSocketFrame>* read_frames_; |
545 // True if we should close the connection. | 568 // True if we should close the connection. |
546 bool done_; | 569 bool done_; |
547 }; | 570 }; |
548 | 571 |
549 // A FakeWebSocketStream where writes trigger a connection reset. | 572 // A FakeWebSocketStream where writes trigger a connection reset. |
550 // This differs from UnWriteableFakeWebSocketStream in that it is asynchronous | 573 // This differs from UnWriteableFakeWebSocketStream in that it is asynchronous |
551 // and triggers ReadFrames to return a reset as well. Tests using this need to | 574 // and triggers ReadFrames to return a reset as well. Tests using this need to |
552 // run the message loop. | 575 // run the message loop. There are two tricky parts here: |
576 // 1. Calling the write callback may call Close(), after which the read callback | |
577 // should not be called. | |
578 // 2. Calling either callback may delete the stream altogether. | |
553 class ResetOnWriteFakeWebSocketStream : public FakeWebSocketStream { | 579 class ResetOnWriteFakeWebSocketStream : public FakeWebSocketStream { |
554 public: | 580 public: |
581 ResetOnWriteFakeWebSocketStream() : closed_(false), weak_ptr_factory_(this) {} | |
582 | |
555 virtual int WriteFrames(ScopedVector<WebSocketFrame>* frames, | 583 virtual int WriteFrames(ScopedVector<WebSocketFrame>* frames, |
556 const CompletionCallback& callback) OVERRIDE { | 584 const CompletionCallback& callback) OVERRIDE { |
557 base::MessageLoop::current()->PostTask( | 585 base::MessageLoop::current()->PostTask( |
558 FROM_HERE, base::Bind(callback, ERR_CONNECTION_RESET)); | 586 FROM_HERE, |
587 base::Bind(&ResetOnWriteFakeWebSocketStream::CallCallbackUnlessClosed, | |
588 weak_ptr_factory_.GetWeakPtr(), | |
589 callback, | |
590 ERR_CONNECTION_RESET)); | |
559 base::MessageLoop::current()->PostTask( | 591 base::MessageLoop::current()->PostTask( |
560 FROM_HERE, base::Bind(read_callback_, ERR_CONNECTION_RESET)); | 592 FROM_HERE, |
593 base::Bind(&ResetOnWriteFakeWebSocketStream::CallCallbackUnlessClosed, | |
594 weak_ptr_factory_.GetWeakPtr(), | |
595 read_callback_, | |
596 ERR_CONNECTION_RESET)); | |
561 return ERR_IO_PENDING; | 597 return ERR_IO_PENDING; |
562 } | 598 } |
563 | 599 |
564 virtual int ReadFrames(ScopedVector<WebSocketFrame>* frames, | 600 virtual int ReadFrames(ScopedVector<WebSocketFrame>* frames, |
565 const CompletionCallback& callback) OVERRIDE { | 601 const CompletionCallback& callback) OVERRIDE { |
566 read_callback_ = callback; | 602 read_callback_ = callback; |
567 return ERR_IO_PENDING; | 603 return ERR_IO_PENDING; |
568 } | 604 } |
569 | 605 |
606 virtual void Close() OVERRIDE { closed_ = true; } | |
607 | |
570 private: | 608 private: |
609 void CallCallbackUnlessClosed(const CompletionCallback& callback, int value) { | |
610 if (!closed_) | |
611 callback.Run(value); | |
612 } | |
613 | |
571 CompletionCallback read_callback_; | 614 CompletionCallback read_callback_; |
615 bool closed_; | |
616 // An IO error can result in the socket being deleted, so we use weak pointers | |
617 // to ensure correct behaviour in that case. | |
618 base::WeakPtrFactory<ResetOnWriteFakeWebSocketStream> weak_ptr_factory_; | |
572 }; | 619 }; |
573 | 620 |
574 // This mock is for verifying that WebSocket protocol semantics are obeyed (to | 621 // This mock is for verifying that WebSocket protocol semantics are obeyed (to |
575 // the extent that they are implemented in WebSocketCommon). | 622 // the extent that they are implemented in WebSocketCommon). |
576 class MockWebSocketStream : public WebSocketStream { | 623 class MockWebSocketStream : public WebSocketStream { |
577 public: | 624 public: |
578 MOCK_METHOD2(ReadFrames, | 625 MOCK_METHOD2(ReadFrames, |
579 int(ScopedVector<WebSocketFrame>* frames, | 626 int(ScopedVector<WebSocketFrame>* frames, |
580 const CompletionCallback& callback)); | 627 const CompletionCallback& callback)); |
581 MOCK_METHOD2(WriteFrames, | 628 MOCK_METHOD2(WriteFrames, |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
683 }; | 730 }; |
684 ConnectData connect_data_; | 731 ConnectData connect_data_; |
685 | 732 |
686 // The channel we are testing. Not initialised until SetChannel() is called. | 733 // The channel we are testing. Not initialised until SetChannel() is called. |
687 scoped_ptr<WebSocketChannel> channel_; | 734 scoped_ptr<WebSocketChannel> channel_; |
688 | 735 |
689 // A mock or fake stream for tests that need one. | 736 // A mock or fake stream for tests that need one. |
690 scoped_ptr<WebSocketStream> stream_; | 737 scoped_ptr<WebSocketStream> stream_; |
691 }; | 738 }; |
692 | 739 |
740 // enum of WebSocketEventInterface calls. These are intended to be or'd together | |
741 // in order to instruct WebSocketChannelDeletingTest when it should fail. | |
742 enum EventInterfaceCall { | |
743 EVENT_ON_ADD_CHANNEL_RESPONSE = 0x1, | |
744 EVENT_ON_DATA_FRAME = 0x2, | |
745 EVENT_ON_FLOW_CONTROL = 0x4, | |
746 EVENT_ON_CLOSING_HANDSHAKE = 0x8, | |
747 EVENT_ON_DROP_CHANNEL = 0x10, | |
748 }; | |
749 | |
693 class WebSocketChannelDeletingTest : public WebSocketChannelTest { | 750 class WebSocketChannelDeletingTest : public WebSocketChannelTest { |
694 public: | 751 public: |
695 void ResetChannel() { channel_.reset(); } | 752 ChannelState DeleteIfDeleting(EventInterfaceCall call) { |
753 if (deleting_ & call) { | |
754 channel_.reset(); | |
755 return CHANNEL_DELETED; | |
756 } else { | |
757 return CHANNEL_ALIVE; | |
758 } | |
759 } | |
696 | 760 |
697 protected: | 761 protected: |
762 WebSocketChannelDeletingTest() | |
763 : deleting_(EVENT_ON_ADD_CHANNEL_RESPONSE | EVENT_ON_DATA_FRAME | | |
764 EVENT_ON_FLOW_CONTROL | | |
765 EVENT_ON_CLOSING_HANDSHAKE | | |
766 EVENT_ON_DROP_CHANNEL) {} | |
698 // Create a ChannelDeletingFakeWebSocketEventInterface. Defined out-of-line to | 767 // Create a ChannelDeletingFakeWebSocketEventInterface. Defined out-of-line to |
699 // avoid circular dependency. | 768 // avoid circular dependency. |
700 virtual scoped_ptr<WebSocketEventInterface> CreateEventInterface() OVERRIDE; | 769 virtual scoped_ptr<WebSocketEventInterface> CreateEventInterface() OVERRIDE; |
770 | |
771 // Tests can set deleting_ to a bitmap of EventInterfaceCall members that they | |
772 // want to cause Channel deletion. The default is for all calls to cause | |
773 // deletion. | |
774 int deleting_; | |
701 }; | 775 }; |
702 | 776 |
703 // A FakeWebSocketEventInterface that deletes the WebSocketChannel on failure to | 777 // A FakeWebSocketEventInterface that deletes the WebSocketChannel on failure to |
704 // connect. | 778 // connect. |
705 class ChannelDeletingFakeWebSocketEventInterface | 779 class ChannelDeletingFakeWebSocketEventInterface |
706 : public FakeWebSocketEventInterface { | 780 : public FakeWebSocketEventInterface { |
707 public: | 781 public: |
708 ChannelDeletingFakeWebSocketEventInterface( | 782 ChannelDeletingFakeWebSocketEventInterface( |
709 WebSocketChannelDeletingTest* fixture) | 783 WebSocketChannelDeletingTest* fixture) |
710 : fixture_(fixture) {} | 784 : fixture_(fixture) {} |
711 | 785 |
712 virtual void OnAddChannelResponse( | 786 virtual ChannelState OnAddChannelResponse( |
713 bool fail, | 787 bool fail, |
714 const std::string& selected_protocol) OVERRIDE { | 788 const std::string& selected_protocol) OVERRIDE { |
715 if (fail) { | 789 return fixture_->DeleteIfDeleting(EVENT_ON_ADD_CHANNEL_RESPONSE); |
716 fixture_->ResetChannel(); | 790 } |
717 } | 791 |
792 virtual ChannelState OnDataFrame(bool fin, | |
793 WebSocketMessageType type, | |
794 const std::vector<char>& data) OVERRIDE { | |
795 return fixture_->DeleteIfDeleting(EVENT_ON_DATA_FRAME); | |
796 } | |
797 | |
798 virtual ChannelState OnFlowControl(int64 quota) OVERRIDE { | |
799 return fixture_->DeleteIfDeleting(EVENT_ON_FLOW_CONTROL); | |
800 } | |
801 | |
802 virtual ChannelState OnClosingHandshake() OVERRIDE { | |
803 return fixture_->DeleteIfDeleting(EVENT_ON_CLOSING_HANDSHAKE); | |
804 } | |
805 | |
806 virtual ChannelState OnDropChannel(uint16 code, | |
807 const std::string& reason) OVERRIDE { | |
808 return fixture_->DeleteIfDeleting(EVENT_ON_DROP_CHANNEL); | |
718 } | 809 } |
719 | 810 |
720 private: | 811 private: |
721 // A pointer to the test fixture. Owned by the test harness; this object will | 812 // A pointer to the test fixture. Owned by the test harness; this object will |
722 // be deleted before it is. | 813 // be deleted before it is. |
723 WebSocketChannelDeletingTest* fixture_; | 814 WebSocketChannelDeletingTest* fixture_; |
724 }; | 815 }; |
725 | 816 |
726 scoped_ptr<WebSocketEventInterface> | 817 scoped_ptr<WebSocketEventInterface> |
727 WebSocketChannelDeletingTest::CreateEventInterface() { | 818 WebSocketChannelDeletingTest::CreateEventInterface() { |
728 return scoped_ptr<WebSocketEventInterface>( | 819 return scoped_ptr<WebSocketEventInterface>( |
729 new ChannelDeletingFakeWebSocketEventInterface(this)); | 820 new ChannelDeletingFakeWebSocketEventInterface(this)); |
730 } | 821 } |
731 | 822 |
732 // Base class for tests which verify that EventInterface methods are called | 823 // Base class for tests which verify that EventInterface methods are called |
733 // appropriately. | 824 // appropriately. |
734 class WebSocketChannelEventInterfaceTest : public WebSocketChannelTest { | 825 class WebSocketChannelEventInterfaceTest : public WebSocketChannelTest { |
735 protected: | 826 protected: |
736 WebSocketChannelEventInterfaceTest() | 827 WebSocketChannelEventInterfaceTest() |
737 : event_interface_(new StrictMock<MockWebSocketEventInterface>) {} | 828 : event_interface_(new StrictMock<MockWebSocketEventInterface>) { |
829 DefaultValue<ChannelState>::Set(CHANNEL_ALIVE); | |
830 ON_CALL(*event_interface_, OnAddChannelResponse(true, _)) | |
831 .WillByDefault(Return(CHANNEL_DELETED)); | |
832 ON_CALL(*event_interface_, OnDropChannel(_, _)) | |
833 .WillByDefault(Return(CHANNEL_DELETED)); | |
834 } | |
738 | 835 |
739 // Tests using this fixture must set expectations on the event_interface_ mock | 836 // Tests using this fixture must set expectations on the event_interface_ mock |
740 // object before calling CreateChannelAndConnect() or | 837 // object before calling CreateChannelAndConnect() or |
741 // CreateChannelAndConnectSuccessfully(). This will only work once per test | 838 // CreateChannelAndConnectSuccessfully(). This will only work once per test |
742 // case, but once should be enough. | 839 // case, but once should be enough. |
743 virtual scoped_ptr<WebSocketEventInterface> CreateEventInterface() OVERRIDE { | 840 virtual scoped_ptr<WebSocketEventInterface> CreateEventInterface() OVERRIDE { |
744 return scoped_ptr<WebSocketEventInterface>(event_interface_.release()); | 841 return scoped_ptr<WebSocketEventInterface>(event_interface_.release()); |
745 } | 842 } |
746 | 843 |
747 scoped_ptr<MockWebSocketEventInterface> event_interface_; | 844 scoped_ptr<MockWebSocketEventInterface> event_interface_; |
(...skipping 24 matching lines...) Expand all Loading... | |
772 CreateChannelAndConnect(); | 869 CreateChannelAndConnect(); |
773 | 870 |
774 EXPECT_EQ(connect_data_.url, connect_data_.factory.socket_url); | 871 EXPECT_EQ(connect_data_.url, connect_data_.factory.socket_url); |
775 EXPECT_EQ(connect_data_.origin, connect_data_.factory.origin); | 872 EXPECT_EQ(connect_data_.origin, connect_data_.factory.origin); |
776 EXPECT_EQ(connect_data_.requested_subprotocols, | 873 EXPECT_EQ(connect_data_.requested_subprotocols, |
777 connect_data_.factory.requested_subprotocols); | 874 connect_data_.factory.requested_subprotocols); |
778 EXPECT_EQ(&connect_data_.url_request_context, | 875 EXPECT_EQ(&connect_data_.url_request_context, |
779 connect_data_.factory.url_request_context); | 876 connect_data_.factory.url_request_context); |
780 } | 877 } |
781 | 878 |
782 // The documentation for WebSocketEventInterface::OnAddChannelResponse() says | 879 // Any WebSocketEventInterface methods can delete the WebSocketChannel and |
783 // that if the first argument is true, ie. the connection failed, then we can | 880 // return CHANNEL_DELETED. The WebSocketChannelDeletingTests are intended to |
784 // safely synchronously delete the WebSocketChannel. This test will only | 881 // verify that there are no use-after-free bugs when this happens. Probably will |
yhirano
2013/10/15 04:50:18
Problems will probably only be found?
| |
785 // reliably find problems if run with a memory debugger such as | 882 // probably only be found when running under ASAN. |
786 // AddressSanitizer. | 883 TEST_F(WebSocketChannelDeletingTest, OnAddChannelResponseFail) { |
787 TEST_F(WebSocketChannelDeletingTest, DeletingFromOnAddChannelResponseWorks) { | |
788 CreateChannelAndConnect(); | 884 CreateChannelAndConnect(); |
885 EXPECT_TRUE(channel_); | |
789 connect_data_.factory.connect_delegate->OnFailure( | 886 connect_data_.factory.connect_delegate->OnFailure( |
790 kWebSocketErrorNoStatusReceived); | 887 kWebSocketErrorNoStatusReceived); |
791 EXPECT_EQ(NULL, channel_.get()); | 888 EXPECT_EQ(NULL, channel_.get()); |
792 } | 889 } |
793 | 890 |
891 // Deletion is possible (due to IPC failure) even if the connect succeeds. | |
892 TEST_F(WebSocketChannelDeletingTest, OnAddChannelResponseSuccess) { | |
893 CreateChannelAndConnectSuccessfully(); | |
894 EXPECT_EQ(NULL, channel_.get()); | |
895 } | |
896 | |
897 TEST_F(WebSocketChannelDeletingTest, OnDataFrameSync) { | |
898 scoped_ptr<ReadableFakeWebSocketStream> stream( | |
899 new ReadableFakeWebSocketStream); | |
900 static const InitFrame frames[] = { | |
901 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, NOT_MASKED, "HELLO"}}; | |
902 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames); | |
903 set_stream(stream.Pass()); | |
904 deleting_ = EVENT_ON_DATA_FRAME; | |
905 | |
906 CreateChannelAndConnectSuccessfully(); | |
907 EXPECT_EQ(NULL, channel_.get()); | |
908 } | |
909 | |
910 TEST_F(WebSocketChannelDeletingTest, OnDataFrameAsync) { | |
911 scoped_ptr<ReadableFakeWebSocketStream> stream( | |
912 new ReadableFakeWebSocketStream); | |
913 static const InitFrame frames[] = { | |
914 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, NOT_MASKED, "HELLO"}}; | |
915 stream->PrepareReadFrames(ReadableFakeWebSocketStream::ASYNC, OK, frames); | |
916 set_stream(stream.Pass()); | |
917 deleting_ = EVENT_ON_DATA_FRAME; | |
918 | |
919 CreateChannelAndConnectSuccessfully(); | |
920 EXPECT_TRUE(channel_); | |
921 base::MessageLoop::current()->RunUntilIdle(); | |
922 EXPECT_EQ(NULL, channel_.get()); | |
923 } | |
924 | |
925 TEST_F(WebSocketChannelDeletingTest, OnFlowControlAfterConnect) { | |
926 deleting_ = EVENT_ON_FLOW_CONTROL; | |
927 | |
928 CreateChannelAndConnectSuccessfully(); | |
929 EXPECT_EQ(NULL, channel_.get()); | |
930 } | |
931 | |
932 TEST_F(WebSocketChannelDeletingTest, OnFlowControlAfterSend) { | |
933 set_stream(make_scoped_ptr(new WriteableFakeWebSocketStream)); | |
934 // Avoid deleting the channel yet. | |
935 deleting_ = EVENT_ON_DROP_CHANNEL; | |
936 CreateChannelAndConnectSuccessfully(); | |
937 ASSERT_TRUE(channel_); | |
938 deleting_ = EVENT_ON_FLOW_CONTROL; | |
939 channel_->SendFrame(true, | |
940 WebSocketFrameHeader::kOpCodeText, | |
941 std::vector<char>(kDefaultInitialQuota, 'B')); | |
942 EXPECT_EQ(NULL, channel_.get()); | |
943 } | |
944 | |
945 TEST_F(WebSocketChannelDeletingTest, OnClosingHandshakeSync) { | |
946 scoped_ptr<ReadableFakeWebSocketStream> stream( | |
947 new ReadableFakeWebSocketStream); | |
948 static const InitFrame frames[] = { | |
949 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, | |
950 NOT_MASKED, CLOSE_DATA(NORMAL_CLOSURE, "Success")}}; | |
951 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames); | |
952 set_stream(stream.Pass()); | |
953 deleting_ = EVENT_ON_CLOSING_HANDSHAKE; | |
954 CreateChannelAndConnectSuccessfully(); | |
955 EXPECT_EQ(NULL, channel_.get()); | |
956 } | |
957 | |
958 TEST_F(WebSocketChannelDeletingTest, OnClosingHandshakeAsync) { | |
959 scoped_ptr<ReadableFakeWebSocketStream> stream( | |
960 new ReadableFakeWebSocketStream); | |
961 static const InitFrame frames[] = { | |
962 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, | |
963 NOT_MASKED, CLOSE_DATA(NORMAL_CLOSURE, "Success")}}; | |
964 stream->PrepareReadFrames(ReadableFakeWebSocketStream::ASYNC, OK, frames); | |
965 set_stream(stream.Pass()); | |
966 deleting_ = EVENT_ON_CLOSING_HANDSHAKE; | |
967 CreateChannelAndConnectSuccessfully(); | |
968 ASSERT_TRUE(channel_); | |
969 base::MessageLoop::current()->RunUntilIdle(); | |
970 EXPECT_EQ(NULL, channel_.get()); | |
971 } | |
972 | |
973 TEST_F(WebSocketChannelDeletingTest, OnDropChannelWriteError) { | |
974 set_stream(make_scoped_ptr(new UnWriteableFakeWebSocketStream)); | |
975 deleting_ = EVENT_ON_DROP_CHANNEL; | |
976 CreateChannelAndConnectSuccessfully(); | |
977 ASSERT_TRUE(channel_); | |
978 channel_->SendFrame( | |
979 true, WebSocketFrameHeader::kOpCodeText, AsVector("this will fail")); | |
980 EXPECT_EQ(NULL, channel_.get()); | |
981 } | |
982 | |
983 TEST_F(WebSocketChannelDeletingTest, OnDropChannelReadError) { | |
984 scoped_ptr<ReadableFakeWebSocketStream> stream( | |
985 new ReadableFakeWebSocketStream); | |
986 stream->PrepareReadFramesError(ReadableFakeWebSocketStream::ASYNC, | |
987 ERR_FAILED); | |
988 set_stream(stream.Pass()); | |
989 deleting_ = EVENT_ON_DROP_CHANNEL; | |
990 CreateChannelAndConnectSuccessfully(); | |
991 ASSERT_TRUE(channel_); | |
992 base::MessageLoop::current()->RunUntilIdle(); | |
993 EXPECT_EQ(NULL, channel_.get()); | |
994 } | |
995 | |
996 TEST_F(WebSocketChannelDeletingTest, FailChannelInSendFrame) { | |
997 set_stream(make_scoped_ptr(new WriteableFakeWebSocketStream)); | |
998 deleting_ = EVENT_ON_DROP_CHANNEL; | |
999 CreateChannelAndConnectSuccessfully(); | |
1000 ASSERT_TRUE(channel_); | |
1001 channel_->SendFrame(true, | |
1002 WebSocketFrameHeader::kOpCodeText, | |
1003 std::vector<char>(kDefaultInitialQuota * 2, 'T')); | |
1004 EXPECT_EQ(NULL, channel_.get()); | |
1005 } | |
1006 | |
1007 TEST_F(WebSocketChannelDeletingTest, FailChannelInOnReadDone) { | |
1008 scoped_ptr<ReadableFakeWebSocketStream> stream( | |
1009 new ReadableFakeWebSocketStream); | |
1010 stream->PrepareReadFramesError(ReadableFakeWebSocketStream::ASYNC, | |
1011 ERR_WS_PROTOCOL_ERROR); | |
1012 set_stream(stream.Pass()); | |
1013 deleting_ = EVENT_ON_DROP_CHANNEL; | |
1014 CreateChannelAndConnectSuccessfully(); | |
1015 ASSERT_TRUE(channel_); | |
1016 base::MessageLoop::current()->RunUntilIdle(); | |
1017 EXPECT_EQ(NULL, channel_.get()); | |
1018 } | |
1019 | |
1020 TEST_F(WebSocketChannelDeletingTest, FailChannelDueToMaskedFrame) { | |
1021 scoped_ptr<ReadableFakeWebSocketStream> stream( | |
1022 new ReadableFakeWebSocketStream); | |
1023 static const InitFrame frames[] = { | |
1024 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, MASKED, "HELLO"}}; | |
1025 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames); | |
1026 set_stream(stream.Pass()); | |
1027 deleting_ = EVENT_ON_DROP_CHANNEL; | |
1028 | |
1029 CreateChannelAndConnectSuccessfully(); | |
1030 EXPECT_EQ(NULL, channel_.get()); | |
1031 } | |
1032 | |
1033 TEST_F(WebSocketChannelDeletingTest, FailChannelDueToBadControlFrame) { | |
1034 scoped_ptr<ReadableFakeWebSocketStream> stream( | |
1035 new ReadableFakeWebSocketStream); | |
1036 static const InitFrame frames[] = { | |
1037 {NOT_FINAL_FRAME, WebSocketFrameHeader::kOpCodePong, NOT_MASKED, ""}}; | |
1038 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames); | |
1039 set_stream(stream.Pass()); | |
1040 deleting_ = EVENT_ON_DROP_CHANNEL; | |
1041 | |
1042 CreateChannelAndConnectSuccessfully(); | |
1043 EXPECT_EQ(NULL, channel_.get()); | |
1044 } | |
1045 | |
1046 TEST_F(WebSocketChannelDeletingTest, FailChannelDueToPongAfterClose) { | |
1047 scoped_ptr<ReadableFakeWebSocketStream> stream( | |
1048 new ReadableFakeWebSocketStream); | |
1049 static const InitFrame frames[] = { | |
1050 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, NOT_MASKED, | |
1051 CLOSE_DATA(NORMAL_CLOSURE, "Success")}, | |
1052 {FINAL_FRAME, WebSocketFrameHeader::kOpCodePong, NOT_MASKED, ""}}; | |
1053 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames); | |
1054 set_stream(stream.Pass()); | |
1055 deleting_ = EVENT_ON_DROP_CHANNEL; | |
1056 | |
1057 CreateChannelAndConnectSuccessfully(); | |
1058 EXPECT_EQ(NULL, channel_.get()); | |
1059 } | |
1060 | |
1061 TEST_F(WebSocketChannelDeletingTest, FailChannelDueToUnknownOpCode) { | |
1062 scoped_ptr<ReadableFakeWebSocketStream> stream( | |
1063 new ReadableFakeWebSocketStream); | |
1064 static const InitFrame frames[] = {{FINAL_FRAME, 0x7, NOT_MASKED, ""}}; | |
1065 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames); | |
1066 set_stream(stream.Pass()); | |
1067 deleting_ = EVENT_ON_DROP_CHANNEL; | |
1068 | |
1069 CreateChannelAndConnectSuccessfully(); | |
1070 EXPECT_EQ(NULL, channel_.get()); | |
1071 } | |
1072 | |
794 TEST_F(WebSocketChannelEventInterfaceTest, ConnectSuccessReported) { | 1073 TEST_F(WebSocketChannelEventInterfaceTest, ConnectSuccessReported) { |
795 // false means success. | 1074 // false means success. |
796 EXPECT_CALL(*event_interface_, OnAddChannelResponse(false, "")); | 1075 EXPECT_CALL(*event_interface_, OnAddChannelResponse(false, "")); |
797 // OnFlowControl is always called immediately after connect to provide initial | 1076 // OnFlowControl is always called immediately after connect to provide initial |
798 // quota to the renderer. | 1077 // quota to the renderer. |
799 EXPECT_CALL(*event_interface_, OnFlowControl(_)); | 1078 EXPECT_CALL(*event_interface_, OnFlowControl(_)); |
800 | 1079 |
801 CreateChannelAndConnect(); | 1080 CreateChannelAndConnect(); |
802 | 1081 |
803 connect_data_.factory.connect_delegate->OnSuccess(stream_.Pass()); | 1082 connect_data_.factory.connect_delegate->OnSuccess(stream_.Pass()); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
890 CreateChannelAndConnectSuccessfully(); | 1169 CreateChannelAndConnectSuccessfully(); |
891 } | 1170 } |
892 | 1171 |
893 TEST_F(WebSocketChannelEventInterfaceTest, NormalAsyncRead) { | 1172 TEST_F(WebSocketChannelEventInterfaceTest, NormalAsyncRead) { |
894 scoped_ptr<ReadableFakeWebSocketStream> stream( | 1173 scoped_ptr<ReadableFakeWebSocketStream> stream( |
895 new ReadableFakeWebSocketStream); | 1174 new ReadableFakeWebSocketStream); |
896 static const InitFrame frames[] = { | 1175 static const InitFrame frames[] = { |
897 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, NOT_MASKED, "HELLO"}}; | 1176 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, NOT_MASKED, "HELLO"}}; |
898 // We use this checkpoint object to verify that the callback isn't called | 1177 // We use this checkpoint object to verify that the callback isn't called |
899 // until we expect it to be. | 1178 // until we expect it to be. |
900 MockFunction<void(int)> checkpoint; | 1179 Checkpoint checkpoint; |
901 stream->PrepareReadFrames(ReadableFakeWebSocketStream::ASYNC, OK, frames); | 1180 stream->PrepareReadFrames(ReadableFakeWebSocketStream::ASYNC, OK, frames); |
902 set_stream(stream.Pass()); | 1181 set_stream(stream.Pass()); |
903 { | 1182 { |
904 InSequence s; | 1183 InSequence s; |
905 EXPECT_CALL(*event_interface_, OnAddChannelResponse(false, _)); | 1184 EXPECT_CALL(*event_interface_, OnAddChannelResponse(false, _)); |
906 EXPECT_CALL(*event_interface_, OnFlowControl(_)); | 1185 EXPECT_CALL(*event_interface_, OnFlowControl(_)); |
907 EXPECT_CALL(checkpoint, Call(1)); | 1186 EXPECT_CALL(checkpoint, Call(1)); |
908 EXPECT_CALL( | 1187 EXPECT_CALL( |
909 *event_interface_, | 1188 *event_interface_, |
910 OnDataFrame( | 1189 OnDataFrame( |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1178 CreateChannelAndConnectSuccessfully(); | 1457 CreateChannelAndConnectSuccessfully(); |
1179 channel_->SendFrame(true, WebSocketFrameHeader::kOpCodeText, AsVector("B")); | 1458 channel_->SendFrame(true, WebSocketFrameHeader::kOpCodeText, AsVector("B")); |
1180 } | 1459 } |
1181 | 1460 |
1182 // If we send enough to go below send_quota_low_water_mask_ we should get our | 1461 // If we send enough to go below send_quota_low_water_mask_ we should get our |
1183 // quota refreshed. | 1462 // quota refreshed. |
1184 TEST_F(WebSocketChannelEventInterfaceTest, LargeWriteUpdatesQuota) { | 1463 TEST_F(WebSocketChannelEventInterfaceTest, LargeWriteUpdatesQuota) { |
1185 set_stream(make_scoped_ptr(new WriteableFakeWebSocketStream)); | 1464 set_stream(make_scoped_ptr(new WriteableFakeWebSocketStream)); |
1186 // We use this checkpoint object to verify that the quota update comes after | 1465 // We use this checkpoint object to verify that the quota update comes after |
1187 // the write. | 1466 // the write. |
1188 MockFunction<void(int)> checkpoint; | 1467 Checkpoint checkpoint; |
1189 { | 1468 { |
1190 InSequence s; | 1469 InSequence s; |
1191 EXPECT_CALL(*event_interface_, OnAddChannelResponse(false, _)); | 1470 EXPECT_CALL(*event_interface_, OnAddChannelResponse(false, _)); |
1192 EXPECT_CALL(*event_interface_, OnFlowControl(_)); | 1471 EXPECT_CALL(*event_interface_, OnFlowControl(_)); |
1193 EXPECT_CALL(checkpoint, Call(1)); | 1472 EXPECT_CALL(checkpoint, Call(1)); |
1194 EXPECT_CALL(*event_interface_, OnFlowControl(_)); | 1473 EXPECT_CALL(*event_interface_, OnFlowControl(_)); |
1195 EXPECT_CALL(checkpoint, Call(2)); | 1474 EXPECT_CALL(checkpoint, Call(2)); |
1196 } | 1475 } |
1197 | 1476 |
1198 CreateChannelAndConnectSuccessfully(); | 1477 CreateChannelAndConnectSuccessfully(); |
1199 checkpoint.Call(1); | 1478 checkpoint.Call(1); |
1200 channel_->SendFrame(true, | 1479 channel_->SendFrame(true, |
1201 WebSocketFrameHeader::kOpCodeText, | 1480 WebSocketFrameHeader::kOpCodeText, |
1202 std::vector<char>(kDefaultInitialQuota, 'B')); | 1481 std::vector<char>(kDefaultInitialQuota, 'B')); |
1203 checkpoint.Call(2); | 1482 checkpoint.Call(2); |
1204 } | 1483 } |
1205 | 1484 |
1206 // Verify that our quota actually is refreshed when we are told it is. | 1485 // Verify that our quota actually is refreshed when we are told it is. |
1207 TEST_F(WebSocketChannelEventInterfaceTest, QuotaReallyIsRefreshed) { | 1486 TEST_F(WebSocketChannelEventInterfaceTest, QuotaReallyIsRefreshed) { |
1208 set_stream(make_scoped_ptr(new WriteableFakeWebSocketStream)); | 1487 set_stream(make_scoped_ptr(new WriteableFakeWebSocketStream)); |
1209 MockFunction<void(int)> checkpoint; | 1488 Checkpoint checkpoint; |
1210 { | 1489 { |
1211 InSequence s; | 1490 InSequence s; |
1212 EXPECT_CALL(*event_interface_, OnAddChannelResponse(false, _)); | 1491 EXPECT_CALL(*event_interface_, OnAddChannelResponse(false, _)); |
1213 EXPECT_CALL(*event_interface_, OnFlowControl(_)); | 1492 EXPECT_CALL(*event_interface_, OnFlowControl(_)); |
1214 EXPECT_CALL(checkpoint, Call(1)); | 1493 EXPECT_CALL(checkpoint, Call(1)); |
1215 EXPECT_CALL(*event_interface_, OnFlowControl(_)); | 1494 EXPECT_CALL(*event_interface_, OnFlowControl(_)); |
1216 EXPECT_CALL(checkpoint, Call(2)); | 1495 EXPECT_CALL(checkpoint, Call(2)); |
1217 // If quota was not really refreshed, we would get an OnDropChannel() | 1496 // If quota was not really refreshed, we would get an OnDropChannel() |
1218 // message. | 1497 // message. |
1219 EXPECT_CALL(*event_interface_, OnFlowControl(_)); | 1498 EXPECT_CALL(*event_interface_, OnFlowControl(_)); |
(...skipping 27 matching lines...) Expand all Loading... | |
1247 | 1526 |
1248 CreateChannelAndConnectSuccessfully(); | 1527 CreateChannelAndConnectSuccessfully(); |
1249 channel_->SendFrame(true, | 1528 channel_->SendFrame(true, |
1250 WebSocketFrameHeader::kOpCodeText, | 1529 WebSocketFrameHeader::kOpCodeText, |
1251 std::vector<char>(kDefaultInitialQuota + 1, 'C')); | 1530 std::vector<char>(kDefaultInitialQuota + 1, 'C')); |
1252 } | 1531 } |
1253 | 1532 |
1254 // If a write fails, the channel is dropped. | 1533 // If a write fails, the channel is dropped. |
1255 TEST_F(WebSocketChannelEventInterfaceTest, FailedWrite) { | 1534 TEST_F(WebSocketChannelEventInterfaceTest, FailedWrite) { |
1256 set_stream(make_scoped_ptr(new UnWriteableFakeWebSocketStream)); | 1535 set_stream(make_scoped_ptr(new UnWriteableFakeWebSocketStream)); |
1257 MockFunction<void(int)> checkpoint; | 1536 Checkpoint checkpoint; |
1258 { | 1537 { |
1259 InSequence s; | 1538 InSequence s; |
1260 EXPECT_CALL(*event_interface_, OnAddChannelResponse(false, _)); | 1539 EXPECT_CALL(*event_interface_, OnAddChannelResponse(false, _)); |
1261 EXPECT_CALL(*event_interface_, OnFlowControl(_)); | 1540 EXPECT_CALL(*event_interface_, OnFlowControl(_)); |
1262 EXPECT_CALL(checkpoint, Call(1)); | 1541 EXPECT_CALL(checkpoint, Call(1)); |
1263 EXPECT_CALL(*event_interface_, | 1542 EXPECT_CALL(*event_interface_, |
1264 OnDropChannel(kWebSocketErrorAbnormalClosure, _)); | 1543 OnDropChannel(kWebSocketErrorAbnormalClosure, _)); |
1265 EXPECT_CALL(checkpoint, Call(2)); | 1544 EXPECT_CALL(checkpoint, Call(2)); |
1266 } | 1545 } |
1267 | 1546 |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1422 static const InitFrame frames_init[] = { | 1701 static const InitFrame frames_init[] = { |
1423 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, | 1702 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, |
1424 NOT_MASKED, CLOSE_DATA(NORMAL_CLOSURE, "Close")}}; | 1703 NOT_MASKED, CLOSE_DATA(NORMAL_CLOSURE, "Close")}}; |
1425 | 1704 |
1426 // We store the parameters that were passed to ReadFrames() so that we can | 1705 // We store the parameters that were passed to ReadFrames() so that we can |
1427 // call them explicitly later. | 1706 // call them explicitly later. |
1428 CompletionCallback read_callback; | 1707 CompletionCallback read_callback; |
1429 ScopedVector<WebSocketFrame>* frames = NULL; | 1708 ScopedVector<WebSocketFrame>* frames = NULL; |
1430 | 1709 |
1431 // Use a checkpoint to make the ordering of events clearer. | 1710 // Use a checkpoint to make the ordering of events clearer. |
1432 MockFunction<void(int)> checkpoint; | 1711 Checkpoint checkpoint; |
1433 { | 1712 { |
1434 InSequence s; | 1713 InSequence s; |
1435 EXPECT_CALL(*mock_stream_, GetSubProtocol()).Times(AnyNumber()); | 1714 EXPECT_CALL(*mock_stream_, GetSubProtocol()).Times(AnyNumber()); |
1436 EXPECT_CALL(*mock_stream_, ReadFrames(_, _)) | 1715 EXPECT_CALL(*mock_stream_, ReadFrames(_, _)) |
1437 .WillOnce(DoAll(SaveArg<0>(&frames), | 1716 .WillOnce(DoAll(SaveArg<0>(&frames), |
1438 SaveArg<1>(&read_callback), | 1717 SaveArg<1>(&read_callback), |
1439 Return(ERR_IO_PENDING))); | 1718 Return(ERR_IO_PENDING))); |
1440 EXPECT_CALL(checkpoint, Call(1)); | 1719 EXPECT_CALL(checkpoint, Call(1)); |
1441 EXPECT_CALL(*mock_stream_, WriteFrames(EqualsFrames(expected), _)) | 1720 EXPECT_CALL(*mock_stream_, WriteFrames(EqualsFrames(expected), _)) |
1442 .WillOnce(Return(OK)); | 1721 .WillOnce(Return(OK)); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1541 } | 1820 } |
1542 | 1821 |
1543 // WriteFrames() may not be called until the previous write has completed. | 1822 // WriteFrames() may not be called until the previous write has completed. |
1544 // WebSocketChannel must buffer writes that happen in the meantime. | 1823 // WebSocketChannel must buffer writes that happen in the meantime. |
1545 TEST_F(WebSocketChannelStreamTest, WriteFramesOneAtATime) { | 1824 TEST_F(WebSocketChannelStreamTest, WriteFramesOneAtATime) { |
1546 static const InitFrame expected1[] = { | 1825 static const InitFrame expected1[] = { |
1547 {NOT_FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, MASKED, "Hello "}}; | 1826 {NOT_FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, MASKED, "Hello "}}; |
1548 static const InitFrame expected2[] = { | 1827 static const InitFrame expected2[] = { |
1549 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, MASKED, "World"}}; | 1828 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, MASKED, "World"}}; |
1550 CompletionCallback write_callback; | 1829 CompletionCallback write_callback; |
1551 MockFunction<void(int)> checkpoint; | 1830 Checkpoint checkpoint; |
1552 | 1831 |
1553 EXPECT_CALL(*mock_stream_, GetSubProtocol()).Times(AnyNumber()); | 1832 EXPECT_CALL(*mock_stream_, GetSubProtocol()).Times(AnyNumber()); |
1554 EXPECT_CALL(*mock_stream_, ReadFrames(_, _)).WillOnce(Return(ERR_IO_PENDING)); | 1833 EXPECT_CALL(*mock_stream_, ReadFrames(_, _)).WillOnce(Return(ERR_IO_PENDING)); |
1555 { | 1834 { |
1556 InSequence s; | 1835 InSequence s; |
1557 EXPECT_CALL(checkpoint, Call(1)); | 1836 EXPECT_CALL(checkpoint, Call(1)); |
1558 EXPECT_CALL(*mock_stream_, WriteFrames(EqualsFrames(expected1), _)) | 1837 EXPECT_CALL(*mock_stream_, WriteFrames(EqualsFrames(expected1), _)) |
1559 .WillOnce(DoAll(SaveArg<1>(&write_callback), Return(ERR_IO_PENDING))); | 1838 .WillOnce(DoAll(SaveArg<1>(&write_callback), Return(ERR_IO_PENDING))); |
1560 EXPECT_CALL(checkpoint, Call(2)); | 1839 EXPECT_CALL(checkpoint, Call(2)); |
1561 EXPECT_CALL(*mock_stream_, WriteFrames(EqualsFrames(expected2), _)) | 1840 EXPECT_CALL(*mock_stream_, WriteFrames(EqualsFrames(expected2), _)) |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1722 .WillOnce(Return(ERR_WS_PROTOCOL_ERROR)); | 2001 .WillOnce(Return(ERR_WS_PROTOCOL_ERROR)); |
1723 EXPECT_CALL(*mock_stream_, WriteFrames(EqualsFrames(expected), _)) | 2002 EXPECT_CALL(*mock_stream_, WriteFrames(EqualsFrames(expected), _)) |
1724 .WillOnce(Return(OK)); | 2003 .WillOnce(Return(OK)); |
1725 EXPECT_CALL(*mock_stream_, Close()); | 2004 EXPECT_CALL(*mock_stream_, Close()); |
1726 | 2005 |
1727 CreateChannelAndConnectSuccessfully(); | 2006 CreateChannelAndConnectSuccessfully(); |
1728 } | 2007 } |
1729 | 2008 |
1730 } // namespace | 2009 } // namespace |
1731 } // namespace net | 2010 } // namespace net |
OLD | NEW |