Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(422)

Side by Side Diff: third_party/WebKit/Source/modules/websockets/DOMWebSocketTest.cpp

Issue 1414553002: Fix out-of-memory crashes related to ArrayBuffer allocation Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase and applied senorblanco+haraken feedbac Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include "modules/websockets/DOMWebSocket.h" 6 #include "modules/websockets/DOMWebSocket.h"
7 7
8 #include "bindings/core/v8/ExceptionState.h" 8 #include "bindings/core/v8/ExceptionState.h"
9 #include "bindings/core/v8/V8Binding.h" 9 #include "bindings/core/v8/V8Binding.h"
10 #include "bindings/core/v8/V8BindingForTesting.h" 10 #include "bindings/core/v8/V8BindingForTesting.h"
(...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after
592 0x0000 592 0x0000
593 }; 593 };
594 m_websocket->send(nonLatin1String, m_exceptionState); 594 m_websocket->send(nonLatin1String, m_exceptionState);
595 595
596 EXPECT_FALSE(m_exceptionState.hadException()); 596 EXPECT_FALSE(m_exceptionState.hadException());
597 EXPECT_EQ(DOMWebSocket::OPEN, m_websocket->readyState()); 597 EXPECT_EQ(DOMWebSocket::OPEN, m_websocket->readyState());
598 } 598 }
599 599
600 TEST_F(DOMWebSocketTest, sendArrayBufferWhenConnecting) 600 TEST_F(DOMWebSocketTest, sendArrayBufferWhenConnecting)
601 { 601 {
602 RefPtr<DOMArrayBufferView> view = DOMUint8Array::create(8); 602 RefPtr<DOMArrayBufferView> view = DOMUint8Array::deprecatedCreateOrCrash(8);
603 { 603 {
604 InSequence s; 604 InSequence s;
605 EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String ())).WillOnce(Return(true)); 605 EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String ())).WillOnce(Return(true));
606 } 606 }
607 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState ); 607 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState );
608 608
609 EXPECT_FALSE(m_exceptionState.hadException()); 609 EXPECT_FALSE(m_exceptionState.hadException());
610 610
611 m_websocket->send(view->buffer().get(), m_exceptionState); 611 RefPtr<DOMArrayBuffer> buffer = view->bufferOrNull();
612 RELEASE_ASSERT(buffer); // Out of memory?
613 m_websocket->send(buffer.get(), m_exceptionState);
612 614
613 EXPECT_TRUE(m_exceptionState.hadException()); 615 EXPECT_TRUE(m_exceptionState.hadException());
614 EXPECT_EQ(InvalidStateError, m_exceptionState.code()); 616 EXPECT_EQ(InvalidStateError, m_exceptionState.code());
615 EXPECT_EQ("Still in CONNECTING state.", m_exceptionState.message()); 617 EXPECT_EQ("Still in CONNECTING state.", m_exceptionState.message());
616 EXPECT_EQ(DOMWebSocket::CONNECTING, m_websocket->readyState()); 618 EXPECT_EQ(DOMWebSocket::CONNECTING, m_websocket->readyState());
617 } 619 }
618 620
619 TEST_F(DOMWebSocketTest, sendArrayBufferWhenClosing) 621 TEST_F(DOMWebSocketTest, sendArrayBufferWhenClosing)
620 { 622 {
621 RefPtr<DOMArrayBufferView> view = DOMUint8Array::create(8); 623 RefPtr<DOMArrayBufferView> view = DOMUint8Array::deprecatedCreateOrCrash(8);
622 { 624 {
623 InSequence s; 625 InSequence s;
624 EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String ())).WillOnce(Return(true)); 626 EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String ())).WillOnce(Return(true));
625 EXPECT_CALL(channel(), fail(_, _, _, _)); 627 EXPECT_CALL(channel(), fail(_, _, _, _));
626 } 628 }
627 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState ); 629 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState );
628 630
629 EXPECT_FALSE(m_exceptionState.hadException()); 631 EXPECT_FALSE(m_exceptionState.hadException());
630 632
631 m_websocket->close(m_exceptionState); 633 m_websocket->close(m_exceptionState);
632 EXPECT_FALSE(m_exceptionState.hadException()); 634 EXPECT_FALSE(m_exceptionState.hadException());
633 635
634 m_websocket->send(view->buffer().get(), m_exceptionState); 636 RefPtr<DOMArrayBuffer> buffer = view->bufferOrNull();
637 RELEASE_ASSERT(buffer); // Out of memory?
638 m_websocket->send(buffer.get(), m_exceptionState);
635 639
636 EXPECT_FALSE(m_exceptionState.hadException()); 640 EXPECT_FALSE(m_exceptionState.hadException());
637 EXPECT_EQ(DOMWebSocket::CLOSING, m_websocket->readyState()); 641 EXPECT_EQ(DOMWebSocket::CLOSING, m_websocket->readyState());
638 } 642 }
639 643
640 TEST_F(DOMWebSocketTest, sendArrayBufferWhenClosed) 644 TEST_F(DOMWebSocketTest, sendArrayBufferWhenClosed)
641 { 645 {
642 Checkpoint checkpoint; 646 Checkpoint checkpoint;
643 RefPtr<DOMArrayBufferView> view = DOMUint8Array::create(8); 647 RefPtr<DOMArrayBufferView> view = DOMUint8Array::deprecatedCreateOrCrash(8);
644 { 648 {
645 InSequence s; 649 InSequence s;
646 EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String ())).WillOnce(Return(true)); 650 EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String ())).WillOnce(Return(true));
647 EXPECT_CALL(channel(), disconnect()); 651 EXPECT_CALL(channel(), disconnect());
648 EXPECT_CALL(checkpoint, Call(1)); 652 EXPECT_CALL(checkpoint, Call(1));
649 } 653 }
650 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState ); 654 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState );
651 655
652 EXPECT_FALSE(m_exceptionState.hadException()); 656 EXPECT_FALSE(m_exceptionState.hadException());
653 657
654 m_websocket->didClose(WebSocketChannelClient::ClosingHandshakeIncomplete, 10 06, ""); 658 m_websocket->didClose(WebSocketChannelClient::ClosingHandshakeIncomplete, 10 06, "");
655 checkpoint.Call(1); 659 checkpoint.Call(1);
656 660
657 m_websocket->send(view->buffer().get(), m_exceptionState); 661 RefPtr<DOMArrayBuffer> buffer = view->bufferOrNull();
662 RELEASE_ASSERT(buffer); // Out of memory?
663 m_websocket->send(buffer.get(), m_exceptionState);
658 664
659 EXPECT_FALSE(m_exceptionState.hadException()); 665 EXPECT_FALSE(m_exceptionState.hadException());
660 EXPECT_EQ(DOMWebSocket::CLOSED, m_websocket->readyState()); 666 EXPECT_EQ(DOMWebSocket::CLOSED, m_websocket->readyState());
661 } 667 }
662 668
663 TEST_F(DOMWebSocketTest, sendArrayBufferSuccess) 669 TEST_F(DOMWebSocketTest, sendArrayBufferSuccess)
664 { 670 {
665 RefPtr<DOMArrayBufferView> view = DOMUint8Array::create(8); 671 RefPtr<DOMArrayBufferView> view = DOMUint8Array::deprecatedCreateOrCrash(8);
666 { 672 {
667 InSequence s; 673 InSequence s;
668 EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String ())).WillOnce(Return(true)); 674 EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String ())).WillOnce(Return(true));
669 EXPECT_CALL(channel(), send(Ref(*view->buffer()), 0, 8)); 675 RefPtr<DOMArrayBuffer> buffer = view->bufferOrNull();
676 RELEASE_ASSERT(buffer); // Out of momry?
haraken 2015/10/29 18:58:37 memory
677 EXPECT_CALL(channel(), send(Ref(*buffer), 0, 8));
670 } 678 }
671 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState ); 679 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState );
672 680
673 EXPECT_FALSE(m_exceptionState.hadException()); 681 EXPECT_FALSE(m_exceptionState.hadException());
674 682
675 m_websocket->didConnect("", ""); 683 m_websocket->didConnect("", "");
676 m_websocket->send(view->buffer().get(), m_exceptionState); 684 RefPtr<DOMArrayBuffer> buffer = view->bufferOrNull();
685 RELEASE_ASSERT(buffer); // Out of momry?
haraken 2015/10/29 18:58:37 memory
686 m_websocket->send(buffer.get(), m_exceptionState);
677 687
678 EXPECT_FALSE(m_exceptionState.hadException()); 688 EXPECT_FALSE(m_exceptionState.hadException());
679 EXPECT_EQ(DOMWebSocket::OPEN, m_websocket->readyState()); 689 EXPECT_EQ(DOMWebSocket::OPEN, m_websocket->readyState());
680 } 690 }
681 691
682 // FIXME: We should have Blob tests here. 692 // FIXME: We should have Blob tests here.
683 // We can't create a Blob because the blob registration cannot be mocked yet. 693 // We can't create a Blob because the blob registration cannot be mocked yet.
684 694
685 // FIXME: We should add tests for bufferedAmount. 695 // FIXME: We should add tests for bufferedAmount.
686 696
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
746 EXPECT_EQ(InvalidAccessError, m_exceptionState.code()); 756 EXPECT_EQ(InvalidAccessError, m_exceptionState.code());
747 EXPECT_EQ(String::format("The code must be either 1000, or between 3000 and 4999. %d is neither.", GetParam()), m_exceptionState.message()); 757 EXPECT_EQ(String::format("The code must be either 1000, or between 3000 and 4999. %d is neither.", GetParam()), m_exceptionState.message());
748 EXPECT_EQ(DOMWebSocket::CONNECTING, m_websocket->readyState()); 758 EXPECT_EQ(DOMWebSocket::CONNECTING, m_websocket->readyState());
749 } 759 }
750 760
751 INSTANTIATE_TEST_CASE_P(DOMWebSocketInvalidClosingCode, DOMWebSocketInvalidClosi ngCodeTest, ::testing::Values(0, 1, 998, 999, 1001, 2999, 5000, 9999, 65535)); 761 INSTANTIATE_TEST_CASE_P(DOMWebSocketInvalidClosingCode, DOMWebSocketInvalidClosi ngCodeTest, ::testing::Values(0, 1, 998, 999, 1001, 2999, 5000, 9999, 65535));
752 762
753 } // namespace 763 } // namespace
754 764
755 } // namespace blink 765 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698