diff options
author | akalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-24 23:28:49 +0000 |
---|---|---|
committer | akalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-24 23:28:49 +0000 |
commit | 15678efb09b01293981c610ba91cb435def425fd (patch) | |
tree | 96d508466ae7fda327d473a40da3da059ca14d86 /net | |
parent | dbd622dc77ca5a41089915014ad6acae5dd7dc89 (diff) | |
download | chromium_src-15678efb09b01293981c610ba91cb435def425fd.zip chromium_src-15678efb09b01293981c610ba91cb435def425fd.tar.gz chromium_src-15678efb09b01293981c610ba91cb435def425fd.tar.bz2 |
[SPDY] Unfork spdy_websocket_test_util_spdy{2,3}.* files
Introduce new SpdyWebSocketTestUtil class and use it in all
SPDY WebSocket tests.
BUG=226192
R=rch@chromium.org
Review URL: https://codereview.chromium.org/17601002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@208295 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r-- | net/net.gyp | 6 | ||||
-rw-r--r-- | net/spdy/spdy_websocket_stream_spdy2_unittest.cc | 27 | ||||
-rw-r--r-- | net/spdy/spdy_websocket_stream_spdy3_unittest.cc | 27 | ||||
-rw-r--r-- | net/spdy/spdy_websocket_test_util.cc | 177 | ||||
-rw-r--r-- | net/spdy/spdy_websocket_test_util.h | 63 | ||||
-rw-r--r-- | net/spdy/spdy_websocket_test_util_spdy2.cc | 173 | ||||
-rw-r--r-- | net/spdy/spdy_websocket_test_util_spdy2.h | 55 | ||||
-rw-r--r-- | net/spdy/spdy_websocket_test_util_spdy3.cc | 173 | ||||
-rw-r--r-- | net/spdy/spdy_websocket_test_util_spdy3.h | 55 | ||||
-rw-r--r-- | net/websockets/websocket_job_spdy2_unittest.cc | 14 | ||||
-rw-r--r-- | net/websockets/websocket_job_spdy3_unittest.cc | 16 |
11 files changed, 284 insertions, 502 deletions
diff --git a/net/net.gyp b/net/net.gyp index 8d0b27e..cdeda2d 100644 --- a/net/net.gyp +++ b/net/net.gyp @@ -1788,10 +1788,8 @@ 'spdy/spdy_test_utils.h', 'spdy/spdy_websocket_stream_spdy2_unittest.cc', 'spdy/spdy_websocket_stream_spdy3_unittest.cc', - 'spdy/spdy_websocket_test_util_spdy2.cc', - 'spdy/spdy_websocket_test_util_spdy2.h', - 'spdy/spdy_websocket_test_util_spdy3.cc', - 'spdy/spdy_websocket_test_util_spdy3.h', + 'spdy/spdy_websocket_test_util.cc', + 'spdy/spdy_websocket_test_util.h', 'spdy/spdy_write_queue_unittest.cc', 'ssl/client_cert_store_impl_unittest.cc', 'ssl/default_server_bound_cert_store_unittest.cc', diff --git a/net/spdy/spdy_websocket_stream_spdy2_unittest.cc b/net/spdy/spdy_websocket_stream_spdy2_unittest.cc index 63789a3..7423166 100644 --- a/net/spdy/spdy_websocket_stream_spdy2_unittest.cc +++ b/net/spdy/spdy_websocket_stream_spdy2_unittest.cc @@ -16,12 +16,9 @@ #include "net/spdy/spdy_http_utils.h" #include "net/spdy/spdy_protocol.h" #include "net/spdy/spdy_session.h" -#include "net/spdy/spdy_test_util_spdy2.h" -#include "net/spdy/spdy_websocket_test_util_spdy2.h" +#include "net/spdy/spdy_websocket_test_util.h" #include "testing/gtest/include/gtest/gtest.h" -using namespace net::test_spdy2; - namespace net { namespace { @@ -189,7 +186,12 @@ class SpdyWebSocketStreamSpdy2Test : public testing::Test { protected: SpdyWebSocketStreamSpdy2Test() : spdy_util_(kProtoSPDY2), - session_deps_(kProtoSPDY2) {} + spdy_settings_id_to_set_(SETTINGS_MAX_CONCURRENT_STREAMS), + spdy_settings_flags_to_set_(SETTINGS_FLAG_PLEASE_PERSIST), + spdy_settings_value_to_set_(1), + session_deps_(kProtoSPDY2), + stream_id_(0), + created_stream_id_(0) {} virtual ~SpdyWebSocketStreamSpdy2Test() {} virtual void SetUp() { @@ -199,10 +201,6 @@ class SpdyWebSocketStreamSpdy2Test : public testing::Test { ProxyServer::Direct(), kPrivacyModeDisabled); - spdy_settings_id_to_set_ = SETTINGS_MAX_CONCURRENT_STREAMS; - spdy_settings_flags_to_set_ = SETTINGS_FLAG_PLEASE_PERSIST; - spdy_settings_value_to_set_ = 1; - spdy_settings_to_send_[spdy_settings_id_to_set_] = SettingsFlagsAndValue( SETTINGS_FLAG_PERSISTED, spdy_settings_value_to_set_); @@ -215,21 +213,22 @@ class SpdyWebSocketStreamSpdy2Test : public testing::Test { void Prepare(SpdyStreamId stream_id) { stream_id_ = stream_id; - request_frame_.reset(ConstructSpdyWebSocketSynStream( + request_frame_.reset(spdy_util_.ConstructSpdyWebSocketSynStream( stream_id_, "/echo", "example.com", "http://example.com/wsdemo")); - response_frame_.reset(ConstructSpdyWebSocketSynReply(stream_id_)); + response_frame_.reset( + spdy_util_.ConstructSpdyWebSocketSynReply(stream_id_)); - message_frame_.reset(ConstructSpdyWebSocketDataFrame( + message_frame_.reset(spdy_util_.ConstructSpdyWebSocketDataFrame( kMessageFrame, kMessageFrameLength, stream_id_, false)); - closing_frame_.reset(ConstructSpdyWebSocketDataFrame( + closing_frame_.reset(spdy_util_.ConstructSpdyWebSocketDataFrame( kClosingFrame, kClosingFrameLength, stream_id_, @@ -283,7 +282,7 @@ class SpdyWebSocketStreamSpdy2Test : public testing::Test { websocket_stream_->SendRequest(headers.Pass()); } - SpdyTestUtil spdy_util_; + SpdyWebSocketTestUtil spdy_util_; SpdySettingsIds spdy_settings_id_to_set_; SpdySettingsFlags spdy_settings_flags_to_set_; uint32 spdy_settings_value_to_set_; diff --git a/net/spdy/spdy_websocket_stream_spdy3_unittest.cc b/net/spdy/spdy_websocket_stream_spdy3_unittest.cc index 447da99..8a64f82 100644 --- a/net/spdy/spdy_websocket_stream_spdy3_unittest.cc +++ b/net/spdy/spdy_websocket_stream_spdy3_unittest.cc @@ -16,12 +16,9 @@ #include "net/spdy/spdy_http_utils.h" #include "net/spdy/spdy_protocol.h" #include "net/spdy/spdy_session.h" -#include "net/spdy/spdy_test_util_spdy3.h" -#include "net/spdy/spdy_websocket_test_util_spdy3.h" +#include "net/spdy/spdy_websocket_test_util.h" #include "testing/gtest/include/gtest/gtest.h" -using namespace net::test_spdy3; - namespace net { namespace { @@ -189,7 +186,12 @@ class SpdyWebSocketStreamSpdy3Test : public testing::Test { protected: SpdyWebSocketStreamSpdy3Test() : spdy_util_(kProtoSPDY3), - session_deps_(kProtoSPDY3) {} + spdy_settings_id_to_set_(SETTINGS_MAX_CONCURRENT_STREAMS), + spdy_settings_flags_to_set_(SETTINGS_FLAG_PLEASE_PERSIST), + spdy_settings_value_to_set_(1), + session_deps_(kProtoSPDY3), + stream_id_(0), + created_stream_id_(0) {} virtual ~SpdyWebSocketStreamSpdy3Test() {} virtual void SetUp() { @@ -200,10 +202,6 @@ class SpdyWebSocketStreamSpdy3Test : public testing::Test { ProxyServer::Direct(), kPrivacyModeDisabled); - spdy_settings_id_to_set_ = SETTINGS_MAX_CONCURRENT_STREAMS; - spdy_settings_flags_to_set_ = SETTINGS_FLAG_PLEASE_PERSIST; - spdy_settings_value_to_set_ = 1; - spdy_settings_to_send_[spdy_settings_id_to_set_] = SettingsFlagsAndValue( SETTINGS_FLAG_PERSISTED, spdy_settings_value_to_set_); @@ -216,21 +214,22 @@ class SpdyWebSocketStreamSpdy3Test : public testing::Test { void Prepare(SpdyStreamId stream_id) { stream_id_ = stream_id; - request_frame_.reset(ConstructSpdyWebSocketSynStream( + request_frame_.reset(spdy_util_.ConstructSpdyWebSocketSynStream( stream_id_, "/echo", "example.com", "http://example.com/wsdemo")); - response_frame_.reset(ConstructSpdyWebSocketSynReply(stream_id_)); + response_frame_.reset( + spdy_util_.ConstructSpdyWebSocketSynReply(stream_id_)); - message_frame_.reset(ConstructSpdyWebSocketDataFrame( + message_frame_.reset(spdy_util_.ConstructSpdyWebSocketDataFrame( kMessageFrame, kMessageFrameLength, stream_id_, false)); - closing_frame_.reset(ConstructSpdyWebSocketDataFrame( + closing_frame_.reset(spdy_util_.ConstructSpdyWebSocketDataFrame( kClosingFrame, kClosingFrameLength, stream_id_, @@ -284,7 +283,7 @@ class SpdyWebSocketStreamSpdy3Test : public testing::Test { websocket_stream_->SendRequest(headers.Pass()); } - SpdyTestUtil spdy_util_; + SpdyWebSocketTestUtil spdy_util_; SpdySettingsIds spdy_settings_id_to_set_; SpdySettingsFlags spdy_settings_flags_to_set_; uint32 spdy_settings_value_to_set_; diff --git a/net/spdy/spdy_websocket_test_util.cc b/net/spdy/spdy_websocket_test_util.cc new file mode 100644 index 0000000..e1faaaf --- /dev/null +++ b/net/spdy/spdy_websocket_test_util.cc @@ -0,0 +1,177 @@ +// Copyright (c) 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. + +#include "net/spdy/spdy_websocket_test_util.h" + +#include "net/spdy/buffered_spdy_framer.h" +#include "net/spdy/spdy_http_utils.h" + +namespace net { + +static const int kDefaultAssociatedStreamId = 0; +static const bool kDefaultCompressed = false; +static const char* const kDefaultDataPointer = NULL; +static const uint32 kDefaultDataLength = 0; +static const char** const kDefaultExtraHeaders = NULL; +static const int kDefaultExtraHeaderCount = 0; + +SpdyWebSocketTestUtil::SpdyWebSocketTestUtil( + NextProto protocol) : SpdyTestUtil(protocol) {} + +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); +} + +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); +} + +SpdyFrame* SpdyWebSocketTestUtil::ConstructSpdyWebSocketHandshakeRequestFrame( + const char* const headers[], + int header_count, + SpdyStreamId stream_id, + RequestPriority request_priority) { + // SPDY SYN_STREAM control frame header. + const SpdyHeaderInfo kSynStreamHeader = { + SYN_STREAM, + stream_id, + kDefaultAssociatedStreamId, + ConvertRequestPriorityToSpdyPriority(request_priority, 2), + kSpdyCredentialSlotUnused, + CONTROL_FLAG_NONE, + kDefaultCompressed, + RST_STREAM_INVALID, + kDefaultDataPointer, + kDefaultDataLength, + DATA_FLAG_NONE + }; + + // Construct SPDY SYN_STREAM control frame. + return ConstructSpdyFrame( + kSynStreamHeader, + kDefaultExtraHeaders, + kDefaultExtraHeaderCount, + headers, + header_count); +} + +SpdyFrame* SpdyWebSocketTestUtil::ConstructSpdyWebSocketHandshakeResponseFrame( + const char* const headers[], + int header_count, + SpdyStreamId stream_id, + RequestPriority request_priority) { + // SPDY SYN_REPLY control frame header. + const SpdyHeaderInfo kSynReplyHeader = { + SYN_REPLY, + stream_id, + kDefaultAssociatedStreamId, + ConvertRequestPriorityToSpdyPriority(request_priority, 2), + kSpdyCredentialSlotUnused, + CONTROL_FLAG_NONE, + kDefaultCompressed, + RST_STREAM_INVALID, + kDefaultDataPointer, + kDefaultDataLength, + DATA_FLAG_NONE + }; + + // Construct SPDY SYN_REPLY control frame. + return ConstructSpdyFrame( + kSynReplyHeader, + kDefaultExtraHeaders, + kDefaultExtraHeaderCount, + headers, + header_count); +} + +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); +} + +SpdyFrame* SpdyWebSocketTestUtil::ConstructSpdyWebSocketDataFrame( + const char* data, + int len, + SpdyStreamId stream_id, + bool fin) { + + // Construct SPDY data frame. + BufferedSpdyFramer framer(spdy_version(), false); + return framer.CreateDataFrame( + stream_id, + data, + len, + 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"; +} + +} // namespace net diff --git a/net/spdy/spdy_websocket_test_util.h b/net/spdy/spdy_websocket_test_util.h new file mode 100644 index 0000000..4d41391 --- /dev/null +++ b/net/spdy/spdy_websocket_test_util.h @@ -0,0 +1,63 @@ +// Copyright (c) 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. + +#ifndef NET_SPDY_SPDY_WEBSOCKET_TEST_UTIL_H_ +#define NET_SPDY_SPDY_WEBSOCKET_TEST_UTIL_H_ + +#include "net/base/request_priority.h" +#include "net/spdy/spdy_protocol.h" +#include "net/spdy/spdy_test_util_common.h" + +namespace net { + +class SpdyWebSocketTestUtil : public SpdyTestUtil { + public: + explicit SpdyWebSocketTestUtil(NextProto protocol); + + // Constructs a standard SPDY SYN_STREAM frame for WebSocket over + // SPDY opening handshake. + SpdyFrame* ConstructSpdyWebSocketSynStream(int stream_id, + const char* path, + const char* host, + const char* origin); + + // Constructs a standard SPDY SYN_REPLY packet to match the + // WebSocket over SPDY opening handshake. + SpdyFrame* ConstructSpdyWebSocketSynReply(int stream_id); + + // Constructs a WebSocket over SPDY handshake request packet. + SpdyFrame* ConstructSpdyWebSocketHandshakeRequestFrame( + const char* const headers[], + int header_count, + SpdyStreamId stream_id, + RequestPriority request_priority); + + // Constructs a WebSocket over SPDY handshake response packet. + SpdyFrame* ConstructSpdyWebSocketHandshakeResponseFrame( + const char* const headers[], + int header_count, + SpdyStreamId stream_id, + RequestPriority request_priority); + + // Constructs a SPDY HEADERS frame for a WebSocket frame over SPDY. + SpdyFrame* ConstructSpdyWebSocketHeadersFrame(int stream_id, + const char* length, + bool fin); + + // Constructs a WebSocket over SPDY data packet. + SpdyFrame* ConstructSpdyWebSocketDataFrame(const char* data, + int len, + 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; +}; + +} // namespace net + +#endif // NET_SPDY_SPDY_WEBSOCKET_TEST_UTIL_H_ diff --git a/net/spdy/spdy_websocket_test_util_spdy2.cc b/net/spdy/spdy_websocket_test_util_spdy2.cc deleted file mode 100644 index e812b5f..0000000 --- a/net/spdy/spdy_websocket_test_util_spdy2.cc +++ /dev/null @@ -1,173 +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/spdy/spdy_websocket_test_util_spdy2.h" - -#include "net/spdy/buffered_spdy_framer.h" -#include "net/spdy/spdy_http_utils.h" -#include "net/spdy/spdy_test_util_spdy2.h" - -static const int kDefaultAssociatedStreamId = 0; -static const bool kDefaultCompressed = false; -static const char* const kDefaultDataPointer = NULL; -static const uint32 kDefaultDataLength = 0; -static const char** const kDefaultExtraHeaders = NULL; -static const int kDefaultExtraHeaderCount = 0; - -namespace net { - -namespace test_spdy2 { - -SpdyFrame* ConstructSpdyWebSocketSynStream(int stream_id, - const char* path, - const char* host, - const char* origin) { - SpdyTestUtil util(kProtoSPDY2); - - const char* const kWebSocketHeaders[] = { - "path", - path, - "host", - host, - "version", - "WebSocket/13", - "scheme", - "ws", - "origin", - origin - }; - return util.ConstructSpdyControlFrame(/*extra_headers*/ NULL, - /*extra_header_count*/ 0, - /*compressed*/ false, - stream_id, - HIGHEST, - SYN_STREAM, - CONTROL_FLAG_NONE, - kWebSocketHeaders, - arraysize(kWebSocketHeaders), - 0); -} - -SpdyFrame* ConstructSpdyWebSocketSynReply(int stream_id) { - SpdyTestUtil util(kProtoSPDY2); - static const char* const kStandardWebSocketHeaders[] = { - "status", - "101" - }; - return util.ConstructSpdyControlFrame(NULL, - 0, - false, - stream_id, - LOWEST, - SYN_REPLY, - CONTROL_FLAG_NONE, - kStandardWebSocketHeaders, - arraysize(kStandardWebSocketHeaders), - 0); -} - -SpdyFrame* ConstructSpdyWebSocketHandshakeRequestFrame( - const char* const headers[], - int header_count, - SpdyStreamId stream_id, - RequestPriority request_priority) { - SpdyTestUtil util(kProtoSPDY2); - - // SPDY SYN_STREAM control frame header. - const SpdyHeaderInfo kSynStreamHeader = { - SYN_STREAM, - stream_id, - kDefaultAssociatedStreamId, - ConvertRequestPriorityToSpdyPriority(request_priority, 2), - kSpdyCredentialSlotUnused, - CONTROL_FLAG_NONE, - kDefaultCompressed, - RST_STREAM_INVALID, - kDefaultDataPointer, - kDefaultDataLength, - DATA_FLAG_NONE - }; - - // Construct SPDY SYN_STREAM control frame. - return util.ConstructSpdyFrame( - kSynStreamHeader, - kDefaultExtraHeaders, - kDefaultExtraHeaderCount, - headers, - header_count); -} - -SpdyFrame* ConstructSpdyWebSocketHandshakeResponseFrame( - const char* const headers[], - int header_count, - SpdyStreamId stream_id, - RequestPriority request_priority) { - SpdyTestUtil util(kProtoSPDY2); - - // SPDY SYN_REPLY control frame header. - const SpdyHeaderInfo kSynReplyHeader = { - SYN_REPLY, - stream_id, - kDefaultAssociatedStreamId, - ConvertRequestPriorityToSpdyPriority(request_priority, 2), - kSpdyCredentialSlotUnused, - CONTROL_FLAG_NONE, - kDefaultCompressed, - RST_STREAM_INVALID, - kDefaultDataPointer, - kDefaultDataLength, - DATA_FLAG_NONE - }; - - // Construct SPDY SYN_REPLY control frame. - return util.ConstructSpdyFrame( - kSynReplyHeader, - kDefaultExtraHeaders, - kDefaultExtraHeaderCount, - headers, - header_count); -} - -SpdyFrame* ConstructSpdyWebSocketHeadersFrame(int stream_id, - const char* length, - bool fin) { - SpdyTestUtil util(kProtoSPDY2); - static const char* const kHeaders[] = { - "opcode", - "1", // text frame - "length", - length, - "fin", - fin ? "1" : "0" - }; - return util.ConstructSpdyControlFrame(/*extra_headers*/ NULL, - /*extra_header_count*/ 0, - /*compression*/ false, - stream_id, - LOWEST, - HEADERS, - CONTROL_FLAG_NONE, - kHeaders, - arraysize(kHeaders), - 0); -} - -SpdyFrame* ConstructSpdyWebSocketDataFrame( - const char* data, - int len, - SpdyStreamId stream_id, - bool fin) { - - // Construct SPDY data frame. - BufferedSpdyFramer framer(SPDY2, false); - return framer.CreateDataFrame( - stream_id, - data, - len, - fin ? DATA_FLAG_FIN : DATA_FLAG_NONE); -} - -} // namespace test_spdy2 - -} // namespace net diff --git a/net/spdy/spdy_websocket_test_util_spdy2.h b/net/spdy/spdy_websocket_test_util_spdy2.h deleted file mode 100644 index 3856bb6..0000000 --- a/net/spdy/spdy_websocket_test_util_spdy2.h +++ /dev/null @@ -1,55 +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. - -#ifndef NET_SPDY_SPDY_WEBSOCKET_TEST_UTIL_H_ -#define NET_SPDY_SPDY_WEBSOCKET_TEST_UTIL_H_ - -#include "net/base/request_priority.h" -#include "net/spdy/spdy_protocol.h" - -namespace net { - -namespace test_spdy2 { - -// Constructs a standard SPDY SYN_STREAM frame for WebSocket over SPDY opening -// handshake. -SpdyFrame* ConstructSpdyWebSocketSynStream(int stream_id, - const char* path, - const char* host, - const char* origin); - -// Constructs a standard SPDY SYN_REPLY packet to match the WebSocket over SPDY -// opening handshake. -SpdyFrame* ConstructSpdyWebSocketSynReply(int stream_id); - -// Constructs a WebSocket over SPDY handshake request packet. -SpdyFrame* ConstructSpdyWebSocketHandshakeRequestFrame( - const char* const headers[], - int header_count, - SpdyStreamId stream_id, - RequestPriority request_priority); - -// Constructs a WebSocket over SPDY handshake response packet. -SpdyFrame* ConstructSpdyWebSocketHandshakeResponseFrame( - const char* const headers[], - int header_count, - SpdyStreamId stream_id, - RequestPriority request_priority); - -// Constructs a SPDY HEADERS frame for a WebSocket frame over SPDY. -SpdyFrame* ConstructSpdyWebSocketHeadersFrame(int stream_id, - const char* length, - bool fin); - -// Constructs a WebSocket over SPDY data packet. -SpdyFrame* ConstructSpdyWebSocketDataFrame(const char* data, - int len, - SpdyStreamId stream_id, - bool fin); - -} // namespace test_spdy2 - -} // namespace net - -#endif // NET_SPDY_SPDY_WEBSOCKET_TEST_UTIL_H_ diff --git a/net/spdy/spdy_websocket_test_util_spdy3.cc b/net/spdy/spdy_websocket_test_util_spdy3.cc deleted file mode 100644 index 25b407c..0000000 --- a/net/spdy/spdy_websocket_test_util_spdy3.cc +++ /dev/null @@ -1,173 +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/spdy/spdy_websocket_test_util_spdy3.h" - -#include "net/spdy/buffered_spdy_framer.h" -#include "net/spdy/spdy_http_utils.h" -#include "net/spdy/spdy_test_util_spdy3.h" - -static const int kDefaultAssociatedStreamId = 0; -static const bool kDefaultCompressed = false; -static const char* const kDefaultDataPointer = NULL; -static const uint32 kDefaultDataLength = 0; -static const char** const kDefaultExtraHeaders = NULL; -static const int kDefaultExtraHeaderCount = 0; -static const int kDefaultCredentialSlot = 0; - -namespace net { - -namespace test_spdy3 { - -SpdyFrame* ConstructSpdyWebSocketSynStream(int stream_id, - const char* path, - const char* host, - const char* origin) { - SpdyTestUtil util(kProtoSPDY3); - const char* const kWebSocketHeaders[] = { - ":path", - path, - ":host", - host, - ":version", - "WebSocket/13", - ":scheme", - "ws", - ":origin", - origin - }; - return util.ConstructSpdyControlFrame(/*extra_headers*/ NULL, - /*extra_header_count*/ 0, - /*compressed*/ false, - stream_id, - HIGHEST, - SYN_STREAM, - CONTROL_FLAG_NONE, - kWebSocketHeaders, - arraysize(kWebSocketHeaders), - 0); -} - -SpdyFrame* ConstructSpdyWebSocketSynReply(int stream_id) { - SpdyTestUtil util(kProtoSPDY3); - static const char* const kStandardWebSocketHeaders[] = { - ":status", - "101" - }; - return util.ConstructSpdyControlFrame(NULL, - 0, - false, - stream_id, - LOWEST, - SYN_REPLY, - CONTROL_FLAG_NONE, - kStandardWebSocketHeaders, - arraysize(kStandardWebSocketHeaders), - 0); -} - -SpdyFrame* ConstructSpdyWebSocketHandshakeRequestFrame( - const char* const headers[], - int header_count, - SpdyStreamId stream_id, - RequestPriority request_priority) { - SpdyTestUtil util(kProtoSPDY3); - - // SPDY SYN_STREAM control frame header. - const SpdyHeaderInfo kSynStreamHeader = { - SYN_STREAM, - stream_id, - kDefaultAssociatedStreamId, - ConvertRequestPriorityToSpdyPriority(request_priority, 3), - kDefaultCredentialSlot, - CONTROL_FLAG_NONE, - kDefaultCompressed, - RST_STREAM_INVALID, - kDefaultDataPointer, - kDefaultDataLength, - DATA_FLAG_NONE - }; - - // Construct SPDY SYN_STREAM control frame. - return util.ConstructSpdyFrame( - kSynStreamHeader, - kDefaultExtraHeaders, - kDefaultExtraHeaderCount, - headers, - header_count); -} - -SpdyFrame* ConstructSpdyWebSocketHandshakeResponseFrame( - const char* const headers[], - int header_count, - SpdyStreamId stream_id, - RequestPriority request_priority) { - SpdyTestUtil util(kProtoSPDY3); - - // SPDY SYN_REPLY control frame header. - const SpdyHeaderInfo kSynReplyHeader = { - SYN_REPLY, - stream_id, - kDefaultAssociatedStreamId, - ConvertRequestPriorityToSpdyPriority(request_priority, 3), - kDefaultCredentialSlot, - CONTROL_FLAG_NONE, - kDefaultCompressed, - RST_STREAM_INVALID, - kDefaultDataPointer, - kDefaultDataLength, - DATA_FLAG_NONE - }; - - // Construct SPDY SYN_REPLY control frame. - return util.ConstructSpdyFrame( - kSynReplyHeader, - kDefaultExtraHeaders, - kDefaultExtraHeaderCount, - headers, - header_count); -} - -SpdyFrame* ConstructSpdyWebSocketHeadersFrame(int stream_id, - const char* length, - bool fin) { - SpdyTestUtil util(kProtoSPDY3); - static const char* const kHeaders[] = { - ":opcode", - "1", // text frame - ":length", - length, - ":fin", - fin ? "1" : "0" - }; - return util.ConstructSpdyControlFrame(/*extra_headers*/ NULL, - /*extra_header_count*/ 0, - /*compression*/ false, - stream_id, - LOWEST, - HEADERS, - CONTROL_FLAG_NONE, - kHeaders, - arraysize(kHeaders), - 0); -} - -SpdyFrame* ConstructSpdyWebSocketDataFrame( - const char* data, - int len, - SpdyStreamId stream_id, - bool fin) { - - // Construct SPDY data frame. - BufferedSpdyFramer framer(SPDY3, false); - return framer.CreateDataFrame( - stream_id, - data, - len, - fin ? DATA_FLAG_FIN : DATA_FLAG_NONE); -} - -} // namespace test_spdy3 - -} // namespace net diff --git a/net/spdy/spdy_websocket_test_util_spdy3.h b/net/spdy/spdy_websocket_test_util_spdy3.h deleted file mode 100644 index 3446738..0000000 --- a/net/spdy/spdy_websocket_test_util_spdy3.h +++ /dev/null @@ -1,55 +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. - -#ifndef NET_SPDY_SPDY_WEBSOCKET_TEST_UTIL_H_ -#define NET_SPDY_SPDY_WEBSOCKET_TEST_UTIL_H_ - -#include "net/base/request_priority.h" -#include "net/spdy/spdy_protocol.h" - -namespace net { - -namespace test_spdy3 { - -// Constructs a standard SPDY SYN_STREAM frame for WebSocket over SPDY opening -// handshake. -SpdyFrame* ConstructSpdyWebSocketSynStream(int stream_id, - const char* path, - const char* host, - const char* origin); - -// Constructs a standard SPDY SYN_REPLY packet to match the WebSocket over SPDY -// opening handshake. -SpdyFrame* ConstructSpdyWebSocketSynReply(int stream_id); - -// Constructs a WebSocket over SPDY handshake request packet. -SpdyFrame* ConstructSpdyWebSocketHandshakeRequestFrame( - const char* const headers[], - int header_count, - SpdyStreamId stream_id, - RequestPriority request_priority); - -// Constructs a WebSocket over SPDY handshake response packet. -SpdyFrame* ConstructSpdyWebSocketHandshakeResponseFrame( - const char* const headers[], - int header_count, - SpdyStreamId stream_id, - RequestPriority request_priority); - -// Constructs a SPDY HEADERS frame for a WebSocket frame over SPDY. -SpdyFrame* ConstructSpdyWebSocketHeadersFrame(int stream_id, - const char* length, - bool fin); - -// Constructs a WebSocket over SPDY data packet. -SpdyFrame* ConstructSpdyWebSocketDataFrame(const char* data, - int len, - SpdyStreamId stream_id, - bool fin); - -} // namespace test_spdy3 - -} // namespace net - -#endif // NET_SPDY_SPDY_WEBSOCKET_TEST_UTIL_H_ diff --git a/net/websockets/websocket_job_spdy2_unittest.cc b/net/websockets/websocket_job_spdy2_unittest.cc index b5ad6c6..42a0895 100644 --- a/net/websockets/websocket_job_spdy2_unittest.cc +++ b/net/websockets/websocket_job_spdy2_unittest.cc @@ -27,8 +27,7 @@ #include "net/socket/socket_test_util.h" #include "net/socket_stream/socket_stream.h" #include "net/spdy/spdy_session.h" -#include "net/spdy/spdy_test_util_spdy2.h" -#include "net/spdy/spdy_websocket_test_util_spdy2.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" @@ -331,6 +330,8 @@ class MockHttpTransactionFactory : public HttpTransactionFactory { class WebSocketJobSpdy2Test : public PlatformTest { public: + WebSocketJobSpdy2Test() : spdy_util_(kProtoSPDY2) {} + virtual void SetUp() OVERRIDE { stream_type_ = STREAM_INVALID; cookie_store_ = new MockCookieStore; @@ -454,6 +455,7 @@ class WebSocketJobSpdy2Test : public PlatformTest { void TestConnectByWebSocket(ThrottlingOption throttling); void TestConnectBySpdy(SpdyOption spdy, ThrottlingOption throttling); + SpdyWebSocketTestUtil spdy_util_; StreamType stream_type_; scoped_refptr<MockCookieStore> cookie_store_; scoped_ptr<MockURLRequestContext> context_; @@ -904,25 +906,25 @@ void WebSocketJobSpdy2Test::TestConnectBySpdy( const SpdyStreamId kStreamId = 1; scoped_ptr<SpdyFrame> request_frame( - ConstructSpdyWebSocketHandshakeRequestFrame( + spdy_util_.ConstructSpdyWebSocketHandshakeRequestFrame( kHandshakeRequestForSpdy, arraysize(kHandshakeRequestForSpdy) / 2, kStreamId, MEDIUM)); scoped_ptr<SpdyFrame> response_frame( - ConstructSpdyWebSocketHandshakeResponseFrame( + spdy_util_.ConstructSpdyWebSocketHandshakeResponseFrame( kHandshakeResponseForSpdy, arraysize(kHandshakeResponseForSpdy) / 2, kStreamId, MEDIUM)); scoped_ptr<SpdyFrame> data_hello_frame( - ConstructSpdyWebSocketDataFrame( + spdy_util_.ConstructSpdyWebSocketDataFrame( kDataHello, kDataHelloLength, kStreamId, false)); scoped_ptr<SpdyFrame> data_world_frame( - ConstructSpdyWebSocketDataFrame( + spdy_util_.ConstructSpdyWebSocketDataFrame( kDataWorld, kDataWorldLength, kStreamId, diff --git a/net/websockets/websocket_job_spdy3_unittest.cc b/net/websockets/websocket_job_spdy3_unittest.cc index 09c70ba..f8e0adb 100644 --- a/net/websockets/websocket_job_spdy3_unittest.cc +++ b/net/websockets/websocket_job_spdy3_unittest.cc @@ -27,8 +27,7 @@ #include "net/socket/socket_test_util.h" #include "net/socket_stream/socket_stream.h" #include "net/spdy/spdy_session.h" -#include "net/spdy/spdy_test_util_spdy3.h" -#include "net/spdy/spdy_websocket_test_util_spdy3.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" @@ -36,8 +35,6 @@ #include "testing/gtest/include/gtest/gtest.h" #include "testing/platform_test.h" -using namespace net::test_spdy3; - namespace net { namespace { @@ -331,6 +328,8 @@ class MockHttpTransactionFactory : public HttpTransactionFactory { class WebSocketJobSpdy3Test : public PlatformTest { public: + WebSocketJobSpdy3Test() : spdy_util_(kProtoSPDY3) {} + virtual void SetUp() { stream_type_ = STREAM_INVALID; cookie_store_ = new MockCookieStore; @@ -454,6 +453,7 @@ class WebSocketJobSpdy3Test : public PlatformTest { 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_; @@ -904,25 +904,25 @@ void WebSocketJobSpdy3Test::TestConnectBySpdy( const SpdyStreamId kStreamId = 1; scoped_ptr<SpdyFrame> request_frame( - ConstructSpdyWebSocketHandshakeRequestFrame( + spdy_util_.ConstructSpdyWebSocketHandshakeRequestFrame( kHandshakeRequestForSpdy, arraysize(kHandshakeRequestForSpdy) / 2, kStreamId, MEDIUM)); scoped_ptr<SpdyFrame> response_frame( - ConstructSpdyWebSocketHandshakeResponseFrame( + spdy_util_.ConstructSpdyWebSocketHandshakeResponseFrame( kHandshakeResponseForSpdy, arraysize(kHandshakeResponseForSpdy) / 2, kStreamId, MEDIUM)); scoped_ptr<SpdyFrame> data_hello_frame( - ConstructSpdyWebSocketDataFrame( + spdy_util_.ConstructSpdyWebSocketDataFrame( kDataHello, kDataHelloLength, kStreamId, false)); scoped_ptr<SpdyFrame> data_world_frame( - ConstructSpdyWebSocketDataFrame( + spdy_util_.ConstructSpdyWebSocketDataFrame( kDataWorld, kDataWorldLength, kStreamId, |