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

Side by Side Diff: net/websockets/websocket_channel_test.cc

Issue 170843007: Introduce url::Origin to represent Web Origin. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 10 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "net/websockets/websocket_channel.h" 5 #include "net/websockets/websocket_channel.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 8
9 #include <iostream> 9 #include <iostream>
10 #include <string> 10 #include <string>
(...skipping 662 matching lines...) Expand 10 before | Expand all | Expand 10 after
673 MOCK_METHOD0(Close, void()); 673 MOCK_METHOD0(Close, void());
674 MOCK_CONST_METHOD0(GetSubProtocol, std::string()); 674 MOCK_CONST_METHOD0(GetSubProtocol, std::string());
675 MOCK_CONST_METHOD0(GetExtensions, std::string()); 675 MOCK_CONST_METHOD0(GetExtensions, std::string());
676 MOCK_METHOD0(AsWebSocketStream, WebSocketStream*()); 676 MOCK_METHOD0(AsWebSocketStream, WebSocketStream*());
677 }; 677 };
678 678
679 struct ArgumentCopyingWebSocketStreamCreator { 679 struct ArgumentCopyingWebSocketStreamCreator {
680 scoped_ptr<WebSocketStreamRequest> Create( 680 scoped_ptr<WebSocketStreamRequest> Create(
681 const GURL& socket_url, 681 const GURL& socket_url,
682 const std::vector<std::string>& requested_subprotocols, 682 const std::vector<std::string>& requested_subprotocols,
683 const GURL& origin, 683 const std::string& origin,
684 URLRequestContext* url_request_context, 684 URLRequestContext* url_request_context,
685 const BoundNetLog& net_log, 685 const BoundNetLog& net_log,
686 scoped_ptr<WebSocketStream::ConnectDelegate> connect_delegate) { 686 scoped_ptr<WebSocketStream::ConnectDelegate> connect_delegate) {
687 this->socket_url = socket_url; 687 this->socket_url = socket_url;
688 this->requested_subprotocols = requested_subprotocols; 688 this->requested_subprotocols = requested_subprotocols;
689 this->origin = origin; 689 this->origin = origin;
690 this->url_request_context = url_request_context; 690 this->url_request_context = url_request_context;
691 this->net_log = net_log; 691 this->net_log = net_log;
692 this->connect_delegate = connect_delegate.Pass(); 692 this->connect_delegate = connect_delegate.Pass();
693 return make_scoped_ptr(new WebSocketStreamRequest); 693 return make_scoped_ptr(new WebSocketStreamRequest);
694 } 694 }
695 695
696 GURL socket_url; 696 GURL socket_url;
697 GURL origin; 697 std::string origin;
698 std::vector<std::string> requested_subprotocols; 698 std::vector<std::string> requested_subprotocols;
699 URLRequestContext* url_request_context; 699 URLRequestContext* url_request_context;
700 BoundNetLog net_log; 700 BoundNetLog net_log;
701 scoped_ptr<WebSocketStream::ConnectDelegate> connect_delegate; 701 scoped_ptr<WebSocketStream::ConnectDelegate> connect_delegate;
702 }; 702 };
703 703
704 // Converts a std::string to a std::vector<char>. For test purposes, it is 704 // Converts a std::string to a std::vector<char>. For test purposes, it is
705 // convenient to be able to specify data as a string, but the 705 // convenient to be able to specify data as a string, but the
706 // WebSocketEventInterface requires the vector<char> type. 706 // WebSocketEventInterface requires the vector<char> type.
707 std::vector<char> AsVector(const std::string& s) { 707 std::vector<char> AsVector(const std::string& s) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
747 void set_stream(scoped_ptr<T> stream) { 747 void set_stream(scoped_ptr<T> stream) {
748 // Since the definition of "PassAs" depends on the type T, the C++ standard 748 // Since the definition of "PassAs" depends on the type T, the C++ standard
749 // requires the "template" keyword to indicate that "PassAs" should be 749 // requires the "template" keyword to indicate that "PassAs" should be
750 // parsed as a template method. 750 // parsed as a template method.
751 stream_ = stream.template PassAs<WebSocketStream>(); 751 stream_ = stream.template PassAs<WebSocketStream>();
752 } 752 }
753 753
754 // A struct containing the data that will be used to connect the channel. 754 // A struct containing the data that will be used to connect the channel.
755 // Grouped for readability. 755 // Grouped for readability.
756 struct ConnectData { 756 struct ConnectData {
757 ConnectData() : socket_url("ws://ws/"), origin("http://ws/") {} 757 ConnectData() : socket_url("ws://ws/"), origin("http://ws") {}
758 758
759 // URLRequestContext object. 759 // URLRequestContext object.
760 URLRequestContext url_request_context; 760 URLRequestContext url_request_context;
761 761
762 // URL to (pretend to) connect to. 762 // URL to (pretend to) connect to.
763 GURL socket_url; 763 GURL socket_url;
764 // Requested protocols for the request. 764 // Requested protocols for the request.
765 std::vector<std::string> requested_subprotocols; 765 std::vector<std::string> requested_subprotocols;
766 // Origin of the request 766 // Origin of the request
767 GURL origin; 767 std::string origin;
768 768
769 // A fake WebSocketStreamCreator that just records its arguments. 769 // A fake WebSocketStreamCreator that just records its arguments.
770 ArgumentCopyingWebSocketStreamCreator creator; 770 ArgumentCopyingWebSocketStreamCreator creator;
771 }; 771 };
772 ConnectData connect_data_; 772 ConnectData connect_data_;
773 773
774 // The channel we are testing. Not initialised until SetChannel() is called. 774 // The channel we are testing. Not initialised until SetChannel() is called.
775 scoped_ptr<WebSocketChannel> channel_; 775 scoped_ptr<WebSocketChannel> channel_;
776 776
777 // A mock or fake stream for tests that need one. 777 // A mock or fake stream for tests that need one.
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
952 // whether these methods are called or not. 952 // whether these methods are called or not.
953 EXPECT_CALL(*mock_stream_, GetSubProtocol()).Times(AnyNumber()); 953 EXPECT_CALL(*mock_stream_, GetSubProtocol()).Times(AnyNumber());
954 EXPECT_CALL(*mock_stream_, GetExtensions()).Times(AnyNumber()); 954 EXPECT_CALL(*mock_stream_, GetExtensions()).Times(AnyNumber());
955 } 955 }
956 }; 956 };
957 957
958 // Simple test that everything that should be passed to the creator function is 958 // Simple test that everything that should be passed to the creator function is
959 // passed to the creator function. 959 // passed to the creator function.
960 TEST_F(WebSocketChannelTest, EverythingIsPassedToTheCreatorFunction) { 960 TEST_F(WebSocketChannelTest, EverythingIsPassedToTheCreatorFunction) {
961 connect_data_.socket_url = GURL("ws://example.com/test"); 961 connect_data_.socket_url = GURL("ws://example.com/test");
962 connect_data_.origin = GURL("http://example.com/test"); 962 connect_data_.origin = "http://example.com";
963 connect_data_.requested_subprotocols.push_back("Sinbad"); 963 connect_data_.requested_subprotocols.push_back("Sinbad");
964 964
965 CreateChannelAndConnect(); 965 CreateChannelAndConnect();
966 966
967 const ArgumentCopyingWebSocketStreamCreator& actual = connect_data_.creator; 967 const ArgumentCopyingWebSocketStreamCreator& actual = connect_data_.creator;
968 968
969 EXPECT_EQ(&connect_data_.url_request_context, actual.url_request_context); 969 EXPECT_EQ(&connect_data_.url_request_context, actual.url_request_context);
970 970
971 EXPECT_EQ(connect_data_.socket_url, actual.socket_url); 971 EXPECT_EQ(connect_data_.socket_url, actual.socket_url);
972 EXPECT_EQ(connect_data_.requested_subprotocols, 972 EXPECT_EQ(connect_data_.requested_subprotocols,
(...skipping 2083 matching lines...) Expand 10 before | Expand all | Expand 10 after
3056 channel_->StartClosingHandshake(kWebSocketNormalClosure, "OK"); 3056 channel_->StartClosingHandshake(kWebSocketNormalClosure, "OK");
3057 ASSERT_TRUE(read_frames); 3057 ASSERT_TRUE(read_frames);
3058 // Provide the "Close" message from the server. 3058 // Provide the "Close" message from the server.
3059 *read_frames = CreateFrameVector(frames); 3059 *read_frames = CreateFrameVector(frames);
3060 read_callback.Run(OK); 3060 read_callback.Run(OK);
3061 completion.WaitForResult(); 3061 completion.WaitForResult();
3062 } 3062 }
3063 3063
3064 } // namespace 3064 } // namespace
3065 } // namespace net 3065 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698