| Index: net/websockets/websocket_end_to_end_test.cc
|
| diff --git a/net/websockets/websocket_end_to_end_test.cc b/net/websockets/websocket_end_to_end_test.cc
|
| index bb1d9519b18b083f5ab530532324088c6d05f4f7..3dcf3361ce2b9621e40a8e619f567704270d82fc 100644
|
| --- a/net/websockets/websocket_end_to_end_test.cc
|
| +++ b/net/websockets/websocket_end_to_end_test.cc
|
| @@ -15,21 +15,21 @@
|
| #include "base/bind_helpers.h"
|
| #include "base/callback.h"
|
| #include "base/location.h"
|
| #include "base/macros.h"
|
| #include "base/memory/scoped_ptr.h"
|
| #include "base/run_loop.h"
|
| #include "base/single_thread_task_runner.h"
|
| #include "base/strings/string_piece.h"
|
| #include "base/thread_task_runner_handle.h"
|
| #include "net/base/auth.h"
|
| -#include "net/base/network_delegate.h"
|
| +#include "net/base/proxy_delegate.h"
|
| #include "net/base/test_data_directory.h"
|
| #include "net/proxy/proxy_service.h"
|
| #include "net/test/embedded_test_server/embedded_test_server.h"
|
| #include "net/test/spawned_test_server/spawned_test_server.h"
|
| #include "net/url_request/url_request_test_util.h"
|
| #include "net/websockets/websocket_channel.h"
|
| #include "net/websockets/websocket_event_interface.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| #include "url/origin.h"
|
|
|
| @@ -188,83 +188,100 @@ ChannelState ConnectTestingEventInterface::OnSSLCertificateError(
|
| ERR_SSL_PROTOCOL_ERROR, &ssl_info));
|
| return CHANNEL_ALIVE;
|
| }
|
|
|
| void ConnectTestingEventInterface::QuitNestedEventLoop() {
|
| run_loop_.Quit();
|
| }
|
|
|
| // A subclass of TestNetworkDelegate that additionally implements the
|
| // OnResolveProxy callback and records the information passed to it.
|
| -class TestNetworkDelegateWithProxyInfo : public TestNetworkDelegate {
|
| +class TestProxyDelegateWithProxyInfo : public ProxyDelegate {
|
| public:
|
| - TestNetworkDelegateWithProxyInfo() {}
|
| + TestProxyDelegateWithProxyInfo() {}
|
|
|
| struct ResolvedProxyInfo {
|
| GURL url;
|
| ProxyInfo proxy_info;
|
| };
|
|
|
| const ResolvedProxyInfo& resolved_proxy_info() const {
|
| return resolved_proxy_info_;
|
| }
|
|
|
| protected:
|
| void OnResolveProxy(const GURL& url,
|
| int load_flags,
|
| const ProxyService& proxy_service,
|
| ProxyInfo* result) override {
|
| resolved_proxy_info_.url = url;
|
| resolved_proxy_info_.proxy_info = *result;
|
| }
|
|
|
| + void OnTunnelConnectCompleted(const HostPortPair& endpoint,
|
| + const HostPortPair& proxy_server,
|
| + int net_error) override {}
|
| + void OnFallback(const ProxyServer& bad_proxy, int net_error) override {}
|
| + void OnBeforeSendHeaders(URLRequest* request,
|
| + const ProxyInfo& proxy_info,
|
| + HttpRequestHeaders* headers) override {}
|
| + void OnBeforeTunnelRequest(const HostPortPair& proxy_server,
|
| + HttpRequestHeaders* extra_headers) override {}
|
| + void OnTunnelHeadersReceived(
|
| + const HostPortPair& origin,
|
| + const HostPortPair& proxy_server,
|
| + const HttpResponseHeaders& response_headers) override {}
|
| + bool IsTrustedSpdyProxy(const net::ProxyServer& proxy_server) override {
|
| + return true;
|
| + }
|
| +
|
| private:
|
| ResolvedProxyInfo resolved_proxy_info_;
|
|
|
| - DISALLOW_COPY_AND_ASSIGN(TestNetworkDelegateWithProxyInfo);
|
| + DISALLOW_COPY_AND_ASSIGN(TestProxyDelegateWithProxyInfo);
|
| };
|
|
|
| class WebSocketEndToEndTest : public ::testing::Test {
|
| protected:
|
| WebSocketEndToEndTest()
|
| : event_interface_(),
|
| - network_delegate_(new TestNetworkDelegateWithProxyInfo),
|
| + proxy_delegate_(new TestProxyDelegateWithProxyInfo),
|
| context_(true),
|
| channel_(),
|
| initialised_context_(false) {}
|
|
|
| // Initialise the URLRequestContext. Normally done automatically by
|
| // ConnectAndWait(). This method is for the use of tests that need the
|
| // URLRequestContext initialised before calling ConnectAndWait().
|
| void InitialiseContext() {
|
| - context_.set_network_delegate(network_delegate_.get());
|
| + context_.set_proxy_delegate(proxy_delegate_.get());
|
| context_.Init();
|
| initialised_context_ = true;
|
| }
|
|
|
| // Send the connect request to |socket_url| and wait for a response. Returns
|
| // true if the handshake succeeded.
|
| bool ConnectAndWait(const GURL& socket_url) {
|
| if (!initialised_context_) {
|
| InitialiseContext();
|
| }
|
| url::Origin origin(GURL("http://localhost"));
|
| event_interface_ = new ConnectTestingEventInterface;
|
| channel_.reset(
|
| new WebSocketChannel(make_scoped_ptr(event_interface_), &context_));
|
| channel_->SendAddChannelRequest(GURL(socket_url), sub_protocols_, origin);
|
| event_interface_->WaitForResponse();
|
| return !event_interface_->failed();
|
| }
|
|
|
| ConnectTestingEventInterface* event_interface_; // owned by channel_
|
| - scoped_ptr<TestNetworkDelegateWithProxyInfo> network_delegate_;
|
| + scoped_ptr<TestProxyDelegateWithProxyInfo> proxy_delegate_;
|
| TestURLRequestContext context_;
|
| scoped_ptr<WebSocketChannel> channel_;
|
| std::vector<std::string> sub_protocols_;
|
| bool initialised_context_;
|
| };
|
|
|
| // None of these tests work on Android.
|
| // TODO(ricea): Make these tests work on Android. See crbug.com/441711.
|
| #if defined(OS_ANDROID)
|
| #define DISABLED_ON_ANDROID(test) DISABLED_##test
|
| @@ -362,22 +379,22 @@ TEST_F(WebSocketEndToEndTest, DISABLED_ON_ANDROID(HttpsProxyUsed)) {
|
| context_.CreateRequest(http_page, DEFAULT_PRIORITY, &delegate));
|
| request->Start();
|
| // TestDelegate exits the message loop when the request completes by
|
| // default.
|
| base::RunLoop().Run();
|
| EXPECT_TRUE(delegate.auth_required_called());
|
| }
|
|
|
| GURL ws_url = ws_server.GetURL(kEchoServer);
|
| EXPECT_TRUE(ConnectAndWait(ws_url));
|
| - const TestNetworkDelegateWithProxyInfo::ResolvedProxyInfo& info =
|
| - network_delegate_->resolved_proxy_info();
|
| + const TestProxyDelegateWithProxyInfo::ResolvedProxyInfo& info =
|
| + proxy_delegate_->resolved_proxy_info();
|
| EXPECT_EQ(ws_url, info.url);
|
| EXPECT_TRUE(info.proxy_info.is_http());
|
| }
|
|
|
| // This is a regression test for crbug.com/408061 Crash in
|
| // net::WebSocketBasicHandshakeStream::Upgrade.
|
| TEST_F(WebSocketEndToEndTest, DISABLED_ON_ANDROID(TruncatedResponse)) {
|
| SpawnedTestServer ws_server(SpawnedTestServer::TYPE_WS,
|
| SpawnedTestServer::kLocalhost,
|
| GetWebSocketTestDataDirectory());
|
|
|