summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorakalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-25 08:51:23 +0000
committerakalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-25 08:51:23 +0000
commite7ca45507c5d2def2fff7303b0d8a7a61741b128 (patch)
treec0ac0c1aae26ea2f95253008b778a249c45fe682
parent1aec355886f0ca1619f3e109402469940361668b (diff)
downloadchromium_src-e7ca45507c5d2def2fff7303b0d8a7a61741b128.zip
chromium_src-e7ca45507c5d2def2fff7303b0d8a7a61741b128.tar.gz
chromium_src-e7ca45507c5d2def2fff7303b0d8a7a61741b128.tar.bz2
[SPDY] Unfork websocket_job_spdy{2,3}_unittest.cc files
Make SpdyWebSocketTestUtil contain and not inherit from SpdyTestUtil. Replace the various Get*Key() functions in SpdyWebSocketTestUtil with a single function SetHeader(). BUG=226192 Review URL: https://chromiumcodereview.appspot.com/17573020 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@208457 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--net/net.gyp3
-rw-r--r--net/socket_stream/socket_stream_job.h3
-rw-r--r--net/spdy/spdy_websocket_stream_unittest.cc11
-rw-r--r--net/spdy/spdy_websocket_test_util.cc136
-rw-r--r--net/spdy/spdy_websocket_test_util.h24
-rw-r--r--net/websockets/websocket_job.h3
-rw-r--r--net/websockets/websocket_job_spdy3_unittest.cc1095
-rw-r--r--net/websockets/websocket_job_unittest.cc (renamed from net/websockets/websocket_job_spdy2_unittest.cc)179
8 files changed, 170 insertions, 1284 deletions
diff --git a/net/net.gyp b/net/net.gyp
index 07fa9f2..41c23d8 100644
--- a/net/net.gyp
+++ b/net/net.gyp
@@ -1830,8 +1830,7 @@
'websockets/websocket_handshake_handler_unittest.cc',
'websockets/websocket_handshake_handler_spdy2_unittest.cc',
'websockets/websocket_handshake_handler_spdy3_unittest.cc',
- 'websockets/websocket_job_spdy2_unittest.cc',
- 'websockets/websocket_job_spdy3_unittest.cc',
+ 'websockets/websocket_job_unittest.cc',
'websockets/websocket_net_log_params_unittest.cc',
'websockets/websocket_throttle_unittest.cc',
],
diff --git a/net/socket_stream/socket_stream_job.h b/net/socket_stream/socket_stream_job.h
index ff3d0b5..13dcf70 100644
--- a/net/socket_stream/socket_stream_job.h
+++ b/net/socket_stream/socket_stream_job.h
@@ -74,8 +74,7 @@ class NET_EXPORT SocketStreamJob
virtual void DetachDelegate();
protected:
- friend class WebSocketJobSpdy2Test;
- friend class WebSocketJobSpdy3Test;
+ friend class WebSocketJobTest;
friend class base::RefCountedThreadSafe<SocketStreamJob>;
virtual ~SocketStreamJob();
diff --git a/net/spdy/spdy_websocket_stream_unittest.cc b/net/spdy/spdy_websocket_stream_unittest.cc
index 1496b9d..174b4f9 100644
--- a/net/spdy/spdy_websocket_stream_unittest.cc
+++ b/net/spdy/spdy_websocket_stream_unittest.cc
@@ -275,12 +275,11 @@ class SpdyWebSocketStreamTest
void SendRequest() {
scoped_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock);
- (*headers)[spdy_util_.GetWebSocketPathKey()] = "/echo";
- (*headers)[spdy_util_.GetHostKey()] = "example.com";
- (*headers)[spdy_util_.GetVersionKey()] = "WebSocket/13";
- (*headers)[spdy_util_.GetSchemeKey()] = "ws";
- (*headers)[spdy_util_.GetOriginKey()] = "http://example.com/wsdemo";
-
+ spdy_util_.SetHeader("path", "/echo", headers.get());
+ spdy_util_.SetHeader("host", "example.com", headers.get());
+ spdy_util_.SetHeader("version", "WebSocket/13", headers.get());
+ spdy_util_.SetHeader("scheme", "ws", headers.get());
+ spdy_util_.SetHeader("origin", "http://example.com/wsdemo", headers.get());
websocket_stream_->SendRequest(headers.Pass());
}
diff --git a/net/spdy/spdy_websocket_test_util.cc b/net/spdy/spdy_websocket_test_util.cc
index 07f9863..2327ee2 100644
--- a/net/spdy/spdy_websocket_test_util.cc
+++ b/net/spdy/spdy_websocket_test_util.cc
@@ -17,52 +17,50 @@ static const char** const kDefaultExtraHeaders = NULL;
static const int kDefaultExtraHeaderCount = 0;
SpdyWebSocketTestUtil::SpdyWebSocketTestUtil(
- NextProto protocol) : SpdyTestUtil(protocol) {}
+ NextProto protocol) : spdy_util_(protocol) {}
+
+void SpdyWebSocketTestUtil::SetHeader(
+ const std::string& key,
+ const std::string& value,
+ SpdyHeaderBlock* headers) const {
+ (*headers)[(spdy_util_.is_spdy2() ? "" : ":") + key] = value;
+}
SpdyFrame* SpdyWebSocketTestUtil::ConstructSpdyWebSocketSynStream(
int stream_id,
const char* path,
const char* host,
const char* origin) {
- const char* const kWebSocketHeaders[] = {
- GetWebSocketPathKey(), path,
- GetHostKey(), host,
- GetVersionKey(), "WebSocket/13",
- GetSchemeKey(), "ws",
- GetOriginKey(), origin
- };
- return ConstructSpdyControlFrame(/*extra_headers*/ NULL,
- /*extra_header_count*/ 0,
- /*compressed*/ false,
- stream_id,
- HIGHEST,
- SYN_STREAM,
- CONTROL_FLAG_NONE,
- kWebSocketHeaders,
- arraysize(kWebSocketHeaders),
- 0);
+ scoped_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock());
+ SetHeader("path", path, headers.get());
+ SetHeader("host", host, headers.get());
+ SetHeader("version", "WebSocket/13", headers.get());
+ SetHeader("scheme", "ws", headers.get());
+ SetHeader("origin", origin, headers.get());
+ return spdy_util_.ConstructSpdyControlFrame(headers.Pass(),
+ /*compressed*/ false,
+ stream_id,
+ HIGHEST,
+ SYN_STREAM,
+ CONTROL_FLAG_NONE,
+ 0);
}
SpdyFrame* SpdyWebSocketTestUtil::ConstructSpdyWebSocketSynReply(
int stream_id) {
- static const char* const kStandardWebSocketHeaders[] = {
- GetStatusKey(), "101"
- };
- return ConstructSpdyControlFrame(NULL,
- 0,
- false,
- stream_id,
- LOWEST,
- SYN_REPLY,
- CONTROL_FLAG_NONE,
- kStandardWebSocketHeaders,
- arraysize(kStandardWebSocketHeaders),
- 0);
+ scoped_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock());
+ SetHeader("status", "101", headers.get());
+ return spdy_util_.ConstructSpdyControlFrame(headers.Pass(),
+ false,
+ stream_id,
+ LOWEST,
+ SYN_REPLY,
+ CONTROL_FLAG_NONE,
+ 0);
}
SpdyFrame* SpdyWebSocketTestUtil::ConstructSpdyWebSocketHandshakeRequestFrame(
- const char* const headers[],
- int header_count,
+ scoped_ptr<SpdyHeaderBlock> headers,
SpdyStreamId stream_id,
RequestPriority request_priority) {
// SPDY SYN_STREAM control frame header.
@@ -81,17 +79,13 @@ SpdyFrame* SpdyWebSocketTestUtil::ConstructSpdyWebSocketHandshakeRequestFrame(
};
// Construct SPDY SYN_STREAM control frame.
- return ConstructSpdyFrame(
+ return spdy_util_.ConstructSpdyFrame(
kSynStreamHeader,
- kDefaultExtraHeaders,
- kDefaultExtraHeaderCount,
- headers,
- header_count);
+ headers.Pass());
}
SpdyFrame* SpdyWebSocketTestUtil::ConstructSpdyWebSocketHandshakeResponseFrame(
- const char* const headers[],
- int header_count,
+ scoped_ptr<SpdyHeaderBlock> headers,
SpdyStreamId stream_id,
RequestPriority request_priority) {
// SPDY SYN_REPLY control frame header.
@@ -110,33 +104,26 @@ SpdyFrame* SpdyWebSocketTestUtil::ConstructSpdyWebSocketHandshakeResponseFrame(
};
// Construct SPDY SYN_REPLY control frame.
- return ConstructSpdyFrame(
+ return spdy_util_.ConstructSpdyFrame(
kSynReplyHeader,
- kDefaultExtraHeaders,
- kDefaultExtraHeaderCount,
- headers,
- header_count);
+ headers.Pass());
}
SpdyFrame* SpdyWebSocketTestUtil::ConstructSpdyWebSocketHeadersFrame(
int stream_id,
const char* length,
bool fin) {
- static const char* const kHeaders[] = {
- GetOpcodeKey(), "1", // text frame
- GetLengthKey(), length,
- GetFinKey(), fin ? "1" : "0"
- };
- return ConstructSpdyControlFrame(/*extra_headers*/ NULL,
- /*extra_header_count*/ 0,
- /*compression*/ false,
- stream_id,
- LOWEST,
- HEADERS,
- CONTROL_FLAG_NONE,
- kHeaders,
- arraysize(kHeaders),
- 0);
+ scoped_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock());
+ SetHeader("opcode", "1", headers.get()); // text frame
+ SetHeader("length", length, headers.get());
+ SetHeader("fin", fin ? "1" : "0", headers.get());
+ return spdy_util_.ConstructSpdyControlFrame(headers.Pass(),
+ /*compression*/ false,
+ stream_id,
+ LOWEST,
+ HEADERS,
+ CONTROL_FLAG_NONE,
+ 0);
}
SpdyFrame* SpdyWebSocketTestUtil::ConstructSpdyWebSocketDataFrame(
@@ -146,7 +133,7 @@ SpdyFrame* SpdyWebSocketTestUtil::ConstructSpdyWebSocketDataFrame(
bool fin) {
// Construct SPDY data frame.
- BufferedSpdyFramer framer(spdy_version(), false);
+ BufferedSpdyFramer framer(spdy_util_.spdy_version(), false);
return framer.CreateDataFrame(
stream_id,
data,
@@ -154,30 +141,9 @@ SpdyFrame* SpdyWebSocketTestUtil::ConstructSpdyWebSocketDataFrame(
fin ? DATA_FLAG_FIN : DATA_FLAG_NONE);
}
-const char* SpdyWebSocketTestUtil::GetWebSocketPathKey() const {
- return is_spdy2() ? "path" : ":path";
-}
-
-const char* SpdyWebSocketTestUtil::GetOriginKey() const {
- return is_spdy2() ? "origin" : ":origin";
-}
-
-const char* SpdyWebSocketTestUtil::GetOpcodeKey() const {
- return is_spdy2() ? "opcode" : ":opcode";
-}
-
-const char* SpdyWebSocketTestUtil::GetLengthKey() const {
- return is_spdy2() ? "length" : ":length";
-}
-
-const char* SpdyWebSocketTestUtil::GetFinKey() const {
- return is_spdy2() ? "fin" : ":fin";
-}
-
-const char* SpdyWebSocketTestUtil::GetPathKey() const {
- // Override this function to avoid erroneous use.
- ADD_FAILURE();
- return "";
+SpdyFrame* SpdyWebSocketTestUtil::ConstructSpdySettings(
+ const SettingsMap& settings) const {
+ return spdy_util_.ConstructSpdySettings(settings);
}
} // namespace net
diff --git a/net/spdy/spdy_websocket_test_util.h b/net/spdy/spdy_websocket_test_util.h
index b8cb8f8..f334919 100644
--- a/net/spdy/spdy_websocket_test_util.h
+++ b/net/spdy/spdy_websocket_test_util.h
@@ -11,10 +11,16 @@
namespace net {
-class SpdyWebSocketTestUtil : public SpdyTestUtil {
+class SpdyWebSocketTestUtil {
public:
explicit SpdyWebSocketTestUtil(NextProto protocol);
+ // Adds the given key/value pair to |headers|, tweaking it depending
+ // on SPDY version.
+ void SetHeader(const std::string& key,
+ const std::string& value,
+ SpdyHeaderBlock* headers) const;
+
// Constructs a standard SPDY SYN_STREAM frame for WebSocket over
// SPDY opening handshake.
SpdyFrame* ConstructSpdyWebSocketSynStream(int stream_id,
@@ -28,15 +34,13 @@ class SpdyWebSocketTestUtil : public SpdyTestUtil {
// Constructs a WebSocket over SPDY handshake request packet.
SpdyFrame* ConstructSpdyWebSocketHandshakeRequestFrame(
- const char* const headers[],
- int header_count,
+ scoped_ptr<SpdyHeaderBlock> headers,
SpdyStreamId stream_id,
RequestPriority request_priority);
// Constructs a WebSocket over SPDY handshake response packet.
SpdyFrame* ConstructSpdyWebSocketHandshakeResponseFrame(
- const char* const headers[],
- int header_count,
+ scoped_ptr<SpdyHeaderBlock> headers,
SpdyStreamId stream_id,
RequestPriority request_priority);
@@ -51,15 +55,11 @@ class SpdyWebSocketTestUtil : public SpdyTestUtil {
SpdyStreamId stream_id,
bool fin);
- const char* GetWebSocketPathKey() const;
- const char* GetOriginKey() const;
- const char* GetOpcodeKey() const;
- const char* GetLengthKey() const;
- const char* GetFinKey() const;
+ // Forwards to |spdy_util_|.
+ SpdyFrame* ConstructSpdySettings(const SettingsMap& settings) const;
private:
- // Hide this function to avoid erroneous use.
- const char* GetPathKey() const;
+ SpdyTestUtil spdy_util_;
};
} // namespace net
diff --git a/net/websockets/websocket_job.h b/net/websockets/websocket_job.h
index ee72390..119c4dc 100644
--- a/net/websockets/websocket_job.h
+++ b/net/websockets/websocket_job.h
@@ -88,8 +88,7 @@ class NET_EXPORT WebSocketJob
private:
friend class WebSocketThrottle;
- friend class WebSocketJobSpdy2Test;
- friend class WebSocketJobSpdy3Test;
+ friend class WebSocketJobTest;
virtual ~WebSocketJob();
bool SendHandshakeRequest(const char* data, int len);
diff --git a/net/websockets/websocket_job_spdy3_unittest.cc b/net/websockets/websocket_job_spdy3_unittest.cc
deleted file mode 100644
index f8e0adb..0000000
--- a/net/websockets/websocket_job_spdy3_unittest.cc
+++ /dev/null
@@ -1,1095 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "net/websockets/websocket_job.h"
-
-#include <string>
-#include <vector>
-
-#include "base/bind.h"
-#include "base/bind_helpers.h"
-#include "base/callback.h"
-#include "base/memory/ref_counted.h"
-#include "base/strings/string_util.h"
-#include "base/strings/string_split.h"
-#include "googleurl/src/gurl.h"
-#include "net/base/completion_callback.h"
-#include "net/base/net_errors.h"
-#include "net/base/test_completion_callback.h"
-#include "net/cookies/cookie_store.h"
-#include "net/cookies/cookie_store_test_helpers.h"
-#include "net/dns/mock_host_resolver.h"
-#include "net/http/http_transaction_factory.h"
-#include "net/http/transport_security_state.h"
-#include "net/proxy/proxy_service.h"
-#include "net/socket/next_proto.h"
-#include "net/socket/socket_test_util.h"
-#include "net/socket_stream/socket_stream.h"
-#include "net/spdy/spdy_session.h"
-#include "net/spdy/spdy_websocket_test_util.h"
-#include "net/ssl/ssl_config_service.h"
-#include "net/url_request/url_request_context.h"
-#include "net/websockets/websocket_throttle.h"
-#include "testing/gmock/include/gmock/gmock.h"
-#include "testing/gtest/include/gtest/gtest.h"
-#include "testing/platform_test.h"
-
-namespace net {
-
-namespace {
-
-class MockSocketStream : public SocketStream {
- public:
- MockSocketStream(const GURL& url, SocketStream::Delegate* delegate)
- : SocketStream(url, delegate) {
- }
-
- virtual void Connect() OVERRIDE {}
- virtual bool SendData(const char* data, int len) OVERRIDE {
- sent_data_ += std::string(data, len);
- return true;
- }
-
- virtual void Close() OVERRIDE {}
- virtual void RestartWithAuth(
- const AuthCredentials& credentials) OVERRIDE {
- }
-
- virtual void DetachDelegate() OVERRIDE {
- delegate_ = NULL;
- }
-
- const std::string& sent_data() const {
- return sent_data_;
- }
-
- protected:
- virtual ~MockSocketStream() {}
-
- private:
- std::string sent_data_;
-};
-
-class MockSocketStreamDelegate : public SocketStream::Delegate {
- public:
- MockSocketStreamDelegate()
- : amount_sent_(0),
- allow_all_cookies_(true) {
- }
-
- void set_allow_all_cookies(bool allow_all_cookies) {
- allow_all_cookies_ = allow_all_cookies;
- }
- virtual ~MockSocketStreamDelegate() {}
-
- void SetOnStartOpenConnection(const base::Closure& callback) {
- on_start_open_connection_ = callback;
- }
- void SetOnConnected(const base::Closure& callback) {
- on_connected_ = callback;
- }
- void SetOnSentData(const base::Closure& callback) {
- on_sent_data_ = callback;
- }
- void SetOnReceivedData(const base::Closure& callback) {
- on_received_data_ = callback;
- }
- void SetOnClose(const base::Closure& callback) {
- on_close_ = callback;
- }
-
- virtual int OnStartOpenConnection(
- SocketStream* socket,
- const CompletionCallback& callback) OVERRIDE {
- if (!on_start_open_connection_.is_null())
- on_start_open_connection_.Run();
- return OK;
- }
- virtual void OnConnected(SocketStream* socket,
- int max_pending_send_allowed) OVERRIDE {
- if (!on_connected_.is_null())
- on_connected_.Run();
- }
- virtual void OnSentData(SocketStream* socket,
- int amount_sent) OVERRIDE {
- amount_sent_ += amount_sent;
- if (!on_sent_data_.is_null())
- on_sent_data_.Run();
- }
- virtual void OnReceivedData(SocketStream* socket,
- const char* data, int len) OVERRIDE {
- received_data_ += std::string(data, len);
- if (!on_received_data_.is_null())
- on_received_data_.Run();
- }
- virtual void OnClose(SocketStream* socket) OVERRIDE {
- if (!on_close_.is_null())
- on_close_.Run();
- }
- virtual bool CanGetCookies(SocketStream* socket,
- const GURL& url) OVERRIDE {
- return allow_all_cookies_;
- }
- virtual bool CanSetCookie(SocketStream* request,
- const GURL& url,
- const std::string& cookie_line,
- CookieOptions* options) OVERRIDE {
- return allow_all_cookies_;
- }
-
- size_t amount_sent() const { return amount_sent_; }
- const std::string& received_data() const { return received_data_; }
-
- private:
- int amount_sent_;
- bool allow_all_cookies_;
- std::string received_data_;
- base::Closure on_start_open_connection_;
- base::Closure on_connected_;
- base::Closure on_sent_data_;
- base::Closure on_received_data_;
- base::Closure on_close_;
-};
-
-class MockCookieStore : public CookieStore {
- public:
- struct Entry {
- GURL url;
- std::string cookie_line;
- CookieOptions options;
- };
-
- MockCookieStore() {}
-
- bool SetCookieWithOptions(const GURL& url,
- const std::string& cookie_line,
- const CookieOptions& options) {
- Entry entry;
- entry.url = url;
- entry.cookie_line = cookie_line;
- entry.options = options;
- entries_.push_back(entry);
- return true;
- }
-
- std::string GetCookiesWithOptions(const GURL& url,
- const CookieOptions& options) {
- std::string result;
- for (size_t i = 0; i < entries_.size(); i++) {
- Entry& entry = entries_[i];
- if (url == entry.url) {
- if (!result.empty()) {
- result += "; ";
- }
- result += entry.cookie_line;
- }
- }
- return result;
- }
-
- // CookieStore:
- virtual void SetCookieWithOptionsAsync(
- const GURL& url,
- const std::string& cookie_line,
- const CookieOptions& options,
- const SetCookiesCallback& callback) OVERRIDE {
- bool result = SetCookieWithOptions(url, cookie_line, options);
- if (!callback.is_null())
- callback.Run(result);
- }
-
- virtual void GetCookiesWithOptionsAsync(
- const GURL& url,
- const CookieOptions& options,
- const GetCookiesCallback& callback) OVERRIDE {
- if (!callback.is_null())
- callback.Run(GetCookiesWithOptions(url, options));
- }
-
- virtual void DeleteCookieAsync(const GURL& url,
- const std::string& cookie_name,
- const base::Closure& callback) OVERRIDE {
- ADD_FAILURE();
- }
-
- virtual void DeleteAllCreatedBetweenAsync(
- const base::Time& delete_begin,
- const base::Time& delete_end,
- const DeleteCallback& callback) OVERRIDE {
- ADD_FAILURE();
- }
-
- virtual void DeleteSessionCookiesAsync(const DeleteCallback&) OVERRIDE {
- ADD_FAILURE();
- }
-
- virtual CookieMonster* GetCookieMonster() OVERRIDE { return NULL; }
-
- const std::vector<Entry>& entries() const { return entries_; }
-
- private:
- friend class base::RefCountedThreadSafe<MockCookieStore>;
- virtual ~MockCookieStore() {}
-
- std::vector<Entry> entries_;
-};
-
-class MockSSLConfigService : public SSLConfigService {
- public:
- virtual void GetSSLConfig(SSLConfig* config) OVERRIDE {}
-
- protected:
- virtual ~MockSSLConfigService() {}
-};
-
-class MockURLRequestContext : public URLRequestContext {
- public:
- explicit MockURLRequestContext(CookieStore* cookie_store)
- : transport_security_state_() {
- set_cookie_store(cookie_store);
- set_transport_security_state(&transport_security_state_);
- base::Time expiry = base::Time::Now() + base::TimeDelta::FromDays(1000);
- bool include_subdomains = false;
- transport_security_state_.AddHSTS("upgrademe.com", expiry,
- include_subdomains);
- }
-
- virtual ~MockURLRequestContext() {}
-
- private:
- TransportSecurityState transport_security_state_;
-};
-
-class MockHttpTransactionFactory : public HttpTransactionFactory {
- public:
- explicit MockHttpTransactionFactory(OrderedSocketData* data) {
- data_ = data;
- MockConnect connect_data(SYNCHRONOUS, OK);
- data_->set_connect_data(connect_data);
- session_deps_.reset(new SpdySessionDependencies(kProtoSPDY3));
- session_deps_->socket_factory->AddSocketDataProvider(data_);
- http_session_ =
- SpdySessionDependencies::SpdyCreateSession(session_deps_.get());
- host_port_pair_.set_host("example.com");
- host_port_pair_.set_port(80);
- spdy_session_key_ = SpdySessionKey(host_port_pair_,
- ProxyServer::Direct(),
- kPrivacyModeDisabled);
- SpdySessionPool* spdy_session_pool =
- http_session_->spdy_session_pool();
- DCHECK(spdy_session_pool);
- EXPECT_FALSE(spdy_session_pool->HasSession(spdy_session_key_));
- session_ =
- spdy_session_pool->Get(spdy_session_key_, BoundNetLog());
- EXPECT_TRUE(spdy_session_pool->HasSession(spdy_session_key_));
-
- transport_params_ =
- new TransportSocketParams(host_port_pair_,
- MEDIUM,
- false,
- false,
- OnHostResolutionCallback());
- ClientSocketHandle* connection = new ClientSocketHandle;
- EXPECT_EQ(OK,
- connection->Init(host_port_pair_.ToString(), transport_params_,
- MEDIUM, CompletionCallback(),
- http_session_->GetTransportSocketPool(
- HttpNetworkSession::NORMAL_SOCKET_POOL),
- BoundNetLog()));
- EXPECT_EQ(OK,
- session_->InitializeWithSocket(connection, false, OK));
- }
- virtual int CreateTransaction(
- RequestPriority priority,
- scoped_ptr<HttpTransaction>* trans,
- HttpTransactionDelegate* delegate) OVERRIDE {
- NOTREACHED();
- return ERR_UNEXPECTED;
- }
- virtual HttpCache* GetCache() OVERRIDE {
- NOTREACHED();
- return NULL;
- }
- virtual HttpNetworkSession* GetSession() OVERRIDE {
- return http_session_.get();
- }
- private:
- OrderedSocketData* data_;
- scoped_ptr<SpdySessionDependencies> session_deps_;
- scoped_refptr<HttpNetworkSession> http_session_;
- scoped_refptr<TransportSocketParams> transport_params_;
- scoped_refptr<SpdySession> session_;
- HostPortPair host_port_pair_;
- SpdySessionKey spdy_session_key_;
-};
-
-} // namespace
-
-class WebSocketJobSpdy3Test : public PlatformTest {
- public:
- WebSocketJobSpdy3Test() : spdy_util_(kProtoSPDY3) {}
-
- virtual void SetUp() {
- stream_type_ = STREAM_INVALID;
- cookie_store_ = new MockCookieStore;
- context_.reset(new MockURLRequestContext(cookie_store_.get()));
- }
- virtual void TearDown() {
- cookie_store_ = NULL;
- context_.reset();
- websocket_ = NULL;
- socket_ = NULL;
- }
- void DoSendRequest() {
- EXPECT_TRUE(websocket_->SendData(kHandshakeRequestWithoutCookie,
- kHandshakeRequestWithoutCookieLength));
- }
- void DoSendData() {
- if (received_data().size() == kHandshakeResponseWithoutCookieLength)
- websocket_->SendData(kDataHello, kDataHelloLength);
- }
- void DoSync() {
- sync_test_callback_.callback().Run(OK);
- }
- int WaitForResult() {
- return sync_test_callback_.WaitForResult();
- }
- protected:
- enum StreamType {
- STREAM_INVALID,
- STREAM_MOCK_SOCKET,
- STREAM_SOCKET,
- STREAM_SPDY_WEBSOCKET,
- };
- enum ThrottlingOption {
- THROTTLING_OFF,
- THROTTLING_ON,
- };
- enum SpdyOption {
- SPDY_OFF,
- SPDY_ON,
- };
- void InitWebSocketJob(const GURL& url,
- MockSocketStreamDelegate* delegate,
- StreamType stream_type) {
- DCHECK_NE(STREAM_INVALID, stream_type);
- stream_type_ = stream_type;
- websocket_ = new WebSocketJob(delegate);
-
- if (stream_type == STREAM_MOCK_SOCKET)
- socket_ = new MockSocketStream(url, websocket_.get());
-
- if (stream_type == STREAM_SOCKET || stream_type == STREAM_SPDY_WEBSOCKET) {
- if (stream_type == STREAM_SPDY_WEBSOCKET) {
- http_factory_.reset(new MockHttpTransactionFactory(data_.get()));
- context_->set_http_transaction_factory(http_factory_.get());
- }
-
- ssl_config_service_ = new MockSSLConfigService();
- context_->set_ssl_config_service(ssl_config_service_.get());
- proxy_service_.reset(ProxyService::CreateDirect());
- context_->set_proxy_service(proxy_service_.get());
- host_resolver_.reset(new MockHostResolver);
- context_->set_host_resolver(host_resolver_.get());
-
- socket_ = new SocketStream(url, websocket_.get());
- socket_factory_.reset(new MockClientSocketFactory);
- DCHECK(data_.get());
- socket_factory_->AddSocketDataProvider(data_.get());
- socket_->SetClientSocketFactory(socket_factory_.get());
- }
-
- websocket_->InitSocketStream(socket_.get());
- websocket_->set_context(context_.get());
- // MockHostResolver resolves all hosts to 127.0.0.1; however, when we create
- // a WebSocketJob purely to block another one in a throttling test, we don't
- // perform a real connect. In that case, the following address is used
- // instead.
- IPAddressNumber ip;
- ParseIPLiteralToNumber("127.0.0.1", &ip);
- websocket_->addresses_ = AddressList::CreateFromIPAddress(ip, 80);
- }
- void SkipToConnecting() {
- websocket_->state_ = WebSocketJob::CONNECTING;
- WebSocketThrottle::GetInstance()->PutInQueue(websocket_.get());
- }
- WebSocketJob::State GetWebSocketJobState() {
- return websocket_->state_;
- }
- void CloseWebSocketJob() {
- if (websocket_->socket_.get()) {
- websocket_->socket_->DetachDelegate();
- WebSocketThrottle::GetInstance()->RemoveFromQueue(websocket_.get());
- }
- websocket_->state_ = WebSocketJob::CLOSED;
- websocket_->delegate_ = NULL;
- websocket_->socket_ = NULL;
- }
- SocketStream* GetSocket(SocketStreamJob* job) {
- return job->socket_.get();
- }
- const std::string& sent_data() const {
- DCHECK_EQ(STREAM_MOCK_SOCKET, stream_type_);
- MockSocketStream* socket =
- static_cast<MockSocketStream*>(socket_.get());
- DCHECK(socket);
- return socket->sent_data();
- }
- const std::string& received_data() const {
- DCHECK_NE(STREAM_INVALID, stream_type_);
- MockSocketStreamDelegate* delegate =
- static_cast<MockSocketStreamDelegate*>(websocket_->delegate_);
- DCHECK(delegate);
- return delegate->received_data();
- }
-
- void TestSimpleHandshake();
- void TestSlowHandshake();
- void TestHandshakeWithCookie();
- void TestHandshakeWithCookieButNotAllowed();
- void TestHSTSUpgrade();
- void TestInvalidSendData();
- void TestConnectByWebSocket(ThrottlingOption throttling);
- void TestConnectBySpdy(SpdyOption spdy, ThrottlingOption throttling);
-
- SpdyWebSocketTestUtil spdy_util_;
- StreamType stream_type_;
- scoped_refptr<MockCookieStore> cookie_store_;
- scoped_refptr<WebSocketJob> websocket_;
- scoped_refptr<SocketStream> socket_;
- scoped_ptr<MockClientSocketFactory> socket_factory_;
- scoped_ptr<OrderedSocketData> data_;
- TestCompletionCallback sync_test_callback_;
- scoped_refptr<MockSSLConfigService> ssl_config_service_;
- scoped_ptr<ProxyService> proxy_service_;
- scoped_ptr<MockHostResolver> host_resolver_;
- scoped_ptr<MockHttpTransactionFactory> http_factory_;
- scoped_ptr<MockURLRequestContext> context_;
-
- static const char kHandshakeRequestWithoutCookie[];
- static const char kHandshakeRequestWithCookie[];
- static const char kHandshakeRequestWithFilteredCookie[];
- static const char kHandshakeResponseWithoutCookie[];
- static const char kHandshakeResponseWithCookie[];
- static const char kDataHello[];
- static const char kDataWorld[];
- static const char* const kHandshakeRequestForSpdy[];
- static const char* const kHandshakeResponseForSpdy[];
- static const size_t kHandshakeRequestWithoutCookieLength;
- static const size_t kHandshakeRequestWithCookieLength;
- static const size_t kHandshakeRequestWithFilteredCookieLength;
- static const size_t kHandshakeResponseWithoutCookieLength;
- static const size_t kHandshakeResponseWithCookieLength;
- static const size_t kDataHelloLength;
- static const size_t kDataWorldLength;
-};
-
-const char WebSocketJobSpdy3Test::kHandshakeRequestWithoutCookie[] =
- "GET /demo HTTP/1.1\r\n"
- "Host: example.com\r\n"
- "Upgrade: WebSocket\r\n"
- "Connection: Upgrade\r\n"
- "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n"
- "Origin: http://example.com\r\n"
- "Sec-WebSocket-Protocol: sample\r\n"
- "Sec-WebSocket-Version: 13\r\n"
- "\r\n";
-
-const char WebSocketJobSpdy3Test::kHandshakeRequestWithCookie[] =
- "GET /demo HTTP/1.1\r\n"
- "Host: example.com\r\n"
- "Upgrade: WebSocket\r\n"
- "Connection: Upgrade\r\n"
- "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n"
- "Origin: http://example.com\r\n"
- "Sec-WebSocket-Protocol: sample\r\n"
- "Sec-WebSocket-Version: 13\r\n"
- "Cookie: WK-test=1\r\n"
- "\r\n";
-
-const char WebSocketJobSpdy3Test::kHandshakeRequestWithFilteredCookie[] =
- "GET /demo HTTP/1.1\r\n"
- "Host: example.com\r\n"
- "Upgrade: WebSocket\r\n"
- "Connection: Upgrade\r\n"
- "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n"
- "Origin: http://example.com\r\n"
- "Sec-WebSocket-Protocol: sample\r\n"
- "Sec-WebSocket-Version: 13\r\n"
- "Cookie: CR-test=1; CR-test-httponly=1\r\n"
- "\r\n";
-
-const char WebSocketJobSpdy3Test::kHandshakeResponseWithoutCookie[] =
- "HTTP/1.1 101 Switching Protocols\r\n"
- "Upgrade: websocket\r\n"
- "Connection: Upgrade\r\n"
- "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n"
- "Sec-WebSocket-Protocol: sample\r\n"
- "\r\n";
-
-const char WebSocketJobSpdy3Test::kHandshakeResponseWithCookie[] =
- "HTTP/1.1 101 Switching Protocols\r\n"
- "Upgrade: websocket\r\n"
- "Connection: Upgrade\r\n"
- "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n"
- "Sec-WebSocket-Protocol: sample\r\n"
- "Set-Cookie: CR-set-test=1\r\n"
- "\r\n";
-
-const char WebSocketJobSpdy3Test::kDataHello[] = "Hello, ";
-
-const char WebSocketJobSpdy3Test::kDataWorld[] = "World!\n";
-
-const char* const WebSocketJobSpdy3Test::kHandshakeRequestForSpdy[] = {
- ":path", "/demo",
- ":version", "WebSocket/13",
- ":scheme", "ws",
- ":host", "example.com",
- ":origin", "http://example.com",
- ":sec-websocket-protocol", "sample"
-};
-
-const char* const WebSocketJobSpdy3Test::kHandshakeResponseForSpdy[] = {
- ":status", "101 Switching Protocols",
- ":sec-websocket-protocol", "sample"
-};
-
-const size_t WebSocketJobSpdy3Test::kHandshakeRequestWithoutCookieLength =
- arraysize(kHandshakeRequestWithoutCookie) - 1;
-const size_t WebSocketJobSpdy3Test::kHandshakeRequestWithCookieLength =
- arraysize(kHandshakeRequestWithCookie) - 1;
-const size_t WebSocketJobSpdy3Test::kHandshakeRequestWithFilteredCookieLength =
- arraysize(kHandshakeRequestWithFilteredCookie) - 1;
-const size_t WebSocketJobSpdy3Test::kHandshakeResponseWithoutCookieLength =
- arraysize(kHandshakeResponseWithoutCookie) - 1;
-const size_t WebSocketJobSpdy3Test::kHandshakeResponseWithCookieLength =
- arraysize(kHandshakeResponseWithCookie) - 1;
-const size_t WebSocketJobSpdy3Test::kDataHelloLength =
- arraysize(kDataHello) - 1;
-const size_t WebSocketJobSpdy3Test::kDataWorldLength =
- arraysize(kDataWorld) - 1;
-
-void WebSocketJobSpdy3Test::TestSimpleHandshake() {
- GURL url("ws://example.com/demo");
- MockSocketStreamDelegate delegate;
- InitWebSocketJob(url, &delegate, STREAM_MOCK_SOCKET);
- SkipToConnecting();
-
- DoSendRequest();
- base::MessageLoop::current()->RunUntilIdle();
- EXPECT_EQ(kHandshakeRequestWithoutCookie, sent_data());
- EXPECT_EQ(WebSocketJob::CONNECTING, GetWebSocketJobState());
- websocket_->OnSentData(socket_.get(),
- kHandshakeRequestWithoutCookieLength);
- EXPECT_EQ(kHandshakeRequestWithoutCookieLength, delegate.amount_sent());
-
- websocket_->OnReceivedData(socket_.get(),
- kHandshakeResponseWithoutCookie,
- kHandshakeResponseWithoutCookieLength);
- base::MessageLoop::current()->RunUntilIdle();
- EXPECT_EQ(kHandshakeResponseWithoutCookie, delegate.received_data());
- EXPECT_EQ(WebSocketJob::OPEN, GetWebSocketJobState());
- CloseWebSocketJob();
-}
-
-void WebSocketJobSpdy3Test::TestSlowHandshake() {
- GURL url("ws://example.com/demo");
- MockSocketStreamDelegate delegate;
- InitWebSocketJob(url, &delegate, STREAM_MOCK_SOCKET);
- SkipToConnecting();
-
- DoSendRequest();
- // We assume request is sent in one data chunk (from WebKit)
- // We don't support streaming request.
- base::MessageLoop::current()->RunUntilIdle();
- EXPECT_EQ(kHandshakeRequestWithoutCookie, sent_data());
- EXPECT_EQ(WebSocketJob::CONNECTING, GetWebSocketJobState());
- websocket_->OnSentData(socket_.get(),
- kHandshakeRequestWithoutCookieLength);
- EXPECT_EQ(kHandshakeRequestWithoutCookieLength, delegate.amount_sent());
-
- std::vector<std::string> lines;
- base::SplitString(kHandshakeResponseWithoutCookie, '\n', &lines);
- for (size_t i = 0; i < lines.size() - 2; i++) {
- std::string line = lines[i] + "\r\n";
- SCOPED_TRACE("Line: " + line);
- websocket_->OnReceivedData(socket_.get(), line.c_str(), line.size());
- base::MessageLoop::current()->RunUntilIdle();
- EXPECT_TRUE(delegate.received_data().empty());
- EXPECT_EQ(WebSocketJob::CONNECTING, GetWebSocketJobState());
- }
- websocket_->OnReceivedData(socket_.get(), "\r\n", 2);
- base::MessageLoop::current()->RunUntilIdle();
- EXPECT_FALSE(delegate.received_data().empty());
- EXPECT_EQ(kHandshakeResponseWithoutCookie, delegate.received_data());
- EXPECT_EQ(WebSocketJob::OPEN, GetWebSocketJobState());
- CloseWebSocketJob();
-}
-
-TEST_F(WebSocketJobSpdy3Test, DelayedCookies) {
- WebSocketJob::set_websocket_over_spdy_enabled(true);
- GURL url("ws://example.com/demo");
- GURL cookieUrl("http://example.com/demo");
- CookieOptions cookie_options;
- scoped_refptr<DelayedCookieMonster> cookie_store = new DelayedCookieMonster();
- context_->set_cookie_store(cookie_store.get());
- cookie_store->SetCookieWithOptionsAsync(cookieUrl,
- "CR-test=1",
- cookie_options,
- CookieMonster::SetCookiesCallback());
- cookie_options.set_include_httponly();
- cookie_store->SetCookieWithOptionsAsync(
- cookieUrl, "CR-test-httponly=1", cookie_options,
- CookieMonster::SetCookiesCallback());
-
- MockSocketStreamDelegate delegate;
- InitWebSocketJob(url, &delegate, STREAM_MOCK_SOCKET);
- SkipToConnecting();
-
- bool sent = websocket_->SendData(kHandshakeRequestWithCookie,
- kHandshakeRequestWithCookieLength);
- EXPECT_TRUE(sent);
- base::MessageLoop::current()->RunUntilIdle();
- EXPECT_EQ(kHandshakeRequestWithFilteredCookie, sent_data());
- EXPECT_EQ(WebSocketJob::CONNECTING, GetWebSocketJobState());
- websocket_->OnSentData(socket_.get(),
- kHandshakeRequestWithFilteredCookieLength);
- EXPECT_EQ(kHandshakeRequestWithCookieLength,
- delegate.amount_sent());
-
- websocket_->OnReceivedData(socket_.get(),
- kHandshakeResponseWithCookie,
- kHandshakeResponseWithCookieLength);
- base::MessageLoop::current()->RunUntilIdle();
- EXPECT_EQ(kHandshakeResponseWithoutCookie, delegate.received_data());
- EXPECT_EQ(WebSocketJob::OPEN, GetWebSocketJobState());
-
- CloseWebSocketJob();
-}
-
-void WebSocketJobSpdy3Test::TestHandshakeWithCookie() {
- GURL url("ws://example.com/demo");
- GURL cookieUrl("http://example.com/demo");
- CookieOptions cookie_options;
- cookie_store_->SetCookieWithOptions(
- cookieUrl, "CR-test=1", cookie_options);
- cookie_options.set_include_httponly();
- cookie_store_->SetCookieWithOptions(
- cookieUrl, "CR-test-httponly=1", cookie_options);
-
- MockSocketStreamDelegate delegate;
- InitWebSocketJob(url, &delegate, STREAM_MOCK_SOCKET);
- SkipToConnecting();
-
- bool sent = websocket_->SendData(kHandshakeRequestWithCookie,
- kHandshakeRequestWithCookieLength);
- EXPECT_TRUE(sent);
- base::MessageLoop::current()->RunUntilIdle();
- EXPECT_EQ(kHandshakeRequestWithFilteredCookie, sent_data());
- EXPECT_EQ(WebSocketJob::CONNECTING, GetWebSocketJobState());
- websocket_->OnSentData(socket_.get(),
- kHandshakeRequestWithFilteredCookieLength);
- EXPECT_EQ(kHandshakeRequestWithCookieLength,
- delegate.amount_sent());
-
- websocket_->OnReceivedData(socket_.get(),
- kHandshakeResponseWithCookie,
- kHandshakeResponseWithCookieLength);
- base::MessageLoop::current()->RunUntilIdle();
- EXPECT_EQ(kHandshakeResponseWithoutCookie, delegate.received_data());
- EXPECT_EQ(WebSocketJob::OPEN, GetWebSocketJobState());
-
- EXPECT_EQ(3U, cookie_store_->entries().size());
- EXPECT_EQ(cookieUrl, cookie_store_->entries()[0].url);
- EXPECT_EQ("CR-test=1", cookie_store_->entries()[0].cookie_line);
- EXPECT_EQ(cookieUrl, cookie_store_->entries()[1].url);
- EXPECT_EQ("CR-test-httponly=1", cookie_store_->entries()[1].cookie_line);
- EXPECT_EQ(cookieUrl, cookie_store_->entries()[2].url);
- EXPECT_EQ("CR-set-test=1", cookie_store_->entries()[2].cookie_line);
-
- CloseWebSocketJob();
-}
-
-void WebSocketJobSpdy3Test::TestHandshakeWithCookieButNotAllowed() {
- GURL url("ws://example.com/demo");
- GURL cookieUrl("http://example.com/demo");
- CookieOptions cookie_options;
- cookie_store_->SetCookieWithOptions(
- cookieUrl, "CR-test=1", cookie_options);
- cookie_options.set_include_httponly();
- cookie_store_->SetCookieWithOptions(
- cookieUrl, "CR-test-httponly=1", cookie_options);
-
- MockSocketStreamDelegate delegate;
- delegate.set_allow_all_cookies(false);
- InitWebSocketJob(url, &delegate, STREAM_MOCK_SOCKET);
- SkipToConnecting();
-
- bool sent = websocket_->SendData(kHandshakeRequestWithCookie,
- kHandshakeRequestWithCookieLength);
- EXPECT_TRUE(sent);
- base::MessageLoop::current()->RunUntilIdle();
- EXPECT_EQ(kHandshakeRequestWithoutCookie, sent_data());
- EXPECT_EQ(WebSocketJob::CONNECTING, GetWebSocketJobState());
- websocket_->OnSentData(socket_.get(), kHandshakeRequestWithoutCookieLength);
- EXPECT_EQ(kHandshakeRequestWithCookieLength, delegate.amount_sent());
-
- websocket_->OnReceivedData(socket_.get(),
- kHandshakeResponseWithCookie,
- kHandshakeResponseWithCookieLength);
- base::MessageLoop::current()->RunUntilIdle();
- EXPECT_EQ(kHandshakeResponseWithoutCookie, delegate.received_data());
- EXPECT_EQ(WebSocketJob::OPEN, GetWebSocketJobState());
-
- EXPECT_EQ(2U, cookie_store_->entries().size());
- EXPECT_EQ(cookieUrl, cookie_store_->entries()[0].url);
- EXPECT_EQ("CR-test=1", cookie_store_->entries()[0].cookie_line);
- EXPECT_EQ(cookieUrl, cookie_store_->entries()[1].url);
- EXPECT_EQ("CR-test-httponly=1", cookie_store_->entries()[1].cookie_line);
-
- CloseWebSocketJob();
-}
-
-void WebSocketJobSpdy3Test::TestHSTSUpgrade() {
- GURL url("ws://upgrademe.com/");
- MockSocketStreamDelegate delegate;
- scoped_refptr<SocketStreamJob> job =
- SocketStreamJob::CreateSocketStreamJob(
- url, &delegate, context_->transport_security_state(),
- context_->ssl_config_service());
- EXPECT_TRUE(GetSocket(job.get())->is_secure());
- job->DetachDelegate();
-
- url = GURL("ws://donotupgrademe.com/");
- job = SocketStreamJob::CreateSocketStreamJob(
- url, &delegate, context_->transport_security_state(),
- context_->ssl_config_service());
- EXPECT_FALSE(GetSocket(job.get())->is_secure());
- job->DetachDelegate();
-}
-
-void WebSocketJobSpdy3Test::TestInvalidSendData() {
- GURL url("ws://example.com/demo");
- MockSocketStreamDelegate delegate;
- InitWebSocketJob(url, &delegate, STREAM_MOCK_SOCKET);
- SkipToConnecting();
-
- DoSendRequest();
- // We assume request is sent in one data chunk (from WebKit)
- // We don't support streaming request.
- base::MessageLoop::current()->RunUntilIdle();
- EXPECT_EQ(kHandshakeRequestWithoutCookie, sent_data());
- EXPECT_EQ(WebSocketJob::CONNECTING, GetWebSocketJobState());
- websocket_->OnSentData(socket_.get(),
- kHandshakeRequestWithoutCookieLength);
- EXPECT_EQ(kHandshakeRequestWithoutCookieLength, delegate.amount_sent());
-
- // We could not send any data until connection is established.
- bool sent = websocket_->SendData(kHandshakeRequestWithoutCookie,
- kHandshakeRequestWithoutCookieLength);
- EXPECT_FALSE(sent);
- EXPECT_EQ(WebSocketJob::CONNECTING, GetWebSocketJobState());
- CloseWebSocketJob();
-}
-
-// Following tests verify cooperation between WebSocketJob and SocketStream.
-// Other former tests use MockSocketStream as SocketStream, so we could not
-// check SocketStream behavior.
-// OrderedSocketData provide socket level verifiation by checking out-going
-// packets in comparison with the MockWrite array and emulating in-coming
-// packets with MockRead array.
-
-void WebSocketJobSpdy3Test::TestConnectByWebSocket(
- ThrottlingOption throttling) {
- // This is a test for verifying cooperation between WebSocketJob and
- // SocketStream. If |throttling| was |THROTTLING_OFF|, it test basic
- // situation. If |throttling| was |THROTTLING_ON|, throttling limits the
- // latter connection.
- MockWrite writes[] = {
- MockWrite(ASYNC,
- kHandshakeRequestWithoutCookie,
- kHandshakeRequestWithoutCookieLength,
- 1),
- MockWrite(ASYNC,
- kDataHello,
- kDataHelloLength,
- 3)
- };
- MockRead reads[] = {
- MockRead(ASYNC,
- kHandshakeResponseWithoutCookie,
- kHandshakeResponseWithoutCookieLength,
- 2),
- MockRead(ASYNC,
- kDataWorld,
- kDataWorldLength,
- 4),
- MockRead(SYNCHRONOUS, 0, 5) // EOF
- };
- data_.reset(new OrderedSocketData(
- reads, arraysize(reads), writes, arraysize(writes)));
-
- GURL url("ws://example.com/demo");
- MockSocketStreamDelegate delegate;
- WebSocketJobSpdy3Test* test = this;
- if (throttling == THROTTLING_ON)
- delegate.SetOnStartOpenConnection(
- base::Bind(&WebSocketJobSpdy3Test::DoSync, base::Unretained(test)));
- delegate.SetOnConnected(
- base::Bind(&WebSocketJobSpdy3Test::DoSendRequest,
- base::Unretained(test)));
- delegate.SetOnReceivedData(
- base::Bind(&WebSocketJobSpdy3Test::DoSendData, base::Unretained(test)));
- delegate.SetOnClose(
- base::Bind(&WebSocketJobSpdy3Test::DoSync, base::Unretained(test)));
- InitWebSocketJob(url, &delegate, STREAM_SOCKET);
-
- scoped_refptr<WebSocketJob> block_websocket;
- if (throttling == THROTTLING_ON) {
- // Create former WebSocket object which obstructs the latter one.
- block_websocket = new WebSocketJob(NULL);
- block_websocket->addresses_ = AddressList(websocket_->address_list());
- WebSocketThrottle::GetInstance()->PutInQueue(block_websocket.get());
- }
-
- websocket_->Connect();
-
- if (throttling == THROTTLING_ON) {
- EXPECT_EQ(OK, WaitForResult());
- EXPECT_TRUE(websocket_->IsWaiting());
-
- // Remove the former WebSocket object from throttling queue to unblock the
- // latter.
- WebSocketThrottle::GetInstance()->RemoveFromQueue(block_websocket.get());
- block_websocket->state_ = WebSocketJob::CLOSED;
- block_websocket = NULL;
- WebSocketThrottle::GetInstance()->WakeupSocketIfNecessary();
- }
-
- EXPECT_EQ(OK, WaitForResult());
- EXPECT_TRUE(data_->at_read_eof());
- EXPECT_TRUE(data_->at_write_eof());
- EXPECT_EQ(WebSocketJob::CLOSED, GetWebSocketJobState());
-}
-
-void WebSocketJobSpdy3Test::TestConnectBySpdy(
- SpdyOption spdy, ThrottlingOption throttling) {
- // This is a test for verifying cooperation between WebSocketJob and
- // SocketStream in the situation we have SPDY session to the server. If
- // |throttling| was |THROTTLING_ON|, throttling limits the latter connection.
- // If you enabled spdy, you should specify |spdy| as |SPDY_ON|. Expected
- // results depend on its configuration.
- MockWrite writes_websocket[] = {
- MockWrite(ASYNC,
- kHandshakeRequestWithoutCookie,
- kHandshakeRequestWithoutCookieLength,
- 1),
- MockWrite(ASYNC,
- kDataHello,
- kDataHelloLength,
- 3)
- };
- MockRead reads_websocket[] = {
- MockRead(ASYNC,
- kHandshakeResponseWithoutCookie,
- kHandshakeResponseWithoutCookieLength,
- 2),
- MockRead(ASYNC,
- kDataWorld,
- kDataWorldLength,
- 4),
- MockRead(SYNCHRONOUS, 0, 5) // EOF
- };
-
- const SpdyStreamId kStreamId = 1;
- scoped_ptr<SpdyFrame> request_frame(
- spdy_util_.ConstructSpdyWebSocketHandshakeRequestFrame(
- kHandshakeRequestForSpdy,
- arraysize(kHandshakeRequestForSpdy) / 2,
- kStreamId,
- MEDIUM));
- scoped_ptr<SpdyFrame> response_frame(
- spdy_util_.ConstructSpdyWebSocketHandshakeResponseFrame(
- kHandshakeResponseForSpdy,
- arraysize(kHandshakeResponseForSpdy) / 2,
- kStreamId,
- MEDIUM));
- scoped_ptr<SpdyFrame> data_hello_frame(
- spdy_util_.ConstructSpdyWebSocketDataFrame(
- kDataHello,
- kDataHelloLength,
- kStreamId,
- false));
- scoped_ptr<SpdyFrame> data_world_frame(
- spdy_util_.ConstructSpdyWebSocketDataFrame(
- kDataWorld,
- kDataWorldLength,
- kStreamId,
- false));
- MockWrite writes_spdy[] = {
- CreateMockWrite(*request_frame.get(), 1),
- CreateMockWrite(*data_hello_frame.get(), 3),
- };
- MockRead reads_spdy[] = {
- CreateMockRead(*response_frame.get(), 2),
- CreateMockRead(*data_world_frame.get(), 4),
- MockRead(SYNCHRONOUS, 0, 5) // EOF
- };
-
- if (spdy == SPDY_ON)
- data_.reset(new OrderedSocketData(
- reads_spdy, arraysize(reads_spdy),
- writes_spdy, arraysize(writes_spdy)));
- else
- data_.reset(new OrderedSocketData(
- reads_websocket, arraysize(reads_websocket),
- writes_websocket, arraysize(writes_websocket)));
-
- GURL url("ws://example.com/demo");
- MockSocketStreamDelegate delegate;
- WebSocketJobSpdy3Test* test = this;
- if (throttling == THROTTLING_ON)
- delegate.SetOnStartOpenConnection(
- base::Bind(&WebSocketJobSpdy3Test::DoSync, base::Unretained(test)));
- delegate.SetOnConnected(
- base::Bind(&WebSocketJobSpdy3Test::DoSendRequest,
- base::Unretained(test)));
- delegate.SetOnReceivedData(
- base::Bind(&WebSocketJobSpdy3Test::DoSendData, base::Unretained(test)));
- delegate.SetOnClose(
- base::Bind(&WebSocketJobSpdy3Test::DoSync, base::Unretained(test)));
- InitWebSocketJob(url, &delegate, STREAM_SPDY_WEBSOCKET);
-
- scoped_refptr<WebSocketJob> block_websocket;
- if (throttling == THROTTLING_ON) {
- // Create former WebSocket object which obstructs the latter one.
- block_websocket = new WebSocketJob(NULL);
- block_websocket->addresses_ = AddressList(websocket_->address_list());
- WebSocketThrottle::GetInstance()->PutInQueue(block_websocket.get());
- }
-
- websocket_->Connect();
-
- if (throttling == THROTTLING_ON) {
- EXPECT_EQ(OK, WaitForResult());
- EXPECT_TRUE(websocket_->IsWaiting());
-
- // Remove the former WebSocket object from throttling queue to unblock the
- // latter.
- WebSocketThrottle::GetInstance()->RemoveFromQueue(block_websocket.get());
- block_websocket->state_ = WebSocketJob::CLOSED;
- block_websocket = NULL;
- WebSocketThrottle::GetInstance()->WakeupSocketIfNecessary();
- }
-
- EXPECT_EQ(OK, WaitForResult());
- EXPECT_TRUE(data_->at_read_eof());
- EXPECT_TRUE(data_->at_write_eof());
- EXPECT_EQ(WebSocketJob::CLOSED, GetWebSocketJobState());
-}
-
-// Execute tests in both spdy-disabled mode and spdy-enabled mode.
-TEST_F(WebSocketJobSpdy3Test, SimpleHandshake) {
- WebSocketJob::set_websocket_over_spdy_enabled(false);
- TestSimpleHandshake();
-}
-
-TEST_F(WebSocketJobSpdy3Test, SlowHandshake) {
- WebSocketJob::set_websocket_over_spdy_enabled(false);
- TestSlowHandshake();
-}
-
-TEST_F(WebSocketJobSpdy3Test, HandshakeWithCookie) {
- WebSocketJob::set_websocket_over_spdy_enabled(false);
- TestHandshakeWithCookie();
-}
-
-TEST_F(WebSocketJobSpdy3Test, HandshakeWithCookieButNotAllowed) {
- WebSocketJob::set_websocket_over_spdy_enabled(false);
- TestHandshakeWithCookieButNotAllowed();
-}
-
-TEST_F(WebSocketJobSpdy3Test, HSTSUpgrade) {
- WebSocketJob::set_websocket_over_spdy_enabled(false);
- TestHSTSUpgrade();
-}
-
-TEST_F(WebSocketJobSpdy3Test, InvalidSendData) {
- WebSocketJob::set_websocket_over_spdy_enabled(false);
- TestInvalidSendData();
-}
-
-TEST_F(WebSocketJobSpdy3Test, SimpleHandshakeSpdyEnabled) {
- WebSocketJob::set_websocket_over_spdy_enabled(true);
- TestSimpleHandshake();
-}
-
-TEST_F(WebSocketJobSpdy3Test, SlowHandshakeSpdyEnabled) {
- WebSocketJob::set_websocket_over_spdy_enabled(true);
- TestSlowHandshake();
-}
-
-TEST_F(WebSocketJobSpdy3Test, HandshakeWithCookieSpdyEnabled) {
- WebSocketJob::set_websocket_over_spdy_enabled(true);
- TestHandshakeWithCookie();
-}
-
-TEST_F(WebSocketJobSpdy3Test, HandshakeWithCookieButNotAllowedSpdyEnabled) {
- WebSocketJob::set_websocket_over_spdy_enabled(true);
- TestHandshakeWithCookieButNotAllowed();
-}
-
-TEST_F(WebSocketJobSpdy3Test, HSTSUpgradeSpdyEnabled) {
- WebSocketJob::set_websocket_over_spdy_enabled(true);
- TestHSTSUpgrade();
-}
-
-TEST_F(WebSocketJobSpdy3Test, InvalidSendDataSpdyEnabled) {
- WebSocketJob::set_websocket_over_spdy_enabled(true);
- TestInvalidSendData();
-}
-
-TEST_F(WebSocketJobSpdy3Test, ConnectByWebSocket) {
- WebSocketJob::set_websocket_over_spdy_enabled(false);
- TestConnectByWebSocket(THROTTLING_OFF);
-}
-
-TEST_F(WebSocketJobSpdy3Test, ConnectByWebSocketSpdyEnabled) {
- WebSocketJob::set_websocket_over_spdy_enabled(true);
- TestConnectByWebSocket(THROTTLING_OFF);
-}
-
-TEST_F(WebSocketJobSpdy3Test, ConnectBySpdy) {
- WebSocketJob::set_websocket_over_spdy_enabled(false);
- TestConnectBySpdy(SPDY_OFF, THROTTLING_OFF);
-}
-
-TEST_F(WebSocketJobSpdy3Test, ConnectBySpdySpdyEnabled) {
- WebSocketJob::set_websocket_over_spdy_enabled(true);
- TestConnectBySpdy(SPDY_ON, THROTTLING_OFF);
-}
-
-TEST_F(WebSocketJobSpdy3Test, ThrottlingWebSocket) {
- WebSocketJob::set_websocket_over_spdy_enabled(false);
- TestConnectByWebSocket(THROTTLING_ON);
-}
-
-TEST_F(WebSocketJobSpdy3Test, ThrottlingWebSocketSpdyEnabled) {
- WebSocketJob::set_websocket_over_spdy_enabled(true);
- TestConnectByWebSocket(THROTTLING_ON);
-}
-
-TEST_F(WebSocketJobSpdy3Test, ThrottlingSpdy) {
- WebSocketJob::set_websocket_over_spdy_enabled(false);
- TestConnectBySpdy(SPDY_OFF, THROTTLING_ON);
-}
-
-TEST_F(WebSocketJobSpdy3Test, ThrottlingSpdySpdyEnabled) {
- WebSocketJob::set_websocket_over_spdy_enabled(true);
- TestConnectBySpdy(SPDY_ON, THROTTLING_ON);
-}
-
-// TODO(toyoshim): Add tests to verify throttling, SPDY stream limitation.
-// TODO(toyoshim,yutak): Add tests to verify closing handshake.
-} // namespace net
diff --git a/net/websockets/websocket_job_spdy2_unittest.cc b/net/websockets/websocket_job_unittest.cc
index 42a0895..db4b068 100644
--- a/net/websockets/websocket_job_spdy2_unittest.cc
+++ b/net/websockets/websocket_job_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -11,8 +11,8 @@
#include "base/bind_helpers.h"
#include "base/callback.h"
#include "base/memory/ref_counted.h"
-#include "base/strings/string_util.h"
#include "base/strings/string_split.h"
+#include "base/strings/string_util.h"
#include "googleurl/src/gurl.h"
#include "net/base/completion_callback.h"
#include "net/base/net_errors.h"
@@ -35,8 +35,6 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"
-using namespace net::test_spdy2;
-
namespace net {
namespace {
@@ -261,11 +259,11 @@ class MockURLRequestContext : public URLRequestContext {
class MockHttpTransactionFactory : public HttpTransactionFactory {
public:
- explicit MockHttpTransactionFactory(OrderedSocketData* data) {
+ MockHttpTransactionFactory(NextProto next_proto, OrderedSocketData* data) {
data_ = data;
MockConnect connect_data(SYNCHRONOUS, OK);
data_->set_connect_data(connect_data);
- session_deps_.reset(new SpdySessionDependencies(kProtoSPDY2));
+ session_deps_.reset(new SpdySessionDependencies(next_proto));
session_deps_->socket_factory->AddSocketDataProvider(data_);
http_session_ =
SpdySessionDependencies::SpdyCreateSession(session_deps_.get());
@@ -328,9 +326,10 @@ class MockHttpTransactionFactory : public HttpTransactionFactory {
} // namespace
-class WebSocketJobSpdy2Test : public PlatformTest {
+class WebSocketJobTest : public PlatformTest,
+ public ::testing::WithParamInterface<NextProto> {
public:
- WebSocketJobSpdy2Test() : spdy_util_(kProtoSPDY2) {}
+ WebSocketJobTest() : spdy_util_(GetParam()) {}
virtual void SetUp() OVERRIDE {
stream_type_ = STREAM_INVALID;
@@ -384,7 +383,8 @@ class WebSocketJobSpdy2Test : public PlatformTest {
if (stream_type == STREAM_SOCKET || stream_type == STREAM_SPDY_WEBSOCKET) {
if (stream_type == STREAM_SPDY_WEBSOCKET) {
- http_factory_.reset(new MockHttpTransactionFactory(data_.get()));
+ http_factory_.reset(
+ new MockHttpTransactionFactory(GetParam(), data_.get()));
context_->set_http_transaction_factory(http_factory_.get());
}
@@ -487,7 +487,7 @@ class WebSocketJobSpdy2Test : public PlatformTest {
static const size_t kDataWorldLength;
};
-const char WebSocketJobSpdy2Test::kHandshakeRequestWithoutCookie[] =
+const char WebSocketJobTest::kHandshakeRequestWithoutCookie[] =
"GET /demo HTTP/1.1\r\n"
"Host: example.com\r\n"
"Upgrade: WebSocket\r\n"
@@ -498,7 +498,7 @@ const char WebSocketJobSpdy2Test::kHandshakeRequestWithoutCookie[] =
"Sec-WebSocket-Version: 13\r\n"
"\r\n";
-const char WebSocketJobSpdy2Test::kHandshakeRequestWithCookie[] =
+const char WebSocketJobTest::kHandshakeRequestWithCookie[] =
"GET /demo HTTP/1.1\r\n"
"Host: example.com\r\n"
"Upgrade: WebSocket\r\n"
@@ -510,7 +510,7 @@ const char WebSocketJobSpdy2Test::kHandshakeRequestWithCookie[] =
"Cookie: WK-test=1\r\n"
"\r\n";
-const char WebSocketJobSpdy2Test::kHandshakeRequestWithFilteredCookie[] =
+const char WebSocketJobTest::kHandshakeRequestWithFilteredCookie[] =
"GET /demo HTTP/1.1\r\n"
"Host: example.com\r\n"
"Upgrade: WebSocket\r\n"
@@ -522,7 +522,7 @@ const char WebSocketJobSpdy2Test::kHandshakeRequestWithFilteredCookie[] =
"Cookie: CR-test=1; CR-test-httponly=1\r\n"
"\r\n";
-const char WebSocketJobSpdy2Test::kHandshakeResponseWithoutCookie[] =
+const char WebSocketJobTest::kHandshakeResponseWithoutCookie[] =
"HTTP/1.1 101 Switching Protocols\r\n"
"Upgrade: websocket\r\n"
"Connection: Upgrade\r\n"
@@ -530,7 +530,7 @@ const char WebSocketJobSpdy2Test::kHandshakeResponseWithoutCookie[] =
"Sec-WebSocket-Protocol: sample\r\n"
"\r\n";
-const char WebSocketJobSpdy2Test::kHandshakeResponseWithCookie[] =
+const char WebSocketJobTest::kHandshakeResponseWithCookie[] =
"HTTP/1.1 101 Switching Protocols\r\n"
"Upgrade: websocket\r\n"
"Connection: Upgrade\r\n"
@@ -539,40 +539,26 @@ const char WebSocketJobSpdy2Test::kHandshakeResponseWithCookie[] =
"Set-Cookie: CR-set-test=1\r\n"
"\r\n";
-const char WebSocketJobSpdy2Test::kDataHello[] = "Hello, ";
-
-const char WebSocketJobSpdy2Test::kDataWorld[] = "World!\n";
+const char WebSocketJobTest::kDataHello[] = "Hello, ";
-const char* const WebSocketJobSpdy2Test::kHandshakeRequestForSpdy[] = {
- "path", "/demo",
- "version", "WebSocket/13",
- "scheme", "ws",
- "host", "example.com",
- "origin", "http://example.com",
- "sec-websocket-protocol", "sample"
-};
-
-const char* const WebSocketJobSpdy2Test::kHandshakeResponseForSpdy[] = {
- "status", "101 Switching Protocols",
- "sec-websocket-protocol", "sample"
-};
+const char WebSocketJobTest::kDataWorld[] = "World!\n";
-const size_t WebSocketJobSpdy2Test::kHandshakeRequestWithoutCookieLength =
+const size_t WebSocketJobTest::kHandshakeRequestWithoutCookieLength =
arraysize(kHandshakeRequestWithoutCookie) - 1;
-const size_t WebSocketJobSpdy2Test::kHandshakeRequestWithCookieLength =
+const size_t WebSocketJobTest::kHandshakeRequestWithCookieLength =
arraysize(kHandshakeRequestWithCookie) - 1;
-const size_t WebSocketJobSpdy2Test::kHandshakeRequestWithFilteredCookieLength =
+const size_t WebSocketJobTest::kHandshakeRequestWithFilteredCookieLength =
arraysize(kHandshakeRequestWithFilteredCookie) - 1;
-const size_t WebSocketJobSpdy2Test::kHandshakeResponseWithoutCookieLength =
+const size_t WebSocketJobTest::kHandshakeResponseWithoutCookieLength =
arraysize(kHandshakeResponseWithoutCookie) - 1;
-const size_t WebSocketJobSpdy2Test::kHandshakeResponseWithCookieLength =
+const size_t WebSocketJobTest::kHandshakeResponseWithCookieLength =
arraysize(kHandshakeResponseWithCookie) - 1;
-const size_t WebSocketJobSpdy2Test::kDataHelloLength =
+const size_t WebSocketJobTest::kDataHelloLength =
arraysize(kDataHello) - 1;
-const size_t WebSocketJobSpdy2Test::kDataWorldLength =
+const size_t WebSocketJobTest::kDataWorldLength =
arraysize(kDataWorld) - 1;
-void WebSocketJobSpdy2Test::TestSimpleHandshake() {
+void WebSocketJobTest::TestSimpleHandshake() {
GURL url("ws://example.com/demo");
MockSocketStreamDelegate delegate;
InitWebSocketJob(url, &delegate, STREAM_MOCK_SOCKET);
@@ -595,7 +581,7 @@ void WebSocketJobSpdy2Test::TestSimpleHandshake() {
CloseWebSocketJob();
}
-void WebSocketJobSpdy2Test::TestSlowHandshake() {
+void WebSocketJobTest::TestSlowHandshake() {
GURL url("ws://example.com/demo");
MockSocketStreamDelegate delegate;
InitWebSocketJob(url, &delegate, STREAM_MOCK_SOCKET);
@@ -629,7 +615,15 @@ void WebSocketJobSpdy2Test::TestSlowHandshake() {
CloseWebSocketJob();
}
-TEST_F(WebSocketJobSpdy2Test, DelayedCookies) {
+INSTANTIATE_TEST_CASE_P(
+ NextProto,
+ WebSocketJobTest,
+ testing::Values(kProtoSPDY2, kProtoSPDY3, kProtoSPDY31, kProtoSPDY4a2));
+
+// TODO(akalin): Don't early-exit in the tests below for values >
+// kProtoSPDY3.
+
+TEST_P(WebSocketJobTest, DelayedCookies) {
WebSocketJob::set_websocket_over_spdy_enabled(true);
GURL url("ws://example.com/demo");
GURL cookieUrl("http://example.com/demo");
@@ -670,7 +664,7 @@ TEST_F(WebSocketJobSpdy2Test, DelayedCookies) {
CloseWebSocketJob();
}
-void WebSocketJobSpdy2Test::TestHandshakeWithCookie() {
+void WebSocketJobTest::TestHandshakeWithCookie() {
GURL url("ws://example.com/demo");
GURL cookieUrl("http://example.com/demo");
CookieOptions cookie_options;
@@ -713,7 +707,7 @@ void WebSocketJobSpdy2Test::TestHandshakeWithCookie() {
CloseWebSocketJob();
}
-void WebSocketJobSpdy2Test::TestHandshakeWithCookieButNotAllowed() {
+void WebSocketJobTest::TestHandshakeWithCookieButNotAllowed() {
GURL url("ws://example.com/demo");
GURL cookieUrl("http://example.com/demo");
CookieOptions cookie_options;
@@ -753,7 +747,7 @@ void WebSocketJobSpdy2Test::TestHandshakeWithCookieButNotAllowed() {
CloseWebSocketJob();
}
-void WebSocketJobSpdy2Test::TestHSTSUpgrade() {
+void WebSocketJobTest::TestHSTSUpgrade() {
GURL url("ws://upgrademe.com/");
MockSocketStreamDelegate delegate;
scoped_refptr<SocketStreamJob> job =
@@ -771,7 +765,7 @@ void WebSocketJobSpdy2Test::TestHSTSUpgrade() {
job->DetachDelegate();
}
-void WebSocketJobSpdy2Test::TestInvalidSendData() {
+void WebSocketJobTest::TestInvalidSendData() {
GURL url("ws://example.com/demo");
MockSocketStreamDelegate delegate;
InitWebSocketJob(url, &delegate, STREAM_MOCK_SOCKET);
@@ -802,7 +796,7 @@ void WebSocketJobSpdy2Test::TestInvalidSendData() {
// packets in comparison with the MockWrite array and emulating in-coming
// packets with MockRead array.
-void WebSocketJobSpdy2Test::TestConnectByWebSocket(
+void WebSocketJobTest::TestConnectByWebSocket(
ThrottlingOption throttling) {
// This is a test for verifying cooperation between WebSocketJob and
// SocketStream. If |throttling| was |THROTTLING_OFF|, it test basic
@@ -834,17 +828,17 @@ void WebSocketJobSpdy2Test::TestConnectByWebSocket(
GURL url("ws://example.com/demo");
MockSocketStreamDelegate delegate;
- WebSocketJobSpdy2Test* test = this;
+ WebSocketJobTest* test = this;
if (throttling == THROTTLING_ON)
delegate.SetOnStartOpenConnection(
- base::Bind(&WebSocketJobSpdy2Test::DoSync, base::Unretained(test)));
+ base::Bind(&WebSocketJobTest::DoSync, base::Unretained(test)));
delegate.SetOnConnected(
- base::Bind(&WebSocketJobSpdy2Test::DoSendRequest,
+ base::Bind(&WebSocketJobTest::DoSendRequest,
base::Unretained(test)));
delegate.SetOnReceivedData(
- base::Bind(&WebSocketJobSpdy2Test::DoSendData, base::Unretained(test)));
+ base::Bind(&WebSocketJobTest::DoSendData, base::Unretained(test)));
delegate.SetOnClose(
- base::Bind(&WebSocketJobSpdy2Test::DoSync, base::Unretained(test)));
+ base::Bind(&WebSocketJobTest::DoSync, base::Unretained(test)));
InitWebSocketJob(url, &delegate, STREAM_SOCKET);
scoped_refptr<WebSocketJob> block_websocket;
@@ -875,7 +869,7 @@ void WebSocketJobSpdy2Test::TestConnectByWebSocket(
EXPECT_EQ(WebSocketJob::CLOSED, GetWebSocketJobState());
}
-void WebSocketJobSpdy2Test::TestConnectBySpdy(
+void WebSocketJobTest::TestConnectBySpdy(
SpdyOption spdy, ThrottlingOption throttling) {
// This is a test for verifying cooperation between WebSocketJob and
// SocketStream in the situation we have SPDY session to the server. If
@@ -904,17 +898,30 @@ void WebSocketJobSpdy2Test::TestConnectBySpdy(
MockRead(SYNCHRONOUS, 0, 5) // EOF
};
+ scoped_ptr<SpdyHeaderBlock> request_headers(new SpdyHeaderBlock());
+ spdy_util_.SetHeader("path", "/demo", request_headers.get());
+ spdy_util_.SetHeader("version", "WebSocket/13", request_headers.get());
+ spdy_util_.SetHeader("scheme", "ws", request_headers.get());
+ spdy_util_.SetHeader("host", "example.com", request_headers.get());
+ spdy_util_.SetHeader("origin", "http://example.com", request_headers.get());
+ spdy_util_.SetHeader("sec-websocket-protocol", "sample",
+ request_headers.get());
+
+ scoped_ptr<SpdyHeaderBlock> response_headers(new SpdyHeaderBlock());
+ spdy_util_.SetHeader("status", "101 Switching Protocols",
+ response_headers.get());
+ spdy_util_.SetHeader("sec-websocket-protocol", "sample",
+ response_headers.get());
+
const SpdyStreamId kStreamId = 1;
scoped_ptr<SpdyFrame> request_frame(
spdy_util_.ConstructSpdyWebSocketHandshakeRequestFrame(
- kHandshakeRequestForSpdy,
- arraysize(kHandshakeRequestForSpdy) / 2,
+ request_headers.Pass(),
kStreamId,
MEDIUM));
scoped_ptr<SpdyFrame> response_frame(
spdy_util_.ConstructSpdyWebSocketHandshakeResponseFrame(
- kHandshakeResponseForSpdy,
- arraysize(kHandshakeResponseForSpdy) / 2,
+ response_headers.Pass(),
kStreamId,
MEDIUM));
scoped_ptr<SpdyFrame> data_hello_frame(
@@ -950,17 +957,17 @@ void WebSocketJobSpdy2Test::TestConnectBySpdy(
GURL url("ws://example.com/demo");
MockSocketStreamDelegate delegate;
- WebSocketJobSpdy2Test* test = this;
+ WebSocketJobTest* test = this;
if (throttling == THROTTLING_ON)
delegate.SetOnStartOpenConnection(
- base::Bind(&WebSocketJobSpdy2Test::DoSync, base::Unretained(test)));
+ base::Bind(&WebSocketJobTest::DoSync, base::Unretained(test)));
delegate.SetOnConnected(
- base::Bind(&WebSocketJobSpdy2Test::DoSendRequest,
+ base::Bind(&WebSocketJobTest::DoSendRequest,
base::Unretained(test)));
delegate.SetOnReceivedData(
- base::Bind(&WebSocketJobSpdy2Test::DoSendData, base::Unretained(test)));
+ base::Bind(&WebSocketJobTest::DoSendData, base::Unretained(test)));
delegate.SetOnClose(
- base::Bind(&WebSocketJobSpdy2Test::DoSync, base::Unretained(test)));
+ base::Bind(&WebSocketJobTest::DoSync, base::Unretained(test)));
InitWebSocketJob(url, &delegate, STREAM_SPDY_WEBSOCKET);
scoped_refptr<WebSocketJob> block_websocket;
@@ -992,102 +999,114 @@ void WebSocketJobSpdy2Test::TestConnectBySpdy(
}
// Execute tests in both spdy-disabled mode and spdy-enabled mode.
-TEST_F(WebSocketJobSpdy2Test, SimpleHandshake) {
+TEST_P(WebSocketJobTest, SimpleHandshake) {
WebSocketJob::set_websocket_over_spdy_enabled(false);
TestSimpleHandshake();
}
-TEST_F(WebSocketJobSpdy2Test, SlowHandshake) {
+TEST_P(WebSocketJobTest, SlowHandshake) {
WebSocketJob::set_websocket_over_spdy_enabled(false);
TestSlowHandshake();
}
-TEST_F(WebSocketJobSpdy2Test, HandshakeWithCookie) {
+TEST_P(WebSocketJobTest, HandshakeWithCookie) {
WebSocketJob::set_websocket_over_spdy_enabled(false);
TestHandshakeWithCookie();
}
-TEST_F(WebSocketJobSpdy2Test, HandshakeWithCookieButNotAllowed) {
+TEST_P(WebSocketJobTest, HandshakeWithCookieButNotAllowed) {
WebSocketJob::set_websocket_over_spdy_enabled(false);
TestHandshakeWithCookieButNotAllowed();
}
-TEST_F(WebSocketJobSpdy2Test, HSTSUpgrade) {
+TEST_P(WebSocketJobTest, HSTSUpgrade) {
WebSocketJob::set_websocket_over_spdy_enabled(false);
TestHSTSUpgrade();
}
-TEST_F(WebSocketJobSpdy2Test, InvalidSendData) {
+TEST_P(WebSocketJobTest, InvalidSendData) {
WebSocketJob::set_websocket_over_spdy_enabled(false);
TestInvalidSendData();
}
-TEST_F(WebSocketJobSpdy2Test, SimpleHandshakeSpdyEnabled) {
+TEST_P(WebSocketJobTest, SimpleHandshakeSpdyEnabled) {
WebSocketJob::set_websocket_over_spdy_enabled(true);
TestSimpleHandshake();
}
-TEST_F(WebSocketJobSpdy2Test, SlowHandshakeSpdyEnabled) {
+TEST_P(WebSocketJobTest, SlowHandshakeSpdyEnabled) {
WebSocketJob::set_websocket_over_spdy_enabled(true);
TestSlowHandshake();
}
-TEST_F(WebSocketJobSpdy2Test, HandshakeWithCookieSpdyEnabled) {
+TEST_P(WebSocketJobTest, HandshakeWithCookieSpdyEnabled) {
WebSocketJob::set_websocket_over_spdy_enabled(true);
TestHandshakeWithCookie();
}
-TEST_F(WebSocketJobSpdy2Test, HandshakeWithCookieButNotAllowedSpdyEnabled) {
+TEST_P(WebSocketJobTest, HandshakeWithCookieButNotAllowedSpdyEnabled) {
WebSocketJob::set_websocket_over_spdy_enabled(true);
TestHandshakeWithCookieButNotAllowed();
}
-TEST_F(WebSocketJobSpdy2Test, HSTSUpgradeSpdyEnabled) {
+TEST_P(WebSocketJobTest, HSTSUpgradeSpdyEnabled) {
WebSocketJob::set_websocket_over_spdy_enabled(true);
TestHSTSUpgrade();
}
-TEST_F(WebSocketJobSpdy2Test, InvalidSendDataSpdyEnabled) {
+TEST_P(WebSocketJobTest, InvalidSendDataSpdyEnabled) {
WebSocketJob::set_websocket_over_spdy_enabled(true);
TestInvalidSendData();
}
-TEST_F(WebSocketJobSpdy2Test, ConnectByWebSocket) {
+TEST_P(WebSocketJobTest, ConnectByWebSocket) {
WebSocketJob::set_websocket_over_spdy_enabled(false);
TestConnectByWebSocket(THROTTLING_OFF);
}
-TEST_F(WebSocketJobSpdy2Test, ConnectByWebSocketSpdyEnabled) {
+TEST_P(WebSocketJobTest, ConnectByWebSocketSpdyEnabled) {
WebSocketJob::set_websocket_over_spdy_enabled(true);
TestConnectByWebSocket(THROTTLING_OFF);
}
-TEST_F(WebSocketJobSpdy2Test, ConnectBySpdy) {
+TEST_P(WebSocketJobTest, ConnectBySpdy) {
+ if (GetParam() > kProtoSPDY3)
+ return;
+
WebSocketJob::set_websocket_over_spdy_enabled(false);
TestConnectBySpdy(SPDY_OFF, THROTTLING_OFF);
}
-TEST_F(WebSocketJobSpdy2Test, ConnectBySpdySpdyEnabled) {
+TEST_P(WebSocketJobTest, ConnectBySpdySpdyEnabled) {
+ if (GetParam() > kProtoSPDY3)
+ return;
+
WebSocketJob::set_websocket_over_spdy_enabled(true);
TestConnectBySpdy(SPDY_ON, THROTTLING_OFF);
}
-TEST_F(WebSocketJobSpdy2Test, ThrottlingWebSocket) {
+TEST_P(WebSocketJobTest, ThrottlingWebSocket) {
WebSocketJob::set_websocket_over_spdy_enabled(false);
TestConnectByWebSocket(THROTTLING_ON);
}
-TEST_F(WebSocketJobSpdy2Test, ThrottlingWebSocketSpdyEnabled) {
+TEST_P(WebSocketJobTest, ThrottlingWebSocketSpdyEnabled) {
WebSocketJob::set_websocket_over_spdy_enabled(true);
TestConnectByWebSocket(THROTTLING_ON);
}
-TEST_F(WebSocketJobSpdy2Test, ThrottlingSpdy) {
+TEST_P(WebSocketJobTest, ThrottlingSpdy) {
+ if (GetParam() > kProtoSPDY3)
+ return;
+
WebSocketJob::set_websocket_over_spdy_enabled(false);
TestConnectBySpdy(SPDY_OFF, THROTTLING_ON);
}
-TEST_F(WebSocketJobSpdy2Test, ThrottlingSpdySpdyEnabled) {
+TEST_P(WebSocketJobTest, ThrottlingSpdySpdyEnabled) {
+ if (GetParam() > kProtoSPDY3)
+ return;
+
WebSocketJob::set_websocket_over_spdy_enabled(true);
TestConnectBySpdy(SPDY_ON, THROTTLING_ON);
}