blob: afb0448dd8b7518237ebfe09f753488d1317a3f3 [file] [log] [blame]
ricea433bdab2015-01-26 07:25:371// 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
tfarina8a2c66c22015-10-13 19:14:4911#include <stdint.h>
ryansturm4bab06832016-03-03 23:41:0712
danakj9c5cab52016-04-16 00:54:3313#include <memory>
ricea433bdab2015-01-26 07:25:3714#include <string>
15
16#include "base/bind.h"
17#include "base/bind_helpers.h"
18#include "base/callback.h"
skyostil4891b25b2015-06-11 11:43:4519#include "base/location.h"
Avi Drissman13fc8932015-12-20 04:40:4620#include "base/macros.h"
danakj9c5cab52016-04-16 00:54:3321#include "base/memory/ptr_util.h"
ricea433bdab2015-01-26 07:25:3722#include "base/run_loop.h"
skyostil4891b25b2015-06-11 11:43:4523#include "base/single_thread_task_runner.h"
Adam Ricecb76ac62015-02-20 05:33:2524#include "base/strings/string_piece.h"
gabf767595f2016-05-11 18:50:3525#include "base/threading/thread_task_runner_handle.h"
ricea433bdab2015-01-26 07:25:3726#include "net/base/auth.h"
ryansturm7de050c2016-02-23 00:10:2127#include "net/base/proxy_delegate.h"
ricea433bdab2015-01-26 07:25:3728#include "net/proxy/proxy_service.h"
tommycli59a63432015-11-06 00:10:5529#include "net/test/embedded_test_server/embedded_test_server.h"
ricea433bdab2015-01-26 07:25:3730#include "net/test/spawned_test_server/spawned_test_server.h"
rsleevia69c79a2016-06-22 03:28:4331#include "net/test/test_data_directory.h"
ricea433bdab2015-01-26 07:25:3732#include "net/url_request/url_request_test_util.h"
33#include "net/websockets/websocket_channel.h"
34#include "net/websockets/websocket_event_interface.h"
35#include "testing/gtest/include/gtest/gtest.h"
mkwst4997ce82015-07-25 12:00:0536#include "url/origin.h"
ricea433bdab2015-01-26 07:25:3737
38namespace net {
39
40namespace {
41
42static const char kEchoServer[] = "echo-with-no-extension";
43
Adam Ricecb76ac62015-02-20 05:33:2544// Simplify changing URL schemes.
45GURL ReplaceUrlScheme(const GURL& in_url, const base::StringPiece& scheme) {
46 GURL::Replacements replacements;
47 replacements.SetSchemeStr(scheme);
48 return in_url.ReplaceComponents(replacements);
49}
50
ricea433bdab2015-01-26 07:25:3751// An implementation of WebSocketEventInterface that waits for and records the
52// results of the connect.
53class ConnectTestingEventInterface : public WebSocketEventInterface {
54 public:
55 ConnectTestingEventInterface();
56
57 void WaitForResponse();
58
59 bool failed() const { return failed_; }
60
61 // Only set if the handshake failed, otherwise empty.
62 std::string failure_message() const;
63
64 std::string selected_subprotocol() const;
65
66 std::string extensions() const;
67
68 // Implementation of WebSocketEventInterface.
tyoshinoc06da562015-03-06 06:02:4269 ChannelState OnAddChannelResponse(const std::string& selected_subprotocol,
ricea433bdab2015-01-26 07:25:3770 const std::string& extensions) override;
71
72 ChannelState OnDataFrame(bool fin,
73 WebSocketMessageType type,
74 const std::vector<char>& data) override;
75
tfarina8a2c66c22015-10-13 19:14:4976 ChannelState OnFlowControl(int64_t quota) override;
ricea433bdab2015-01-26 07:25:3777
78 ChannelState OnClosingHandshake() override;
79
80 ChannelState OnDropChannel(bool was_clean,
tfarina8a2c66c22015-10-13 19:14:4981 uint16_t code,
ricea433bdab2015-01-26 07:25:3782 const std::string& reason) override;
83
84 ChannelState OnFailChannel(const std::string& message) override;
85
86 ChannelState OnStartOpeningHandshake(
danakj9c5cab52016-04-16 00:54:3387 std::unique_ptr<WebSocketHandshakeRequestInfo> request) override;
ricea433bdab2015-01-26 07:25:3788
89 ChannelState OnFinishOpeningHandshake(
danakj9c5cab52016-04-16 00:54:3390 std::unique_ptr<WebSocketHandshakeResponseInfo> response) override;
ricea433bdab2015-01-26 07:25:3791
92 ChannelState OnSSLCertificateError(
danakj9c5cab52016-04-16 00:54:3393 std::unique_ptr<SSLErrorCallbacks> ssl_error_callbacks,
ricea433bdab2015-01-26 07:25:3794 const GURL& url,
95 const SSLInfo& ssl_info,
96 bool fatal) override;
97
98 private:
99 void QuitNestedEventLoop();
100
101 // failed_ is true if the handshake failed (ie. OnFailChannel was called).
102 bool failed_;
103 std::string selected_subprotocol_;
104 std::string extensions_;
105 std::string failure_message_;
106 base::RunLoop run_loop_;
107
108 DISALLOW_COPY_AND_ASSIGN(ConnectTestingEventInterface);
109};
110
tyoshinoc06da562015-03-06 06:02:42111ConnectTestingEventInterface::ConnectTestingEventInterface() : failed_(false) {
ricea433bdab2015-01-26 07:25:37112}
113
114void ConnectTestingEventInterface::WaitForResponse() {
115 run_loop_.Run();
116}
117
118std::string ConnectTestingEventInterface::failure_message() const {
119 return failure_message_;
120}
121
122std::string ConnectTestingEventInterface::selected_subprotocol() const {
123 return selected_subprotocol_;
124}
125
126std::string ConnectTestingEventInterface::extensions() const {
127 return extensions_;
128}
129
130// Make the function definitions below less verbose.
131typedef ConnectTestingEventInterface::ChannelState ChannelState;
132
133ChannelState ConnectTestingEventInterface::OnAddChannelResponse(
ricea433bdab2015-01-26 07:25:37134 const std::string& selected_subprotocol,
135 const std::string& extensions) {
ricea433bdab2015-01-26 07:25:37136 selected_subprotocol_ = selected_subprotocol;
137 extensions_ = extensions;
138 QuitNestedEventLoop();
tyoshinoc06da562015-03-06 06:02:42139 return CHANNEL_ALIVE;
ricea433bdab2015-01-26 07:25:37140}
141
142ChannelState ConnectTestingEventInterface::OnDataFrame(
143 bool fin,
144 WebSocketMessageType type,
145 const std::vector<char>& data) {
146 return CHANNEL_ALIVE;
147}
148
tfarina8a2c66c22015-10-13 19:14:49149ChannelState ConnectTestingEventInterface::OnFlowControl(int64_t quota) {
ricea433bdab2015-01-26 07:25:37150 return CHANNEL_ALIVE;
151}
152
153ChannelState ConnectTestingEventInterface::OnClosingHandshake() {
154 return CHANNEL_ALIVE;
155}
156
157ChannelState ConnectTestingEventInterface::OnDropChannel(
158 bool was_clean,
tfarina8a2c66c22015-10-13 19:14:49159 uint16_t code,
ricea433bdab2015-01-26 07:25:37160 const std::string& reason) {
161 return CHANNEL_DELETED;
162}
163
164ChannelState ConnectTestingEventInterface::OnFailChannel(
165 const std::string& message) {
166 failed_ = true;
167 failure_message_ = message;
168 QuitNestedEventLoop();
169 return CHANNEL_DELETED;
170}
171
172ChannelState ConnectTestingEventInterface::OnStartOpeningHandshake(
danakj9c5cab52016-04-16 00:54:33173 std::unique_ptr<WebSocketHandshakeRequestInfo> request) {
ricea433bdab2015-01-26 07:25:37174 return CHANNEL_ALIVE;
175}
176
177ChannelState ConnectTestingEventInterface::OnFinishOpeningHandshake(
danakj9c5cab52016-04-16 00:54:33178 std::unique_ptr<WebSocketHandshakeResponseInfo> response) {
ricea433bdab2015-01-26 07:25:37179 return CHANNEL_ALIVE;
180}
181
182ChannelState ConnectTestingEventInterface::OnSSLCertificateError(
danakj9c5cab52016-04-16 00:54:33183 std::unique_ptr<SSLErrorCallbacks> ssl_error_callbacks,
ricea433bdab2015-01-26 07:25:37184 const GURL& url,
185 const SSLInfo& ssl_info,
186 bool fatal) {
skyostil4891b25b2015-06-11 11:43:45187 base::ThreadTaskRunnerHandle::Get()->PostTask(
ricea433bdab2015-01-26 07:25:37188 FROM_HERE, base::Bind(&SSLErrorCallbacks::CancelSSLRequest,
189 base::Owned(ssl_error_callbacks.release()),
190 ERR_SSL_PROTOCOL_ERROR, &ssl_info));
191 return CHANNEL_ALIVE;
192}
193
194void ConnectTestingEventInterface::QuitNestedEventLoop() {
195 run_loop_.Quit();
196}
197
198// A subclass of TestNetworkDelegate that additionally implements the
199// OnResolveProxy callback and records the information passed to it.
ryansturm7de050c2016-02-23 00:10:21200class TestProxyDelegateWithProxyInfo : public ProxyDelegate {
ricea433bdab2015-01-26 07:25:37201 public:
ryansturm7de050c2016-02-23 00:10:21202 TestProxyDelegateWithProxyInfo() {}
ricea433bdab2015-01-26 07:25:37203
204 struct ResolvedProxyInfo {
205 GURL url;
206 ProxyInfo proxy_info;
207 };
208
209 const ResolvedProxyInfo& resolved_proxy_info() const {
210 return resolved_proxy_info_;
211 }
212
213 protected:
214 void OnResolveProxy(const GURL& url,
ryansturm4bab06832016-03-03 23:41:07215 const std::string& method,
ricea433bdab2015-01-26 07:25:37216 int load_flags,
217 const ProxyService& proxy_service,
218 ProxyInfo* result) override {
219 resolved_proxy_info_.url = url;
220 resolved_proxy_info_.proxy_info = *result;
221 }
222
ryansturm7de050c2016-02-23 00:10:21223 void OnTunnelConnectCompleted(const HostPortPair& endpoint,
224 const HostPortPair& proxy_server,
225 int net_error) override {}
226 void OnFallback(const ProxyServer& bad_proxy, int net_error) override {}
ryansturm7de050c2016-02-23 00:10:21227 void OnBeforeTunnelRequest(const HostPortPair& proxy_server,
228 HttpRequestHeaders* extra_headers) override {}
229 void OnTunnelHeadersReceived(
230 const HostPortPair& origin,
231 const HostPortPair& proxy_server,
232 const HttpResponseHeaders& response_headers) override {}
233 bool IsTrustedSpdyProxy(const net::ProxyServer& proxy_server) override {
234 return true;
235 }
236
ricea433bdab2015-01-26 07:25:37237 private:
238 ResolvedProxyInfo resolved_proxy_info_;
239
ryansturm7de050c2016-02-23 00:10:21240 DISALLOW_COPY_AND_ASSIGN(TestProxyDelegateWithProxyInfo);
ricea433bdab2015-01-26 07:25:37241};
242
243class WebSocketEndToEndTest : public ::testing::Test {
244 protected:
245 WebSocketEndToEndTest()
Adam Ricecb76ac62015-02-20 05:33:25246 : event_interface_(),
ryansturm7de050c2016-02-23 00:10:21247 proxy_delegate_(new TestProxyDelegateWithProxyInfo),
ricea433bdab2015-01-26 07:25:37248 context_(true),
Adam Ricecb76ac62015-02-20 05:33:25249 channel_(),
ricea433bdab2015-01-26 07:25:37250 initialised_context_(false) {}
251
252 // Initialise the URLRequestContext. Normally done automatically by
253 // ConnectAndWait(). This method is for the use of tests that need the
254 // URLRequestContext initialised before calling ConnectAndWait().
255 void InitialiseContext() {
ryansturm7de050c2016-02-23 00:10:21256 context_.set_proxy_delegate(proxy_delegate_.get());
ricea433bdab2015-01-26 07:25:37257 context_.Init();
258 initialised_context_ = true;
259 }
260
261 // Send the connect request to |socket_url| and wait for a response. Returns
262 // true if the handshake succeeded.
263 bool ConnectAndWait(const GURL& socket_url) {
264 if (!initialised_context_) {
265 InitialiseContext();
266 }
mkwst4997ce82015-07-25 12:00:05267 url::Origin origin(GURL("http://localhost"));
Adam Ricecb76ac62015-02-20 05:33:25268 event_interface_ = new ConnectTestingEventInterface;
269 channel_.reset(
danakj9c5cab52016-04-16 00:54:33270 new WebSocketChannel(base::WrapUnique(event_interface_), &context_));
ricea5acb1faf72015-03-16 15:34:00271 channel_->SendAddChannelRequest(GURL(socket_url), sub_protocols_, origin);
ricea433bdab2015-01-26 07:25:37272 event_interface_->WaitForResponse();
273 return !event_interface_->failed();
274 }
275
276 ConnectTestingEventInterface* event_interface_; // owned by channel_
danakj9c5cab52016-04-16 00:54:33277 std::unique_ptr<TestProxyDelegateWithProxyInfo> proxy_delegate_;
ricea433bdab2015-01-26 07:25:37278 TestURLRequestContext context_;
danakj9c5cab52016-04-16 00:54:33279 std::unique_ptr<WebSocketChannel> channel_;
ricea5acb1faf72015-03-16 15:34:00280 std::vector<std::string> sub_protocols_;
ricea433bdab2015-01-26 07:25:37281 bool initialised_context_;
282};
283
284// None of these tests work on Android.
285// TODO(ricea): Make these tests work on Android. See crbug.com/441711.
286#if defined(OS_ANDROID)
287#define DISABLED_ON_ANDROID(test) DISABLED_##test
288#else
289#define DISABLED_ON_ANDROID(test) test
290#endif
291
292// Basic test of connectivity. If this test fails, nothing else can be expected
293// to work.
294TEST_F(WebSocketEndToEndTest, DISABLED_ON_ANDROID(BasicSmokeTest)) {
295 SpawnedTestServer ws_server(SpawnedTestServer::TYPE_WS,
296 SpawnedTestServer::kLocalhost,
297 GetWebSocketTestDataDirectory());
298 ASSERT_TRUE(ws_server.Start());
299 EXPECT_TRUE(ConnectAndWait(ws_server.GetURL(kEchoServer)));
300}
301
302// Test for issue crbug.com/433695 "Unencrypted WebSocket connection via
303// authenticated proxy times out"
304// TODO(ricea): Enable this when the issue is fixed.
305TEST_F(WebSocketEndToEndTest, DISABLED_HttpsProxyUnauthedFails) {
306 SpawnedTestServer proxy_server(SpawnedTestServer::TYPE_BASIC_AUTH_PROXY,
307 SpawnedTestServer::kLocalhost,
308 base::FilePath());
309 SpawnedTestServer ws_server(SpawnedTestServer::TYPE_WS,
310 SpawnedTestServer::kLocalhost,
311 GetWebSocketTestDataDirectory());
312 ASSERT_TRUE(proxy_server.StartInBackground());
313 ASSERT_TRUE(ws_server.StartInBackground());
314 ASSERT_TRUE(proxy_server.BlockUntilStarted());
315 ASSERT_TRUE(ws_server.BlockUntilStarted());
316 std::string proxy_config =
317 "https=" + proxy_server.host_port_pair().ToString();
danakj9c5cab52016-04-16 00:54:33318 std::unique_ptr<ProxyService> proxy_service(
ricea433bdab2015-01-26 07:25:37319 ProxyService::CreateFixed(proxy_config));
320 ASSERT_TRUE(proxy_service);
321 context_.set_proxy_service(proxy_service.get());
322 EXPECT_FALSE(ConnectAndWait(ws_server.GetURL(kEchoServer)));
323 EXPECT_EQ("Proxy authentication failed", event_interface_->failure_message());
324}
325
326TEST_F(WebSocketEndToEndTest, DISABLED_ON_ANDROID(HttpsWssProxyUnauthedFails)) {
327 SpawnedTestServer proxy_server(SpawnedTestServer::TYPE_BASIC_AUTH_PROXY,
328 SpawnedTestServer::kLocalhost,
329 base::FilePath());
330 SpawnedTestServer wss_server(SpawnedTestServer::TYPE_WSS,
331 SpawnedTestServer::kLocalhost,
332 GetWebSocketTestDataDirectory());
333 ASSERT_TRUE(proxy_server.StartInBackground());
334 ASSERT_TRUE(wss_server.StartInBackground());
335 ASSERT_TRUE(proxy_server.BlockUntilStarted());
336 ASSERT_TRUE(wss_server.BlockUntilStarted());
337 std::string proxy_config =
338 "https=" + proxy_server.host_port_pair().ToString();
danakj9c5cab52016-04-16 00:54:33339 std::unique_ptr<ProxyService> proxy_service(
ricea433bdab2015-01-26 07:25:37340 ProxyService::CreateFixed(proxy_config));
341 ASSERT_TRUE(proxy_service);
342 context_.set_proxy_service(proxy_service.get());
343 EXPECT_FALSE(ConnectAndWait(wss_server.GetURL(kEchoServer)));
344 EXPECT_EQ("Proxy authentication failed", event_interface_->failure_message());
345}
346
347// Regression test for crbug/426736 "WebSocket connections not using configured
348// system HTTPS Proxy".
349TEST_F(WebSocketEndToEndTest, DISABLED_ON_ANDROID(HttpsProxyUsed)) {
350 SpawnedTestServer proxy_server(SpawnedTestServer::TYPE_BASIC_AUTH_PROXY,
351 SpawnedTestServer::kLocalhost,
352 base::FilePath());
353 SpawnedTestServer ws_server(SpawnedTestServer::TYPE_WS,
354 SpawnedTestServer::kLocalhost,
355 GetWebSocketTestDataDirectory());
356 ASSERT_TRUE(proxy_server.StartInBackground());
357 ASSERT_TRUE(ws_server.StartInBackground());
358 ASSERT_TRUE(proxy_server.BlockUntilStarted());
359 ASSERT_TRUE(ws_server.BlockUntilStarted());
360 std::string proxy_config = "https=" +
361 proxy_server.host_port_pair().ToString() + ";" +
362 "http=" + proxy_server.host_port_pair().ToString();
danakj9c5cab52016-04-16 00:54:33363 std::unique_ptr<ProxyService> proxy_service(
ricea433bdab2015-01-26 07:25:37364 ProxyService::CreateFixed(proxy_config));
365 context_.set_proxy_service(proxy_service.get());
366 InitialiseContext();
367
368 // The test server doesn't have an unauthenticated proxy mode. WebSockets
369 // cannot provide auth information that isn't already cached, so it's
370 // necessary to preflight an HTTP request to authenticate against the proxy.
ricea433bdab2015-01-26 07:25:37371 // It doesn't matter what the URL is, as long as it is an HTTP navigation.
372 GURL http_page =
Adam Ricecb76ac62015-02-20 05:33:25373 ReplaceUrlScheme(ws_server.GetURL("connect_check.html"), "http");
ricea433bdab2015-01-26 07:25:37374 TestDelegate delegate;
375 delegate.set_credentials(
376 AuthCredentials(base::ASCIIToUTF16("foo"), base::ASCIIToUTF16("bar")));
377 {
danakj9c5cab52016-04-16 00:54:33378 std::unique_ptr<URLRequest> request(
davidben151423e2015-03-23 18:48:36379 context_.CreateRequest(http_page, DEFAULT_PRIORITY, &delegate));
ricea433bdab2015-01-26 07:25:37380 request->Start();
381 // TestDelegate exits the message loop when the request completes by
382 // default.
383 base::RunLoop().Run();
384 EXPECT_TRUE(delegate.auth_required_called());
385 }
386
387 GURL ws_url = ws_server.GetURL(kEchoServer);
388 EXPECT_TRUE(ConnectAndWait(ws_url));
ryansturm7de050c2016-02-23 00:10:21389 const TestProxyDelegateWithProxyInfo::ResolvedProxyInfo& info =
390 proxy_delegate_->resolved_proxy_info();
ricea433bdab2015-01-26 07:25:37391 EXPECT_EQ(ws_url, info.url);
392 EXPECT_TRUE(info.proxy_info.is_http());
393}
394
ricea23c3f942015-02-02 13:35:13395// This is a regression test for crbug.com/408061 Crash in
396// net::WebSocketBasicHandshakeStream::Upgrade.
397TEST_F(WebSocketEndToEndTest, DISABLED_ON_ANDROID(TruncatedResponse)) {
398 SpawnedTestServer ws_server(SpawnedTestServer::TYPE_WS,
399 SpawnedTestServer::kLocalhost,
400 GetWebSocketTestDataDirectory());
401 ASSERT_TRUE(ws_server.Start());
402 InitialiseContext();
403
404 GURL ws_url = ws_server.GetURL("truncated-headers");
405 EXPECT_FALSE(ConnectAndWait(ws_url));
406}
407
Adam Ricecb76ac62015-02-20 05:33:25408// Regression test for crbug.com/455215 "HSTS not applied to WebSocket"
409TEST_F(WebSocketEndToEndTest, DISABLED_ON_ANDROID(HstsHttpsToWebSocket)) {
tommycli59a63432015-11-06 00:10:55410 EmbeddedTestServer https_server(net::EmbeddedTestServer::Type::TYPE_HTTPS);
411 https_server.SetSSLConfig(
412 net::EmbeddedTestServer::CERT_COMMON_NAME_IS_DOMAIN);
413 https_server.ServeFilesFromSourceDirectory("net/data/url_request_unittest");
414
estarka5da76702015-04-09 04:00:16415 SpawnedTestServer::SSLOptions ssl_options(
416 SpawnedTestServer::SSLOptions::CERT_COMMON_NAME_IS_DOMAIN);
Adam Ricecb76ac62015-02-20 05:33:25417 SpawnedTestServer wss_server(SpawnedTestServer::TYPE_WSS, ssl_options,
418 GetWebSocketTestDataDirectory());
estarka5da76702015-04-09 04:00:16419
tommycli59a63432015-11-06 00:10:55420 ASSERT_TRUE(https_server.Start());
421 ASSERT_TRUE(wss_server.Start());
Adam Ricecb76ac62015-02-20 05:33:25422 InitialiseContext();
423 // Set HSTS via https:
424 TestDelegate delegate;
tommycli59a63432015-11-06 00:10:55425 GURL https_page = https_server.GetURL("/hsts-headers.html");
danakj9c5cab52016-04-16 00:54:33426 std::unique_ptr<URLRequest> request(
davidben151423e2015-03-23 18:48:36427 context_.CreateRequest(https_page, DEFAULT_PRIORITY, &delegate));
Adam Ricecb76ac62015-02-20 05:33:25428 request->Start();
429 // TestDelegate exits the message loop when the request completes.
430 base::RunLoop().Run();
431 EXPECT_TRUE(request->status().is_success());
432
433 // Check HSTS with ws:
434 // Change the scheme from wss: to ws: to verify that it is switched back.
435 GURL ws_url = ReplaceUrlScheme(wss_server.GetURL(kEchoServer), "ws");
436 EXPECT_TRUE(ConnectAndWait(ws_url));
437}
438
439TEST_F(WebSocketEndToEndTest, DISABLED_ON_ANDROID(HstsWebSocketToHttps)) {
tommycli59a63432015-11-06 00:10:55440 EmbeddedTestServer https_server(net::EmbeddedTestServer::Type::TYPE_HTTPS);
441 https_server.SetSSLConfig(
442 net::EmbeddedTestServer::CERT_COMMON_NAME_IS_DOMAIN);
443 https_server.ServeFilesFromSourceDirectory("net/data/url_request_unittest");
444
estarka5da76702015-04-09 04:00:16445 SpawnedTestServer::SSLOptions ssl_options(
446 SpawnedTestServer::SSLOptions::CERT_COMMON_NAME_IS_DOMAIN);
Adam Ricecb76ac62015-02-20 05:33:25447 SpawnedTestServer wss_server(SpawnedTestServer::TYPE_WSS, ssl_options,
448 GetWebSocketTestDataDirectory());
tommycli59a63432015-11-06 00:10:55449 ASSERT_TRUE(https_server.Start());
450 ASSERT_TRUE(wss_server.Start());
Adam Ricecb76ac62015-02-20 05:33:25451 InitialiseContext();
452 // Set HSTS via wss:
453 GURL wss_url = wss_server.GetURL("set-hsts");
454 EXPECT_TRUE(ConnectAndWait(wss_url));
455
456 // Verify via http:
457 TestDelegate delegate;
458 GURL http_page =
tommycli59a63432015-11-06 00:10:55459 ReplaceUrlScheme(https_server.GetURL("/simple.html"), "http");
danakj9c5cab52016-04-16 00:54:33460 std::unique_ptr<URLRequest> request(
davidben151423e2015-03-23 18:48:36461 context_.CreateRequest(http_page, DEFAULT_PRIORITY, &delegate));
Adam Ricecb76ac62015-02-20 05:33:25462 request->Start();
463 // TestDelegate exits the message loop when the request completes.
464 base::RunLoop().Run();
465 EXPECT_TRUE(request->status().is_success());
466 EXPECT_TRUE(request->url().SchemeIs("https"));
467}
468
469TEST_F(WebSocketEndToEndTest, DISABLED_ON_ANDROID(HstsWebSocketToWebSocket)) {
estarka5da76702015-04-09 04:00:16470 SpawnedTestServer::SSLOptions ssl_options(
471 SpawnedTestServer::SSLOptions::CERT_COMMON_NAME_IS_DOMAIN);
Adam Ricecb76ac62015-02-20 05:33:25472 SpawnedTestServer wss_server(SpawnedTestServer::TYPE_WSS, ssl_options,
473 GetWebSocketTestDataDirectory());
474 ASSERT_TRUE(wss_server.Start());
475 InitialiseContext();
476 // Set HSTS via wss:
477 GURL wss_url = wss_server.GetURL("set-hsts");
478 EXPECT_TRUE(ConnectAndWait(wss_url));
479
480 // Verify via wss:
481 GURL ws_url = ReplaceUrlScheme(wss_server.GetURL(kEchoServer), "ws");
482 EXPECT_TRUE(ConnectAndWait(ws_url));
483}
484
ricea5acb1faf72015-03-16 15:34:00485// Regression test for crbug.com/180504 "WebSocket handshake fails when HTTP
486// headers have trailing LWS".
487TEST_F(WebSocketEndToEndTest, DISABLED_ON_ANDROID(TrailingWhitespace)) {
488 SpawnedTestServer ws_server(SpawnedTestServer::TYPE_WS,
489 SpawnedTestServer::kLocalhost,
490 GetWebSocketTestDataDirectory());
491 ASSERT_TRUE(ws_server.Start());
492
493 GURL ws_url = ws_server.GetURL("trailing-whitespace");
494 sub_protocols_.push_back("sip");
495 EXPECT_TRUE(ConnectAndWait(ws_url));
496 EXPECT_EQ("sip", event_interface_->selected_subprotocol());
497}
498
riceae1d67672015-03-19 10:10:17499// This is a regression test for crbug.com/169448 "WebSockets should support
500// header continuations"
501// TODO(ricea): HTTP continuation headers have been deprecated by RFC7230. If
502// support for continuation headers is removed from Chrome, then this test will
503// break and should be removed.
504TEST_F(WebSocketEndToEndTest, DISABLED_ON_ANDROID(HeaderContinuations)) {
505 SpawnedTestServer ws_server(SpawnedTestServer::TYPE_WS,
506 SpawnedTestServer::kLocalhost,
507 GetWebSocketTestDataDirectory());
508 ASSERT_TRUE(ws_server.Start());
509
510 GURL ws_url = ws_server.GetURL("header-continuation");
511
512 EXPECT_TRUE(ConnectAndWait(ws_url));
513 EXPECT_EQ("permessage-deflate; server_max_window_bits=10",
514 event_interface_->extensions());
515}
516
ricea433bdab2015-01-26 07:25:37517} // namespace
518
519} // namespace net