| 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 | 6 |
| 7 #include "modules/websockets/WebSocket.h" | 7 #include "modules/websockets/WebSocket.h" |
| 8 | 8 |
| 9 #include "bindings/v8/ExceptionState.h" | 9 #include "bindings/v8/ExceptionState.h" |
| 10 #include "bindings/v8/V8Binding.h" | 10 #include "bindings/v8/V8Binding.h" |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 virtual ~WebSocketTestBase() | 111 virtual ~WebSocketTestBase() |
| 112 { | 112 { |
| 113 if (!m_websocket) | 113 if (!m_websocket) |
| 114 return; | 114 return; |
| 115 // These statements are needed to clear WebSocket::m_channel to | 115 // These statements are needed to clear WebSocket::m_channel to |
| 116 // avoid ASSERTION failure on ~WebSocket. | 116 // avoid ASSERTION failure on ~WebSocket. |
| 117 ASSERT(m_websocket->channel()); | 117 ASSERT(m_websocket->channel()); |
| 118 ::testing::Mock::VerifyAndClear(m_websocket->channel()); | 118 ::testing::Mock::VerifyAndClear(m_websocket->channel()); |
| 119 EXPECT_CALL(channel(), disconnect()).Times(AnyNumber()); | 119 EXPECT_CALL(channel(), disconnect()).Times(AnyNumber()); |
| 120 | 120 |
| 121 m_websocket->didClose(0, WebSocketChannelClient::ClosingHandshakeIncompl
ete, 1006, ""); | 121 m_websocket->didClose(WebSocketChannelClient::ClosingHandshakeIncomplete
, 1006, ""); |
| 122 m_websocket.clear(); | 122 m_websocket.clear(); |
| 123 Heap::collectAllGarbage(); | 123 Heap::collectAllGarbage(); |
| 124 } | 124 } |
| 125 | 125 |
| 126 MockWebSocketChannel& channel() { return *m_websocket->channel(); } | 126 MockWebSocketChannel& channel() { return *m_websocket->channel(); } |
| 127 | 127 |
| 128 OwnPtr<DummyPageHolder> m_pageHolder; | 128 OwnPtr<DummyPageHolder> m_pageHolder; |
| 129 RefPtrWillBePersistent<WebSocketWithMockChannel> m_websocket; | 129 RefPtrWillBePersistent<WebSocketWithMockChannel> m_websocket; |
| 130 V8TestingScope m_executionScope; | 130 V8TestingScope m_executionScope; |
| 131 ExceptionState m_exceptionState; | 131 ExceptionState m_exceptionState; |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 { | 291 { |
| 292 InSequence s; | 292 InSequence s; |
| 293 EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String
())).WillOnce(Return(true)); | 293 EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String
())).WillOnce(Return(true)); |
| 294 EXPECT_CALL(channel(), disconnect()); | 294 EXPECT_CALL(channel(), disconnect()); |
| 295 } | 295 } |
| 296 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState
); | 296 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState
); |
| 297 | 297 |
| 298 EXPECT_FALSE(m_exceptionState.hadException()); | 298 EXPECT_FALSE(m_exceptionState.hadException()); |
| 299 EXPECT_EQ(WebSocket::CONNECTING, m_websocket->readyState()); | 299 EXPECT_EQ(WebSocket::CONNECTING, m_websocket->readyState()); |
| 300 | 300 |
| 301 m_websocket->didClose(0, WebSocketChannelClient::ClosingHandshakeIncomplete,
1006, ""); | 301 m_websocket->didClose(WebSocketChannelClient::ClosingHandshakeIncomplete, 10
06, ""); |
| 302 | 302 |
| 303 EXPECT_EQ(WebSocket::CLOSED, m_websocket->readyState()); | 303 EXPECT_EQ(WebSocket::CLOSED, m_websocket->readyState()); |
| 304 } | 304 } |
| 305 | 305 |
| 306 TEST_F(WebSocketTest, maximumReasonSize) | 306 TEST_F(WebSocketTest, maximumReasonSize) |
| 307 { | 307 { |
| 308 { | 308 { |
| 309 InSequence s; | 309 InSequence s; |
| 310 EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String
())).WillOnce(Return(true)); | 310 EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String
())).WillOnce(Return(true)); |
| 311 EXPECT_CALL(channel(), fail(_, _, _, _)); | 311 EXPECT_CALL(channel(), fail(_, _, _, _)); |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 470 | 470 |
| 471 EXPECT_FALSE(m_exceptionState.hadException()); | 471 EXPECT_FALSE(m_exceptionState.hadException()); |
| 472 EXPECT_EQ(WebSocket::CONNECTING, m_websocket->readyState()); | 472 EXPECT_EQ(WebSocket::CONNECTING, m_websocket->readyState()); |
| 473 | 473 |
| 474 m_websocket->didConnect(); | 474 m_websocket->didConnect(); |
| 475 EXPECT_EQ(WebSocket::OPEN, m_websocket->readyState()); | 475 EXPECT_EQ(WebSocket::OPEN, m_websocket->readyState()); |
| 476 m_websocket->close(m_exceptionState); | 476 m_websocket->close(m_exceptionState); |
| 477 EXPECT_FALSE(m_exceptionState.hadException()); | 477 EXPECT_FALSE(m_exceptionState.hadException()); |
| 478 EXPECT_EQ(WebSocket::CLOSING, m_websocket->readyState()); | 478 EXPECT_EQ(WebSocket::CLOSING, m_websocket->readyState()); |
| 479 | 479 |
| 480 m_websocket->didClose(0, WebSocketChannelClient::ClosingHandshakeComplete, 1
000, String()); | 480 m_websocket->didClose(WebSocketChannelClient::ClosingHandshakeComplete, 1000
, String()); |
| 481 EXPECT_EQ(WebSocket::CLOSED, m_websocket->readyState()); | 481 EXPECT_EQ(WebSocket::CLOSED, m_websocket->readyState()); |
| 482 m_websocket->close(m_exceptionState); | 482 m_websocket->close(m_exceptionState); |
| 483 | 483 |
| 484 EXPECT_FALSE(m_exceptionState.hadException()); | 484 EXPECT_FALSE(m_exceptionState.hadException()); |
| 485 EXPECT_EQ(WebSocket::CLOSED, m_websocket->readyState()); | 485 EXPECT_EQ(WebSocket::CLOSED, m_websocket->readyState()); |
| 486 } | 486 } |
| 487 | 487 |
| 488 TEST_F(WebSocketTest, sendStringWhenConnecting) | 488 TEST_F(WebSocketTest, sendStringWhenConnecting) |
| 489 { | 489 { |
| 490 { | 490 { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 530 { | 530 { |
| 531 InSequence s; | 531 InSequence s; |
| 532 EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String
())).WillOnce(Return(true)); | 532 EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String
())).WillOnce(Return(true)); |
| 533 EXPECT_CALL(channel(), disconnect()); | 533 EXPECT_CALL(channel(), disconnect()); |
| 534 EXPECT_CALL(checkpoint, Call(1)); | 534 EXPECT_CALL(checkpoint, Call(1)); |
| 535 } | 535 } |
| 536 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState
); | 536 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState
); |
| 537 | 537 |
| 538 EXPECT_FALSE(m_exceptionState.hadException()); | 538 EXPECT_FALSE(m_exceptionState.hadException()); |
| 539 | 539 |
| 540 m_websocket->didClose(0, WebSocketChannelClient::ClosingHandshakeIncomplete,
1006, ""); | 540 m_websocket->didClose(WebSocketChannelClient::ClosingHandshakeIncomplete, 10
06, ""); |
| 541 checkpoint.Call(1); | 541 checkpoint.Call(1); |
| 542 | 542 |
| 543 m_websocket->send("hello", m_exceptionState); | 543 m_websocket->send("hello", m_exceptionState); |
| 544 | 544 |
| 545 EXPECT_FALSE(m_exceptionState.hadException()); | 545 EXPECT_FALSE(m_exceptionState.hadException()); |
| 546 EXPECT_EQ(WebSocket::CLOSED, m_websocket->readyState()); | 546 EXPECT_EQ(WebSocket::CLOSED, m_websocket->readyState()); |
| 547 } | 547 } |
| 548 | 548 |
| 549 TEST_F(WebSocketTest, sendStringSuccess) | 549 TEST_F(WebSocketTest, sendStringSuccess) |
| 550 { | 550 { |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 655 { | 655 { |
| 656 InSequence s; | 656 InSequence s; |
| 657 EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String
())).WillOnce(Return(true)); | 657 EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String
())).WillOnce(Return(true)); |
| 658 EXPECT_CALL(channel(), disconnect()); | 658 EXPECT_CALL(channel(), disconnect()); |
| 659 EXPECT_CALL(checkpoint, Call(1)); | 659 EXPECT_CALL(checkpoint, Call(1)); |
| 660 } | 660 } |
| 661 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState
); | 661 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState
); |
| 662 | 662 |
| 663 EXPECT_FALSE(m_exceptionState.hadException()); | 663 EXPECT_FALSE(m_exceptionState.hadException()); |
| 664 | 664 |
| 665 m_websocket->didClose(0, WebSocketChannelClient::ClosingHandshakeIncomplete,
1006, ""); | 665 m_websocket->didClose(WebSocketChannelClient::ClosingHandshakeIncomplete, 10
06, ""); |
| 666 checkpoint.Call(1); | 666 checkpoint.Call(1); |
| 667 | 667 |
| 668 m_websocket->send(view->buffer().get(), m_exceptionState); | 668 m_websocket->send(view->buffer().get(), m_exceptionState); |
| 669 | 669 |
| 670 EXPECT_FALSE(m_exceptionState.hadException()); | 670 EXPECT_FALSE(m_exceptionState.hadException()); |
| 671 EXPECT_EQ(WebSocket::CLOSED, m_websocket->readyState()); | 671 EXPECT_EQ(WebSocket::CLOSED, m_websocket->readyState()); |
| 672 } | 672 } |
| 673 | 673 |
| 674 TEST_F(WebSocketTest, sendArrayBufferSuccess) | 674 TEST_F(WebSocketTest, sendArrayBufferSuccess) |
| 675 { | 675 { |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 811 EXPECT_EQ(InvalidAccessError, m_exceptionState.code()); | 811 EXPECT_EQ(InvalidAccessError, m_exceptionState.code()); |
| 812 EXPECT_EQ(String::format("The code must be either 1000, or between 3000 and
4999. %d is neither.", GetParam()), m_exceptionState.message()); | 812 EXPECT_EQ(String::format("The code must be either 1000, or between 3000 and
4999. %d is neither.", GetParam()), m_exceptionState.message()); |
| 813 EXPECT_EQ(WebSocket::CONNECTING, m_websocket->readyState()); | 813 EXPECT_EQ(WebSocket::CONNECTING, m_websocket->readyState()); |
| 814 } | 814 } |
| 815 | 815 |
| 816 INSTANTIATE_TEST_CASE_P(WebSocketInvalidClosingCode, WebSocketInvalidClosingCode
Test, ::testing::Values(0, 1, 998, 999, 1001, 2999, 5000, 9999, 65535)); | 816 INSTANTIATE_TEST_CASE_P(WebSocketInvalidClosingCode, WebSocketInvalidClosingCode
Test, ::testing::Values(0, 1, 998, 999, 1001, 2999, 5000, 9999, 65535)); |
| 817 | 817 |
| 818 } // namespace | 818 } // namespace |
| 819 | 819 |
| 820 } // namespace WebCore | 820 } // namespace WebCore |
| OLD | NEW |