ricea | 433bdab | 2015-01-26 07:25:37 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | // End-to-end tests for WebSocket. |
| 6 | // |
| 7 | // A python server is (re)started for each test, which is moderately |
| 8 | // inefficient. However, it makes these tests a good fit for scenarios which |
| 9 | // require special server configurations. |
| 10 | |
tfarina | 8a2c66c2 | 2015-10-13 19:14:49 | [diff] [blame] | 11 | #include <stdint.h> |
ryansturm | 4bab0683 | 2016-03-03 23:41:07 | [diff] [blame] | 12 | |
danakj | 9c5cab5 | 2016-04-16 00:54:33 | [diff] [blame] | 13 | #include <memory> |
ricea | 433bdab | 2015-01-26 07:25:37 | [diff] [blame] | 14 | #include <string> |
Adam Rice | 5b4a3d8 | 2018-08-02 15:28:43 | [diff] [blame] | 15 | #include <utility> |
ricea | 433bdab | 2015-01-26 07:25:37 | [diff] [blame] | 16 | |
| 17 | #include "base/bind.h" |
| 18 | #include "base/bind_helpers.h" |
| 19 | #include "base/callback.h" |
skyostil | 4891b25b | 2015-06-11 11:43:45 | [diff] [blame] | 20 | #include "base/location.h" |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 21 | #include "base/macros.h" |
danakj | 9c5cab5 | 2016-04-16 00:54:33 | [diff] [blame] | 22 | #include "base/memory/ptr_util.h" |
Bence Béky | 6562397 | 2018-03-05 15:31:56 | [diff] [blame] | 23 | #include "base/memory/scoped_refptr.h" |
ricea | 433bdab | 2015-01-26 07:25:37 | [diff] [blame] | 24 | #include "base/run_loop.h" |
skyostil | 4891b25b | 2015-06-11 11:43:45 | [diff] [blame] | 25 | #include "base/single_thread_task_runner.h" |
Adam Rice | 5b4a3d8 | 2018-08-02 15:28:43 | [diff] [blame] | 26 | #include "base/strings/strcat.h" |
Adam Rice | cb76ac6 | 2015-02-20 05:33:25 | [diff] [blame] | 27 | #include "base/strings/string_piece.h" |
Adam Rice | 5b4a3d8 | 2018-08-02 15:28:43 | [diff] [blame] | 28 | #include "base/strings/stringprintf.h" |
gab | f767595f | 2016-05-11 18:50:35 | [diff] [blame] | 29 | #include "base/threading/thread_task_runner_handle.h" |
Sergey Ulanov | a337dcd | 2017-09-08 20:53:14 | [diff] [blame] | 30 | #include "build/build_config.h" |
ricea | 433bdab | 2015-01-26 07:25:37 | [diff] [blame] | 31 | #include "net/base/auth.h" |
Adam Rice | 5b4a3d8 | 2018-08-02 15:28:43 | [diff] [blame] | 32 | #include "net/base/host_port_pair.h" |
ryansturm | 7de050c | 2016-02-23 00:10:21 | [diff] [blame] | 33 | #include "net/base/proxy_delegate.h" |
Adam Rice | 5b4a3d8 | 2018-08-02 15:28:43 | [diff] [blame] | 34 | #include "net/base/url_util.h" |
Yutaka Hirano | 2f65eec | 2018-05-23 01:58:22 | [diff] [blame] | 35 | #include "net/http/http_request_headers.h" |
Adam Rice | 5b4a3d8 | 2018-08-02 15:28:43 | [diff] [blame] | 36 | #include "net/log/net_log.h" |
| 37 | #include "net/proxy_resolution/proxy_config.h" |
| 38 | #include "net/proxy_resolution/proxy_config_service.h" |
| 39 | #include "net/proxy_resolution/proxy_config_service_fixed.h" |
| 40 | #include "net/proxy_resolution/proxy_config_with_annotation.h" |
| 41 | #include "net/proxy_resolution/proxy_info.h" |
Lily Houghton | ffe89daa0 | 2018-03-09 18:30:03 | [diff] [blame] | 42 | #include "net/proxy_resolution/proxy_resolution_service.h" |
tommycli | 59a6343 | 2015-11-06 00:10:55 | [diff] [blame] | 43 | #include "net/test/embedded_test_server/embedded_test_server.h" |
Adam Rice | 5b4a3d8 | 2018-08-02 15:28:43 | [diff] [blame] | 44 | #include "net/test/embedded_test_server/http_request.h" |
| 45 | #include "net/test/embedded_test_server/http_response.h" |
ricea | 433bdab | 2015-01-26 07:25:37 | [diff] [blame] | 46 | #include "net/test/spawned_test_server/spawned_test_server.h" |
rsleevi | a69c79a | 2016-06-22 03:28:43 | [diff] [blame] | 47 | #include "net/test/test_data_directory.h" |
Bence Béky | 98447b1 | 2018-05-08 03:14:01 | [diff] [blame] | 48 | #include "net/test/test_with_scoped_task_environment.h" |
rhalavati | 9ebaba7e | 2017-04-27 06:16:29 | [diff] [blame] | 49 | #include "net/traffic_annotation/network_traffic_annotation_test_helper.h" |
Adam Rice | 5b4a3d8 | 2018-08-02 15:28:43 | [diff] [blame] | 50 | #include "net/url_request/url_request.h" |
| 51 | #include "net/url_request/url_request_context.h" |
ricea | 433bdab | 2015-01-26 07:25:37 | [diff] [blame] | 52 | #include "net/url_request/url_request_test_util.h" |
| 53 | #include "net/websockets/websocket_channel.h" |
| 54 | #include "net/websockets/websocket_event_interface.h" |
| 55 | #include "testing/gtest/include/gtest/gtest.h" |
Adam Rice | 5b4a3d8 | 2018-08-02 15:28:43 | [diff] [blame] | 56 | #include "url/gurl.h" |
mkwst | 4997ce8 | 2015-07-25 12:00:05 | [diff] [blame] | 57 | #include "url/origin.h" |
ricea | 433bdab | 2015-01-26 07:25:37 | [diff] [blame] | 58 | |
| 59 | namespace net { |
| 60 | |
yhirano | 4a59383 | 2016-10-24 18:58:22 | [diff] [blame] | 61 | class URLRequest; |
| 62 | |
ricea | 433bdab | 2015-01-26 07:25:37 | [diff] [blame] | 63 | namespace { |
| 64 | |
Adam Rice | 5b4a3d8 | 2018-08-02 15:28:43 | [diff] [blame] | 65 | using test_server::BasicHttpResponse; |
| 66 | using test_server::HttpRequest; |
| 67 | using test_server::HttpResponse; |
| 68 | |
ricea | 433bdab | 2015-01-26 07:25:37 | [diff] [blame] | 69 | static const char kEchoServer[] = "echo-with-no-extension"; |
| 70 | |
Adam Rice | cb76ac6 | 2015-02-20 05:33:25 | [diff] [blame] | 71 | // Simplify changing URL schemes. |
| 72 | GURL ReplaceUrlScheme(const GURL& in_url, const base::StringPiece& scheme) { |
| 73 | GURL::Replacements replacements; |
| 74 | replacements.SetSchemeStr(scheme); |
| 75 | return in_url.ReplaceComponents(replacements); |
| 76 | } |
| 77 | |
ricea | 433bdab | 2015-01-26 07:25:37 | [diff] [blame] | 78 | // An implementation of WebSocketEventInterface that waits for and records the |
| 79 | // results of the connect. |
| 80 | class ConnectTestingEventInterface : public WebSocketEventInterface { |
| 81 | public: |
| 82 | ConnectTestingEventInterface(); |
| 83 | |
| 84 | void WaitForResponse(); |
| 85 | |
| 86 | bool failed() const { return failed_; } |
| 87 | |
| 88 | // Only set if the handshake failed, otherwise empty. |
| 89 | std::string failure_message() const; |
| 90 | |
| 91 | std::string selected_subprotocol() const; |
| 92 | |
| 93 | std::string extensions() const; |
| 94 | |
| 95 | // Implementation of WebSocketEventInterface. |
yhirano | 4a59383 | 2016-10-24 18:58:22 | [diff] [blame] | 96 | void OnCreateURLRequest(URLRequest* request) override {} |
| 97 | |
Yutaka Hirano | 4165de9 | 2018-04-10 11:46:49 | [diff] [blame] | 98 | void OnAddChannelResponse(const std::string& selected_subprotocol, |
| 99 | const std::string& extensions) override; |
ricea | 433bdab | 2015-01-26 07:25:37 | [diff] [blame] | 100 | |
Yutaka Hirano | 4165de9 | 2018-04-10 11:46:49 | [diff] [blame] | 101 | void OnDataFrame(bool fin, |
| 102 | WebSocketMessageType type, |
| 103 | scoped_refptr<IOBuffer> data, |
| 104 | size_t data_size) override; |
ricea | 433bdab | 2015-01-26 07:25:37 | [diff] [blame] | 105 | |
Yutaka Hirano | 4165de9 | 2018-04-10 11:46:49 | [diff] [blame] | 106 | void OnFlowControl(int64_t quota) override; |
ricea | 433bdab | 2015-01-26 07:25:37 | [diff] [blame] | 107 | |
Yutaka Hirano | 4165de9 | 2018-04-10 11:46:49 | [diff] [blame] | 108 | void OnClosingHandshake() override; |
ricea | 433bdab | 2015-01-26 07:25:37 | [diff] [blame] | 109 | |
Yutaka Hirano | 4165de9 | 2018-04-10 11:46:49 | [diff] [blame] | 110 | void OnDropChannel(bool was_clean, |
| 111 | uint16_t code, |
| 112 | const std::string& reason) override; |
ricea | 433bdab | 2015-01-26 07:25:37 | [diff] [blame] | 113 | |
Yutaka Hirano | 4165de9 | 2018-04-10 11:46:49 | [diff] [blame] | 114 | void OnFailChannel(const std::string& message) override; |
ricea | 433bdab | 2015-01-26 07:25:37 | [diff] [blame] | 115 | |
Yutaka Hirano | 4165de9 | 2018-04-10 11:46:49 | [diff] [blame] | 116 | void OnStartOpeningHandshake( |
danakj | 9c5cab5 | 2016-04-16 00:54:33 | [diff] [blame] | 117 | std::unique_ptr<WebSocketHandshakeRequestInfo> request) override; |
ricea | 433bdab | 2015-01-26 07:25:37 | [diff] [blame] | 118 | |
Yutaka Hirano | 4165de9 | 2018-04-10 11:46:49 | [diff] [blame] | 119 | void OnFinishOpeningHandshake( |
danakj | 9c5cab5 | 2016-04-16 00:54:33 | [diff] [blame] | 120 | std::unique_ptr<WebSocketHandshakeResponseInfo> response) override; |
ricea | 433bdab | 2015-01-26 07:25:37 | [diff] [blame] | 121 | |
Yutaka Hirano | 4165de9 | 2018-04-10 11:46:49 | [diff] [blame] | 122 | void OnSSLCertificateError( |
danakj | 9c5cab5 | 2016-04-16 00:54:33 | [diff] [blame] | 123 | std::unique_ptr<SSLErrorCallbacks> ssl_error_callbacks, |
ricea | 433bdab | 2015-01-26 07:25:37 | [diff] [blame] | 124 | const GURL& url, |
| 125 | const SSLInfo& ssl_info, |
| 126 | bool fatal) override; |
| 127 | |
Yutaka Hirano | 70fa2591 | 2018-06-06 05:26:54 | [diff] [blame] | 128 | int OnAuthRequired(scoped_refptr<AuthChallengeInfo> auth_info, |
| 129 | scoped_refptr<HttpResponseHeaders> response_headers, |
| 130 | const HostPortPair& host_port_pair, |
| 131 | base::OnceCallback<void(const AuthCredentials*)> callback, |
| 132 | base::Optional<AuthCredentials>* credentials) override; |
| 133 | |
ricea | 433bdab | 2015-01-26 07:25:37 | [diff] [blame] | 134 | private: |
| 135 | void QuitNestedEventLoop(); |
| 136 | |
| 137 | // failed_ is true if the handshake failed (ie. OnFailChannel was called). |
| 138 | bool failed_; |
| 139 | std::string selected_subprotocol_; |
| 140 | std::string extensions_; |
| 141 | std::string failure_message_; |
| 142 | base::RunLoop run_loop_; |
| 143 | |
| 144 | DISALLOW_COPY_AND_ASSIGN(ConnectTestingEventInterface); |
| 145 | }; |
| 146 | |
tyoshino | c06da56 | 2015-03-06 06:02:42 | [diff] [blame] | 147 | ConnectTestingEventInterface::ConnectTestingEventInterface() : failed_(false) { |
ricea | 433bdab | 2015-01-26 07:25:37 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | void ConnectTestingEventInterface::WaitForResponse() { |
| 151 | run_loop_.Run(); |
| 152 | } |
| 153 | |
| 154 | std::string ConnectTestingEventInterface::failure_message() const { |
| 155 | return failure_message_; |
| 156 | } |
| 157 | |
| 158 | std::string ConnectTestingEventInterface::selected_subprotocol() const { |
| 159 | return selected_subprotocol_; |
| 160 | } |
| 161 | |
| 162 | std::string ConnectTestingEventInterface::extensions() const { |
| 163 | return extensions_; |
| 164 | } |
| 165 | |
Yutaka Hirano | 4165de9 | 2018-04-10 11:46:49 | [diff] [blame] | 166 | void ConnectTestingEventInterface::OnAddChannelResponse( |
ricea | 433bdab | 2015-01-26 07:25:37 | [diff] [blame] | 167 | const std::string& selected_subprotocol, |
| 168 | const std::string& extensions) { |
ricea | 433bdab | 2015-01-26 07:25:37 | [diff] [blame] | 169 | selected_subprotocol_ = selected_subprotocol; |
| 170 | extensions_ = extensions; |
| 171 | QuitNestedEventLoop(); |
ricea | 433bdab | 2015-01-26 07:25:37 | [diff] [blame] | 172 | } |
| 173 | |
Yutaka Hirano | 4165de9 | 2018-04-10 11:46:49 | [diff] [blame] | 174 | void ConnectTestingEventInterface::OnDataFrame(bool fin, |
| 175 | WebSocketMessageType type, |
| 176 | scoped_refptr<IOBuffer> data, |
| 177 | size_t data_size) {} |
ricea | 433bdab | 2015-01-26 07:25:37 | [diff] [blame] | 178 | |
Yutaka Hirano | 4165de9 | 2018-04-10 11:46:49 | [diff] [blame] | 179 | void ConnectTestingEventInterface::OnFlowControl(int64_t quota) {} |
ricea | 433bdab | 2015-01-26 07:25:37 | [diff] [blame] | 180 | |
Yutaka Hirano | 4165de9 | 2018-04-10 11:46:49 | [diff] [blame] | 181 | void ConnectTestingEventInterface::OnClosingHandshake() {} |
ricea | 433bdab | 2015-01-26 07:25:37 | [diff] [blame] | 182 | |
Yutaka Hirano | 4165de9 | 2018-04-10 11:46:49 | [diff] [blame] | 183 | void ConnectTestingEventInterface::OnDropChannel(bool was_clean, |
| 184 | uint16_t code, |
| 185 | const std::string& reason) {} |
ricea | 433bdab | 2015-01-26 07:25:37 | [diff] [blame] | 186 | |
Yutaka Hirano | 4165de9 | 2018-04-10 11:46:49 | [diff] [blame] | 187 | void ConnectTestingEventInterface::OnFailChannel(const std::string& message) { |
ricea | 433bdab | 2015-01-26 07:25:37 | [diff] [blame] | 188 | failed_ = true; |
| 189 | failure_message_ = message; |
| 190 | QuitNestedEventLoop(); |
ricea | 433bdab | 2015-01-26 07:25:37 | [diff] [blame] | 191 | } |
| 192 | |
Yutaka Hirano | 4165de9 | 2018-04-10 11:46:49 | [diff] [blame] | 193 | void ConnectTestingEventInterface::OnStartOpeningHandshake( |
| 194 | std::unique_ptr<WebSocketHandshakeRequestInfo> request) {} |
ricea | 433bdab | 2015-01-26 07:25:37 | [diff] [blame] | 195 | |
Yutaka Hirano | 4165de9 | 2018-04-10 11:46:49 | [diff] [blame] | 196 | void ConnectTestingEventInterface::OnFinishOpeningHandshake( |
| 197 | std::unique_ptr<WebSocketHandshakeResponseInfo> response) {} |
ricea | 433bdab | 2015-01-26 07:25:37 | [diff] [blame] | 198 | |
Yutaka Hirano | 4165de9 | 2018-04-10 11:46:49 | [diff] [blame] | 199 | void ConnectTestingEventInterface::OnSSLCertificateError( |
danakj | 9c5cab5 | 2016-04-16 00:54:33 | [diff] [blame] | 200 | std::unique_ptr<SSLErrorCallbacks> ssl_error_callbacks, |
ricea | 433bdab | 2015-01-26 07:25:37 | [diff] [blame] | 201 | const GURL& url, |
| 202 | const SSLInfo& ssl_info, |
| 203 | bool fatal) { |
skyostil | 4891b25b | 2015-06-11 11:43:45 | [diff] [blame] | 204 | base::ThreadTaskRunnerHandle::Get()->PostTask( |
ricea | 433bdab | 2015-01-26 07:25:37 | [diff] [blame] | 205 | FROM_HERE, base::Bind(&SSLErrorCallbacks::CancelSSLRequest, |
| 206 | base::Owned(ssl_error_callbacks.release()), |
| 207 | ERR_SSL_PROTOCOL_ERROR, &ssl_info)); |
ricea | 433bdab | 2015-01-26 07:25:37 | [diff] [blame] | 208 | } |
| 209 | |
Yutaka Hirano | 70fa2591 | 2018-06-06 05:26:54 | [diff] [blame] | 210 | int ConnectTestingEventInterface::OnAuthRequired( |
| 211 | scoped_refptr<AuthChallengeInfo> auth_info, |
| 212 | scoped_refptr<HttpResponseHeaders> response_headers, |
| 213 | const HostPortPair& host_port_pair, |
| 214 | base::OnceCallback<void(const AuthCredentials*)> callback, |
| 215 | base::Optional<AuthCredentials>* credentials) { |
| 216 | *credentials = base::nullopt; |
| 217 | return OK; |
| 218 | } |
| 219 | |
ricea | 433bdab | 2015-01-26 07:25:37 | [diff] [blame] | 220 | void ConnectTestingEventInterface::QuitNestedEventLoop() { |
| 221 | run_loop_.Quit(); |
| 222 | } |
| 223 | |
| 224 | // A subclass of TestNetworkDelegate that additionally implements the |
| 225 | // OnResolveProxy callback and records the information passed to it. |
ryansturm | 7de050c | 2016-02-23 00:10:21 | [diff] [blame] | 226 | class TestProxyDelegateWithProxyInfo : public ProxyDelegate { |
ricea | 433bdab | 2015-01-26 07:25:37 | [diff] [blame] | 227 | public: |
Chris Watkins | 28c2fdd | 2017-11-30 06:06:52 | [diff] [blame] | 228 | TestProxyDelegateWithProxyInfo() = default; |
ricea | 433bdab | 2015-01-26 07:25:37 | [diff] [blame] | 229 | |
| 230 | struct ResolvedProxyInfo { |
| 231 | GURL url; |
| 232 | ProxyInfo proxy_info; |
| 233 | }; |
| 234 | |
| 235 | const ResolvedProxyInfo& resolved_proxy_info() const { |
| 236 | return resolved_proxy_info_; |
| 237 | } |
| 238 | |
| 239 | protected: |
| 240 | void OnResolveProxy(const GURL& url, |
ryansturm | 4bab0683 | 2016-03-03 23:41:07 | [diff] [blame] | 241 | const std::string& method, |
Reilly Grant | b414ace7 | 2017-11-14 23:03:22 | [diff] [blame] | 242 | const ProxyRetryInfoMap& proxy_retry_info, |
ricea | 433bdab | 2015-01-26 07:25:37 | [diff] [blame] | 243 | ProxyInfo* result) override { |
| 244 | resolved_proxy_info_.url = url; |
| 245 | resolved_proxy_info_.proxy_info = *result; |
| 246 | } |
| 247 | |
ryansturm | 7de050c | 2016-02-23 00:10:21 | [diff] [blame] | 248 | void OnFallback(const ProxyServer& bad_proxy, int net_error) override {} |
ryansturm | 7de050c | 2016-02-23 00:10:21 | [diff] [blame] | 249 | |
ricea | 433bdab | 2015-01-26 07:25:37 | [diff] [blame] | 250 | private: |
| 251 | ResolvedProxyInfo resolved_proxy_info_; |
| 252 | |
ryansturm | 7de050c | 2016-02-23 00:10:21 | [diff] [blame] | 253 | DISALLOW_COPY_AND_ASSIGN(TestProxyDelegateWithProxyInfo); |
ricea | 433bdab | 2015-01-26 07:25:37 | [diff] [blame] | 254 | }; |
| 255 | |
Bence Béky | 98447b1 | 2018-05-08 03:14:01 | [diff] [blame] | 256 | class WebSocketEndToEndTest : public TestWithScopedTaskEnvironment { |
ricea | 433bdab | 2015-01-26 07:25:37 | [diff] [blame] | 257 | protected: |
| 258 | WebSocketEndToEndTest() |
Adam Rice | cb76ac6 | 2015-02-20 05:33:25 | [diff] [blame] | 259 | : event_interface_(), |
Bence Béky | 6562397 | 2018-03-05 15:31:56 | [diff] [blame] | 260 | proxy_delegate_(std::make_unique<TestProxyDelegateWithProxyInfo>()), |
ricea | 433bdab | 2015-01-26 07:25:37 | [diff] [blame] | 261 | context_(true), |
Adam Rice | cb76ac6 | 2015-02-20 05:33:25 | [diff] [blame] | 262 | channel_(), |
ricea | 433bdab | 2015-01-26 07:25:37 | [diff] [blame] | 263 | initialised_context_(false) {} |
| 264 | |
| 265 | // Initialise the URLRequestContext. Normally done automatically by |
| 266 | // ConnectAndWait(). This method is for the use of tests that need the |
| 267 | // URLRequestContext initialised before calling ConnectAndWait(). |
| 268 | void InitialiseContext() { |
ricea | 433bdab | 2015-01-26 07:25:37 | [diff] [blame] | 269 | context_.Init(); |
Eric Roman | 3d8546a | 2018-09-10 17:00:52 | [diff] [blame] | 270 | context_.proxy_resolution_service()->SetProxyDelegate( |
| 271 | proxy_delegate_.get()); |
ricea | 433bdab | 2015-01-26 07:25:37 | [diff] [blame] | 272 | initialised_context_ = true; |
| 273 | } |
| 274 | |
| 275 | // Send the connect request to |socket_url| and wait for a response. Returns |
| 276 | // true if the handshake succeeded. |
| 277 | bool ConnectAndWait(const GURL& socket_url) { |
| 278 | if (!initialised_context_) { |
| 279 | InitialiseContext(); |
| 280 | } |
Daniel Cheng | 88186bd5 | 2017-10-20 08:14:46 | [diff] [blame] | 281 | url::Origin origin = url::Origin::Create(GURL("http://localhost")); |
Mike West | b85da8ed | 2017-08-10 14:16:46 | [diff] [blame] | 282 | GURL site_for_cookies("http://localhost/"); |
Adam Rice | 5b4a3d8 | 2018-08-02 15:28:43 | [diff] [blame] | 283 | event_interface_ = new ConnectTestingEventInterface(); |
Bence Béky | 6562397 | 2018-03-05 15:31:56 | [diff] [blame] | 284 | channel_ = std::make_unique<WebSocketChannel>( |
| 285 | base::WrapUnique(event_interface_), &context_); |
allada | cef397d | 2016-06-29 17:52:23 | [diff] [blame] | 286 | channel_->SendAddChannelRequest(GURL(socket_url), sub_protocols_, origin, |
Yutaka Hirano | 2f65eec | 2018-05-23 01:58:22 | [diff] [blame] | 287 | site_for_cookies, HttpRequestHeaders()); |
ricea | 433bdab | 2015-01-26 07:25:37 | [diff] [blame] | 288 | event_interface_->WaitForResponse(); |
| 289 | return !event_interface_->failed(); |
| 290 | } |
| 291 | |
| 292 | ConnectTestingEventInterface* event_interface_; // owned by channel_ |
danakj | 9c5cab5 | 2016-04-16 00:54:33 | [diff] [blame] | 293 | std::unique_ptr<TestProxyDelegateWithProxyInfo> proxy_delegate_; |
ricea | 433bdab | 2015-01-26 07:25:37 | [diff] [blame] | 294 | TestURLRequestContext context_; |
danakj | 9c5cab5 | 2016-04-16 00:54:33 | [diff] [blame] | 295 | std::unique_ptr<WebSocketChannel> channel_; |
ricea | 5acb1faf7 | 2015-03-16 15:34:00 | [diff] [blame] | 296 | std::vector<std::string> sub_protocols_; |
ricea | 433bdab | 2015-01-26 07:25:37 | [diff] [blame] | 297 | bool initialised_context_; |
| 298 | }; |
| 299 | |
ricea | 433bdab | 2015-01-26 07:25:37 | [diff] [blame] | 300 | // Basic test of connectivity. If this test fails, nothing else can be expected |
| 301 | // to work. |
Sergey Ulanov | 4c786d3 | 2017-09-08 22:53:25 | [diff] [blame] | 302 | TEST_F(WebSocketEndToEndTest, BasicSmokeTest) { |
ricea | 433bdab | 2015-01-26 07:25:37 | [diff] [blame] | 303 | SpawnedTestServer ws_server(SpawnedTestServer::TYPE_WS, |
ricea | 433bdab | 2015-01-26 07:25:37 | [diff] [blame] | 304 | GetWebSocketTestDataDirectory()); |
| 305 | ASSERT_TRUE(ws_server.Start()); |
| 306 | EXPECT_TRUE(ConnectAndWait(ws_server.GetURL(kEchoServer))); |
| 307 | } |
| 308 | |
| 309 | // Test for issue crbug.com/433695 "Unencrypted WebSocket connection via |
| 310 | // authenticated proxy times out" |
| 311 | // TODO(ricea): Enable this when the issue is fixed. |
| 312 | TEST_F(WebSocketEndToEndTest, DISABLED_HttpsProxyUnauthedFails) { |
| 313 | SpawnedTestServer proxy_server(SpawnedTestServer::TYPE_BASIC_AUTH_PROXY, |
ricea | 433bdab | 2015-01-26 07:25:37 | [diff] [blame] | 314 | base::FilePath()); |
| 315 | SpawnedTestServer ws_server(SpawnedTestServer::TYPE_WS, |
ricea | 433bdab | 2015-01-26 07:25:37 | [diff] [blame] | 316 | GetWebSocketTestDataDirectory()); |
| 317 | ASSERT_TRUE(proxy_server.StartInBackground()); |
| 318 | ASSERT_TRUE(ws_server.StartInBackground()); |
| 319 | ASSERT_TRUE(proxy_server.BlockUntilStarted()); |
| 320 | ASSERT_TRUE(ws_server.BlockUntilStarted()); |
| 321 | std::string proxy_config = |
| 322 | "https=" + proxy_server.host_port_pair().ToString(); |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 323 | std::unique_ptr<ProxyResolutionService> proxy_resolution_service( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 324 | ProxyResolutionService::CreateFixed(proxy_config, |
| 325 | TRAFFIC_ANNOTATION_FOR_TESTS)); |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 326 | ASSERT_TRUE(proxy_resolution_service); |
| 327 | context_.set_proxy_resolution_service(proxy_resolution_service.get()); |
ricea | 433bdab | 2015-01-26 07:25:37 | [diff] [blame] | 328 | EXPECT_FALSE(ConnectAndWait(ws_server.GetURL(kEchoServer))); |
| 329 | EXPECT_EQ("Proxy authentication failed", event_interface_->failure_message()); |
| 330 | } |
| 331 | |
Sergey Ulanov | 4c786d3 | 2017-09-08 22:53:25 | [diff] [blame] | 332 | // These test are not compatible with RemoteTestServer because RemoteTestServer |
| 333 | // doesn't support TYPE_BASIC_AUTH_PROXY. |
| 334 | // TODO(ricea): Make these tests work. See crbug.com/441711. |
| 335 | #if defined(OS_ANDROID) || defined(OS_FUCHSIA) |
| 336 | #define MAYBE_HttpsWssProxyUnauthedFails DISABLED_HttpsWssProxyUnauthedFails |
| 337 | #define MAYBE_HttpsProxyUsed DISABLED_HttpsProxyUsed |
| 338 | #else |
| 339 | #define MAYBE_HttpsWssProxyUnauthedFails HttpsWssProxyUnauthedFails |
| 340 | #define MAYBE_HttpsProxyUsed HttpsProxyUsed |
| 341 | #endif |
| 342 | |
| 343 | TEST_F(WebSocketEndToEndTest, MAYBE_HttpsWssProxyUnauthedFails) { |
ricea | 433bdab | 2015-01-26 07:25:37 | [diff] [blame] | 344 | SpawnedTestServer proxy_server(SpawnedTestServer::TYPE_BASIC_AUTH_PROXY, |
ricea | 433bdab | 2015-01-26 07:25:37 | [diff] [blame] | 345 | base::FilePath()); |
| 346 | SpawnedTestServer wss_server(SpawnedTestServer::TYPE_WSS, |
ricea | 433bdab | 2015-01-26 07:25:37 | [diff] [blame] | 347 | GetWebSocketTestDataDirectory()); |
| 348 | ASSERT_TRUE(proxy_server.StartInBackground()); |
| 349 | ASSERT_TRUE(wss_server.StartInBackground()); |
| 350 | ASSERT_TRUE(proxy_server.BlockUntilStarted()); |
| 351 | ASSERT_TRUE(wss_server.BlockUntilStarted()); |
Eric Roman | da790f9 | 2018-11-07 19:17:15 | [diff] [blame] | 352 | ProxyConfig proxy_config; |
| 353 | proxy_config.proxy_rules().ParseFromString( |
| 354 | "https=" + proxy_server.host_port_pair().ToString()); |
| 355 | // TODO(https://crbug.com/901896): Don't rely on proxying localhost. |
| 356 | proxy_config.proxy_rules().bypass_rules.AddRulesToSubtractImplicit(); |
| 357 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 358 | std::unique_ptr<ProxyResolutionService> proxy_resolution_service( |
Eric Roman | da790f9 | 2018-11-07 19:17:15 | [diff] [blame] | 359 | ProxyResolutionService::CreateFixed(ProxyConfigWithAnnotation( |
| 360 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS))); |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 361 | ASSERT_TRUE(proxy_resolution_service); |
| 362 | context_.set_proxy_resolution_service(proxy_resolution_service.get()); |
ricea | 433bdab | 2015-01-26 07:25:37 | [diff] [blame] | 363 | EXPECT_FALSE(ConnectAndWait(wss_server.GetURL(kEchoServer))); |
| 364 | EXPECT_EQ("Proxy authentication failed", event_interface_->failure_message()); |
| 365 | } |
| 366 | |
| 367 | // Regression test for crbug/426736 "WebSocket connections not using configured |
| 368 | // system HTTPS Proxy". |
Sergey Ulanov | 4c786d3 | 2017-09-08 22:53:25 | [diff] [blame] | 369 | TEST_F(WebSocketEndToEndTest, MAYBE_HttpsProxyUsed) { |
Adam Rice | 5b4a3d8 | 2018-08-02 15:28:43 | [diff] [blame] | 370 | SpawnedTestServer proxy_server(SpawnedTestServer::TYPE_PROXY, |
ricea | 433bdab | 2015-01-26 07:25:37 | [diff] [blame] | 371 | base::FilePath()); |
| 372 | SpawnedTestServer ws_server(SpawnedTestServer::TYPE_WS, |
ricea | 433bdab | 2015-01-26 07:25:37 | [diff] [blame] | 373 | GetWebSocketTestDataDirectory()); |
| 374 | ASSERT_TRUE(proxy_server.StartInBackground()); |
| 375 | ASSERT_TRUE(ws_server.StartInBackground()); |
| 376 | ASSERT_TRUE(proxy_server.BlockUntilStarted()); |
| 377 | ASSERT_TRUE(ws_server.BlockUntilStarted()); |
Eric Roman | da790f9 | 2018-11-07 19:17:15 | [diff] [blame] | 378 | ProxyConfig proxy_config; |
| 379 | proxy_config.proxy_rules().ParseFromString( |
| 380 | "https=" + proxy_server.host_port_pair().ToString() + ";" + |
| 381 | "http=" + proxy_server.host_port_pair().ToString()); |
| 382 | // TODO(https://crbug.com/901896): Don't rely on proxying localhost. |
| 383 | proxy_config.proxy_rules().bypass_rules.AddRulesToSubtractImplicit(); |
| 384 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 385 | std::unique_ptr<ProxyResolutionService> proxy_resolution_service( |
Eric Roman | da790f9 | 2018-11-07 19:17:15 | [diff] [blame] | 386 | ProxyResolutionService::CreateFixed(ProxyConfigWithAnnotation( |
| 387 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS))); |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 388 | context_.set_proxy_resolution_service(proxy_resolution_service.get()); |
ricea | 433bdab | 2015-01-26 07:25:37 | [diff] [blame] | 389 | InitialiseContext(); |
| 390 | |
ricea | 433bdab | 2015-01-26 07:25:37 | [diff] [blame] | 391 | GURL ws_url = ws_server.GetURL(kEchoServer); |
| 392 | EXPECT_TRUE(ConnectAndWait(ws_url)); |
ryansturm | 7de050c | 2016-02-23 00:10:21 | [diff] [blame] | 393 | const TestProxyDelegateWithProxyInfo::ResolvedProxyInfo& info = |
| 394 | proxy_delegate_->resolved_proxy_info(); |
ricea | 433bdab | 2015-01-26 07:25:37 | [diff] [blame] | 395 | EXPECT_EQ(ws_url, info.url); |
| 396 | EXPECT_TRUE(info.proxy_info.is_http()); |
| 397 | } |
| 398 | |
Adam Rice | 5b4a3d8 | 2018-08-02 15:28:43 | [diff] [blame] | 399 | std::unique_ptr<HttpResponse> ProxyPacHandler(const HttpRequest& request) { |
| 400 | GURL url = request.GetURL(); |
| 401 | EXPECT_EQ(url.path_piece(), "/proxy.pac"); |
| 402 | EXPECT_TRUE(url.has_query()); |
| 403 | std::string proxy; |
| 404 | EXPECT_TRUE(GetValueForKeyInQuery(url, "proxy", &proxy)); |
| 405 | auto response = std::make_unique<BasicHttpResponse>(); |
| 406 | response->set_content_type("application/x-ns-proxy-autoconfig"); |
| 407 | response->set_content( |
| 408 | base::StringPrintf("function FindProxyForURL(url, host) {\n" |
| 409 | " return 'PROXY %s';\n" |
| 410 | "}\n", |
| 411 | proxy.c_str())); |
| 412 | return response; |
| 413 | } |
| 414 | |
| 415 | // This tests the proxy.pac resolver that is built into the system. This is not |
| 416 | // the one that Chrome normally uses. Chrome's normal implementation is defined |
| 417 | // as a mojo service. It is outside //net and we can't use it from here. This |
| 418 | // tests the alternative implementations that are selected when the |
| 419 | // --winhttp-proxy-resolver flag is provided to Chrome. These only exist on OS X |
| 420 | // and Windows. |
| 421 | // TODO(ricea): Remove this test if --winhttp-proxy-resolver flag is removed. |
| 422 | // See crbug.com/644030. |
| 423 | |
| 424 | #if defined(OS_WIN) || defined(OS_MACOSX) |
| 425 | #define MAYBE_ProxyPacUsed ProxyPacUsed |
| 426 | #else |
| 427 | #define MAYBE_ProxyPacUsed DISABLED_ProxyPacUsed |
| 428 | #endif |
| 429 | |
| 430 | TEST_F(WebSocketEndToEndTest, MAYBE_ProxyPacUsed) { |
| 431 | EmbeddedTestServer proxy_pac_server(net::EmbeddedTestServer::Type::TYPE_HTTP); |
| 432 | SpawnedTestServer proxy_server(SpawnedTestServer::TYPE_PROXY, |
| 433 | base::FilePath()); |
| 434 | SpawnedTestServer ws_server(SpawnedTestServer::TYPE_WS, |
| 435 | GetWebSocketTestDataDirectory()); |
| 436 | proxy_pac_server.RegisterRequestHandler(base::BindRepeating(ProxyPacHandler)); |
| 437 | proxy_server.set_redirect_connect_to_localhost(true); |
| 438 | |
| 439 | ASSERT_TRUE(proxy_pac_server.Start()); |
| 440 | ASSERT_TRUE(proxy_server.StartInBackground()); |
| 441 | ASSERT_TRUE(ws_server.StartInBackground()); |
| 442 | ASSERT_TRUE(proxy_server.BlockUntilStarted()); |
| 443 | ASSERT_TRUE(ws_server.BlockUntilStarted()); |
| 444 | |
| 445 | ProxyConfig proxy_config = |
| 446 | ProxyConfig::CreateFromCustomPacURL(proxy_pac_server.GetURL(base::StrCat( |
| 447 | {"/proxy.pac?proxy=", proxy_server.host_port_pair().ToString()}))); |
| 448 | proxy_config.set_pac_mandatory(true); |
| 449 | auto proxy_config_service = std::make_unique<ProxyConfigServiceFixed>( |
| 450 | ProxyConfigWithAnnotation(proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 451 | NetLog net_log; |
| 452 | std::unique_ptr<ProxyResolutionService> proxy_resolution_service( |
| 453 | ProxyResolutionService::CreateUsingSystemProxyResolver( |
| 454 | std::move(proxy_config_service), &net_log)); |
| 455 | ASSERT_EQ(ws_server.host_port_pair().host(), "127.0.0.1"); |
| 456 | context_.set_proxy_resolution_service(proxy_resolution_service.get()); |
| 457 | InitialiseContext(); |
| 458 | |
Eric Roman | da790f9 | 2018-11-07 19:17:15 | [diff] [blame] | 459 | // Use a name other than localhost, since localhost implicitly bypasses the |
| 460 | // use of proxy.pac. |
Adam Rice | 5b4a3d8 | 2018-08-02 15:28:43 | [diff] [blame] | 461 | HostPortPair fake_ws_host_port_pair("stealth-localhost", |
| 462 | ws_server.host_port_pair().port()); |
| 463 | |
| 464 | GURL ws_url(base::StrCat( |
| 465 | {"ws://", fake_ws_host_port_pair.ToString(), "/", kEchoServer})); |
| 466 | EXPECT_TRUE(ConnectAndWait(ws_url)); |
| 467 | const auto& info = proxy_delegate_->resolved_proxy_info(); |
| 468 | EXPECT_EQ(ws_url, info.url); |
| 469 | EXPECT_TRUE(info.proxy_info.is_http()); |
| 470 | EXPECT_EQ(info.proxy_info.ToPacString(), |
| 471 | base::StrCat({"PROXY ", proxy_server.host_port_pair().ToString()})); |
| 472 | } |
| 473 | |
ricea | 23c3f94 | 2015-02-02 13:35:13 | [diff] [blame] | 474 | // This is a regression test for crbug.com/408061 Crash in |
| 475 | // net::WebSocketBasicHandshakeStream::Upgrade. |
Sergey Ulanov | 4c786d3 | 2017-09-08 22:53:25 | [diff] [blame] | 476 | TEST_F(WebSocketEndToEndTest, TruncatedResponse) { |
ricea | 23c3f94 | 2015-02-02 13:35:13 | [diff] [blame] | 477 | SpawnedTestServer ws_server(SpawnedTestServer::TYPE_WS, |
ricea | 23c3f94 | 2015-02-02 13:35:13 | [diff] [blame] | 478 | GetWebSocketTestDataDirectory()); |
| 479 | ASSERT_TRUE(ws_server.Start()); |
| 480 | InitialiseContext(); |
| 481 | |
| 482 | GURL ws_url = ws_server.GetURL("truncated-headers"); |
| 483 | EXPECT_FALSE(ConnectAndWait(ws_url)); |
| 484 | } |
| 485 | |
Adam Rice | cb76ac6 | 2015-02-20 05:33:25 | [diff] [blame] | 486 | // Regression test for crbug.com/455215 "HSTS not applied to WebSocket" |
Sergey Ulanov | 4c786d3 | 2017-09-08 22:53:25 | [diff] [blame] | 487 | TEST_F(WebSocketEndToEndTest, HstsHttpsToWebSocket) { |
tommycli | 59a6343 | 2015-11-06 00:10:55 | [diff] [blame] | 488 | EmbeddedTestServer https_server(net::EmbeddedTestServer::Type::TYPE_HTTPS); |
| 489 | https_server.SetSSLConfig( |
| 490 | net::EmbeddedTestServer::CERT_COMMON_NAME_IS_DOMAIN); |
| 491 | https_server.ServeFilesFromSourceDirectory("net/data/url_request_unittest"); |
| 492 | |
estark | a5da7670 | 2015-04-09 04:00:16 | [diff] [blame] | 493 | SpawnedTestServer::SSLOptions ssl_options( |
| 494 | SpawnedTestServer::SSLOptions::CERT_COMMON_NAME_IS_DOMAIN); |
Adam Rice | cb76ac6 | 2015-02-20 05:33:25 | [diff] [blame] | 495 | SpawnedTestServer wss_server(SpawnedTestServer::TYPE_WSS, ssl_options, |
| 496 | GetWebSocketTestDataDirectory()); |
estark | a5da7670 | 2015-04-09 04:00:16 | [diff] [blame] | 497 | |
tommycli | 59a6343 | 2015-11-06 00:10:55 | [diff] [blame] | 498 | ASSERT_TRUE(https_server.Start()); |
| 499 | ASSERT_TRUE(wss_server.Start()); |
Adam Rice | cb76ac6 | 2015-02-20 05:33:25 | [diff] [blame] | 500 | InitialiseContext(); |
| 501 | // Set HSTS via https: |
| 502 | TestDelegate delegate; |
tommycli | 59a6343 | 2015-11-06 00:10:55 | [diff] [blame] | 503 | GURL https_page = https_server.GetURL("/hsts-headers.html"); |
rhalavati | 9ebaba7e | 2017-04-27 06:16:29 | [diff] [blame] | 504 | std::unique_ptr<URLRequest> request(context_.CreateRequest( |
| 505 | https_page, DEFAULT_PRIORITY, &delegate, TRAFFIC_ANNOTATION_FOR_TESTS)); |
Adam Rice | cb76ac6 | 2015-02-20 05:33:25 | [diff] [blame] | 506 | request->Start(); |
Wez | 2a31b22 | 2018-06-07 22:07:15 | [diff] [blame] | 507 | delegate.RunUntilComplete(); |
maksim.sisov | 7f60c8e | 2016-09-16 19:38:17 | [diff] [blame] | 508 | EXPECT_EQ(OK, delegate.request_status()); |
Adam Rice | cb76ac6 | 2015-02-20 05:33:25 | [diff] [blame] | 509 | |
| 510 | // Check HSTS with ws: |
| 511 | // Change the scheme from wss: to ws: to verify that it is switched back. |
| 512 | GURL ws_url = ReplaceUrlScheme(wss_server.GetURL(kEchoServer), "ws"); |
| 513 | EXPECT_TRUE(ConnectAndWait(ws_url)); |
| 514 | } |
| 515 | |
Sergey Ulanov | 4c786d3 | 2017-09-08 22:53:25 | [diff] [blame] | 516 | TEST_F(WebSocketEndToEndTest, HstsWebSocketToHttps) { |
tommycli | 59a6343 | 2015-11-06 00:10:55 | [diff] [blame] | 517 | EmbeddedTestServer https_server(net::EmbeddedTestServer::Type::TYPE_HTTPS); |
| 518 | https_server.SetSSLConfig( |
| 519 | net::EmbeddedTestServer::CERT_COMMON_NAME_IS_DOMAIN); |
| 520 | https_server.ServeFilesFromSourceDirectory("net/data/url_request_unittest"); |
| 521 | |
estark | a5da7670 | 2015-04-09 04:00:16 | [diff] [blame] | 522 | SpawnedTestServer::SSLOptions ssl_options( |
| 523 | SpawnedTestServer::SSLOptions::CERT_COMMON_NAME_IS_DOMAIN); |
Adam Rice | cb76ac6 | 2015-02-20 05:33:25 | [diff] [blame] | 524 | SpawnedTestServer wss_server(SpawnedTestServer::TYPE_WSS, ssl_options, |
| 525 | GetWebSocketTestDataDirectory()); |
tommycli | 59a6343 | 2015-11-06 00:10:55 | [diff] [blame] | 526 | ASSERT_TRUE(https_server.Start()); |
| 527 | ASSERT_TRUE(wss_server.Start()); |
Adam Rice | cb76ac6 | 2015-02-20 05:33:25 | [diff] [blame] | 528 | InitialiseContext(); |
| 529 | // Set HSTS via wss: |
| 530 | GURL wss_url = wss_server.GetURL("set-hsts"); |
| 531 | EXPECT_TRUE(ConnectAndWait(wss_url)); |
| 532 | |
| 533 | // Verify via http: |
| 534 | TestDelegate delegate; |
| 535 | GURL http_page = |
tommycli | 59a6343 | 2015-11-06 00:10:55 | [diff] [blame] | 536 | ReplaceUrlScheme(https_server.GetURL("/simple.html"), "http"); |
rhalavati | 9ebaba7e | 2017-04-27 06:16:29 | [diff] [blame] | 537 | std::unique_ptr<URLRequest> request(context_.CreateRequest( |
| 538 | http_page, DEFAULT_PRIORITY, &delegate, TRAFFIC_ANNOTATION_FOR_TESTS)); |
Adam Rice | cb76ac6 | 2015-02-20 05:33:25 | [diff] [blame] | 539 | request->Start(); |
Wez | 2a31b22 | 2018-06-07 22:07:15 | [diff] [blame] | 540 | delegate.RunUntilComplete(); |
maksim.sisov | 7f60c8e | 2016-09-16 19:38:17 | [diff] [blame] | 541 | EXPECT_EQ(OK, delegate.request_status()); |
Adam Rice | cb76ac6 | 2015-02-20 05:33:25 | [diff] [blame] | 542 | EXPECT_TRUE(request->url().SchemeIs("https")); |
| 543 | } |
| 544 | |
Sergey Ulanov | 4c786d3 | 2017-09-08 22:53:25 | [diff] [blame] | 545 | TEST_F(WebSocketEndToEndTest, HstsWebSocketToWebSocket) { |
estark | a5da7670 | 2015-04-09 04:00:16 | [diff] [blame] | 546 | SpawnedTestServer::SSLOptions ssl_options( |
| 547 | SpawnedTestServer::SSLOptions::CERT_COMMON_NAME_IS_DOMAIN); |
Adam Rice | cb76ac6 | 2015-02-20 05:33:25 | [diff] [blame] | 548 | SpawnedTestServer wss_server(SpawnedTestServer::TYPE_WSS, ssl_options, |
| 549 | GetWebSocketTestDataDirectory()); |
| 550 | ASSERT_TRUE(wss_server.Start()); |
| 551 | InitialiseContext(); |
| 552 | // Set HSTS via wss: |
| 553 | GURL wss_url = wss_server.GetURL("set-hsts"); |
| 554 | EXPECT_TRUE(ConnectAndWait(wss_url)); |
| 555 | |
| 556 | // Verify via wss: |
| 557 | GURL ws_url = ReplaceUrlScheme(wss_server.GetURL(kEchoServer), "ws"); |
| 558 | EXPECT_TRUE(ConnectAndWait(ws_url)); |
| 559 | } |
| 560 | |
ricea | 5acb1faf7 | 2015-03-16 15:34:00 | [diff] [blame] | 561 | // Regression test for crbug.com/180504 "WebSocket handshake fails when HTTP |
| 562 | // headers have trailing LWS". |
Sergey Ulanov | 4c786d3 | 2017-09-08 22:53:25 | [diff] [blame] | 563 | TEST_F(WebSocketEndToEndTest, TrailingWhitespace) { |
ricea | 5acb1faf7 | 2015-03-16 15:34:00 | [diff] [blame] | 564 | SpawnedTestServer ws_server(SpawnedTestServer::TYPE_WS, |
ricea | 5acb1faf7 | 2015-03-16 15:34:00 | [diff] [blame] | 565 | GetWebSocketTestDataDirectory()); |
| 566 | ASSERT_TRUE(ws_server.Start()); |
| 567 | |
| 568 | GURL ws_url = ws_server.GetURL("trailing-whitespace"); |
| 569 | sub_protocols_.push_back("sip"); |
| 570 | EXPECT_TRUE(ConnectAndWait(ws_url)); |
| 571 | EXPECT_EQ("sip", event_interface_->selected_subprotocol()); |
| 572 | } |
| 573 | |
ricea | e1d6767 | 2015-03-19 10:10:17 | [diff] [blame] | 574 | // This is a regression test for crbug.com/169448 "WebSockets should support |
| 575 | // header continuations" |
| 576 | // TODO(ricea): HTTP continuation headers have been deprecated by RFC7230. If |
| 577 | // support for continuation headers is removed from Chrome, then this test will |
| 578 | // break and should be removed. |
Sergey Ulanov | 4c786d3 | 2017-09-08 22:53:25 | [diff] [blame] | 579 | TEST_F(WebSocketEndToEndTest, HeaderContinuations) { |
ricea | e1d6767 | 2015-03-19 10:10:17 | [diff] [blame] | 580 | SpawnedTestServer ws_server(SpawnedTestServer::TYPE_WS, |
ricea | e1d6767 | 2015-03-19 10:10:17 | [diff] [blame] | 581 | GetWebSocketTestDataDirectory()); |
| 582 | ASSERT_TRUE(ws_server.Start()); |
| 583 | |
| 584 | GURL ws_url = ws_server.GetURL("header-continuation"); |
| 585 | |
| 586 | EXPECT_TRUE(ConnectAndWait(ws_url)); |
| 587 | EXPECT_EQ("permessage-deflate; server_max_window_bits=10", |
| 588 | event_interface_->extensions()); |
| 589 | } |
| 590 | |
ricea | 433bdab | 2015-01-26 07:25:37 | [diff] [blame] | 591 | } // namespace |
| 592 | |
| 593 | } // namespace net |