| 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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 virtual ~WebSocketTestBase() | 109 virtual ~WebSocketTestBase() |
| 110 { | 110 { |
| 111 if (!m_websocket) | 111 if (!m_websocket) |
| 112 return; | 112 return; |
| 113 // These statements are needed to clear WebSocket::m_channel to | 113 // These statements are needed to clear WebSocket::m_channel to |
| 114 // avoid ASSERTION failure on ~WebSocket. | 114 // avoid ASSERTION failure on ~WebSocket. |
| 115 ASSERT(m_websocket->channel()); | 115 ASSERT(m_websocket->channel()); |
| 116 ::testing::Mock::VerifyAndClear(m_websocket->channel()); | 116 ::testing::Mock::VerifyAndClear(m_websocket->channel()); |
| 117 EXPECT_CALL(channel(), disconnect()).Times(AnyNumber()); | 117 EXPECT_CALL(channel(), disconnect()).Times(AnyNumber()); |
| 118 | 118 |
| 119 m_websocket->didClose(0, WebSocketChannelClient::ClosingHandshakeIncompl
ete, 1006, ""); | 119 m_websocket->didClose(WebSocketChannelClient::ClosingHandshakeIncomplete
, 1006, ""); |
| 120 m_websocket.clear(); | 120 m_websocket.clear(); |
| 121 Heap::collectAllGarbage(); | 121 Heap::collectAllGarbage(); |
| 122 } | 122 } |
| 123 | 123 |
| 124 MockWebSocketChannel& channel() { return *m_websocket->channel(); } | 124 MockWebSocketChannel& channel() { return *m_websocket->channel(); } |
| 125 | 125 |
| 126 OwnPtr<DummyPageHolder> m_pageHolder; | 126 OwnPtr<DummyPageHolder> m_pageHolder; |
| 127 RefPtrWillBePersistent<WebSocketWithMockChannel> m_websocket; | 127 RefPtrWillBePersistent<WebSocketWithMockChannel> m_websocket; |
| 128 V8TestingScope m_executionScope; | 128 V8TestingScope m_executionScope; |
| 129 ExceptionState m_exceptionState; | 129 ExceptionState m_exceptionState; |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 { | 287 { |
| 288 InSequence s; | 288 InSequence s; |
| 289 EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String
())).WillOnce(Return(true)); | 289 EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String
())).WillOnce(Return(true)); |
| 290 EXPECT_CALL(channel(), disconnect()); | 290 EXPECT_CALL(channel(), disconnect()); |
| 291 } | 291 } |
| 292 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState
); | 292 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState
); |
| 293 | 293 |
| 294 EXPECT_FALSE(m_exceptionState.hadException()); | 294 EXPECT_FALSE(m_exceptionState.hadException()); |
| 295 EXPECT_EQ(WebSocket::CONNECTING, m_websocket->readyState()); | 295 EXPECT_EQ(WebSocket::CONNECTING, m_websocket->readyState()); |
| 296 | 296 |
| 297 m_websocket->didClose(0, WebSocketChannelClient::ClosingHandshakeIncomplete,
1006, ""); | 297 m_websocket->didClose(WebSocketChannelClient::ClosingHandshakeIncomplete, 10
06, ""); |
| 298 | 298 |
| 299 EXPECT_EQ(WebSocket::CLOSED, m_websocket->readyState()); | 299 EXPECT_EQ(WebSocket::CLOSED, m_websocket->readyState()); |
| 300 } | 300 } |
| 301 | 301 |
| 302 TEST_F(WebSocketTest, maximumReasonSize) | 302 TEST_F(WebSocketTest, maximumReasonSize) |
| 303 { | 303 { |
| 304 { | 304 { |
| 305 InSequence s; | 305 InSequence s; |
| 306 EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String
())).WillOnce(Return(true)); | 306 EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String
())).WillOnce(Return(true)); |
| 307 EXPECT_CALL(channel(), fail(_, _, _, _)); | 307 EXPECT_CALL(channel(), fail(_, _, _, _)); |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 | 456 |
| 457 EXPECT_FALSE(m_exceptionState.hadException()); | 457 EXPECT_FALSE(m_exceptionState.hadException()); |
| 458 EXPECT_EQ(WebSocket::CONNECTING, m_websocket->readyState()); | 458 EXPECT_EQ(WebSocket::CONNECTING, m_websocket->readyState()); |
| 459 | 459 |
| 460 m_websocket->didConnect("", ""); | 460 m_websocket->didConnect("", ""); |
| 461 EXPECT_EQ(WebSocket::OPEN, m_websocket->readyState()); | 461 EXPECT_EQ(WebSocket::OPEN, m_websocket->readyState()); |
| 462 m_websocket->close(m_exceptionState); | 462 m_websocket->close(m_exceptionState); |
| 463 EXPECT_FALSE(m_exceptionState.hadException()); | 463 EXPECT_FALSE(m_exceptionState.hadException()); |
| 464 EXPECT_EQ(WebSocket::CLOSING, m_websocket->readyState()); | 464 EXPECT_EQ(WebSocket::CLOSING, m_websocket->readyState()); |
| 465 | 465 |
| 466 m_websocket->didClose(0, WebSocketChannelClient::ClosingHandshakeComplete, 1
000, String()); | 466 m_websocket->didClose(WebSocketChannelClient::ClosingHandshakeComplete, 1000
, String()); |
| 467 EXPECT_EQ(WebSocket::CLOSED, m_websocket->readyState()); | 467 EXPECT_EQ(WebSocket::CLOSED, m_websocket->readyState()); |
| 468 m_websocket->close(m_exceptionState); | 468 m_websocket->close(m_exceptionState); |
| 469 | 469 |
| 470 EXPECT_FALSE(m_exceptionState.hadException()); | 470 EXPECT_FALSE(m_exceptionState.hadException()); |
| 471 EXPECT_EQ(WebSocket::CLOSED, m_websocket->readyState()); | 471 EXPECT_EQ(WebSocket::CLOSED, m_websocket->readyState()); |
| 472 } | 472 } |
| 473 | 473 |
| 474 TEST_F(WebSocketTest, sendStringWhenConnecting) | 474 TEST_F(WebSocketTest, sendStringWhenConnecting) |
| 475 { | 475 { |
| 476 { | 476 { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 516 { | 516 { |
| 517 InSequence s; | 517 InSequence s; |
| 518 EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String
())).WillOnce(Return(true)); | 518 EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String
())).WillOnce(Return(true)); |
| 519 EXPECT_CALL(channel(), disconnect()); | 519 EXPECT_CALL(channel(), disconnect()); |
| 520 EXPECT_CALL(checkpoint, Call(1)); | 520 EXPECT_CALL(checkpoint, Call(1)); |
| 521 } | 521 } |
| 522 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState
); | 522 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState
); |
| 523 | 523 |
| 524 EXPECT_FALSE(m_exceptionState.hadException()); | 524 EXPECT_FALSE(m_exceptionState.hadException()); |
| 525 | 525 |
| 526 m_websocket->didClose(0, WebSocketChannelClient::ClosingHandshakeIncomplete,
1006, ""); | 526 m_websocket->didClose(WebSocketChannelClient::ClosingHandshakeIncomplete, 10
06, ""); |
| 527 checkpoint.Call(1); | 527 checkpoint.Call(1); |
| 528 | 528 |
| 529 m_websocket->send("hello", m_exceptionState); | 529 m_websocket->send("hello", m_exceptionState); |
| 530 | 530 |
| 531 EXPECT_FALSE(m_exceptionState.hadException()); | 531 EXPECT_FALSE(m_exceptionState.hadException()); |
| 532 EXPECT_EQ(WebSocket::CLOSED, m_websocket->readyState()); | 532 EXPECT_EQ(WebSocket::CLOSED, m_websocket->readyState()); |
| 533 } | 533 } |
| 534 | 534 |
| 535 TEST_F(WebSocketTest, sendStringSuccess) | 535 TEST_F(WebSocketTest, sendStringSuccess) |
| 536 { | 536 { |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 635 { | 635 { |
| 636 InSequence s; | 636 InSequence s; |
| 637 EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String
())).WillOnce(Return(true)); | 637 EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String
())).WillOnce(Return(true)); |
| 638 EXPECT_CALL(channel(), disconnect()); | 638 EXPECT_CALL(channel(), disconnect()); |
| 639 EXPECT_CALL(checkpoint, Call(1)); | 639 EXPECT_CALL(checkpoint, Call(1)); |
| 640 } | 640 } |
| 641 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState
); | 641 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState
); |
| 642 | 642 |
| 643 EXPECT_FALSE(m_exceptionState.hadException()); | 643 EXPECT_FALSE(m_exceptionState.hadException()); |
| 644 | 644 |
| 645 m_websocket->didClose(0, WebSocketChannelClient::ClosingHandshakeIncomplete,
1006, ""); | 645 m_websocket->didClose(WebSocketChannelClient::ClosingHandshakeIncomplete, 10
06, ""); |
| 646 checkpoint.Call(1); | 646 checkpoint.Call(1); |
| 647 | 647 |
| 648 m_websocket->send(view->buffer().get(), m_exceptionState); | 648 m_websocket->send(view->buffer().get(), m_exceptionState); |
| 649 | 649 |
| 650 EXPECT_FALSE(m_exceptionState.hadException()); | 650 EXPECT_FALSE(m_exceptionState.hadException()); |
| 651 EXPECT_EQ(WebSocket::CLOSED, m_websocket->readyState()); | 651 EXPECT_EQ(WebSocket::CLOSED, m_websocket->readyState()); |
| 652 } | 652 } |
| 653 | 653 |
| 654 TEST_F(WebSocketTest, sendArrayBufferSuccess) | 654 TEST_F(WebSocketTest, sendArrayBufferSuccess) |
| 655 { | 655 { |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 785 EXPECT_EQ(InvalidAccessError, m_exceptionState.code()); | 785 EXPECT_EQ(InvalidAccessError, m_exceptionState.code()); |
| 786 EXPECT_EQ(String::format("The code must be either 1000, or between 3000 and
4999. %d is neither.", GetParam()), m_exceptionState.message()); | 786 EXPECT_EQ(String::format("The code must be either 1000, or between 3000 and
4999. %d is neither.", GetParam()), m_exceptionState.message()); |
| 787 EXPECT_EQ(WebSocket::CONNECTING, m_websocket->readyState()); | 787 EXPECT_EQ(WebSocket::CONNECTING, m_websocket->readyState()); |
| 788 } | 788 } |
| 789 | 789 |
| 790 INSTANTIATE_TEST_CASE_P(WebSocketInvalidClosingCode, WebSocketInvalidClosingCode
Test, ::testing::Values(0, 1, 998, 999, 1001, 2999, 5000, 9999, 65535)); | 790 INSTANTIATE_TEST_CASE_P(WebSocketInvalidClosingCode, WebSocketInvalidClosingCode
Test, ::testing::Values(0, 1, 998, 999, 1001, 2999, 5000, 9999, 65535)); |
| 791 | 791 |
| 792 } // namespace | 792 } // namespace |
| 793 | 793 |
| 794 } // namespace WebCore | 794 } // namespace WebCore |
| OLD | NEW |