summaryrefslogtreecommitdiffstats
path: root/net/spdy
diff options
context:
space:
mode:
authortoyoshim@chromium.org <toyoshim@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-07 08:18:02 +0000
committertoyoshim@chromium.org <toyoshim@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-07 08:18:02 +0000
commit30f851947494842c126829624aeb25052702b545 (patch)
treee6ef4de5b5b02eefdf10add1fe71063cc670d04e /net/spdy
parent8cb2f3aca2d071d973dd655b6c085b16036f3bf2 (diff)
downloadchromium_src-30f851947494842c126829624aeb25052702b545.zip
chromium_src-30f851947494842c126829624aeb25052702b545.tar.gz
chromium_src-30f851947494842c126829624aeb25052702b545.tar.bz2
Refactoring on WebSocket over SPDY unit tests
Move WebSocket over SPDY packet constructors into independent utility file. These constructors will be used in both of SpdyWebSocketStreamTest and WebSocketJobTest. BUG=NONE TEST=net_unittests Review URL: http://codereview.chromium.org/7312005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@91678 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/spdy')
-rw-r--r--net/spdy/spdy_framer.h2
-rw-r--r--net/spdy/spdy_websocket_stream_unittest.cc136
-rw-r--r--net/spdy/spdy_websocket_test_util.cc93
-rw-r--r--net/spdy/spdy_websocket_test_util.h37
4 files changed, 163 insertions, 105 deletions
diff --git a/net/spdy/spdy_framer.h b/net/spdy/spdy_framer.h
index 6bfe3865..4fe68d2 100644
--- a/net/spdy/spdy_framer.h
+++ b/net/spdy/spdy_framer.h
@@ -30,6 +30,7 @@ class SpdyProxyClientSocketTest;
class SpdySessionTest;
class SpdyStreamTest;
class SpdyWebSocketStreamTest;
+class WebSocketJobTest;
}
namespace spdy {
@@ -270,6 +271,7 @@ class NET_TEST SpdyFramer {
friend class net::SpdySessionTest;
friend class net::SpdyStreamTest;
friend class net::SpdyWebSocketStreamTest;
+ friend class net::WebSocketJobTest;
friend class test::TestSpdyVisitor;
friend void test::FramerSetEnableCompressionHelper(SpdyFramer* framer,
bool compress);
diff --git a/net/spdy/spdy_websocket_stream_unittest.cc b/net/spdy/spdy_websocket_stream_unittest.cc
index b964174..76ae76a 100644
--- a/net/spdy/spdy_websocket_stream_unittest.cc
+++ b/net/spdy/spdy_websocket_stream_unittest.cc
@@ -13,101 +13,11 @@
#include "net/spdy/spdy_protocol.h"
#include "net/spdy/spdy_session.h"
#include "net/spdy/spdy_test_util.h"
+#include "net/spdy/spdy_websocket_test_util.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
-spdy::SpdyFrame* ConstructSpdyWebSocketHandshakeReq(
- const char* const url,
- const char* const origin,
- const char* const protocol,
- bool compressed,
- spdy::SpdyStreamId stream_id,
- net::RequestPriority request_priority) {
- const net::SpdyHeaderInfo kSynStreamHeader = {
- spdy::SYN_STREAM,
- stream_id,
- 0, // Associated stream ID
- net::ConvertRequestPriorityToSpdyPriority(request_priority),
- spdy::CONTROL_FLAG_NONE,
- compressed,
- spdy::INVALID, // Status
- NULL, // Data,
- 0, // Length
- spdy::DATA_FLAG_NONE
- };
-
- const char* const headers[] = {
- "url",
- url,
- "origin",
- origin,
- "protocol",
- protocol,
- };
- int header_size = arraysize(headers) / 2;
- if (protocol == NULL)
- header_size -= 1;
-
- return ConstructSpdyPacket(
- kSynStreamHeader,
- NULL,
- 0,
- headers,
- header_size);
-}
-
-spdy::SpdyFrame* ConstructSpdyWebSocketHandshakeResp(
- const char* const url,
- const char* const origin,
- const char* const protocol,
- bool compressed,
- spdy::SpdyStreamId stream_id,
- net::RequestPriority request_priority) {
- const net::SpdyHeaderInfo kSynReplyHeader = {
- spdy::SYN_REPLY,
- stream_id,
- 0, // Associated stream ID
- net::ConvertRequestPriorityToSpdyPriority(request_priority),
- spdy::CONTROL_FLAG_NONE,
- false,
- spdy::INVALID, // Status
- NULL, // Data
- 0, // Length
- spdy::DATA_FLAG_NONE
- };
-
- const char* const headers[] = {
- "sec-websocket-location",
- url,
- "sec-websocket-origin",
- origin,
- "sec-websocket-protocol",
- protocol,
- };
- int header_size = arraysize(headers) / 2;
- if (protocol == NULL)
- header_size -= 1;
-
- return ConstructSpdyPacket(
- kSynReplyHeader,
- NULL,
- 0,
- headers,
- header_size);
-}
-
-spdy::SpdyFrame* ConstructSpdyWebSocketFrame(
- const char* data,
- int len,
- spdy::SpdyStreamId stream_id,
- bool fin) {
- spdy::SpdyFramer framer;
- return framer.CreateDataFrame(
- stream_id, data, len,
- fin ? spdy::DATA_FLAG_FIN : spdy::DATA_FLAG_NONE);
-}
-
struct SpdyWebSocketStreamEvent {
enum EventType {
EVENT_CREATED,
@@ -298,26 +208,42 @@ class SpdyWebSocketStreamTest : public testing::Test {
void Prepare(spdy::SpdyStreamId stream_id) {
stream_id_ = stream_id;
- request_frame_.reset(ConstructSpdyWebSocketHandshakeReq(
- "ws://example.com/echo",
- "http://example.com/wsdemo",
- NULL,
- false,
+ const char* const request_headers[] = {
+ "url", "ws://example.com/echo",
+ "origin", "http://example.com/wsdemo",
+ };
+
+ int request_header_count = arraysize(request_headers) / 2;
+
+ const char* const response_headers[] = {
+ "sec-websocket-location", "ws://example.com/echo",
+ "sec-websocket-origin", "http://example.com/wsdemo",
+ };
+
+ int response_header_count = arraysize(response_headers) / 2;
+
+ request_frame_.reset(ConstructSpdyWebSocketHandshakeRequestFrame(
+ request_headers,
+ request_header_count,
stream_id_,
HIGHEST));
- response_frame_.reset(ConstructSpdyWebSocketHandshakeResp(
- "ws://example.com/echo",
- "http://example.com/wsdemo",
- NULL,
- false,
+ response_frame_.reset(ConstructSpdyWebSocketHandshakeResponseFrame(
+ response_headers,
+ response_header_count,
stream_id_,
HIGHEST));
- message_frame_.reset(ConstructSpdyWebSocketFrame(
- kMessageFrame, kMessageFrameLength, stream_id_, false));
+ message_frame_.reset(ConstructSpdyWebSocketDataFrame(
+ kMessageFrame,
+ kMessageFrameLength,
+ stream_id_,
+ false));
- closing_frame_.reset(ConstructSpdyWebSocketFrame(
- kClosingFrame, kClosingFrameLength, stream_id_, false));
+ closing_frame_.reset(ConstructSpdyWebSocketDataFrame(
+ kClosingFrame,
+ kClosingFrameLength,
+ stream_id_,
+ false));
}
int InitSession(MockRead* reads, size_t reads_count,
MockWrite* writes, size_t writes_count,
diff --git a/net/spdy/spdy_websocket_test_util.cc b/net/spdy/spdy_websocket_test_util.cc
new file mode 100644
index 0000000..ad635fb
--- /dev/null
+++ b/net/spdy/spdy_websocket_test_util.cc
@@ -0,0 +1,93 @@
+// Copyright (c) 2011 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/spdy_framer.h"
+#include "net/spdy/spdy_http_utils.h"
+#include "net/spdy/spdy_test_util.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 {
+
+spdy::SpdyFrame* ConstructSpdyWebSocketHandshakeRequestFrame(
+ const char* const headers[],
+ int header_count,
+ spdy::SpdyStreamId stream_id,
+ RequestPriority request_priority) {
+
+ // SPDY SYN_STREAM control frame header.
+ const SpdyHeaderInfo kSynStreamHeader = {
+ spdy::SYN_STREAM,
+ stream_id,
+ kDefaultAssociatedStreamId,
+ ConvertRequestPriorityToSpdyPriority(request_priority),
+ spdy::CONTROL_FLAG_NONE,
+ kDefaultCompressed,
+ spdy::INVALID,
+ kDefaultDataPointer,
+ kDefaultDataLength,
+ spdy::DATA_FLAG_NONE
+ };
+
+ // Construct SPDY SYN_STREAM control frame.
+ return ConstructSpdyPacket(
+ kSynStreamHeader,
+ kDefaultExtraHeaders,
+ kDefaultExtraHeaderCount,
+ headers,
+ header_count);
+}
+
+spdy::SpdyFrame* ConstructSpdyWebSocketHandshakeResponseFrame(
+ const char* const headers[],
+ int header_count,
+ spdy::SpdyStreamId stream_id,
+ RequestPriority request_priority) {
+
+ // SPDY SYN_REPLY control frame header.
+ const SpdyHeaderInfo kSynReplyHeader = {
+ spdy::SYN_REPLY,
+ stream_id,
+ kDefaultAssociatedStreamId,
+ ConvertRequestPriorityToSpdyPriority(request_priority),
+ spdy::CONTROL_FLAG_NONE,
+ kDefaultCompressed,
+ spdy::INVALID,
+ kDefaultDataPointer,
+ kDefaultDataLength,
+ spdy::DATA_FLAG_NONE
+ };
+
+ // Construct SPDY SYN_REPLY control frame.
+ return ConstructSpdyPacket(
+ kSynReplyHeader,
+ kDefaultExtraHeaders,
+ kDefaultExtraHeaderCount,
+ headers,
+ header_count);
+}
+
+spdy::SpdyFrame* ConstructSpdyWebSocketDataFrame(
+ const char* data,
+ int len,
+ spdy::SpdyStreamId stream_id,
+ bool fin) {
+
+ // Construct SPDY data frame.
+ spdy::SpdyFramer framer;
+ return framer.CreateDataFrame(
+ stream_id,
+ data,
+ len,
+ fin ? spdy::DATA_FLAG_FIN : spdy::DATA_FLAG_NONE);
+}
+
+} // 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..5c16d07
--- /dev/null
+++ b/net/spdy/spdy_websocket_test_util.h
@@ -0,0 +1,37 @@
+// Copyright (c) 2011 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_
+#pragma once
+
+#include "net/base/request_priority.h"
+#include "net/spdy/spdy_protocol.h"
+
+namespace net {
+
+// Construct a WebSocket over SPDY handshake request packet.
+spdy::SpdyFrame* ConstructSpdyWebSocketHandshakeRequestFrame(
+ const char* const headers[],
+ int header_count,
+ spdy::SpdyStreamId stream_id,
+ RequestPriority request_priority);
+
+// Construct a WebSocket over SPDY handshake response packet.
+spdy::SpdyFrame* ConstructSpdyWebSocketHandshakeResponseFrame(
+ const char* const headers[],
+ int header_count,
+ spdy::SpdyStreamId stream_id,
+ RequestPriority request_priority);
+
+// Construct a WebSocket over SPDY data packet.
+spdy::SpdyFrame* ConstructSpdyWebSocketDataFrame(
+ const char* data,
+ int len,
+ spdy::SpdyStreamId stream_id,
+ bool fin);
+
+} // namespace net
+
+#endif // NET_SPDY_SPDY_WEBSOCKET_TEST_UTIL_H_