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/DOMWebSocket.h" | 5 #include "modules/websockets/DOMWebSocket.h" |
6 | 6 |
7 #include "bindings/core/v8/ExceptionState.h" | 7 #include "bindings/core/v8/ExceptionState.h" |
8 #include "bindings/core/v8/V8Binding.h" | 8 #include "bindings/core/v8/V8Binding.h" |
9 #include "bindings/core/v8/V8BindingForTesting.h" | 9 #include "bindings/core/v8/V8BindingForTesting.h" |
10 #include "core/dom/DOMTypedArray.h" | 10 #include "core/dom/DOMTypedArray.h" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 { | 55 { |
56 sendTextAsCharVectorMock(vector.get()); | 56 sendTextAsCharVectorMock(vector.get()); |
57 } | 57 } |
58 MOCK_METHOD1(sendBinaryAsCharVectorMock, void(Vector<char>*)); | 58 MOCK_METHOD1(sendBinaryAsCharVectorMock, void(Vector<char>*)); |
59 void sendBinaryAsCharVector(PassOwnPtr<Vector<char>> vector) | 59 void sendBinaryAsCharVector(PassOwnPtr<Vector<char>> vector) |
60 { | 60 { |
61 sendBinaryAsCharVectorMock(vector.get()); | 61 sendBinaryAsCharVectorMock(vector.get()); |
62 } | 62 } |
63 MOCK_CONST_METHOD0(bufferedAmount, unsigned()); | 63 MOCK_CONST_METHOD0(bufferedAmount, unsigned()); |
64 MOCK_METHOD2(close, void(int, const String&)); | 64 MOCK_METHOD2(close, void(int, const String&)); |
65 MOCK_METHOD4(fail, void(const String&, MessageLevel, const String&, unsigned
)); | 65 MOCK_METHOD3(failMock, void(const String&, MessageLevel, SourceLocation*)); |
| 66 void fail(const String& reason, MessageLevel level, PassOwnPtr<SourceLocatio
n> location) |
| 67 { |
| 68 failMock(reason, level, location.get()); |
| 69 } |
66 MOCK_METHOD0(disconnect, void()); | 70 MOCK_METHOD0(disconnect, void()); |
67 | 71 |
68 MockWebSocketChannel() | 72 MockWebSocketChannel() |
69 { | 73 { |
70 } | 74 } |
71 }; | 75 }; |
72 | 76 |
73 class DOMWebSocketWithMockChannel final : public DOMWebSocket { | 77 class DOMWebSocketWithMockChannel final : public DOMWebSocket { |
74 public: | 78 public: |
75 static DOMWebSocketWithMockChannel* create(ExecutionContext* context) | 79 static DOMWebSocketWithMockChannel* create(ExecutionContext* context) |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 m_websocket->didClose(WebSocketChannelClient::ClosingHandshakeIncomplete, 10
06, ""); | 332 m_websocket->didClose(WebSocketChannelClient::ClosingHandshakeIncomplete, 10
06, ""); |
329 | 333 |
330 EXPECT_EQ(DOMWebSocket::CLOSED, m_websocket->readyState()); | 334 EXPECT_EQ(DOMWebSocket::CLOSED, m_websocket->readyState()); |
331 } | 335 } |
332 | 336 |
333 TEST_F(DOMWebSocketTest, maximumReasonSize) | 337 TEST_F(DOMWebSocketTest, maximumReasonSize) |
334 { | 338 { |
335 { | 339 { |
336 InSequence s; | 340 InSequence s; |
337 EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String
())).WillOnce(Return(true)); | 341 EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String
())).WillOnce(Return(true)); |
338 EXPECT_CALL(channel(), fail(_, _, _, _)); | 342 EXPECT_CALL(channel(), failMock(_, _, _)); |
339 } | 343 } |
340 String reason; | 344 String reason; |
341 for (size_t i = 0; i < 123; ++i) | 345 for (size_t i = 0; i < 123; ++i) |
342 reason.append("a"); | 346 reason.append("a"); |
343 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState
); | 347 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState
); |
344 | 348 |
345 EXPECT_FALSE(m_exceptionState.hadException()); | 349 EXPECT_FALSE(m_exceptionState.hadException()); |
346 EXPECT_EQ(DOMWebSocket::CONNECTING, m_websocket->readyState()); | 350 EXPECT_EQ(DOMWebSocket::CONNECTING, m_websocket->readyState()); |
347 | 351 |
348 m_websocket->close(1000, reason, m_exceptionState); | 352 m_websocket->close(1000, reason, m_exceptionState); |
(...skipping 22 matching lines...) Expand all Loading... |
371 EXPECT_EQ(SyntaxError, m_exceptionState.code()); | 375 EXPECT_EQ(SyntaxError, m_exceptionState.code()); |
372 EXPECT_EQ("The message must not be greater than 123 bytes.", m_exceptionStat
e.message()); | 376 EXPECT_EQ("The message must not be greater than 123 bytes.", m_exceptionStat
e.message()); |
373 EXPECT_EQ(DOMWebSocket::CONNECTING, m_websocket->readyState()); | 377 EXPECT_EQ(DOMWebSocket::CONNECTING, m_websocket->readyState()); |
374 } | 378 } |
375 | 379 |
376 TEST_F(DOMWebSocketTest, closeWhenConnecting) | 380 TEST_F(DOMWebSocketTest, closeWhenConnecting) |
377 { | 381 { |
378 { | 382 { |
379 InSequence s; | 383 InSequence s; |
380 EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String
())).WillOnce(Return(true)); | 384 EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String
())).WillOnce(Return(true)); |
381 EXPECT_CALL(channel(), fail(String("WebSocket is closed before the conne
ction is established."), WarningMessageLevel, String(), 0)); | 385 EXPECT_CALL(channel(), failMock(String("WebSocket is closed before the c
onnection is established."), WarningMessageLevel, _)); |
382 } | 386 } |
383 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState
); | 387 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState
); |
384 | 388 |
385 EXPECT_FALSE(m_exceptionState.hadException()); | 389 EXPECT_FALSE(m_exceptionState.hadException()); |
386 EXPECT_EQ(DOMWebSocket::CONNECTING, m_websocket->readyState()); | 390 EXPECT_EQ(DOMWebSocket::CONNECTING, m_websocket->readyState()); |
387 | 391 |
388 m_websocket->close(1000, "bye", m_exceptionState); | 392 m_websocket->close(1000, "bye", m_exceptionState); |
389 | 393 |
390 EXPECT_FALSE(m_exceptionState.hadException()); | 394 EXPECT_FALSE(m_exceptionState.hadException()); |
391 EXPECT_EQ(DOMWebSocket::CLOSING, m_websocket->readyState()); | 395 EXPECT_EQ(DOMWebSocket::CLOSING, m_websocket->readyState()); |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
519 EXPECT_EQ("Still in CONNECTING state.", m_exceptionState.message()); | 523 EXPECT_EQ("Still in CONNECTING state.", m_exceptionState.message()); |
520 EXPECT_EQ(DOMWebSocket::CONNECTING, m_websocket->readyState()); | 524 EXPECT_EQ(DOMWebSocket::CONNECTING, m_websocket->readyState()); |
521 } | 525 } |
522 | 526 |
523 TEST_F(DOMWebSocketTest, sendStringWhenClosing) | 527 TEST_F(DOMWebSocketTest, sendStringWhenClosing) |
524 { | 528 { |
525 Checkpoint checkpoint; | 529 Checkpoint checkpoint; |
526 { | 530 { |
527 InSequence s; | 531 InSequence s; |
528 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)); |
529 EXPECT_CALL(channel(), fail(_, _, _, _)); | 533 EXPECT_CALL(channel(), failMock(_, _, _)); |
530 } | 534 } |
531 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState
); | 535 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState
); |
532 | 536 |
533 EXPECT_FALSE(m_exceptionState.hadException()); | 537 EXPECT_FALSE(m_exceptionState.hadException()); |
534 | 538 |
535 m_websocket->close(m_exceptionState); | 539 m_websocket->close(m_exceptionState); |
536 EXPECT_FALSE(m_exceptionState.hadException()); | 540 EXPECT_FALSE(m_exceptionState.hadException()); |
537 | 541 |
538 m_websocket->send("hello", m_exceptionState); | 542 m_websocket->send("hello", m_exceptionState); |
539 | 543 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
622 EXPECT_EQ("Still in CONNECTING state.", m_exceptionState.message()); | 626 EXPECT_EQ("Still in CONNECTING state.", m_exceptionState.message()); |
623 EXPECT_EQ(DOMWebSocket::CONNECTING, m_websocket->readyState()); | 627 EXPECT_EQ(DOMWebSocket::CONNECTING, m_websocket->readyState()); |
624 } | 628 } |
625 | 629 |
626 TEST_F(DOMWebSocketTest, sendArrayBufferWhenClosing) | 630 TEST_F(DOMWebSocketTest, sendArrayBufferWhenClosing) |
627 { | 631 { |
628 DOMArrayBufferView* view = DOMUint8Array::create(8); | 632 DOMArrayBufferView* view = DOMUint8Array::create(8); |
629 { | 633 { |
630 InSequence s; | 634 InSequence s; |
631 EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String
())).WillOnce(Return(true)); | 635 EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String
())).WillOnce(Return(true)); |
632 EXPECT_CALL(channel(), fail(_, _, _, _)); | 636 EXPECT_CALL(channel(), failMock(_, _, _)); |
633 } | 637 } |
634 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState
); | 638 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState
); |
635 | 639 |
636 EXPECT_FALSE(m_exceptionState.hadException()); | 640 EXPECT_FALSE(m_exceptionState.hadException()); |
637 | 641 |
638 m_websocket->close(m_exceptionState); | 642 m_websocket->close(m_exceptionState); |
639 EXPECT_FALSE(m_exceptionState.hadException()); | 643 EXPECT_FALSE(m_exceptionState.hadException()); |
640 | 644 |
641 m_websocket->send(view->buffer(), m_exceptionState); | 645 m_websocket->send(view->buffer(), m_exceptionState); |
642 | 646 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
710 | 714 |
711 class DOMWebSocketValidClosingTest : public DOMWebSocketTestBase, public ::testi
ng::TestWithParam<unsigned short> { | 715 class DOMWebSocketValidClosingTest : public DOMWebSocketTestBase, public ::testi
ng::TestWithParam<unsigned short> { |
712 public: | 716 public: |
713 }; | 717 }; |
714 | 718 |
715 TEST_P(DOMWebSocketValidClosingTest, test) | 719 TEST_P(DOMWebSocketValidClosingTest, test) |
716 { | 720 { |
717 { | 721 { |
718 InSequence s; | 722 InSequence s; |
719 EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String
())).WillOnce(Return(true)); | 723 EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String
())).WillOnce(Return(true)); |
720 EXPECT_CALL(channel(), fail(_, _, _, _)); | 724 EXPECT_CALL(channel(), failMock(_, _, _)); |
721 } | 725 } |
722 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState
); | 726 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState
); |
723 | 727 |
724 EXPECT_FALSE(m_exceptionState.hadException()); | 728 EXPECT_FALSE(m_exceptionState.hadException()); |
725 EXPECT_EQ(DOMWebSocket::CONNECTING, m_websocket->readyState()); | 729 EXPECT_EQ(DOMWebSocket::CONNECTING, m_websocket->readyState()); |
726 | 730 |
727 m_websocket->close(GetParam(), "bye", m_exceptionState); | 731 m_websocket->close(GetParam(), "bye", m_exceptionState); |
728 | 732 |
729 EXPECT_FALSE(m_exceptionState.hadException()); | 733 EXPECT_FALSE(m_exceptionState.hadException()); |
730 EXPECT_EQ(DOMWebSocket::CLOSING, m_websocket->readyState()); | 734 EXPECT_EQ(DOMWebSocket::CLOSING, m_websocket->readyState()); |
(...skipping 22 matching lines...) Expand all Loading... |
753 EXPECT_EQ(InvalidAccessError, m_exceptionState.code()); | 757 EXPECT_EQ(InvalidAccessError, m_exceptionState.code()); |
754 EXPECT_EQ(String::format("The code must be either 1000, or between 3000 and
4999. %d is neither.", GetParam()), m_exceptionState.message()); | 758 EXPECT_EQ(String::format("The code must be either 1000, or between 3000 and
4999. %d is neither.", GetParam()), m_exceptionState.message()); |
755 EXPECT_EQ(DOMWebSocket::CONNECTING, m_websocket->readyState()); | 759 EXPECT_EQ(DOMWebSocket::CONNECTING, m_websocket->readyState()); |
756 } | 760 } |
757 | 761 |
758 INSTANTIATE_TEST_CASE_P(DOMWebSocketInvalidClosingCode, DOMWebSocketInvalidClosi
ngCodeTest, ::testing::Values(0, 1, 998, 999, 1001, 2999, 5000, 9999, 65535)); | 762 INSTANTIATE_TEST_CASE_P(DOMWebSocketInvalidClosingCode, DOMWebSocketInvalidClosi
ngCodeTest, ::testing::Values(0, 1, 998, 999, 1001, 2999, 5000, 9999, 65535)); |
759 | 763 |
760 } // namespace | 764 } // namespace |
761 | 765 |
762 } // namespace blink | 766 } // namespace blink |
OLD | NEW |