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 | |
| 11 | #include <string> |
| 12 | |
| 13 | #include "base/bind.h" |
| 14 | #include "base/bind_helpers.h" |
| 15 | #include "base/callback.h" |
| 16 | #include "base/memory/scoped_ptr.h" |
| 17 | #include "base/message_loop/message_loop.h" |
| 18 | #include "base/run_loop.h" |
Adam Rice | cb76ac6 | 2015-02-20 05:33:25 | [diff] [blame] | 19 | #include "base/strings/string_piece.h" |
ricea | 433bdab | 2015-01-26 07:25:37 | [diff] [blame] | 20 | #include "net/base/auth.h" |
| 21 | #include "net/base/network_delegate.h" |
| 22 | #include "net/base/test_data_directory.h" |
| 23 | #include "net/proxy/proxy_service.h" |
| 24 | #include "net/test/spawned_test_server/spawned_test_server.h" |
| 25 | #include "net/url_request/url_request_test_util.h" |
| 26 | #include "net/websockets/websocket_channel.h" |
| 27 | #include "net/websockets/websocket_event_interface.h" |
| 28 | #include "testing/gtest/include/gtest/gtest.h" |
| 29 | #include "url/origin.h" |
| 30 | |
| 31 | namespace net { |
| 32 | |
| 33 | namespace { |
| 34 | |
| 35 | static const char kEchoServer[] = "echo-with-no-extension"; |
| 36 | |
Adam Rice | cb76ac6 | 2015-02-20 05:33:25 | [diff] [blame] | 37 | // Simplify changing URL schemes. |
| 38 | GURL ReplaceUrlScheme(const GURL& in_url, const base::StringPiece& scheme) { |
| 39 | GURL::Replacements replacements; |
| 40 | replacements.SetSchemeStr(scheme); |
| 41 | return in_url.ReplaceComponents(replacements); |
| 42 | } |
| 43 | |
ricea | 433bdab | 2015-01-26 07:25:37 | [diff] [blame] | 44 | // An implementation of WebSocketEventInterface that waits for and records the |
| 45 | // results of the connect. |
| 46 | class ConnectTestingEventInterface : public WebSocketEventInterface { |
| 47 | public: |
| 48 | ConnectTestingEventInterface(); |
| 49 | |
| 50 | void WaitForResponse(); |
| 51 | |
| 52 | bool failed() const { return failed_; } |
| 53 | |
| 54 | // Only set if the handshake failed, otherwise empty. |
| 55 | std::string failure_message() const; |
| 56 | |
| 57 | std::string selected_subprotocol() const; |
| 58 | |
| 59 | std::string extensions() const; |
| 60 | |
| 61 | // Implementation of WebSocketEventInterface. |
tyoshino | c06da56 | 2015-03-06 06:02:42 | [diff] [blame] | 62 | ChannelState OnAddChannelResponse(const std::string& selected_subprotocol, |
ricea | 433bdab | 2015-01-26 07:25:37 | [diff] [blame] | 63 | const std::string& extensions) override; |
| 64 | |
| 65 | ChannelState OnDataFrame(bool fin, |
| 66 | WebSocketMessageType type, |
| 67 | const std::vector<char>& data) override; |
| 68 | |
| 69 | ChannelState OnFlowControl(int64 quota) override; |
| 70 | |
| 71 | ChannelState OnClosingHandshake() override; |
| 72 | |
| 73 | ChannelState OnDropChannel(bool was_clean, |
| 74 | uint16 code, |
| 75 | const std::string& reason) override; |
| 76 | |
| 77 | ChannelState OnFailChannel(const std::string& message) override; |
| 78 | |
| 79 | ChannelState OnStartOpeningHandshake( |
| 80 | scoped_ptr<WebSocketHandshakeRequestInfo> request) override; |
| 81 | |
| 82 | ChannelState OnFinishOpeningHandshake( |
| 83 | scoped_ptr<WebSocketHandshakeResponseInfo> response) override; |
| 84 | |
| 85 | ChannelState OnSSLCertificateError( |
| 86 | scoped_ptr<SSLErrorCallbacks> ssl_error_callbacks, |
| 87 | const GURL& url, |
| 88 | const SSLInfo& ssl_info, |
| 89 | bool fatal) override; |
| 90 | |
| 91 | private: |
| 92 | void QuitNestedEventLoop(); |
| 93 | |
| 94 | // failed_ is true if the handshake failed (ie. OnFailChannel was called). |
| 95 | bool failed_; |
| 96 | std::string selected_subprotocol_; |
| 97 | std::string extensions_; |
| 98 | std::string failure_message_; |
| 99 | base::RunLoop run_loop_; |
| 100 | |
| 101 | DISALLOW_COPY_AND_ASSIGN(ConnectTestingEventInterface); |
| 102 | }; |
| 103 | |
tyoshino | c06da56 | 2015-03-06 06:02:42 | [diff] [blame] | 104 | ConnectTestingEventInterface::ConnectTestingEventInterface() : failed_(false) { |
ricea | 433bdab | 2015-01-26 07:25:37 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | void ConnectTestingEventInterface::WaitForResponse() { |
| 108 | run_loop_.Run(); |
| 109 | } |
| 110 | |
| 111 | std::string ConnectTestingEventInterface::failure_message() const { |
| 112 | return failure_message_; |
| 113 | } |
| 114 | |
| 115 | std::string ConnectTestingEventInterface::selected_subprotocol() const { |
| 116 | return selected_subprotocol_; |
| 117 | } |
| 118 | |
| 119 | std::string ConnectTestingEventInterface::extensions() const { |
| 120 | return extensions_; |
| 121 | } |
| 122 | |
| 123 | // Make the function definitions below less verbose. |
| 124 | typedef ConnectTestingEventInterface::ChannelState ChannelState; |
| 125 | |
| 126 | ChannelState ConnectTestingEventInterface::OnAddChannelResponse( |
ricea | 433bdab | 2015-01-26 07:25:37 | [diff] [blame] | 127 | const std::string& selected_subprotocol, |
| 128 | const std::string& extensions) { |
ricea | 433bdab | 2015-01-26 07:25:37 | [diff] [blame] | 129 | selected_subprotocol_ = selected_subprotocol; |
| 130 | extensions_ = extensions; |
| 131 | QuitNestedEventLoop(); |
tyoshino | c06da56 | 2015-03-06 06:02:42 | [diff] [blame] | 132 | return CHANNEL_ALIVE; |
ricea | 433bdab | 2015-01-26 07:25:37 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | ChannelState ConnectTestingEventInterface::OnDataFrame( |
| 136 | bool fin, |
| 137 | WebSocketMessageType type, |
| 138 | const std::vector<char>& data) { |
| 139 | return CHANNEL_ALIVE; |
| 140 | } |
| 141 | |
| 142 | ChannelState ConnectTestingEventInterface::OnFlowControl(int64 quota) { |
| 143 | return CHANNEL_ALIVE; |
| 144 | } |
| 145 | |
| 146 | ChannelState ConnectTestingEventInterface::OnClosingHandshake() { |
| 147 | return CHANNEL_ALIVE; |
| 148 | } |
| 149 | |
| 150 | ChannelState ConnectTestingEventInterface::OnDropChannel( |
| 151 | bool was_clean, |
| 152 | uint16 code, |
| 153 | const std::string& reason) { |
| 154 | return CHANNEL_DELETED; |
| 155 | } |
| 156 | |
| 157 | ChannelState ConnectTestingEventInterface::OnFailChannel( |
| 158 | const std::string& message) { |
| 159 | failed_ = true; |
| 160 | failure_message_ = message; |
| 161 | QuitNestedEventLoop(); |
| 162 | return CHANNEL_DELETED; |
| 163 | } |
| 164 | |
| 165 | ChannelState ConnectTestingEventInterface::OnStartOpeningHandshake( |
| 166 | scoped_ptr<WebSocketHandshakeRequestInfo> request) { |
| 167 | return CHANNEL_ALIVE; |
| 168 | } |
| 169 | |
| 170 | ChannelState ConnectTestingEventInterface::OnFinishOpeningHandshake( |
| 171 | scoped_ptr<WebSocketHandshakeResponseInfo> response) { |
| 172 | return CHANNEL_ALIVE; |
| 173 | } |
| 174 | |
| 175 | ChannelState ConnectTestingEventInterface::OnSSLCertificateError( |
| 176 | scoped_ptr<SSLErrorCallbacks> ssl_error_callbacks, |
| 177 | const GURL& url, |
| 178 | const SSLInfo& ssl_info, |
| 179 | bool fatal) { |
| 180 | base::MessageLoop::current()->PostTask( |
| 181 | FROM_HERE, base::Bind(&SSLErrorCallbacks::CancelSSLRequest, |
| 182 | base::Owned(ssl_error_callbacks.release()), |
| 183 | ERR_SSL_PROTOCOL_ERROR, &ssl_info)); |
| 184 | return CHANNEL_ALIVE; |
| 185 | } |
| 186 | |
| 187 | void ConnectTestingEventInterface::QuitNestedEventLoop() { |
| 188 | run_loop_.Quit(); |
| 189 | } |
| 190 | |
| 191 | // A subclass of TestNetworkDelegate that additionally implements the |
| 192 | // OnResolveProxy callback and records the information passed to it. |
| 193 | class TestNetworkDelegateWithProxyInfo : public TestNetworkDelegate { |
| 194 | public: |
| 195 | TestNetworkDelegateWithProxyInfo() {} |
| 196 | |
| 197 | struct ResolvedProxyInfo { |
| 198 | GURL url; |
| 199 | ProxyInfo proxy_info; |
| 200 | }; |
| 201 | |
| 202 | const ResolvedProxyInfo& resolved_proxy_info() const { |
| 203 | return resolved_proxy_info_; |
| 204 | } |
| 205 | |
| 206 | protected: |
| 207 | void OnResolveProxy(const GURL& url, |
| 208 | int load_flags, |
| 209 | const ProxyService& proxy_service, |
| 210 | ProxyInfo* result) override { |
| 211 | resolved_proxy_info_.url = url; |
| 212 | resolved_proxy_info_.proxy_info = *result; |
| 213 | } |
| 214 | |
| 215 | private: |
| 216 | ResolvedProxyInfo resolved_proxy_info_; |
| 217 | |
| 218 | DISALLOW_COPY_AND_ASSIGN(TestNetworkDelegateWithProxyInfo); |
| 219 | }; |
| 220 | |
| 221 | class WebSocketEndToEndTest : public ::testing::Test { |
| 222 | protected: |
| 223 | WebSocketEndToEndTest() |
Adam Rice | cb76ac6 | 2015-02-20 05:33:25 | [diff] [blame] | 224 | : event_interface_(), |
ricea | 433bdab | 2015-01-26 07:25:37 | [diff] [blame] | 225 | network_delegate_(new TestNetworkDelegateWithProxyInfo), |
| 226 | context_(true), |
Adam Rice | cb76ac6 | 2015-02-20 05:33:25 | [diff] [blame] | 227 | channel_(), |
ricea | 433bdab | 2015-01-26 07:25:37 | [diff] [blame] | 228 | initialised_context_(false) {} |
| 229 | |
| 230 | // Initialise the URLRequestContext. Normally done automatically by |
| 231 | // ConnectAndWait(). This method is for the use of tests that need the |
| 232 | // URLRequestContext initialised before calling ConnectAndWait(). |
| 233 | void InitialiseContext() { |
| 234 | context_.set_network_delegate(network_delegate_.get()); |
| 235 | context_.Init(); |
| 236 | initialised_context_ = true; |
| 237 | } |
| 238 | |
| 239 | // Send the connect request to |socket_url| and wait for a response. Returns |
| 240 | // true if the handshake succeeded. |
| 241 | bool ConnectAndWait(const GURL& socket_url) { |
| 242 | if (!initialised_context_) { |
| 243 | InitialiseContext(); |
| 244 | } |
ricea | 433bdab | 2015-01-26 07:25:37 | [diff] [blame] | 245 | url::Origin origin("http://localhost"); |
Adam Rice | cb76ac6 | 2015-02-20 05:33:25 | [diff] [blame] | 246 | event_interface_ = new ConnectTestingEventInterface; |
| 247 | channel_.reset( |
| 248 | new WebSocketChannel(make_scoped_ptr(event_interface_), &context_)); |
ricea | 5acb1faf7 | 2015-03-16 15:34:00 | [diff] [blame] | 249 | channel_->SendAddChannelRequest(GURL(socket_url), sub_protocols_, origin); |
ricea | 433bdab | 2015-01-26 07:25:37 | [diff] [blame] | 250 | event_interface_->WaitForResponse(); |
| 251 | return !event_interface_->failed(); |
| 252 | } |
| 253 | |
| 254 | ConnectTestingEventInterface* event_interface_; // owned by channel_ |
| 255 | scoped_ptr<TestNetworkDelegateWithProxyInfo> network_delegate_; |
| 256 | TestURLRequestContext context_; |
Adam Rice | cb76ac6 | 2015-02-20 05:33:25 | [diff] [blame] | 257 | scoped_ptr<WebSocketChannel> channel_; |
ricea | 5acb1faf7 | 2015-03-16 15:34:00 | [diff] [blame] | 258 | std::vector<std::string> sub_protocols_; |
ricea | 433bdab | 2015-01-26 07:25:37 | [diff] [blame] | 259 | bool initialised_context_; |
| 260 | }; |
| 261 | |
| 262 | // None of these tests work on Android. |
| 263 | // TODO(ricea): Make these tests work on Android. See crbug.com/441711. |
| 264 | #if defined(OS_ANDROID) |
| 265 | #define DISABLED_ON_ANDROID(test) DISABLED_##test |
| 266 | #else |
| 267 | #define DISABLED_ON_ANDROID(test) test |
| 268 | #endif |
| 269 | |
| 270 | // Basic test of connectivity. If this test fails, nothing else can be expected |
| 271 | // to work. |
| 272 | TEST_F(WebSocketEndToEndTest, DISABLED_ON_ANDROID(BasicSmokeTest)) { |
| 273 | SpawnedTestServer ws_server(SpawnedTestServer::TYPE_WS, |
| 274 | SpawnedTestServer::kLocalhost, |
| 275 | GetWebSocketTestDataDirectory()); |
| 276 | ASSERT_TRUE(ws_server.Start()); |
| 277 | EXPECT_TRUE(ConnectAndWait(ws_server.GetURL(kEchoServer))); |
| 278 | } |
| 279 | |
| 280 | // Test for issue crbug.com/433695 "Unencrypted WebSocket connection via |
| 281 | // authenticated proxy times out" |
| 282 | // TODO(ricea): Enable this when the issue is fixed. |
| 283 | TEST_F(WebSocketEndToEndTest, DISABLED_HttpsProxyUnauthedFails) { |
| 284 | SpawnedTestServer proxy_server(SpawnedTestServer::TYPE_BASIC_AUTH_PROXY, |
| 285 | SpawnedTestServer::kLocalhost, |
| 286 | base::FilePath()); |
| 287 | SpawnedTestServer ws_server(SpawnedTestServer::TYPE_WS, |
| 288 | SpawnedTestServer::kLocalhost, |
| 289 | GetWebSocketTestDataDirectory()); |
| 290 | ASSERT_TRUE(proxy_server.StartInBackground()); |
| 291 | ASSERT_TRUE(ws_server.StartInBackground()); |
| 292 | ASSERT_TRUE(proxy_server.BlockUntilStarted()); |
| 293 | ASSERT_TRUE(ws_server.BlockUntilStarted()); |
| 294 | std::string proxy_config = |
| 295 | "https=" + proxy_server.host_port_pair().ToString(); |
| 296 | scoped_ptr<ProxyService> proxy_service( |
| 297 | ProxyService::CreateFixed(proxy_config)); |
| 298 | ASSERT_TRUE(proxy_service); |
| 299 | context_.set_proxy_service(proxy_service.get()); |
| 300 | EXPECT_FALSE(ConnectAndWait(ws_server.GetURL(kEchoServer))); |
| 301 | EXPECT_EQ("Proxy authentication failed", event_interface_->failure_message()); |
| 302 | } |
| 303 | |
| 304 | TEST_F(WebSocketEndToEndTest, DISABLED_ON_ANDROID(HttpsWssProxyUnauthedFails)) { |
| 305 | SpawnedTestServer proxy_server(SpawnedTestServer::TYPE_BASIC_AUTH_PROXY, |
| 306 | SpawnedTestServer::kLocalhost, |
| 307 | base::FilePath()); |
| 308 | SpawnedTestServer wss_server(SpawnedTestServer::TYPE_WSS, |
| 309 | SpawnedTestServer::kLocalhost, |
| 310 | GetWebSocketTestDataDirectory()); |
| 311 | ASSERT_TRUE(proxy_server.StartInBackground()); |
| 312 | ASSERT_TRUE(wss_server.StartInBackground()); |
| 313 | ASSERT_TRUE(proxy_server.BlockUntilStarted()); |
| 314 | ASSERT_TRUE(wss_server.BlockUntilStarted()); |
| 315 | std::string proxy_config = |
| 316 | "https=" + proxy_server.host_port_pair().ToString(); |
| 317 | scoped_ptr<ProxyService> proxy_service( |
| 318 | ProxyService::CreateFixed(proxy_config)); |
| 319 | ASSERT_TRUE(proxy_service); |
| 320 | context_.set_proxy_service(proxy_service.get()); |
| 321 | EXPECT_FALSE(ConnectAndWait(wss_server.GetURL(kEchoServer))); |
| 322 | EXPECT_EQ("Proxy authentication failed", event_interface_->failure_message()); |
| 323 | } |
| 324 | |
| 325 | // Regression test for crbug/426736 "WebSocket connections not using configured |
| 326 | // system HTTPS Proxy". |
| 327 | TEST_F(WebSocketEndToEndTest, DISABLED_ON_ANDROID(HttpsProxyUsed)) { |
| 328 | SpawnedTestServer proxy_server(SpawnedTestServer::TYPE_BASIC_AUTH_PROXY, |
| 329 | SpawnedTestServer::kLocalhost, |
| 330 | base::FilePath()); |
| 331 | SpawnedTestServer ws_server(SpawnedTestServer::TYPE_WS, |
| 332 | SpawnedTestServer::kLocalhost, |
| 333 | GetWebSocketTestDataDirectory()); |
| 334 | ASSERT_TRUE(proxy_server.StartInBackground()); |
| 335 | ASSERT_TRUE(ws_server.StartInBackground()); |
| 336 | ASSERT_TRUE(proxy_server.BlockUntilStarted()); |
| 337 | ASSERT_TRUE(ws_server.BlockUntilStarted()); |
| 338 | std::string proxy_config = "https=" + |
| 339 | proxy_server.host_port_pair().ToString() + ";" + |
| 340 | "http=" + proxy_server.host_port_pair().ToString(); |
| 341 | scoped_ptr<ProxyService> proxy_service( |
| 342 | ProxyService::CreateFixed(proxy_config)); |
| 343 | context_.set_proxy_service(proxy_service.get()); |
| 344 | InitialiseContext(); |
| 345 | |
| 346 | // The test server doesn't have an unauthenticated proxy mode. WebSockets |
| 347 | // cannot provide auth information that isn't already cached, so it's |
| 348 | // necessary to preflight an HTTP request to authenticate against the proxy. |
ricea | 433bdab | 2015-01-26 07:25:37 | [diff] [blame] | 349 | // It doesn't matter what the URL is, as long as it is an HTTP navigation. |
| 350 | GURL http_page = |
Adam Rice | cb76ac6 | 2015-02-20 05:33:25 | [diff] [blame] | 351 | ReplaceUrlScheme(ws_server.GetURL("connect_check.html"), "http"); |
ricea | 433bdab | 2015-01-26 07:25:37 | [diff] [blame] | 352 | TestDelegate delegate; |
| 353 | delegate.set_credentials( |
| 354 | AuthCredentials(base::ASCIIToUTF16("foo"), base::ASCIIToUTF16("bar"))); |
| 355 | { |
| 356 | scoped_ptr<URLRequest> request( |
| 357 | context_.CreateRequest(http_page, DEFAULT_PRIORITY, &delegate, NULL)); |
| 358 | request->Start(); |
| 359 | // TestDelegate exits the message loop when the request completes by |
| 360 | // default. |
| 361 | base::RunLoop().Run(); |
| 362 | EXPECT_TRUE(delegate.auth_required_called()); |
| 363 | } |
| 364 | |
| 365 | GURL ws_url = ws_server.GetURL(kEchoServer); |
| 366 | EXPECT_TRUE(ConnectAndWait(ws_url)); |
| 367 | const TestNetworkDelegateWithProxyInfo::ResolvedProxyInfo& info = |
| 368 | network_delegate_->resolved_proxy_info(); |
| 369 | EXPECT_EQ(ws_url, info.url); |
| 370 | EXPECT_TRUE(info.proxy_info.is_http()); |
| 371 | } |
| 372 | |
ricea | 23c3f94 | 2015-02-02 13:35:13 | [diff] [blame] | 373 | // This is a regression test for crbug.com/408061 Crash in |
| 374 | // net::WebSocketBasicHandshakeStream::Upgrade. |
| 375 | TEST_F(WebSocketEndToEndTest, DISABLED_ON_ANDROID(TruncatedResponse)) { |
| 376 | SpawnedTestServer ws_server(SpawnedTestServer::TYPE_WS, |
| 377 | SpawnedTestServer::kLocalhost, |
| 378 | GetWebSocketTestDataDirectory()); |
| 379 | ASSERT_TRUE(ws_server.Start()); |
| 380 | InitialiseContext(); |
| 381 | |
| 382 | GURL ws_url = ws_server.GetURL("truncated-headers"); |
| 383 | EXPECT_FALSE(ConnectAndWait(ws_url)); |
| 384 | } |
| 385 | |
Adam Rice | cb76ac6 | 2015-02-20 05:33:25 | [diff] [blame] | 386 | // Regression test for crbug.com/455215 "HSTS not applied to WebSocket" |
| 387 | TEST_F(WebSocketEndToEndTest, DISABLED_ON_ANDROID(HstsHttpsToWebSocket)) { |
| 388 | SpawnedTestServer::SSLOptions ssl_options; |
| 389 | SpawnedTestServer https_server( |
| 390 | SpawnedTestServer::TYPE_HTTPS, ssl_options, |
| 391 | base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); |
| 392 | SpawnedTestServer wss_server(SpawnedTestServer::TYPE_WSS, ssl_options, |
| 393 | GetWebSocketTestDataDirectory()); |
| 394 | ASSERT_TRUE(https_server.StartInBackground()); |
| 395 | ASSERT_TRUE(wss_server.StartInBackground()); |
| 396 | ASSERT_TRUE(https_server.BlockUntilStarted()); |
| 397 | ASSERT_TRUE(wss_server.BlockUntilStarted()); |
| 398 | InitialiseContext(); |
| 399 | // Set HSTS via https: |
| 400 | TestDelegate delegate; |
| 401 | GURL https_page = https_server.GetURL("files/hsts-headers.html"); |
| 402 | scoped_ptr<URLRequest> request( |
| 403 | context_.CreateRequest(https_page, DEFAULT_PRIORITY, &delegate, NULL)); |
| 404 | request->Start(); |
| 405 | // TestDelegate exits the message loop when the request completes. |
| 406 | base::RunLoop().Run(); |
| 407 | EXPECT_TRUE(request->status().is_success()); |
| 408 | |
| 409 | // Check HSTS with ws: |
| 410 | // Change the scheme from wss: to ws: to verify that it is switched back. |
| 411 | GURL ws_url = ReplaceUrlScheme(wss_server.GetURL(kEchoServer), "ws"); |
| 412 | EXPECT_TRUE(ConnectAndWait(ws_url)); |
| 413 | } |
| 414 | |
| 415 | TEST_F(WebSocketEndToEndTest, DISABLED_ON_ANDROID(HstsWebSocketToHttps)) { |
| 416 | SpawnedTestServer::SSLOptions ssl_options; |
| 417 | SpawnedTestServer https_server( |
| 418 | SpawnedTestServer::TYPE_HTTPS, ssl_options, |
| 419 | base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); |
| 420 | SpawnedTestServer wss_server(SpawnedTestServer::TYPE_WSS, ssl_options, |
| 421 | GetWebSocketTestDataDirectory()); |
| 422 | ASSERT_TRUE(https_server.StartInBackground()); |
| 423 | ASSERT_TRUE(wss_server.StartInBackground()); |
| 424 | ASSERT_TRUE(https_server.BlockUntilStarted()); |
| 425 | ASSERT_TRUE(wss_server.BlockUntilStarted()); |
| 426 | InitialiseContext(); |
| 427 | // Set HSTS via wss: |
| 428 | GURL wss_url = wss_server.GetURL("set-hsts"); |
| 429 | EXPECT_TRUE(ConnectAndWait(wss_url)); |
| 430 | |
| 431 | // Verify via http: |
| 432 | TestDelegate delegate; |
| 433 | GURL http_page = |
| 434 | ReplaceUrlScheme(https_server.GetURL("files/simple.html"), "http"); |
| 435 | scoped_ptr<URLRequest> request( |
| 436 | context_.CreateRequest(http_page, DEFAULT_PRIORITY, &delegate, NULL)); |
| 437 | request->Start(); |
| 438 | // TestDelegate exits the message loop when the request completes. |
| 439 | base::RunLoop().Run(); |
| 440 | EXPECT_TRUE(request->status().is_success()); |
| 441 | EXPECT_TRUE(request->url().SchemeIs("https")); |
| 442 | } |
| 443 | |
| 444 | TEST_F(WebSocketEndToEndTest, DISABLED_ON_ANDROID(HstsWebSocketToWebSocket)) { |
| 445 | SpawnedTestServer::SSLOptions ssl_options; |
| 446 | SpawnedTestServer wss_server(SpawnedTestServer::TYPE_WSS, ssl_options, |
| 447 | GetWebSocketTestDataDirectory()); |
| 448 | ASSERT_TRUE(wss_server.Start()); |
| 449 | InitialiseContext(); |
| 450 | // Set HSTS via wss: |
| 451 | GURL wss_url = wss_server.GetURL("set-hsts"); |
| 452 | EXPECT_TRUE(ConnectAndWait(wss_url)); |
| 453 | |
| 454 | // Verify via wss: |
| 455 | GURL ws_url = ReplaceUrlScheme(wss_server.GetURL(kEchoServer), "ws"); |
| 456 | EXPECT_TRUE(ConnectAndWait(ws_url)); |
| 457 | } |
| 458 | |
ricea | 5acb1faf7 | 2015-03-16 15:34:00 | [diff] [blame] | 459 | // Regression test for crbug.com/180504 "WebSocket handshake fails when HTTP |
| 460 | // headers have trailing LWS". |
| 461 | TEST_F(WebSocketEndToEndTest, DISABLED_ON_ANDROID(TrailingWhitespace)) { |
| 462 | SpawnedTestServer ws_server(SpawnedTestServer::TYPE_WS, |
| 463 | SpawnedTestServer::kLocalhost, |
| 464 | GetWebSocketTestDataDirectory()); |
| 465 | ASSERT_TRUE(ws_server.Start()); |
| 466 | |
| 467 | GURL ws_url = ws_server.GetURL("trailing-whitespace"); |
| 468 | sub_protocols_.push_back("sip"); |
| 469 | EXPECT_TRUE(ConnectAndWait(ws_url)); |
| 470 | EXPECT_EQ("sip", event_interface_->selected_subprotocol()); |
| 471 | } |
| 472 | |
ricea | e1d6767 | 2015-03-19 10:10:17 | [diff] [blame^] | 473 | // This is a regression test for crbug.com/169448 "WebSockets should support |
| 474 | // header continuations" |
| 475 | // TODO(ricea): HTTP continuation headers have been deprecated by RFC7230. If |
| 476 | // support for continuation headers is removed from Chrome, then this test will |
| 477 | // break and should be removed. |
| 478 | TEST_F(WebSocketEndToEndTest, DISABLED_ON_ANDROID(HeaderContinuations)) { |
| 479 | SpawnedTestServer ws_server(SpawnedTestServer::TYPE_WS, |
| 480 | SpawnedTestServer::kLocalhost, |
| 481 | GetWebSocketTestDataDirectory()); |
| 482 | ASSERT_TRUE(ws_server.Start()); |
| 483 | |
| 484 | GURL ws_url = ws_server.GetURL("header-continuation"); |
| 485 | |
| 486 | EXPECT_TRUE(ConnectAndWait(ws_url)); |
| 487 | EXPECT_EQ("permessage-deflate; server_max_window_bits=10", |
| 488 | event_interface_->extensions()); |
| 489 | } |
| 490 | |
ricea | 433bdab | 2015-01-26 07:25:37 | [diff] [blame] | 491 | } // namespace |
| 492 | |
| 493 | } // namespace net |