| 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/testing/DummyPageHolder.h" | 10 #include "core/testing/DummyPageHolder.h" |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 public: | 74 public: |
| 75 static MockWebSocketHandle* create() | 75 static MockWebSocketHandle* create() |
| 76 { | 76 { |
| 77 return new testing::StrictMock<MockWebSocketHandle>(); | 77 return new testing::StrictMock<MockWebSocketHandle>(); |
| 78 } | 78 } |
| 79 | 79 |
| 80 MockWebSocketHandle() { } | 80 MockWebSocketHandle() { } |
| 81 | 81 |
| 82 ~MockWebSocketHandle() override { } | 82 ~MockWebSocketHandle() override { } |
| 83 | 83 |
| 84 MOCK_METHOD4(connect, void(const WebURL&, const WebVector<WebString>&, const
WebSecurityOrigin&, WebSocketHandleClient*)); | 84 MOCK_METHOD5(connect, void(const WebURL&, const WebVector<WebString>&, const
WebSecurityOrigin&, const WebString&, WebSocketHandleClient*)); |
| 85 MOCK_METHOD4(send, void(bool, WebSocketHandle::MessageType, const char*, siz
e_t)); | 85 MOCK_METHOD4(send, void(bool, WebSocketHandle::MessageType, const char*, siz
e_t)); |
| 86 MOCK_METHOD1(flowControl, void(int64_t)); | 86 MOCK_METHOD1(flowControl, void(int64_t)); |
| 87 MOCK_METHOD2(close, void(unsigned short, const WebString&)); | 87 MOCK_METHOD2(close, void(unsigned short, const WebString&)); |
| 88 }; | 88 }; |
| 89 | 89 |
| 90 class DocumentWebSocketChannelTest : public ::testing::Test { | 90 class DocumentWebSocketChannelTest : public ::testing::Test { |
| 91 public: | 91 public: |
| 92 DocumentWebSocketChannelTest() | 92 DocumentWebSocketChannelTest() |
| 93 : m_pageHolder(DummyPageHolder::create()) | 93 : m_pageHolder(DummyPageHolder::create()) |
| 94 , m_channelClient(MockWebSocketChannelClient::create()) | 94 , m_channelClient(MockWebSocketChannelClient::create()) |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 | 126 |
| 127 void didConsumeBufferedAmount(unsigned long a) | 127 void didConsumeBufferedAmount(unsigned long a) |
| 128 { | 128 { |
| 129 m_sumOfConsumedBufferedAmount += a; | 129 m_sumOfConsumedBufferedAmount += a; |
| 130 } | 130 } |
| 131 | 131 |
| 132 void connect() | 132 void connect() |
| 133 { | 133 { |
| 134 { | 134 { |
| 135 InSequence s; | 135 InSequence s; |
| 136 EXPECT_CALL(*handle(), connect(WebURL(KURL(KURL(), "ws://localhost/"
)), _, _, handleClient())); | 136 EXPECT_CALL(*handle(), connect(WebURL(KURL(KURL(), "ws://localhost/"
)), _, _, _, handleClient())); |
| 137 EXPECT_CALL(*handle(), flowControl(65536)); | 137 EXPECT_CALL(*handle(), flowControl(65536)); |
| 138 EXPECT_CALL(*channelClient(), didConnect(String("a"), String("b"))); | 138 EXPECT_CALL(*channelClient(), didConnect(String("a"), String("b"))); |
| 139 } | 139 } |
| 140 EXPECT_TRUE(channel()->connect(KURL(KURL(), "ws://localhost/"), "x")); | 140 EXPECT_TRUE(channel()->connect(KURL(KURL(), "ws://localhost/"), "x")); |
| 141 handleClient()->didConnect(handle(), WebString("a"), WebString("b")); | 141 handleClient()->didConnect(handle(), WebString("a"), WebString("b")); |
| 142 ::testing::Mock::VerifyAndClearExpectations(this); | 142 ::testing::Mock::VerifyAndClearExpectations(this); |
| 143 } | 143 } |
| 144 | 144 |
| 145 std::unique_ptr<DummyPageHolder> m_pageHolder; | 145 std::unique_ptr<DummyPageHolder> m_pageHolder; |
| 146 Persistent<MockWebSocketChannelClient> m_channelClient; | 146 Persistent<MockWebSocketChannelClient> m_channelClient; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 157 ) | 157 ) |
| 158 { | 158 { |
| 159 return memcmp(arg, p, len) == 0; | 159 return memcmp(arg, p, len) == 0; |
| 160 } | 160 } |
| 161 | 161 |
| 162 TEST_F(DocumentWebSocketChannelTest, connectSuccess) | 162 TEST_F(DocumentWebSocketChannelTest, connectSuccess) |
| 163 { | 163 { |
| 164 Checkpoint checkpoint; | 164 Checkpoint checkpoint; |
| 165 { | 165 { |
| 166 InSequence s; | 166 InSequence s; |
| 167 EXPECT_CALL(*handle(), connect(WebURL(KURL(KURL(), "ws://localhost/")),
_, _, handleClient())); | 167 EXPECT_CALL(*handle(), connect(WebURL(KURL(KURL(), "ws://localhost/")),
_, _, _, handleClient())); |
| 168 EXPECT_CALL(*handle(), flowControl(65536)); | 168 EXPECT_CALL(*handle(), flowControl(65536)); |
| 169 EXPECT_CALL(checkpoint, Call(1)); | 169 EXPECT_CALL(checkpoint, Call(1)); |
| 170 EXPECT_CALL(*channelClient(), didConnect(String("a"), String("b"))); | 170 EXPECT_CALL(*channelClient(), didConnect(String("a"), String("b"))); |
| 171 } | 171 } |
| 172 | 172 |
| 173 EXPECT_TRUE(channel()->connect(KURL(KURL(), "ws://localhost/"), "x")); | 173 EXPECT_TRUE(channel()->connect(KURL(KURL(), "ws://localhost/"), "x")); |
| 174 checkpoint.Call(1); | 174 checkpoint.Call(1); |
| 175 handleClient()->didConnect(handle(), WebString("a"), WebString("b")); | 175 handleClient()->didConnect(handle(), WebString("a"), WebString("b")); |
| 176 } | 176 } |
| 177 | 177 |
| (...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 680 EXPECT_CALL(*channelClient(), didError()); | 680 EXPECT_CALL(*channelClient(), didError()); |
| 681 EXPECT_CALL(*channelClient(), didClose(WebSocketChannelClient::ClosingHa
ndshakeIncomplete, WebSocketChannel::CloseEventCodeAbnormalClosure, String())); | 681 EXPECT_CALL(*channelClient(), didClose(WebSocketChannelClient::ClosingHa
ndshakeIncomplete, WebSocketChannel::CloseEventCodeAbnormalClosure, String())); |
| 682 } | 682 } |
| 683 | 683 |
| 684 channel()->fail("fail message from WebSocket", ErrorMessageLevel, SourceLoca
tion::create(String(), 0, 0, nullptr)); | 684 channel()->fail("fail message from WebSocket", ErrorMessageLevel, SourceLoca
tion::create(String(), 0, 0, nullptr)); |
| 685 } | 685 } |
| 686 | 686 |
| 687 } // namespace | 687 } // namespace |
| 688 | 688 |
| 689 } // namespace blink | 689 } // namespace blink |
| OLD | NEW |