| OLD | NEW |
| 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_handshake_stream_create_helper.h" | 5 #include "net/websockets/websocket_handshake_stream_create_helper.h" |
| 6 | 6 |
| 7 #include <string> |
| 8 #include <vector> |
| 9 |
| 7 #include "net/base/completion_callback.h" | 10 #include "net/base/completion_callback.h" |
| 8 #include "net/base/net_errors.h" | 11 #include "net/base/net_errors.h" |
| 9 #include "net/http/http_request_headers.h" | 12 #include "net/http/http_request_headers.h" |
| 10 #include "net/http/http_request_info.h" | 13 #include "net/http/http_request_info.h" |
| 11 #include "net/http/http_response_headers.h" | 14 #include "net/http/http_response_headers.h" |
| 12 #include "net/http/http_response_info.h" | 15 #include "net/http/http_response_info.h" |
| 13 #include "net/socket/client_socket_handle.h" | 16 #include "net/socket/client_socket_handle.h" |
| 14 #include "net/socket/socket_test_util.h" | 17 #include "net/socket/socket_test_util.h" |
| 15 #include "net/websockets/websocket_basic_handshake_stream.h" | 18 #include "net/websockets/websocket_basic_handshake_stream.h" |
| 16 #include "net/websockets/websocket_stream.h" | 19 #include "net/websockets/websocket_stream.h" |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 EXPECT_EQ("", stream->GetExtensions()); | 142 EXPECT_EQ("", stream->GetExtensions()); |
| 140 EXPECT_EQ("", stream->GetSubProtocol()); | 143 EXPECT_EQ("", stream->GetSubProtocol()); |
| 141 } | 144 } |
| 142 | 145 |
| 143 // Verify that the sub-protocols are passed through. | 146 // Verify that the sub-protocols are passed through. |
| 144 TEST_F(WebSocketHandshakeStreamCreateHelperTest, SubProtocols) { | 147 TEST_F(WebSocketHandshakeStreamCreateHelperTest, SubProtocols) { |
| 145 std::vector<std::string> sub_protocols; | 148 std::vector<std::string> sub_protocols; |
| 146 sub_protocols.push_back("chat"); | 149 sub_protocols.push_back("chat"); |
| 147 sub_protocols.push_back("superchat"); | 150 sub_protocols.push_back("superchat"); |
| 148 scoped_ptr<WebSocketStream> stream = | 151 scoped_ptr<WebSocketStream> stream = |
| 149 CreateAndInitializeStream("ws://localhost/", "/", | 152 CreateAndInitializeStream("ws://localhost/", |
| 150 sub_protocols, "http://localhost/", | 153 "/", |
| 154 sub_protocols, |
| 155 "http://localhost/", |
| 151 "Sec-WebSocket-Protocol: chat, superchat\r\n", | 156 "Sec-WebSocket-Protocol: chat, superchat\r\n", |
| 152 "Sec-WebSocket-Protocol: superchat\r\n"); | 157 "Sec-WebSocket-Protocol: superchat\r\n"); |
| 153 EXPECT_EQ("superchat", stream->GetSubProtocol()); | 158 EXPECT_EQ("superchat", stream->GetSubProtocol()); |
| 154 } | 159 } |
| 155 | 160 |
| 156 // TODO(ricea): Test extensions once they are implemented. | 161 // Verify that extension name is available. Bad extension names are tested in |
| 162 // websocket_stream_test.cc. |
| 163 TEST_F(WebSocketHandshakeStreamCreateHelperTest, Extensions) { |
| 164 scoped_ptr<WebSocketStream> stream = CreateAndInitializeStream( |
| 165 "ws://localhost/", |
| 166 "/", |
| 167 std::vector<std::string>(), |
| 168 "http://localhost/", |
| 169 "", |
| 170 "Sec-WebSocket-Extensions: permessage-deflate\r\n"); |
| 171 EXPECT_EQ("permessage-deflate", stream->GetExtensions()); |
| 172 } |
| 173 |
| 174 // Verify that extension parameters are available. Bad parameters are tested in |
| 175 // websocket_stream_test.cc. |
| 176 TEST_F(WebSocketHandshakeStreamCreateHelperTest, ExtensionParameters) { |
| 177 scoped_ptr<WebSocketStream> stream = CreateAndInitializeStream( |
| 178 "ws://localhost/", |
| 179 "/", |
| 180 std::vector<std::string>(), |
| 181 "http://localhost/", |
| 182 "", |
| 183 "Sec-WebSocket-Extensions: permessage-deflate;" |
| 184 " client_max_window_bits=14; server_max_window_bits=14;" |
| 185 " server_no_context_takeover; client_no_context_takeover\r\n"); |
| 186 |
| 187 EXPECT_EQ( |
| 188 "permessage-deflate;" |
| 189 " client_max_window_bits=14; server_max_window_bits=14;" |
| 190 " server_no_context_takeover; client_no_context_takeover", |
| 191 stream->GetExtensions()); |
| 192 } |
| 157 | 193 |
| 158 } // namespace | 194 } // namespace |
| 159 } // namespace net | 195 } // namespace net |
| OLD | NEW |