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

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

Issue 606653006: bindings: Adds DOMArrayBuffer, etc. as thin wrappers for ArrayBuffer, etc. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fixed Win GPU tests (DOMDataView). Created 6 years, 2 months 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 | Annotate | Revision Log
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
7 #include "modules/websockets/DOMWebSocket.h" 6 #include "modules/websockets/DOMWebSocket.h"
8 7
9 #include "bindings/core/v8/ExceptionState.h" 8 #include "bindings/core/v8/ExceptionState.h"
10 #include "bindings/core/v8/V8Binding.h" 9 #include "bindings/core/v8/V8Binding.h"
10 #include "core/dom/DOMTypedArray.h"
11 #include "core/dom/Document.h" 11 #include "core/dom/Document.h"
12 #include "core/dom/ExceptionCode.h" 12 #include "core/dom/ExceptionCode.h"
13 #include "core/fileapi/Blob.h" 13 #include "core/fileapi/Blob.h"
14 #include "core/frame/ConsoleTypes.h" 14 #include "core/frame/ConsoleTypes.h"
15 #include "core/testing/DummyPageHolder.h" 15 #include "core/testing/DummyPageHolder.h"
16 #include "wtf/ArrayBuffer.h"
17 #include "wtf/OwnPtr.h" 16 #include "wtf/OwnPtr.h"
18 #include "wtf/Uint8Array.h"
19 #include "wtf/Vector.h" 17 #include "wtf/Vector.h"
20 #include "wtf/testing/WTFTestHelpers.h" 18 #include "wtf/testing/WTFTestHelpers.h"
21 #include "wtf/text/WTFString.h" 19 #include "wtf/text/WTFString.h"
22 #include <gmock/gmock.h> 20 #include <gmock/gmock.h>
23 #include <gtest/gtest.h> 21 #include <gtest/gtest.h>
24 #include <v8.h> 22 #include <v8.h>
25 23
26 using testing::_; 24 using testing::_;
27 using testing::AnyNumber; 25 using testing::AnyNumber;
28 using testing::InSequence; 26 using testing::InSequence;
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 537
540 m_websocket->didConnect("", ""); 538 m_websocket->didConnect("", "");
541 m_websocket->send("hello", m_exceptionState); 539 m_websocket->send("hello", m_exceptionState);
542 540
543 EXPECT_FALSE(m_exceptionState.hadException()); 541 EXPECT_FALSE(m_exceptionState.hadException());
544 EXPECT_EQ(DOMWebSocket::OPEN, m_websocket->readyState()); 542 EXPECT_EQ(DOMWebSocket::OPEN, m_websocket->readyState());
545 } 543 }
546 544
547 TEST_F(DOMWebSocketTest, sendArrayBufferWhenConnecting) 545 TEST_F(DOMWebSocketTest, sendArrayBufferWhenConnecting)
548 { 546 {
549 RefPtr<ArrayBufferView> view = Uint8Array::create(8); 547 RefPtr<DOMArrayBufferView> view = DOMUint8Array::create(8);
550 { 548 {
551 InSequence s; 549 InSequence s;
552 EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String ())).WillOnce(Return(true)); 550 EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String ())).WillOnce(Return(true));
553 } 551 }
554 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState ); 552 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState );
555 553
556 EXPECT_FALSE(m_exceptionState.hadException()); 554 EXPECT_FALSE(m_exceptionState.hadException());
557 555
558 m_websocket->send(view->buffer().get(), m_exceptionState); 556 m_websocket->send(view->buffer().get(), m_exceptionState);
559 557
560 EXPECT_TRUE(m_exceptionState.hadException()); 558 EXPECT_TRUE(m_exceptionState.hadException());
561 EXPECT_EQ(InvalidStateError, m_exceptionState.code()); 559 EXPECT_EQ(InvalidStateError, m_exceptionState.code());
562 EXPECT_EQ("Still in CONNECTING state.", m_exceptionState.message()); 560 EXPECT_EQ("Still in CONNECTING state.", m_exceptionState.message());
563 EXPECT_EQ(DOMWebSocket::CONNECTING, m_websocket->readyState()); 561 EXPECT_EQ(DOMWebSocket::CONNECTING, m_websocket->readyState());
564 } 562 }
565 563
566 TEST_F(DOMWebSocketTest, sendArrayBufferWhenClosing) 564 TEST_F(DOMWebSocketTest, sendArrayBufferWhenClosing)
567 { 565 {
568 RefPtr<ArrayBufferView> view = Uint8Array::create(8); 566 RefPtr<DOMArrayBufferView> view = DOMUint8Array::create(8);
569 { 567 {
570 InSequence s; 568 InSequence s;
571 EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String ())).WillOnce(Return(true)); 569 EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String ())).WillOnce(Return(true));
572 EXPECT_CALL(channel(), fail(_, _, _, _)); 570 EXPECT_CALL(channel(), fail(_, _, _, _));
573 } 571 }
574 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState ); 572 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState );
575 573
576 EXPECT_FALSE(m_exceptionState.hadException()); 574 EXPECT_FALSE(m_exceptionState.hadException());
577 575
578 m_websocket->close(m_exceptionState); 576 m_websocket->close(m_exceptionState);
579 EXPECT_FALSE(m_exceptionState.hadException()); 577 EXPECT_FALSE(m_exceptionState.hadException());
580 578
581 m_websocket->send(view->buffer().get(), m_exceptionState); 579 m_websocket->send(view->buffer().get(), m_exceptionState);
582 580
583 EXPECT_FALSE(m_exceptionState.hadException()); 581 EXPECT_FALSE(m_exceptionState.hadException());
584 EXPECT_EQ(DOMWebSocket::CLOSING, m_websocket->readyState()); 582 EXPECT_EQ(DOMWebSocket::CLOSING, m_websocket->readyState());
585 } 583 }
586 584
587 TEST_F(DOMWebSocketTest, sendArrayBufferWhenClosed) 585 TEST_F(DOMWebSocketTest, sendArrayBufferWhenClosed)
588 { 586 {
589 Checkpoint checkpoint; 587 Checkpoint checkpoint;
590 RefPtr<ArrayBufferView> view = Uint8Array::create(8); 588 RefPtr<DOMArrayBufferView> view = DOMUint8Array::create(8);
591 { 589 {
592 InSequence s; 590 InSequence s;
593 EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String ())).WillOnce(Return(true)); 591 EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String ())).WillOnce(Return(true));
594 EXPECT_CALL(channel(), disconnect()); 592 EXPECT_CALL(channel(), disconnect());
595 EXPECT_CALL(checkpoint, Call(1)); 593 EXPECT_CALL(checkpoint, Call(1));
596 } 594 }
597 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState ); 595 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState );
598 596
599 EXPECT_FALSE(m_exceptionState.hadException()); 597 EXPECT_FALSE(m_exceptionState.hadException());
600 598
601 m_websocket->didClose(WebSocketChannelClient::ClosingHandshakeIncomplete, 10 06, ""); 599 m_websocket->didClose(WebSocketChannelClient::ClosingHandshakeIncomplete, 10 06, "");
602 checkpoint.Call(1); 600 checkpoint.Call(1);
603 601
604 m_websocket->send(view->buffer().get(), m_exceptionState); 602 m_websocket->send(view->buffer().get(), m_exceptionState);
605 603
606 EXPECT_FALSE(m_exceptionState.hadException()); 604 EXPECT_FALSE(m_exceptionState.hadException());
607 EXPECT_EQ(DOMWebSocket::CLOSED, m_websocket->readyState()); 605 EXPECT_EQ(DOMWebSocket::CLOSED, m_websocket->readyState());
608 } 606 }
609 607
610 TEST_F(DOMWebSocketTest, sendArrayBufferSuccess) 608 TEST_F(DOMWebSocketTest, sendArrayBufferSuccess)
611 { 609 {
612 RefPtr<ArrayBufferView> view = Uint8Array::create(8); 610 RefPtr<DOMArrayBufferView> view = DOMUint8Array::create(8);
613 { 611 {
614 InSequence s; 612 InSequence s;
615 EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String ())).WillOnce(Return(true)); 613 EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String ())).WillOnce(Return(true));
616 EXPECT_CALL(channel(), send(Ref(*view->buffer()), 0, 8)); 614 EXPECT_CALL(channel(), send(Ref(*view->view()->buffer()), 0, 8));
617 } 615 }
618 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState ); 616 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState );
619 617
620 EXPECT_FALSE(m_exceptionState.hadException()); 618 EXPECT_FALSE(m_exceptionState.hadException());
621 619
622 m_websocket->didConnect("", ""); 620 m_websocket->didConnect("", "");
623 m_websocket->send(view->buffer().get(), m_exceptionState); 621 m_websocket->send(view->buffer().get(), m_exceptionState);
624 622
625 EXPECT_FALSE(m_exceptionState.hadException()); 623 EXPECT_FALSE(m_exceptionState.hadException());
626 EXPECT_EQ(DOMWebSocket::OPEN, m_websocket->readyState()); 624 EXPECT_EQ(DOMWebSocket::OPEN, m_websocket->readyState());
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
701 EXPECT_EQ(InvalidAccessError, m_exceptionState.code()); 699 EXPECT_EQ(InvalidAccessError, m_exceptionState.code());
702 EXPECT_EQ(String::format("The code must be either 1000, or between 3000 and 4999. %d is neither.", GetParam()), m_exceptionState.message()); 700 EXPECT_EQ(String::format("The code must be either 1000, or between 3000 and 4999. %d is neither.", GetParam()), m_exceptionState.message());
703 EXPECT_EQ(DOMWebSocket::CONNECTING, m_websocket->readyState()); 701 EXPECT_EQ(DOMWebSocket::CONNECTING, m_websocket->readyState());
704 } 702 }
705 703
706 INSTANTIATE_TEST_CASE_P(DOMWebSocketInvalidClosingCode, DOMWebSocketInvalidClosi ngCodeTest, ::testing::Values(0, 1, 998, 999, 1001, 2999, 5000, 9999, 65535)); 704 INSTANTIATE_TEST_CASE_P(DOMWebSocketInvalidClosingCode, DOMWebSocketInvalidClosi ngCodeTest, ::testing::Values(0, 1, 998, 999, 1001, 2999, 5000, 9999, 65535));
707 705
708 } // namespace 706 } // namespace
709 707
710 } // namespace blink 708 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698