summaryrefslogtreecommitdiffstats
path: root/net/flip/flip_stream_unittest.cc
diff options
context:
space:
mode:
authorwillchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-22 00:43:00 +0000
committerwillchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-22 00:43:00 +0000
commita677f2b546d2034b459d40e6d0f24977e9b9ade3 (patch)
tree899e1150d0518fe318309301b215bc4ccc7690df /net/flip/flip_stream_unittest.cc
parent967dd54183a539e2c178fed766c48a61f407f8ff (diff)
downloadchromium_src-a677f2b546d2034b459d40e6d0f24977e9b9ade3.zip
chromium_src-a677f2b546d2034b459d40e6d0f24977e9b9ade3.tar.gz
chromium_src-a677f2b546d2034b459d40e6d0f24977e9b9ade3.tar.bz2
Flip: Merge FlipStreamParser and FlipStream. Eliminate FlipDelegate.
FlipStream now conceptually contains everything associated with a single Flip stream. This primarily consists of 2 things: (1) FlipStream as a consumer of network events from FlipSession (2) FlipStream as a network provider to consumers (such as FlipNetworkTransaction). Conceptually, FlipStream also should be agnostic of wire level protocol framing details, only dealing with HTTP style headers and responses. Anything wire level has been moved out of FlipStream into FlipSession. FlipStream is now reference counted since it is referenced by both the FlipSession and the consumer (only FlipNetworkTransaction currently). FlipNetworkTransaction can be cancelled prior to all network events finishing up, therefore the code needs to handle this gracefully. FlipStream supports a Cancel() function for this reason. FlipStream now communicates with consumers via CompletionCallbacks rather than using FlipDelegates. Review URL: http://codereview.chromium.org/410006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@32765 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/flip/flip_stream_unittest.cc')
-rw-r--r--net/flip/flip_stream_unittest.cc98
1 files changed, 98 insertions, 0 deletions
diff --git a/net/flip/flip_stream_unittest.cc b/net/flip/flip_stream_unittest.cc
new file mode 100644
index 0000000..bb661c0
--- /dev/null
+++ b/net/flip/flip_stream_unittest.cc
@@ -0,0 +1,98 @@
+// Copyright (c) 2009 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/flip/flip_stream.h"
+#include "base/ref_counted.h"
+#include "net/base/mock_host_resolver.h"
+#include "net/base/net_errors.h"
+#include "net/base/ssl_config_service.h"
+#include "net/base/ssl_config_service_defaults.h"
+#include "net/base/test_completion_callback.h"
+#include "net/flip/flip_session.h"
+#include "net/flip/flip_session_pool.h"
+#include "net/http/http_network_session.h"
+#include "net/http/http_request_info.h"
+#include "net/proxy/proxy_service.h"
+#include "net/socket/socket_test_util.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace net {
+
+namespace {
+
+// Create a proxy service which fails on all requests (falls back to direct).
+ProxyService* CreateNullProxyService() {
+ return ProxyService::CreateNull();
+}
+
+// Helper to manage the lifetimes of the dependencies for a
+// FlipNetworkTransaction.
+class SessionDependencies {
+ public:
+ // Default set of dependencies -- "null" proxy service.
+ SessionDependencies()
+ : host_resolver(new MockHostResolver),
+ proxy_service(CreateNullProxyService()),
+ ssl_config_service(new SSLConfigServiceDefaults),
+ flip_session_pool(new FlipSessionPool) {}
+
+ // Custom proxy service dependency.
+ explicit SessionDependencies(ProxyService* proxy_service)
+ : host_resolver(new MockHostResolver),
+ proxy_service(proxy_service),
+ ssl_config_service(new SSLConfigServiceDefaults),
+ flip_session_pool(new FlipSessionPool) {}
+
+ scoped_refptr<MockHostResolverBase> host_resolver;
+ scoped_refptr<ProxyService> proxy_service;
+ scoped_refptr<SSLConfigService> ssl_config_service;
+ MockClientSocketFactory socket_factory;
+ scoped_refptr<FlipSessionPool> flip_session_pool;
+};
+
+HttpNetworkSession* CreateSession(SessionDependencies* session_deps) {
+ return new HttpNetworkSession(session_deps->host_resolver,
+ session_deps->proxy_service,
+ &session_deps->socket_factory,
+ session_deps->ssl_config_service,
+ session_deps->flip_session_pool);
+}
+
+class FlipStreamTest : public testing::Test {
+ protected:
+ FlipStreamTest()
+ : session_(CreateSession(&session_deps_)) {}
+
+ scoped_refptr<FlipSession> CreateFlipSession() {
+ HostResolver::RequestInfo resolve_info("www.google.com", 80);
+ scoped_refptr<FlipSession> session(
+ session_->flip_session_pool()->Get(resolve_info, session_));
+ return session;
+ }
+
+ virtual void TearDown() {
+ MessageLoop::current()->RunAllPending();
+ }
+
+ SessionDependencies session_deps_;
+ scoped_refptr<HttpNetworkSession> session_;
+};
+
+TEST_F(FlipStreamTest, SendRequest) {
+ scoped_refptr<FlipSession> session(CreateFlipSession());
+ HttpRequestInfo request;
+ request.method = "GET";
+ request.url = GURL("http://www.google.com/");
+ TestCompletionCallback callback;
+
+ scoped_refptr<FlipStream> stream(new FlipStream(session, 1, false));
+ EXPECT_EQ(ERR_IO_PENDING, stream->SendRequest(NULL, &callback));
+}
+
+// TODO(willchan): Write a longer test for FlipStream that exercises all
+// methods.
+
+} // namespace
+
+} // namespace net